:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --text: #16202c;
  --muted: #5d6b7c;
  --border: #d8dee7;
  /* HELIOT.AI brand: orange #f97125, green #00af50, sky blue; accent is the blue deepened for contrast */
  --accent: #007bb8;
  --accent-text: #ffffff;
  --brand-orange: #f97125;
  --map-mask: #f4f6f9;     /* outside India: faded towards the page background */
  --map-mask-opacity: 0.68;
  --india-border: #007bb8; /* brand blue */
  --shadow: 0 6px 24px rgba(15, 30, 50, 0.14);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --surface: #171e27;
    --surface-2: #1f2833;
    --text: #e6ebf1;
    --muted: #93a1b2;
    --border: #2c3744;
    --accent: #2ebdf2;
    --accent-text: #08141c;
    --map-mask: #0f141a;
    --map-mask-opacity: 0.66;
    --india-border: #2ebdf2;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
}
.muted { color: var(--muted); font-weight: 400; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  border-top: 3px solid var(--brand-orange);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { height: 34px; width: auto; display: block; }
.brand-name { font-size: 17px; font-weight: 500; white-space: nowrap; color: var(--text); }
.brand-divider { width: 1px; height: 26px; background: var(--border); }
.brand-title { font-weight: 650; font-size: 16px; white-space: nowrap; }
.status { color: var(--muted); font-size: 13px; text-align: right; }
.status .live { color: #16a34a; font-weight: 600; }
.status .busy { color: #d97706; font-weight: 600; }

.layout { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 340px; flex-shrink: 0; overflow-y: auto; display: flex; flex-direction: column;
  gap: 10px; padding: 12px; background: var(--bg); border-right: 1px solid var(--border);
}
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px;
}
.panel.grow { flex: 1; display: flex; flex-direction: column; min-height: 240px; }
.panel h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  margin: 0 0 8px;
}
.field { display: block; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.field select, .search {
  display: block; width: 100%; margin-top: 4px; padding: 7px 8px; font: inherit;
  color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 7px;
}
.field input {
  display: block; width: 100%; margin-top: 4px; padding: 7px 8px; font: inherit;
  color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 7px;
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btns { display: flex; gap: 6px; align-items: flex-end; }
.btn {
  flex: 1; padding: 7px 8px; font: inherit; font-weight: 600; border-radius: 7px; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text);
}
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); font-weight: 500; }
.hint { font-size: 12px; color: var(--muted); margin: 0; }
.hint.error { color: #dc2626; }
.check { display: flex; gap: 8px; align-items: center; margin-top: 8px; cursor: pointer; }
.topic-desc { font-size: 12px; color: var(--muted); margin: 0 0 10px; }
.sub-h {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  margin: 12px 0 0; font-weight: 600;
}
#opt-rain, #opt-risk { margin-bottom: 4px; }
.list .bar { height: 6px; border-radius: 3px; background: var(--surface-2); margin-top: 4px; overflow: hidden; }
.list .bar span { display: block; height: 100%; border-radius: 3px; }
.list li.static { cursor: default; }

.segmented { display: flex; background: var(--surface-2); border-radius: 8px; padding: 3px; gap: 3px; }
.segmented button, .tabs button {
  flex: 1; border: 0; background: transparent; color: var(--text); font: inherit;
  padding: 6px 4px; border-radius: 6px; cursor: pointer;
}
.segmented button.active, .tabs button.active { background: var(--accent); color: var(--accent-text); font-weight: 600; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.stats .stat:last-child:nth-child(odd) { grid-column: span 2; }
.stat .v { font-size: 18px; font-weight: 650; }
.stat .k { font-size: 11px; color: var(--muted); }

.list { list-style: none; margin: 8px 0 0; padding: 0; overflow-y: auto; flex: 1; }
.list li {
  display: flex; justify-content: space-between; gap: 8px; padding: 7px 6px;
  border-bottom: 1px solid var(--border); cursor: pointer; border-radius: 6px;
}
.list li:hover, .list li.sel { background: var(--surface-2); }
.list .name { font-weight: 550; }
.list .sub { font-size: 12px; color: var(--muted); }
.list .val { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }

.mapwrap { position: relative; flex: 1; min-width: 0; }
#map { position: absolute; inset: 0; }
.legend {
  position: absolute; left: 12px; bottom: 22px; z-index: 500; background: var(--surface);
  color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 10px; font-size: 12px; box-shadow: var(--shadow); max-width: 240px;
}
.legend h4 { margin: 0 0 4px; font-size: 12px; }
.legend .row { display: flex; align-items: center; gap: 6px; }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.legend .toggle {
  width: calc(100% + 8px); margin: 0 -4px; padding: 2px 4px; border: 0; border-radius: 5px;
  background: transparent; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.legend .toggle:hover { background: var(--surface-2); }
.legend .toggle[aria-pressed="true"] { font-weight: 600; }
.legend .toggle.off { opacity: 0.4; }
.legend .lbl { flex: 1; }
.legend .cnt { color: var(--muted); font-variant-numeric: tabular-nums; margin-left: 12px; }
.legend-hint { font-size: 11px; color: var(--muted); margin: -2px 0 4px; }
.legend .linkbtn {
  border: 0; background: none; padding: 0; color: var(--accent); font: inherit; font-weight: 600;
  cursor: pointer;
}

.detail {
  position: absolute; right: 12px; top: 12px; z-index: 600; width: min(460px, calc(100% - 24px));
  max-height: calc(100% - 24px); overflow-y: auto; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px;
}
.detail-head { display: flex; justify-content: space-between; gap: 8px; }
.detail h3 { margin: 0; font-size: 16px; }
.detail-head p { margin: 2px 0 0; font-size: 12px; }
.icon-btn {
  border: 0; background: var(--surface-2); color: var(--text); width: 28px; height: 28px;
  border-radius: 7px; font-size: 18px; cursor: pointer; flex-shrink: 0;
}
.facts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin: 6px 0 10px; }
.facts .stat .v { font-size: 15px; }
.d-section {
  margin: 10px 0 0; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
}
.loc {
  display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 10px 0 0; font-size: 13px;
  padding: 8px 10px; background: var(--surface-2); border-radius: 8px;
}
.loc dt { color: var(--muted); }
.loc dd { margin: 0; font-weight: 550; overflow-wrap: anywhere; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); border-radius: 8px; padding: 3px; }
.chart-box { position: relative; height: 240px; margin-top: 10px; }
.note { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.note.warn { color: #b45309; font-weight: 600; }
.list.near { flex: none; overflow: visible; margin-top: 4px; }

.leaflet-container { background: var(--map-mask); font: inherit; }
.leaflet-popup-content { font-size: 13px; }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; row-gap: 4px; padding: 6px 12px; }
  .logo { height: 26px; }
  .brand-name { font-size: 14px; }
  .brand { gap: 8px; }
  .brand-divider { height: 20px; }
  .brand-title { font-size: 14px; }
  .status { text-align: left; font-size: 12px; }
  .layout { flex-direction: column; }
  .sidebar { width: 100%; max-height: 46vh; border-right: 0; border-bottom: 1px solid var(--border); }
  .mapwrap { min-height: 54vh; }
  .detail { top: auto; bottom: 0; right: 0; width: 100%; max-height: 70%; border-radius: var(--radius) var(--radius) 0 0; }
  .legend { bottom: 12px; font-size: 11px; max-height: 38%; overflow-y: auto; }
}

/* Topic panel: Current / Future switch and future controls */
.segmented.mode { margin-bottom: 10px; }
.segmented.small button { font-size: 12px; padding: 6px 2px; }
.segmented button:disabled { opacity: 0.4; cursor: not-allowed; }
#future-controls .field .segmented { margin-top: 4px; }

/* Header user box */
.top-right { display: flex; align-items: center; gap: 14px; min-width: 0; }
.user-box { display: flex; align-items: center; gap: 8px; margin: 0; }
.user-name { font-size: 13px; font-weight: 600; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn.small { flex: 0 0 auto; padding: 4px 10px; font-size: 12px; }

/* Login page */
.login-page { align-items: center; justify-content: center; min-height: 100%; padding: 16px; border-top: 3px solid var(--brand-orange); }
.login-card {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px 24px;
}
.login-card { text-align: center; }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 14px; }
.login-logo { height: 44px; width: auto; display: block; }
.login-card h1 { font-size: 20px; margin: 0; }
.login-card > p { margin: 4px 0 18px; }
.login-card form .field { margin-bottom: 12px; text-align: left; }
.login-btn { width: 100%; margin-top: 6px; padding: 10px; }
.login-error {
  background: color-mix(in srgb, #dc2626 12%, transparent); color: #dc2626; border-radius: 7px;
  padding: 8px 10px; font-size: 13px; margin: 0 0 14px;
}
.login-help { font-size: 12px; margin: 14px 0 0; text-align: center; }
@media (max-width: 760px) {
  .user-name { display: none; }
  .top-right { gap: 8px; }
}
