:root {
  color-scheme: dark;
  --bg: #0f172a;
  --panel: #111827;
  --panel-2: #172033;
  --panel-3: #1f2937;
  --border: #334155;
  --border-soft: #475569;
  --text: #f8fafc;
  --muted: #94a3b8;
  --muted-2: #64748b;
  --accent: #0ea5e9;
  --accent-2: #38bdf8;
  --filters-height: 260px;
  --filters-collapsed-height: 43px;
  --status-height: 34px;
  --topbar-height: 58px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

#appShell {
  width: 100%;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto var(--filters-height) 8px minmax(160px, 1fr) var(--status-height);
  background: var(--bg);
}

.topbar {
  min-height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 8px 16px;
  background: #0b1220;
  border-bottom: 1px solid #1e293b;
}

.brand { display: flex; align-items: center; min-width: 0; gap: 10px; }
.brand-icon { width: 36px; height: 36px; border-radius: 8px; flex: none; }
.brand-title { font-size: 18px; font-weight: 700; white-space: nowrap; }
.brand-subtitle { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 560px; }
.dataset-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.button {
  min-height: 34px;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 6px 12px;
  background: #1e293b;
  color: var(--text);
  cursor: pointer;
}
.button:hover { background: #27364b; }
.button:disabled { opacity: .45; cursor: default; }
.button.primary { background: #0369a1; border-color: #0284c7; }
.button.primary:hover { background: #075985; }
.button.ghost { background: transparent; }
.link-button { border: 0; background: transparent; color: #7dd3fc; cursor: pointer; padding: 2px 4px; font-size: 11px; }
.link-button:hover { text-decoration: underline; }

.remember-option, .toggle { display: inline-flex; align-items: center; gap: 7px; color: #cbd5e1; font-size: 13px; }
.remember-option input, .toggle input { width: 16px; height: 16px; accent-color: var(--accent); }
.toggle.strong { font-weight: 700; }

.filter-panel { min-height: 0; background: var(--panel); padding: 8px 16px 0; display: flex; flex-direction: column; overflow: hidden; }
.filter-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; min-height: 28px; }
.dataset-chip { color: #e2e8f0; background: #1e293b; border: 1px solid var(--border); border-radius: 999px; padding: 4px 9px; font-size: 11px; max-width: 52%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.security-note { font-size: 10px; color: var(--muted); text-align: right; }

.tabs-row { display: flex; align-items: stretch; gap: 6px; flex: none; min-height: 35px; }
.tabs { display: flex; align-items: flex-end; gap: 3px; border-bottom: 1px solid var(--border); flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: thin; }
.panel-collapse-button { flex: none; align-self: stretch; display: inline-flex; align-items: center; justify-content: center; gap: 5px; min-width: 92px; border: 1px solid var(--border); border-bottom-color: var(--border); border-radius: 7px 7px 0 0; padding: 5px 9px; background: #1e293b; color: #cbd5e1; cursor: pointer; font-size: 11px; }
.panel-collapse-button:hover { background: #27364b; color: white; }
.collapse-icon { font-size: 12px; line-height: 1; }
.tab { border: 1px solid transparent; border-bottom: 0; border-radius: 8px 8px 0 0; background: #1f2937; color: #cbd5e1; padding: 7px 16px; font-weight: 650; cursor: pointer; white-space: nowrap; }
.tab.active { background: var(--panel-2); border-color: var(--border); color: white; }

.tab-viewport { flex: 1; min-height: 0; background: var(--panel-2); border: 1px solid var(--border); border-top: 0; overflow: hidden; }
.filter-panel.collapsed { padding-top: 4px; padding-bottom: 0; }
.filter-panel.collapsed .filter-header,
.filter-panel.collapsed .tab-viewport { display: none; }
.filter-panel.collapsed .tabs-row { min-height: 35px; }
.filter-panel.collapsed .panel-collapse-button { border-radius: 7px; border-bottom-color: var(--border); }
.filter-panel.collapsed + .panel-splitter { cursor: ns-resize; }
.tab-pane { display: none; height: 100%; overflow: auto; padding: 12px 14px; }
.tab-pane.active { display: block; }
.eda-pane.active { display: flex; }

.field-row { display: flex; align-items: end; gap: 14px; }
.field-row.wrap { flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 170px; color: #cbd5e1; font-size: 12px; }
.field.wide { min-width: 250px; }
.field.grow-0 { min-width: 260px; }
.field select, .field input, .search-input {
  min-height: 34px;
  width: 100%;
  color: #111827;
  background: #f8fafc;
  border: 1px solid #94a3b8;
  border-radius: 6px;
  padding: 5px 8px;
}
.helper { margin-top: 8px; color: var(--muted); font-size: 12px; line-height: 1.35; }
.helper.small { font-size: 10px; }
.helper.tiny { font-size: 9px; color: var(--muted-2); }

.eda-grid { width: 100%; min-height: 100%; display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 12px; }
.eda-options { display: flex; flex-direction: column; align-items: flex-start; gap: 7px; padding-top: 2px; }
.eda-filter-fields { min-width: 0; min-height: 0; border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: minmax(220px, 1fr) minmax(210px, 1fr) minmax(250px, 1fr); gap: 12px; }
.eda-filter-fields:disabled { opacity: .52; }
.eda-filter-card { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.filter-card-title { display: flex; justify-content: space-between; gap: 8px; align-items: center; color: #cbd5e1; font-size: 12px; font-weight: 650; margin-bottom: 5px; }
.search-input { min-height: 30px; margin-bottom: 5px; }
.multi-select { flex: 1; min-height: 68px; width: 100%; color: #111827; background: #f8fafc; border: 1px solid #64748b; border-radius: 5px; padding: 2px; }
.multi-select option { padding: 3px 5px; }
.date-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.panel-splitter { display: grid; place-items: center; background: #273449; cursor: ns-resize; touch-action: none; user-select: none; border-top: 1px solid #475569; border-bottom: 1px solid #0f172a; }
.panel-splitter:hover, .panel-splitter:focus { background: #334155; outline: none; }
.splitter-grip { width: 52px; height: 3px; border-radius: 3px; background: #94a3b8; opacity: .65; }

.map-region { position: relative; min-height: 0; margin: 10px 12px; border-radius: 14px; overflow: hidden; background: #1f2937; border: 1px solid #1f2937; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; background: #0f172a; }
.leaflet-control-attribution { font-size: 9px; }
.map-message, .map-label, .legend { position: absolute; z-index: 800; background: rgba(15,23,42,.92); color: white; border: 1px solid rgba(148,163,184,.22); box-shadow: 0 5px 25px rgba(0,0,0,.24); }
.map-message { top: 14px; left: 50%; transform: translateX(-50%); padding: 9px 12px; border-radius: 9px; max-width: min(560px, calc(100% - 28px)); text-align: center; }
.map-label { left: 14px; bottom: 14px; padding: 7px 10px; border-radius: 8px; font-size: 11px; max-width: calc(100% - 200px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend { right: 14px; bottom: 14px; padding: 8px 10px; border-radius: 9px; font-size: 10px; line-height: 1.35; }
.legend-title { font-weight: 700; margin-bottom: 4px; }
.legend-space { margin-top: 5px; }
.legend-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; border: 1px solid rgba(255,255,255,.72); }
.eda-legend { background: #ec4899; }

.drop-overlay { position: absolute; inset: 14px; z-index: 1200; display: grid; place-items: center; border: 3px dashed #38bdf8; border-radius: 14px; background: rgba(3,105,161,.84); font-size: 20px; font-weight: 700; pointer-events: none; }
.drop-overlay[hidden] { display: none !important; }

.statusbar { min-height: var(--status-height); display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--panel); color: #cbd5e1; padding: 0 14px; font-size: 11px; border-top: 1px solid #1e293b; overflow: hidden; }
.statusbar span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.install-hint { color: #7dd3fc; flex: none; }

.toast { position: fixed; z-index: 2000; left: 50%; bottom: 50px; transform: translateX(-50%); background: rgba(15,23,42,.96); color: white; border: 1px solid #475569; border-radius: 9px; padding: 9px 13px; box-shadow: 0 8px 28px rgba(0,0,0,.38); max-width: min(520px, calc(100% - 28px)); font-size: 12px; }

/* Map marker/popup styles retained from the Windows viewer. */
.cms-marker { width: 22px; height: 22px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); border: 3px solid white; box-shadow: 0 3px 12px rgba(0,0,0,.45); }
.cms-marker::after { content: ''; width: 8px; height: 8px; margin: 4px 0 0 4px; background: white; position: absolute; border-radius: 50%; }
.target-marker { width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 3px 12px rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; font-size: 17px; line-height: 1; }
.target-marker::after { content: '☺'; color: white; font-weight: 800; transform: translateY(-1px); }
.eda-marker { width: 13px; height: 13px; border-radius: 50%; background: #ec4899; border: 2px solid #fff; box-shadow: 0 2px 7px rgba(0,0,0,.35); }
.marker-age-new { background: #22c55e; }
.marker-age-mid { background: #eab308; }
.marker-age-older { background: #f97316; }
.marker-age-oldest { background: #ef4444; }
.marker-age-unknown { background: #64748b; }
.target-tier-1 { background: #a855f7; }
.target-tier-2 { background: #0ea5e9; }
.target-tier-3 { background: #f59e0b; }
.target-tier-unknown { background: #64748b; }
.popup-title { font-size: 15px; font-weight: 700; margin-bottom: 6px; color: #111827; }
.popup-line { margin: 2px 0; color: #374151; }
.popup-label { font-weight: 600; color: #111827; }
.eda-equipment { margin: 6px 0 0; padding-top: 5px; border-top: 1px solid #e5e7eb; }
.eda-equipment-item { margin: 4px 0; }
.copy-pin-details { margin-top: 9px; padding: 6px 10px; border: 1px solid #cbd5e1; border-radius: 6px; background: #f8fafc; color: #0f172a; font-weight: 600; cursor: pointer; }
.copy-pin-details:hover { background: #e2e8f0; }

@media (max-width: 900px) {
  :root { --filters-height: 330px; }
  .brand-subtitle { display: none; }
  .remember-option { display: none; }
  .topbar { align-items: flex-start; padding: 7px 10px; }
  .brand-title { font-size: 16px; }
  .dataset-actions { gap: 5px; }
  .button { min-height: 32px; padding: 5px 9px; font-size: 12px; }
  .filter-panel { padding-left: 8px; padding-right: 8px; }
  .security-note { display: none; }
  .dataset-chip { max-width: 100%; }
  .tab { padding: 7px 11px; font-size: 12px; }
  .eda-grid { grid-template-columns: 130px minmax(0, 1fr); }
  .eda-filter-fields { grid-template-columns: minmax(190px, 1fr) minmax(180px, 1fr); overflow: auto; }
  .dates-card { grid-column: 1 / -1; }
  .legend { right: 8px; bottom: 8px; }
  .map-label { left: 8px; bottom: 8px; max-width: calc(100% - 170px); }
}

@media (max-width: 620px) {
  :root { --filters-height: 390px; }
  #appShell { grid-template-rows: auto var(--filters-height) 8px minmax(140px, 1fr) var(--status-height); }
  .brand-icon { width: 30px; height: 30px; }
  .brand-title { font-size: 14px; }
  #forgetDatasetButton { display: none; }
  .field-row { align-items: stretch; flex-direction: column; gap: 8px; }
  .field, .field.wide, .field.grow-0 { width: 100%; min-width: 0; }
  .eda-grid { grid-template-columns: 1fr; overflow: auto; }
  .eda-options { flex-direction: row; flex-wrap: wrap; }
  .eda-filter-fields { grid-template-columns: 1fr; overflow: visible; row-gap: 18px; }
  .eda-filter-card { min-height: auto; }
  .dates-card { grid-column: auto; margin-top: 6px; }
  .multi-select { min-height: 92px; flex: none; }
  .legend { display: none; }
  .map-label { max-width: calc(100% - 16px); }
  .statusbar { font-size: 10px; }
}

@media (max-width: 620px) {
  .panel-collapse-button { min-width: 38px; padding-left: 8px; padding-right: 8px; }
  .panel-collapse-button .collapse-label { display: none; }
}
