:root {
  color-scheme: dark;
  --bg: #0a0a0f;
  --panel: rgba(20, 20, 30, 0.8);
  --panel-hover: rgba(30, 30, 45, 0.9);
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.5);
  --line: rgba(255, 255, 255, 0.1);
  --buy: #ef4444;
  --sell: #10b981;
  --accent: #667eea;
  --accent-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --glow: rgba(102, 126, 234, 0.5);
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  background: var(--bg);
  color: var(--text);
  position: relative;
  min-height: 100vh;
}

/* Background effects */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  background: 
    radial-gradient(ellipse at 20% 20%, rgba(102, 126, 234, 0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 80%, rgba(118, 75, 162, 0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 50%, rgba(102, 126, 234, 0.05) 0%, transparent 70%);
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1320px, 96vw);
  margin: 20px auto 28px;
}

.topbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 24px;
}

.topbar h1 {
  margin: 0;
  font-size: 32px;
  font-weight: 700;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 1px;
}

.topbar p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-top: 16px;
  backdrop-filter: blur(20px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.query-grid {
  display: grid;
  grid-template-columns: 170px 1fr 170px 170px 110px;
  gap: 16px;
  align-items: end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

input,
select {
  height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.2);
  color: var(--text);
  padding: 0 16px;
  outline: none;
  font-family: inherit;
  font-size: 14px;
  transition: all 0.3s ease;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.2);
}

.btn-primary,
.btn-ghost {
  height: 44px;
  border-radius: var(--radius-sm);
  border: none;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  font-family: inherit;
  font-size: 14px;
}

.btn-primary {
  background: var(--accent-gradient);
  color: #fff;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border: 1px solid var(--line);
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.detail-btn {
  height: 32px;
  min-width: 68px;
  border-radius: var(--radius-sm);
  padding: 0 12px;
  font-size: 13px;
}

.btn-primary:disabled,
.btn-ghost:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.status-text {
  margin: 16px 0 0;
  color: var(--accent);
  min-height: 22px;
  font-size: 14px;
  font-weight: 500;
}

.metrics-panel {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.metric-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: all 0.3s ease;
}

.metric-card:hover {
  background: rgba(102, 126, 234, 0.05);
  border-color: rgba(102, 126, 234, 0.3);
}

.metric-card span {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.metric-card strong {
  font-size: 24px;
  font-weight: 700;
}

.table-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 14px;
}

.pager {
  display: flex;
  gap: 8px;
}

.table-wrap {
  overflow: auto;
  max-height: 65vh;
  border-radius: var(--radius-md);
  padding-right: 4px;
}

/* Scrollbar styling */
.table-wrap::-webkit-scrollbar {
  width: 8px;
}

.table-wrap::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.02);
  border-radius: 4px;
}

.table-wrap::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}

.table-wrap::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

.card-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.result-card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: all 0.3s ease;
}

.result-card:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.15);
}

.card-title {
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-meta {
  font-size: 13px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
  padding: 2px 8px;
  border-radius: 12px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.card-grid div,
.detail-grid div {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-grid span,
.detail-grid span {
  color: var(--muted);
  font-size: 12px;
}

.card-grid strong,
.detail-grid strong {
  font-size: 16px;
  font-weight: 600;
}

.detail-wrap {
  display: grid;
  gap: 10px;
  margin-top: 4px;
}

.detail-card {
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-left: 3px solid var(--accent);
}

.detail-title {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
}

.muted {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.detail-grid div {
  background: rgba(255, 255, 255, 0.02);
}

.detail-org {
  color: var(--muted);
  font-size: 12px;
  background: rgba(255, 255, 255, 0.03);
  padding: 6px 10px;
  border-radius: 6px;
  margin-top: 4px;
}

/* Daily Flow Section */
.daily-flow-section {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 12px;
}

.flow-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.flow-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.flow-row {
  display: grid;
  grid-template-columns: 90px 1fr 80px;
  gap: 12px;
  align-items: center;
}

.flow-date {
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
}

.flow-bar-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.flow-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 20px;
}

.flow-bar-container {
  flex: 1 1 0%;
  min-width: 0;
  height: 12px;
}

.flow-arrow {
  font-size: 10px;
  width: 14px;
  text-align: center;
}

.flow-bar {
  height: 12px;
  border-radius: 3px;
  min-width: 2px;
  transition: width 0.3s ease;
}

.buy-bar {
  background: linear-gradient(90deg, rgba(239, 68, 68, 0.6) 0%, rgba(239, 68, 68, 0.9) 100%);
}

.sell-bar {
  background: linear-gradient(90deg, rgba(16, 185, 129, 0.6) 0%, rgba(16, 185, 129, 0.9) 100%);
}

.flow-value {
  font-size: 12px;
  font-weight: 500;
  min-width: 60px;
  text-align: right;
}

.flow-net {
  font-size: 14px;
  font-weight: 700;
  text-align: right;
  padding-right: 4px;
}

.empty-card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed var(--line);
  border-radius: var(--radius-md);
  color: var(--muted);
  padding: 32px;
  text-align: center;
  font-size: 14px;
}

.buy {
  color: var(--buy);
}

.sell {
  color: var(--sell);
}

/* Toggle Switch Styling */
.dimension-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.dimension-toggle label {
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
}

/* Switch styling implementation... (skipped if not strictly needed, but let's just make sure regular selects look fine, which they do) */

@media (max-width: 1100px) {
  .query-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .metrics-panel {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 900px) {
  .app-shell {
    width: calc(100vw - 32px);
    margin: 16px auto;
  }

  .topbar h1 {
    font-size: 28px;
  }

  .panel {
    padding: 16px;
  }

  .query-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .query-grid .btn-primary {
    width: 100%;
  }

  .table-actions {
    flex-wrap: wrap;
    gap: 12px;
  }

  .pager {
    width: 100%;
    justify-content: space-between;
  }

  .pager .btn-ghost {
    flex: 1;
  }

  .table-wrap {
    max-height: 62vh;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 640px) {
  .topbar h1 {
    font-size: 24px;
  }

  .topbar p {
    font-size: 13px;
  }

  .query-grid {
    grid-template-columns: 1fr;
  }

  input,
  select {
    height: 44px;
  }

  .metrics-panel {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .flow-row {
    grid-template-columns: 80px 1fr 70px;
    gap: 8px;
  }

  .flow-value {
    font-size: 11px;
    min-width: 50px;
  }

}
