/* ══════════════════════════════════════════════════════════════════
   AquaLens — stylesheet
   Dark "deep water" theme by default; light theme via [data-theme=light]
   ══════════════════════════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0b111d;
  --bg-2:      #0f1626;
  --panel:     #131c2e;
  --panel-2:   #18233a;
  --border:    #243149;
  --border-2:  #2e3d59;
  --text:      #e6edf7;
  --text-dim:  #8a9bb8;
  --text-mute: #5e6f8c;
  --accent:    #38bdf8;
  --accent-2:  #818cf8;
  --accent-dim:#15293f;
  --good:      #34d399;
  --warn:      #fbbf24;
  --bad:       #f87171;
  --grid:      #20304a;
  --shadow:    0 4px 16px rgba(0,0,0,.35);
  --radius:    8px;
  --radius-lg: 12px;
  --topbar-h:  56px;
}

[data-theme="light"] {
  --bg:        #eef3fb;
  --bg-2:      #e4ecf8;
  --panel:     #ffffff;
  --panel-2:   #f3f7fe;
  --border:    #d3e0f2;
  --border-2:  #c2d4ed;
  --text:      #142036;
  --text-dim:  #5a6b86;
  --text-mute: #8595af;
  --accent:    #2563eb;
  --accent-2:  #6366f1;
  --accent-dim:#dbeafe;
  --grid:      #dde7f5;
  --shadow:    0 2px 10px rgba(30,64,120,.10);
}

html, body { height: 100%; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.hidden { display: none !important; }
.muted  { color: var(--text-mute); font-weight: 400; font-size: 11px; }
.spacer { flex: 1; }

/* ── Top bar ─────────────────────────────────────────────────── */
#topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  background: linear-gradient(90deg, var(--panel), var(--bg-2));
  border-bottom: 1px solid var(--border);
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  font-size: 26px; line-height: 1;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; font-weight: 800;
}
.brand-title { font-size: 16px; font-weight: 800; letter-spacing: .3px; }
.brand-sub   { font-size: 10.5px; color: var(--text-dim); margin-top: -2px; }

.active-dataset {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 5px 12px; border-radius: 20px;
  font-size: 12px;
}
.ad-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.ad-name { font-weight: 700; }
.ad-unit { color: var(--text-dim); }
.ad-rows { color: var(--text-mute); font-size: 11px; }

.topbar-tools { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.search-box {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px;
  width: 320px;
}
.search-box.small { width: 240px; padding: 5px 9px; }
.search-box:focus-within { border-color: var(--accent); }
.search-box input { flex: 1; background: none; border: none; color: var(--text); font-size: 12.5px; outline: none; }
.search-ic { color: var(--text-mute); font-size: 15px; }
.search-box kbd {
  font-size: 10px; color: var(--text-mute);
  border: 1px solid var(--border-2); border-radius: 4px;
  padding: 1px 5px; font-family: inherit;
}
.icon-btn {
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text-dim); cursor: pointer; font-size: 16px;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }

/* ── App layout ──────────────────────────────────────────────── */
#app { flex: 1; display: flex; min-height: 0; }

aside#sidebar {
  width: 270px; flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.side-head, .section-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 14px; font-weight: 700; font-size: 12px;
  text-transform: uppercase; letter-spacing: .6px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}
.dataset-list { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.ds-group-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-mute); margin: 6px 2px 2px; font-weight: 700; }

.ds-card {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 11px; cursor: pointer;
  transition: border-color .12s, transform .08s;
}
.ds-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.ds-card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.ds-card-top { display: flex; align-items: center; gap: 8px; }
.ds-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.ds-label { font-weight: 700; font-size: 13px; }
.ds-badge { margin-left: auto; font-size: 10px; padding: 2px 7px; border-radius: 10px; background: var(--accent-dim); color: var(--accent); font-weight: 700; }
.ds-meta { margin-top: 6px; font-size: 11px; color: var(--text-dim); display: flex; flex-wrap: wrap; gap: 3px 10px; }
.ds-meta b { color: var(--text); font-weight: 600; }

