/* ===== FONTS ===== */
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ===== DARK THEME (default) ===== */
:root {
  --bg:           #0d1117;
  --surface:      #161b22;
  --surface-2:    #21262d;
  --border:       #30363d;
  --text:         #c9d1d9;
  --text-bright:  #f0f6fc;
  --muted:        #6e7681;
  --primary:      #3fb950;
  --primary-dim:  rgba(63, 185, 80, 0.10);
  --secondary:    #e3b341;
  --danger:       #f85149;
  --danger-dim:   rgba(248, 81, 73, 0.12);
  --info:         #58a6ff;
  --info-dim:     rgba(88, 166, 255, 0.12);

  /* chart-specific */
  --c-line:   #3fb950;
  --c-fill:   rgba(63, 185, 80, 0.08);
  --c-bar:    rgba(227, 179, 65, 0.65);
  --c-axis:   rgba(201, 209, 217, 0.07);
  --c-axis2:  rgba(201, 209, 217, 0.13);
  --c-label:  #6e7681;
  --c-hover:  rgba(201, 209, 217, 0.22);
  --c-dot:    #e3b341;
}

/* ===== LIGHT THEME ===== */
[data-theme="light"] {
  --bg:           #f5f7fa;
  --surface:      #ffffff;
  --surface-2:    #eef0f3;
  --border:       #d1d5db;
  --text:         #1f2937;
  --text-bright:  #030712;
  --muted:        #6b7280;
  --primary:      #047857;
  --primary-dim:  rgba(4, 120, 87, 0.08);
  --secondary:    #b45309;
  --danger:       #dc2626;
  --danger-dim:   rgba(220, 38, 38, 0.08);
  --info:         #1d4ed8;
  --info-dim:     rgba(29, 78, 216, 0.08);

  /* chart-specific */
  --c-line:   #047857;
  --c-fill:   rgba(4, 120, 87, 0.07);
  --c-bar:    rgba(180, 83, 9, 0.55);
  --c-axis:   rgba(31, 41, 55, 0.07);
  --c-axis2:  rgba(31, 41, 55, 0.14);
  --c-label:  #9ca3af;
  --c-hover:  rgba(31, 41, 55, 0.18);
  --c-dot:    #b45309;
}

/* ===== RESET ===== */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

/* ===== SHELL ===== */
.shell {
  max-width: 1500px;
  margin: 0 auto;
  padding: 0 16px 40px;
}

/* ===== TOPBAR ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 10px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
}

.prompt  { color: var(--primary); font-weight: 600; }
.host    { color: var(--info); }
.sep     { color: var(--muted); }
.cmd     { color: var(--text-bright); font-weight: 600; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ===== TABS ===== */
.tab-nav {
  display: flex;
  gap: 4px;
}

.tab-btn {
  height: 26px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}

.tab-btn:hover {
  color: var(--text);
  border-color: var(--text);
}

.tab-btn.active {
  background: var(--primary-dim);
  border-color: var(--primary);
  color: var(--primary);
}

/* ===== THEME TOGGLE ===== */
.theme-btn {
  height: 26px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
}

.theme-btn:hover {
  color: var(--text);
  border-color: var(--text);
}

/* ===== LAYOUT ===== */
.layout {
  display: grid;
  grid-template-columns: 288px 1fr;
  gap: 12px;
  align-items: start;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

/* ===== PANELS ===== */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
}

.controls-panel,
.summary-panel {
  padding: 12px 14px;
}

.section-label {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 8px;
}

.sublabel {
  font-weight: 400;
  font-size: 10px;
}

/* ===== INPUTS ===== */
input, select, button { font: inherit; }

label {
  font-size: 10px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  display: block;
  margin-bottom: 4px;
}

input,
select {
  width: 100%;
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  transition: border-color .15s;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
}

/* ===== SEARCH ===== */
.field-group {
  display: flex;
  flex-direction: column;
}

.field-group.compact {
  flex: 1;
  min-width: 0;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.input-prompt {
  position: absolute;
  left: 9px;
  color: var(--primary);
  pointer-events: none;
  z-index: 1;
  font-size: 13px;
}

#search-input {
  padding-left: 24px;
}

