/* ================================================================
   StormCell — design system
   Tokens, type, controls and the app shell. Light is the default;
   html[data-theme="dark"] switches every token.
   ================================================================ */

:root {
  --bg:          #F3F4F6;
  --surface:     #FFFFFF;
  --surface-2:   #F8F9FA;
  --ink:         #1E2733;
  --ink-2:       #4E5866;
  --ink-3:       #737C89;
  --rule:        #D8DCE1;
  --rule-strong: #BFC5CC;
  --accent:      #2B5A86;
  --accent-hover:#234B70;
  --accent-ink:  #FFFFFF;
  --accent-soft: #E6EEF6;
  --alert:       #B45309;
  --alert-soft:  #FBF1E4;
  --ok:          #2F7D4F;
  --ok-soft:     #E5F2EA;
  --bad:         #B42318;
  --focus:       #2B5A86;

  /* Chart series (validated categorical set: blue, aqua, orange) */
  --series-1:    #2a78d6;
  --series-2:    #1baf7a;
  --series-3:    #eb6834;

  --font: "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius-sm: 3px;
  --radius:    5px;

  color-scheme: light;
}

html[data-theme="dark"] {
  --bg:          #12161B;
  --surface:     #1A1F26;
  --surface-2:   #20262E;
  --ink:         #E4E8ED;
  --ink-2:       #A9B1BC;
  --ink-3:       #848D99;
  --rule:        #2C333C;
  --rule-strong: #3A424D;
  --accent:      #8DB3D9;
  --accent-hover:#A6C4E3;
  --accent-ink:  #0F1A26;
  --accent-soft: #1E2A38;
  --alert:       #E3A250;
  --alert-soft:  #2E2416;
  --ok:          #6BBF8A;
  --ok-soft:     #1A2A20;
  --bad:         #EF8A7F;
  --focus:       #8DB3D9;

  --series-1:    #3987e5;
  --series-2:    #199e70;
  --series-3:    #d95926;

  color-scheme: dark;
}

/* ------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 15px/1.5 var(--font);
  font-feature-settings: "tnum" 0;
}
h1, h2, h3, p { margin: 0; }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* --------------------------------------------------------- controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 38px; padding: 0 16px;
  border: 1px solid transparent; border-radius: var(--radius);
  font: 600 14px/1 var(--font); text-decoration: none; cursor: pointer;
  transition: background-color .12s, border-color .12s, color .12s;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); color: var(--accent-ink); }
.btn-quiet { background: transparent; color: var(--ink-2); border-color: var(--rule-strong); }
.btn-quiet:hover { color: var(--ink); border-color: var(--ink-3); }
.btn-sm { min-height: 30px; padding: 0 12px; font-size: 13px; }

.segmented {
  display: inline-flex; border: 1px solid var(--rule-strong); border-radius: var(--radius);
  overflow: hidden; background: var(--surface);
}
.segmented button {
  appearance: none; border: 0; background: transparent; color: var(--ink-2);
  font: 500 13px/1 var(--font); padding: 8px 14px; cursor: pointer;
}
.segmented button + button { border-left: 1px solid var(--rule); }
.segmented button:hover { color: var(--ink); background: var(--surface-2); }
.segmented button[aria-pressed="true"],
.segmented button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---------------------------------------------------------- brand */
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand svg { width: 26px; height: 26px; color: var(--accent); flex: none; }
.brand-name { font: 700 16px/1.1 var(--font); letter-spacing: -.01em; }
.brand-sub { font: 400 12.5px/1.2 var(--font); color: var(--ink-3); }

