/* ══════════════════════════════════════════════════════════════════
   GeoVisor — Dark GIS Theme
   ══════════════════════════════════════════════════════════════════ */

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

:root {
  --bg-deep:      #0d1117;
  --bg-panel:     #161b22;
  --bg-section:   #1c2128;
  --bg-input:     #21262d;
  --bg-hover:     #2d333b;
  --bg-active:    #388bfd20;
  --border:       #30363d;
  --border-light: #3d444e;
  --text-primary: #e6edf3;
  --text-muted:   #848d97;
  --text-dim:     #545d68;
  --accent:       #388bfd;
  --accent-hover: #58a6ff;
  --accent-dim:   #1f6feb;
  --red:          #e05252;
  --green:        #3fb950;
  --blue:         #58a6ff;
  --yellow:       #d29922;
  --sidebar-w:    300px;
  --header-h:     48px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  background: var(--bg-deep);
  color: var(--text-primary);
  overflow: hidden;
}

/* ─── App layout ─────────────────────────────────────────────────── */

#app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ─── Sidebar ─────────────────────────────────────────────────────── */

#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 10;
}

#sidebar::-webkit-scrollbar { width: 5px; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }

#sidebar-header {
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-shrink: 0;
}

.logo-text {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent-hover);
  letter-spacing: 0.5px;
}
.logo-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

/* ─── Panel sections ──────────────────────────────────────────────── */

.panel-section {
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.section-title:hover { background: var(--bg-hover); }
.section-title .chevron { font-size: 10px; transition: transform 0.2s; }
.section-title.collapsed .chevron { transform: rotate(-90deg); }

.section-body {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.section-body.hidden { display: none; }

/* ─── Upload ─────────────────────────────────────────────────────── */

.btn-upload {
  display: block;
  text-align: center;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px dashed var(--border-light);
  border-radius: 6px;
  color: var(--accent-hover);
  cursor: pointer;
  font-size: 12px;
  transition: background 0.15s, border-color 0.15s;
}
.btn-upload:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

.progress-bar {
  height: 4px;
  background: var(--bg-input);
  border-radius: 2px;
  overflow: hidden;
}
#progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0;
  transition: width 0.3s;
}
#progress-label { font-size: 11px; color: var(--text-muted); }

/* ─── File list ──────────────────────────────────────────────────── */

#file-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 5px;
  transition: background 0.12s;
}
.file-item:hover { background: var(--bg-hover); }

.file-icon {
  width: 20px;
  height: 20px;
  background: var(--accent-dim);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.file-info { flex: 1; overflow: hidden; }
.file-name { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-meta { font-size: 10px; color: var(--text-muted); }

.file-del {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 3px;
  transition: color 0.15s, background 0.15s;
}
.file-del:hover { color: var(--red); background: rgba(224,82,82,0.1); }

/* ─── Channel selectors ──────────────────────────────────────────── */

.preset-buttons { display: flex; flex-direction: column; gap: 6px; }
.preset-label { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.6px; }
.preset-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
}
.preset-btn {
  padding: 5px 4px;
  font-size: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.preset-btn:hover { background: var(--bg-hover); border-color: var(--accent); }
.preset-btn.active { background: var(--bg-active); border-color: var(--accent); color: var(--accent-hover); }

.channel-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.ch-label {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  flex-shrink: 0;
}
.red-dot   { background: var(--red);   color: white; }
.green-dot { background: var(--green); color: white; }
.blue-dot  { background: var(--blue);  color: white; }

.ch-select { flex: 1; }
.ch-band   { width: 52px; }

select, input[type="number"] {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-primary);
  padding: 5px 7px;
  font-size: 12px;
  outline: none;
  transition: border-color 0.15s;
  appearance: none;
  -webkit-appearance: none;
}
select:focus, input[type="number"]:focus { border-color: var(--accent); }
select option { background: var(--bg-panel); }

.stretch-row { display: flex; flex-direction: column; gap: 4px; }
.stretch-row label { font-size: 11px; color: var(--text-muted); }
.range-inputs {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
}
.range-inputs input { width: 60px; text-align: center; }

/* ─── Buttons ────────────────────────────────────────────────────── */

.btn-primary {
  padding: 8px 14px;
  background: var(--accent-dim);
  border: none;
  border-radius: 5px;
  color: white;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  width: 100%;
}
.btn-primary:hover { background: var(--accent); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

/* ─── Index section ──────────────────────────────────────────────── */

.field-row { display: flex; flex-direction: column; gap: 4px; }
.field-row label { font-size: 11px; color: var(--text-muted); }
.field-row select { width: 100%; }

#index-band-inputs { display: flex; flex-direction: column; gap: 8px; }

.index-band-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.index-band-row label {
  width: 62px;
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.index-band-row select { flex: 1; }
.index-band-row .ch-band { width: 52px; }

.formula-box {
  font-size: 11px;
  font-family: "SF Mono", "Fira Code", monospace;
  color: var(--yellow);
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  word-break: break-all;
}
.formula-box:empty { display: none; }

/* ─── Stats section ──────────────────────────────────────────────── */

#stats-table {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 10px;
  font-size: 12px;
}
.stat-key { color: var(--text-muted); }
.stat-val { color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }

#histogram-container {
  position: relative;
  height: 130px;
}

/* ─── Map wrapper ────────────────────────────────────────────────── */

#map-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
  background: #1a1a2e;
}

/* Leaflet dark base */
.leaflet-tile-pane { filter: brightness(0.85) saturate(0.8); }

/* ─── Status bar ─────────────────────────────────────────────────── */

#status-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 26px;
  background: rgba(13,17,23,0.88);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  font-size: 11px;
  color: var(--text-muted);
  z-index: 500;
  pointer-events: none;
}
#coords-display { font-variant-numeric: tabular-nums; }

/* ─── Layer controls ─────────────────────────────────────────────── */

#layer-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 180px;
  max-width: 240px;
}

.layer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(22,27,34,0.92);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 12px;
}
.layer-item label { flex: 1; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.layer-item input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.layer-item input[type="range"] {
  width: 60px;
  height: 4px;
  background: var(--bg-input);
  border-radius: 2px;
  outline: none;
  border: none;
  padding: 0;
  accent-color: var(--accent-hover);
  cursor: pointer;
}

.layer-color-badge {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
}

.layer-remove {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0 2px;
  transition: color 0.15s;
}
.layer-remove:hover { color: var(--red); }

/* ─── Spinner ────────────────────────────────────────────────────── */

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Toast notifications ────────────────────────────────────────── */

#toast-container {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}
.toast {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 12px;
  opacity: 0;
  animation: toast-in 0.2s forwards, toast-out 0.3s 2.8s forwards;
  max-width: 340px;
  text-align: center;
}
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error   { border-color: var(--red);   color: var(--red);   }
.toast.info    { border-color: var(--accent); color: var(--accent-hover); }
@keyframes toast-in  { from { opacity:0; transform:translateY(-8px); } to { opacity:1; transform:translateY(0); } }
@keyframes toast-out { from { opacity:1; } to { opacity:0; } }

/* ─── Utilities ──────────────────────────────────────────────────── */
.hidden { display: none !important; }