.search-results {
  position: absolute;
  inset: calc(100% + 4px) 0 auto;
  display: none;
  max-height: 300px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  z-index: 20;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.search-results.visible { display: block; }

.search-result {
  display: block;
  width: 100%;
  padding: 7px 12px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  transition: background .1s;
}

.search-result:hover,
.search-result.active  { background: var(--primary-dim); }
.search-result:last-child { border-bottom: none; }

.result-title {
  display: block;
  color: var(--text-bright);
  font-weight: 500;
}

.result-subtitle {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
}

/* ===== FIELD ROW ===== */
.field-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.preset-row {
  display: flex;
  gap: 4px;
  margin-top: 10px;
  flex-wrap: wrap;
}

/* ===== BUTTONS ===== */
.primary-button,
.ghost-button {
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  transition: color .15s, border-color .15s, background .15s;
  white-space: nowrap;
}

.primary-button {
  background: var(--primary-dim);
  border-color: var(--primary);
  color: var(--primary);
  align-self: flex-end;
}

.primary-button:hover {
  background: var(--primary);
  color: var(--bg);
}

.ghost-button {
  background: transparent;
  color: var(--muted);
}

.ghost-button:hover {
  color: var(--text);
  border-color: var(--text);
}

.preset-button {
  padding: 0 7px;
  font-size: 11px;
  height: 24px;
}

/* ===== SUMMARY ===== */
.summary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.item-title {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-bright);
  word-break: break-word;
  line-height: 1.45;
}

.status-badge {
  font: inherit;
  font-size: 10px;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 2px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.status-badge.idle    { color: var(--muted);    border-color: var(--border); }
.status-badge.loading { color: var(--info);     border-color: var(--info);   background: var(--info-dim); }
.status-badge.ready   { color: var(--primary);  border-color: var(--primary); background: var(--primary-dim); }
.status-badge.error   { color: var(--danger);   border-color: var(--danger);  background: var(--danger-dim); }

/* ===== STATS LIST ===== */
.stats-list {
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 4px 9px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.stat-row:last-child { border-bottom: none; }

.stat-key {
  color: var(--muted);
  font-size: 11px;
  flex-shrink: 0;
}

.stat-val {
  color: var(--text-bright);
  font-size: 12px;
  font-weight: 500;
  text-align: right;
}

.stat-val--xs {
  font-size: 10px;
  word-break: break-all;
}

/* ===== CURSOR PANEL ===== */
.cursor-panel {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.cursor-label {
  font-size: 10px;
  color: var(--text);
  margin-bottom: 8px;
  word-break: break-all;
  line-height: 1.4;
}

.interval-stats { margin-top: 0; }

/* ===== CHARTS ===== */
.charts-panel {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chart-block { display: flex; flex-direction: column; gap: 6px; }

.chart-wrap {
  position: relative;
  height: 300px;
}

.vol-wrap { height: 170px; }

canvas {
  width: 100%;
  height: 100%;
  display: block;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--surface-2);
}

/* ===== CHART LOADER ===== */
.chart-loader {
  position: absolute;
  inset: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border-radius: 3px;
  z-index: 5;
  pointer-events: none;
}

.chart-loader.hidden { display: none; }

.loader-text {
  margin: 0;
  font: 12px/1.7 'JetBrains Mono', 'Fira Code', monospace;
  color: var(--primary);
  text-align: left;
  white-space: pre;
}

/* ===== TOOLTIP ===== */
.chart-tooltip {
  position: absolute;
  min-width: 155px;
  max-width: 210px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  pointer-events: none;
  font-size: 11px;
  z-index: 10;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.chart-tooltip.hidden { display: none; }

.chart-tooltip strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text-bright);
}

.chart-tooltip div {
  color: var(--muted);
  line-height: 1.85;
}

/* ===== MOBILE ===== */
@media (max-width: 900px) {
  .layout {
    grid-template-columns: 240px 1fr;
    gap: 10px;
  }

  .chart-wrap { height: 240px; }
  .vol-wrap   { height: 140px; }
}

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

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

  .chart-wrap { height: 200px; }
  .vol-wrap   { height: 120px; }

  .shell { padding: 0 12px 28px; }

  .topbar { padding: 8px 0; }

  /* 2-col stats on mobile */
  .stats-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .stats-list .stat-row {
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
  }

  .stats-list .stat-row:nth-child(even) {
    border-right: none;
  }

  .stats-list .stat-row:nth-last-child(-n+2) {
    border-bottom: none;
  }

  .interval-stats {
    grid-template-columns: 1fr 1fr;
    display: grid;
  }
}

@media (max-width: 400px) {
  .stats-list {
    grid-template-columns: 1fr;
  }

  .stats-list .stat-row {
    border-right: none;
  }

  .stats-list .stat-row:nth-last-child(-n+2) {
    border-bottom: 1px solid var(--border);
  }

  .stats-list .stat-row:last-child {
    border-bottom: none;
  }
}