/* ------------------------------------------------------- app shell */
.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  grid-template-rows: 60px 1fr;
  grid-template-areas: "side top" "side main";
}
.sidebar {
  grid-area: side;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--rule);
  padding: 16px 12px;
}
.sidebar .brand { padding: 4px 8px 18px; }
.nav-group { display: flex; flex-direction: column; gap: 1px; margin-bottom: 18px; }
.nav-label { font: 500 12px/1 var(--font); color: var(--ink-3); padding: 0 10px 8px; }
.nav-link {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--ink-2); font: 500 14px/1.3 var(--font); text-decoration: none;
}
.nav-link:hover { background: var(--surface-2); color: var(--ink); }
.nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-link .ext { color: var(--ink-3); font-size: 12px; }
.nav-link.primary { color: var(--ink); font-weight: 600; }
.sidebar-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--rule); }
.link-button {
  appearance: none; border: 0; background: none; padding: 0; cursor: pointer;
  color: var(--ink-2); font: 500 13px/1.3 var(--font);
}
.link-button:hover { color: var(--ink); text-decoration: underline; text-underline-offset: 2px; }

.topbar {
  grid-area: top;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 28px; background: var(--surface); border-bottom: 1px solid var(--rule);
}
.topbar h1 { font: 600 18px/1.2 var(--font); letter-spacing: -.01em; }
.topbar-meta { display: flex; align-items: center; gap: 16px; font-size: 13px; color: var(--ink-3); }
.menu-toggle { display: none; }

.main { grid-area: main; padding: 28px; display: flex; flex-direction: column; gap: 28px; min-width: 0; }

/* --------------------------------------------------------- panels */
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); min-width: 0; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 14px 18px; border-bottom: 1px solid var(--rule);
}
.panel-head h2 { font: 600 15px/1.3 var(--font); }
.panel-head p { font-size: 13px; color: var(--ink-3); }
.panel-body { padding: 18px; }

/* --------------------------------------------------------- tables */
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
  text-align: left; font: 600 12.5px/1.2 var(--font); color: var(--ink-2);
  padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--rule);
  white-space: nowrap; position: sticky; top: 0;
}
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--rule); vertical-align: middle; white-space: nowrap; }
.data-table a { text-decoration: none; }
.data-table a:hover { text-decoration: underline; }
.data-table .time { font-variant-numeric: tabular-nums; color: var(--ink-2); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: var(--surface-2); }
.data-table .num { text-align: right; }
.data-table th.num { text-align: right; }
.data-table .mac { font-variant-numeric: tabular-nums; letter-spacing: .01em; color: var(--ink-2); white-space: nowrap; }

/* --------------------------------------------------------- status */
.status {
  display: inline-flex; align-items: center; gap: 6px;
  font: 500 13px/1 var(--font); color: var(--ink-2); white-space: nowrap;
}
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); }
.status.online { color: var(--ok); }
.status.online::before { background: var(--ok); }
.status.alert { color: var(--alert); font-weight: 600; }
.status.alert::before { background: var(--alert); }

.tag {
  display: inline-block; padding: 2px 7px; border-radius: var(--radius-sm);
  font: 500 12px/1.4 var(--font); color: var(--ink-2); background: var(--surface-2);
  border: 1px solid var(--rule); white-space: nowrap;
}
.tag.warn { color: var(--alert); background: var(--alert-soft); border-color: transparent; }

.empty { padding: 36px 18px; text-align: left; color: var(--ink-2); max-width: 60ch; }
.empty strong { display: block; color: var(--ink); font-weight: 600; margin-bottom: 4px; }