.side-foot { border-top: 1px solid var(--border); padding: 10px 14px; }
.legend-title { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-mute); margin-bottom: 6px; }
.param-legend { display: flex; flex-direction: column; gap: 4px; }
.pl-item { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--text-dim); }
.pl-dot { width: 9px; height: 9px; border-radius: 50%; }

/* ── Main workspace ─────────────────────────────────────────── */
main#main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }

#tabbar {
  display: flex; gap: 2px; padding: 8px 12px 0;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab {
  padding: 8px 15px; border: none; background: none;
  color: var(--text-dim); font-size: 12.5px; font-weight: 600;
  cursor: pointer; border-radius: 7px 7px 0 0;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--text); background: var(--panel-2); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); background: var(--bg); }

.filter-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 14px 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-dim); color: var(--accent);
  font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 12px;
  border: 1px solid var(--accent);
}
.chip .x { cursor: pointer; opacity: .7; font-weight: 800; }
.chip .x:hover { opacity: 1; }

#tab-content { flex: 1; min-height: 0; position: relative; overflow: hidden; }
.panel { position: absolute; inset: 0; padding: 14px; overflow: auto; display: none; }
.panel.active { display: block; }

/* ── Control rows ───────────────────────────────────────────── */
.ctrl-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 9px 13px; margin-bottom: 12px;
}
.ctrl-row label { font-size: 11.5px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; }
.ctrl-row select, .ctrl-row input[type=text], .ctrl-row input[type=number], .ctrl-row input[type=date] {
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 6px; padding: 5px 8px; font-size: 12px; font-family: inherit;
}
.ctrl-row select:focus, .ctrl-row input:focus { outline: none; border-color: var(--accent); }
.chk { cursor: pointer; user-select: none; }
.chk input { accent-color: var(--accent); }
.ctrl-note { font-size: 11px; color: var(--text-mute); }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 7px; padding: 7px 13px;
  font-size: 12px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #04121f; }
.btn.primary:hover { filter: brightness(1.1); color: #04121f; }
.btn.big { width: 100%; padding: 11px; margin-top: 8px; font-size: 13px; }
.mini-btn {
  background: var(--panel-2); border: 1px solid var(--border);
  color: var(--text-dim); border-radius: 6px; padding: 3px 9px;
  font-size: 11px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.mini-btn:hover { border-color: var(--accent); color: var(--accent); }
.mini-btn.primary { background: var(--accent); border-color: var(--accent); color: #04121f; }
.mini-btn.dirty { animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(56,189,248,.5);} 50% { box-shadow: 0 0 0 4px rgba(56,189,248,0);} }

/* ── KPI cards ──────────────────────────────────────────────── */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: 12px; margin-bottom: 14px; }
.kpi {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 13px 15px; position: relative; overflow: hidden;
}
.kpi::after { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.kpi-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-dim); }
.kpi-value { font-size: 24px; font-weight: 800; margin-top: 3px; }
.kpi-sub   { font-size: 11px; color: var(--text-mute); margin-top: 2px; }

.overview-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ov-card, .corr-card, .exp-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 12px;
}
.ov-card-head { font-size: 12px; font-weight: 700; color: var(--text-dim); margin-bottom: 8px; }
.ov-plot { height: 230px; }
.big-plot { height: calc(100vh - 230px); min-height: 360px; }
.map-canvas { height: calc(100vh - 210px); min-height: 380px; border-radius: var(--radius-lg); overflow: hidden; border: 1px solid var(--border); }

.insights { margin-top: 14px; display: grid; grid-template-columns: repeat(auto-fit, minmax(260px,1fr)); gap: 10px; }
.insight {
  background: var(--panel-2); border: 1px solid var(--border);
  border-left: 3px solid var(--accent); border-radius: var(--radius);
  padding: 10px 12px; font-size: 12px; color: var(--text-dim); line-height: 1.5;
}
.insight b { color: var(--text); }

.corr-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; height: calc(100vh - 200px); }
.corr-card { display: flex; flex-direction: column; }
.corr-card .big-plot { height: 100%; flex: 1; }