/* ----------------------------------------------------- responsive */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; grid-template-areas: "top" "side" "main"; }
  .sidebar { position: static; height: auto; display: none; border-right: 0; border-bottom: 1px solid var(--rule); }
  .sidebar .brand { display: none; }
  .app.nav-open .sidebar { display: flex; }
  .menu-toggle { display: inline-flex; }
  .topbar { padding: 12px 16px; flex-wrap: wrap; }
  .topbar .who { display: none; }
  .main { padding: 16px; gap: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ------------------------------------------------- nav: sub-links, foot */
.nav-link.sub { padding-left: 24px; font-size: 13.5px; }
.sidebar-foot { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.sidebar-foot .who { font-size: 12.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* ---------------------------------------------------------- forms */
.input {
  width: 100%; min-height: 38px; padding: 8px 10px;
  border: 1px solid var(--rule-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); font: 400 14px/1.3 var(--font);
}
.input::placeholder { color: var(--ink-3); }
.input:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
textarea.input { min-height: 84px; resize: vertical; }
.field-label { display: block; font: 500 13px/1.3 var(--font); color: var(--ink-2); margin: 0 0 6px; }
.help { font-size: 13px; color: var(--ink-3); line-height: 1.45; }
.btn[disabled] { opacity: .55; cursor: default; }
.btn-danger { background: transparent; color: var(--bad); border-color: var(--rule-strong); }
.btn-danger:hover { border-color: var(--bad); color: var(--bad); }

/* --------------------------------------------------------- modals */
.modal-overlay {
  position: fixed; inset: 0; z-index: 5000; display: none;
  align-items: center; justify-content: center; padding: 16px;
  background: rgba(18, 22, 27, .45);
}
.modal-overlay.show { display: flex; }
.modal {
  width: min(560px, 100%); max-height: 90vh; display: flex; flex-direction: column;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--rule); border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .18);
}
.modal.wide { width: min(980px, 100%); }
.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--rule);
}
.modal-head h2 { font: 600 16px/1.3 var(--font); }
.modal-head p { font-size: 13px; color: var(--ink-3); margin-top: 2px; }
.modal-body { padding: 18px; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--rule); }
.modal-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; font-size: 13px; color: var(--ink-2); }
.modal-body .data-table { font-size: 13px; }
.modal-body .data-table td { padding: 8px 12px; }
.modal-body .data-table th { padding: 8px 12px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.chip-list { display: flex; flex-wrap: wrap; gap: 4px; white-space: normal; }

/* ---------------------------------------------------- Leaflet maps */
.leaflet-container { font-family: var(--font); background: var(--surface-2); }
.leaflet-bar, .leaflet-control-layers { border: 1px solid var(--rule-strong) !important; border-radius: var(--radius) !important; box-shadow: none !important; }
.leaflet-bar a, .leaflet-control-layers { background: var(--surface) !important; color: var(--ink) !important; }
.leaflet-bar a { border-bottom-color: var(--rule) !important; }
.leaflet-bar a:hover { background: var(--surface-2) !important; }
.leaflet-control-layers label { color: var(--ink); font: 400 13px/1.6 var(--font); }
.leaflet-control-layers-separator { border-top-color: var(--rule) !important; }
.leaflet-control-attribution { background: var(--surface) !important; color: var(--ink-3) !important; }
.leaflet-control-attribution a { color: var(--ink-2) !important; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--surface); color: var(--ink);
  border-radius: var(--radius); box-shadow: 0 4px 18px rgba(0, 0, 0, .16);
}
.leaflet-popup-content-wrapper { border: 1px solid var(--rule); }
.leaflet-popup-content { margin: 14px 16px; font: 400 14px/1.45 var(--font); }
.leaflet-container a.leaflet-popup-close-button { color: var(--ink-3); }
html[data-theme="dark"] .leaflet-control-layers-toggle { filter: invert(1); }

/* Muted basemaps: OpenStreetMap tiles toned to match the interface */
.tiles-light img.leaflet-tile { filter: grayscale(1) contrast(.88) brightness(1.04); }
.tiles-dark  img.leaflet-tile { filter: grayscale(1) invert(1) contrast(.82) brightness(.82); }

/* ----------------------------------------- section tabs (in topbar) */
.topbar-title { display: flex; align-items: center; gap: 12px; align-self: stretch; min-width: 0; }
.section-tabs { display: flex; align-self: stretch; margin-left: 16px; }
.section-tabs a {
  display: flex; align-items: center; padding: 0 12px; margin-bottom: -1px;
  color: var(--ink-2); font: 500 14px/1 var(--font); text-decoration: none;
  border-bottom: 2px solid transparent;
}
.section-tabs a:hover { color: var(--ink); }
.section-tabs a[aria-current="page"] { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
@media (max-width: 900px) {
  .topbar-title { flex-wrap: wrap; align-self: auto; }
  .section-tabs { margin-left: 0; width: 100%; }
  .section-tabs a { padding: 10px 12px 10px 0; margin-right: 8px; }
}