/* ── Right panel ────────────────────────────────────────────── */
aside#right-panel {
  width: 290px; flex-shrink: 0;
  background: var(--panel);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}
#right-scroll { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; }
.section { flex-shrink: 0; border-bottom: 1px solid var(--border); }
.filter-body, .stats-body, .corr-body { padding: 11px 13px; }

.fgroup { margin-bottom: 13px; }
.fgroup-label { font-size: 11px; font-weight: 700; color: var(--text-dim); margin-bottom: 6px; display: flex; justify-content: space-between; }
.fgroup-label .clr { font-size: 10px; color: var(--text-mute); cursor: pointer; }
.fgroup-label .clr:hover { color: var(--accent); }
.check-list { max-height: 165px; overflow-y: auto; border: 1px solid var(--border); border-radius: 6px; padding: 5px 7px; background: var(--bg-2); }
.check-row { display: flex; align-items: center; gap: 7px; padding: 2px 0; font-size: 11.5px; cursor: pointer; }
.check-row input { accent-color: var(--accent); }
.check-row .cnt { margin-left: auto; color: var(--text-mute); font-size: 10px; }
.range-row { display: flex; align-items: center; gap: 6px; }
.range-row input { width: 100%; background: var(--bg-2); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 5px 7px; font-size: 11.5px; }
.range-row span { color: var(--text-mute); }
.mini-search { width: 100%; background: var(--bg-2); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 5px 7px; font-size: 11px; margin-bottom: 5px; }
.mini-select { background: var(--bg-2); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 5px 7px; font-size: 11.5px; }
.adv-filter-row { margin-top: 6px; padding: 6px 7px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-2); }
.adv-filter-head { display: flex; align-items: center; justify-content: space-between; font-size: 11px; color: var(--text-dim); margin-bottom: 4px; }
.adv-filter-head .x { cursor: pointer; color: var(--text-mute); font-size: 11px; }
.adv-filter-head .x:hover { color: var(--accent); }
.tier-pills { display: flex; gap: 5px; flex-wrap: wrap; }
.tier-pill { font-size: 11px; padding: 4px 9px; border-radius: 14px; border: 1px solid var(--border); background: var(--bg-2); color: var(--text-dim); cursor: pointer; }
.tier-pill.active { background: var(--accent); border-color: var(--accent); color: #04121f; font-weight: 700; }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.stat { background: var(--bg-2); border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; }
.stat-k { font-size: 10px; color: var(--text-mute); text-transform: uppercase; letter-spacing: .4px; }
.stat-v { font-size: 15px; font-weight: 700; margin-top: 1px; }

.corr-bar-row { display: flex; align-items: center; gap: 7px; margin-bottom: 4px; font-size: 11px; }
.corr-bar-row .lbl { width: 62px; flex-shrink: 0; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.corr-bar-track { flex: 1; height: 13px; background: var(--bg-2); border-radius: 3px; position: relative; overflow: hidden; }
.corr-bar-fill { position: absolute; top: 0; bottom: 0; }
.corr-bar-row .val { width: 40px; text-align: right; font-variant-numeric: tabular-nums; color: var(--text); }

/* ── Data table ─────────────────────────────────────────────── */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); max-height: calc(100vh - 230px); }
#data-table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
#data-table thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--panel-2); color: var(--text-dim);
  text-align: left; padding: 8px 10px; white-space: nowrap;
  border-bottom: 2px solid var(--border); cursor: pointer; user-select: none;
}
#data-table thead th:hover { color: var(--accent); }
#data-table tbody td { padding: 6px 10px; white-space: nowrap; border-bottom: 1px solid var(--border); max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
#data-table tbody tr:hover { background: var(--panel-2); }
#data-table td.band-col  { color: var(--accent-2); font-variant-numeric: tabular-nums; }
#data-table td.index-col { color: #f0abfc; font-variant-numeric: tabular-nums; }
#data-table td.numeric   { color: var(--accent); font-variant-numeric: tabular-nums; }

.qc-badge { border-radius: 4px; padding: 1px 7px; font-size: 10px; font-weight: 600; }
.qc-standard { background: rgba(52,211,153,.16); color: var(--good); }
.qc-low_pixels { background: rgba(251,191,36,.16); color: var(--warn); }
.qc-no_valid_scene, .qc-no_scenes { background: rgba(248,113,113,.16); color: var(--bad); }
.qc-gee_error { background: rgba(148,163,184,.16); color: var(--text-dim); }

.pager { display: flex; align-items: center; gap: 6px; padding: 10px 2px; flex-wrap: wrap; }
.pager button { background: var(--panel-2); border: 1px solid var(--border); color: var(--text-dim); border-radius: 6px; padding: 4px 10px; font-size: 11.5px; cursor: pointer; }
.pager button.active { background: var(--accent); border-color: var(--accent); color: #04121f; font-weight: 700; }
.pager button:disabled { opacity: .4; cursor: default; }

/* ── Export studio ──────────────────────────────────────────── */
.export-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.exp-card hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.exp-card .chk { display: flex; align-items: center; gap: 7px; padding: 4px 0; font-size: 12px; color: var(--text-dim); }
.col-tools { display: flex; gap: 5px; flex-wrap: wrap; margin-bottom: 8px; }
.exp-cols { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: 6px; padding: 7px; background: var(--bg-2); }
.exp-cols .check-row { font-size: 11.5px; }
.exp-summary { font-size: 11.5px; color: var(--text-dim); background: var(--bg-2); border: 1px solid var(--border); border-radius: 6px; padding: 9px; margin: 8px 0; line-height: 1.6; }
.exp-card.preview #exp-preview { max-height: 240px; }
.exp-card .ctrl-row, .exp-card label select { width: 100%; }
.exp-card > label { font-size: 11.5px; color: var(--text-dim); display: block; margin-top: 4px; }
.exp-card > label select { width: 100%; margin-top: 4px; background: var(--panel-2); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 6px 8px; font-size: 12px; }

/* ── Table builder ──────────────────────────────────────────── */
.tb-grid { display: grid; grid-template-columns: 320px 1fr; gap: 12px; align-items: start; }
.tb-cols-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.tb-cols { max-height: calc(100vh - 290px); overflow-y: auto; border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; background: var(--bg-2); }
.tb-col-group { margin-bottom: 8px; }
.tb-col-group-h { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-mute); margin: 6px 0 3px; font-weight: 700; }
.tb-grid .table-wrap { max-height: calc(100vh - 290px); }
@media (max-width: 1100px) { .tb-grid { grid-template-columns: 1fr; } }

/* ── Loader / toast / menus ─────────────────────────────────── */
.loader { position: fixed; inset: 0; background: rgba(8,12,20,.72); display: grid; place-items: center; z-index: 100; gap: 14px; grid-auto-flow: row; }
.spinner { width: 44px; height: 44px; border: 4px solid var(--border-2); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loader-text { color: var(--text); font-size: 13px; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--accent); color: var(--text); padding: 10px 18px; border-radius: 10px; box-shadow: var(--shadow); z-index: 120; font-size: 12.5px; }

.export-menu { position: fixed; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); z-index: 60; overflow: hidden; }
.export-menu button { display: block; width: 100%; text-align: left; padding: 8px 16px; background: none; border: none; color: var(--text); font-size: 12px; cursor: pointer; }
.export-menu button:hover { background: var(--accent-dim); color: var(--accent); }

.placeholder { color: var(--text-mute); font-size: 12px; padding: 20px 6px; text-align: center; }

/* scrollbars */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-mute); }
::-webkit-scrollbar-track { background: transparent; }

/* leaflet popup theming */
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); }
.leaflet-popup-content { font-family: 'Inter', sans-serif; font-size: 12px; }
.map-popup b { color: var(--accent); }

@media (max-width: 1200px) {
  .overview-grid, .corr-grid, .export-grid { grid-template-columns: 1fr; }
  .corr-grid { height: auto; }
}
