/* ==========================================================================
   TranXwatch-Solar Console — components
   Depends on tokens.css + base.css. No raw hex values below.
   ========================================================================== */

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 9px 15px;
  font-weight: 600;
  color: var(--on-accent);
  background: var(--blue);
  border: 1px solid transparent;
  border-radius: var(--r-md);
}
.btn:hover { background: var(--blue-hover); }

.btn.ghost {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--ink);
  font-weight: 500;
}
.btn.ghost:hover { background: var(--surface-1); }

.btn.sm { padding: 5px 10px; font-size: var(--fs-xs); border-radius: var(--r-sm); }
.btn.active { background: var(--cyan); color: var(--navy-deep); }
.btn.danger { background: var(--crit); color: var(--navy-deep); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-block { width: 100%; justify-content: center; }

/* ==========================================================================
   Utilities
   ========================================================================== */
.flush    { margin: 0; }
.grow     { flex: 1; }
.stack-b  { margin-bottom: var(--sp-4); }
.stack-sm { margin-top: var(--sp-2); }
.icon-xs  { width: 13px; height: 13px; }
.accent   { color: var(--cyan); }
.hint     { font-size: var(--fs-xs); }

/* Service cards lead with an icon beside the heading. */
.service h2 { display: flex; align-items: center; gap: var(--sp-2); }
.service h2 .icon { width: 18px; height: 18px; flex: none; color: var(--cyan); }

/* Anomaly / recommendation lists inside the LOLA-AI panel. */
ul.findings {
  margin: var(--sp-2) 0 var(--sp-3);
  padding-left: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
ul.findings:last-child { margin-bottom: 0; }

/* ==========================================================================
   DisCo selection screens.
   #landing  = PRE-LOGIN front door: all 11 DisCos, no availability badge.
   #discoPick = POST-LOGIN switch, staff only: just the caller's own networks.
   Both share the same centred layout and card grid.
   ========================================================================== */
/* The landing lists all 11 DisCos, which is tall. Start at the top and let the
   page scroll (justify-content:center would push the lower cards off-screen and
   make them feel missing). The header is kept compact so more cards sit above
   the fold. */
#landing {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: var(--sp-4);
  padding: var(--sp-5) var(--sp-5) var(--sp-8);
}
/* The post-login switch shows only the account's own 1-2 networks, so it stays
   vertically centred. */
#discoPick {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-6);
  padding: var(--sp-8) var(--sp-5);
}
#landing.hide,
#discoPick.hide { display: none; }

.landing-head { text-align: center; max-width: 60ch; }
.landing-logo { width: 150px; margin-bottom: var(--sp-3); }
.landing-head h1 { font-size: var(--fs-2xl); color: var(--cyan); margin-bottom: var(--sp-1); }
.landing-head .tagline { color: var(--muted); margin: 0 0 var(--sp-4); font-size: var(--fs-md); }
.landing-lede { color: var(--ink); font-size: var(--fs-md); margin: 0; }

/* Compact header on the landing specifically, so the 11-card grid starts high
   and most DisCos are visible without scrolling. */
#landing .landing-logo { width: 96px; margin-bottom: var(--sp-2); }
#landing .landing-head h1 { font-size: var(--fs-xl); }
#landing .landing-head .tagline { margin-bottom: var(--sp-2); }

.disco-grid {
  display: grid;
  /* Denser than before (was 220px/980px): at ~1100px this fits up to 5 columns,
     so all 11 DisCos land in 2-3 rows and are visible without scrolling on a
     normal screen. Still collapses to 2 columns on narrow windows. */
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: var(--sp-3);
  width: 100%;
  max-width: 1100px;
}

/* A button, not a div: choosing a DisCo is an action, and it must be keyboard
   reachable and announce itself. */
.disco-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
  font: inherit;
  color: var(--ink);
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-strong);
  border-radius: var(--r-md);
  cursor: pointer;
}
.disco-card:hover:not(:disabled) {
  background: var(--surface-2);
  border-left-color: var(--cyan);
}
.disco-card:disabled { opacity: .5; cursor: not-allowed; }

.disco-card .code {
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: var(--ls-caps);
  color: var(--cyan);
}
.disco-card:disabled .code { color: var(--muted); }
.disco-card .nm { font-size: var(--fs-sm); font-weight: 600; line-height: var(--lh-snug); }
.disco-card .st { font-size: var(--fs-xs); color: var(--muted); line-height: var(--lh-snug); }
.disco-card .status-line { margin-top: var(--sp-1); font-size: var(--fs-2xs); font-weight: 600; }
.disco-card .status-line.live { color: var(--ok); }
.disco-card .status-line.soon { color: var(--muted); }

/* ==========================================================================
   Login
   ========================================================================== */
#login {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-5);
  padding: var(--sp-5);
}
#login.hide { display: none; }
#login .card {
  width: 100%;
  max-width: 390px;
  padding: var(--sp-8) 30px;
  text-align: center;
  box-shadow: var(--shadow-2);
  border-radius: var(--r-xl);
}
#login img { width: 190px; margin-bottom: var(--sp-2); }
#login h1 { font-size: var(--fs-xl); margin: var(--sp-1) 0 2px; color: var(--cyan); }
#login .tagline { color: var(--muted); margin: 0 0 var(--sp-4); font-size: var(--fs-md); }

/* Which DisCo you are signing in to, and a way back to change it. */
.disco-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  margin: var(--sp-3) 0 var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-xs);
  color: var(--muted);
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
}
.disco-badge-code {
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: var(--ls-caps);
  color: var(--cyan);
}

/* A real button styled as a link — keeps keyboard and screen-reader semantics. */
.linkbtn {
  padding: 0;
  font: inherit;
  font-size: var(--fs-xs);
  color: var(--cyan);
  background: none;
  border: 0;
  text-decoration: underline;
  cursor: pointer;
}
.linkbtn:hover { text-decoration-thickness: 2px; }

/* DisCo name under the sidebar wordmark. */
.brand-disco {
  display: block;
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: var(--ls-caps);
  text-transform: uppercase;
  color: var(--muted);
  line-height: 1.3;
}

/* Sign-in / validation errors: small text on a card ground -> --crit-text.
   This is the one message a locked-out operator must be able to read. */
.err {
  min-height: 18px;
  margin-top: var(--sp-3);
  font-size: var(--fs-sm);
  color: var(--crit-text);
}

/* ==========================================================================
   Shell
   ========================================================================== */
#app {
  display: none;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 1fr auto;
  grid-template-areas:
    "side main"
    "foot foot";
  min-height: 100vh;
}
#app.ready { display: grid; }

.sidebar {
  grid-area: side;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: var(--sp-5) var(--sp-3);
  background: rgba(8, 18, 40, .55);
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-1) var(--sp-2) var(--sp-4);
}
.brand img { width: 40px; }
.brand b { font-size: var(--fs-lg); font-weight: 600; letter-spacing: var(--ls-tight); }

.nav-group {
  margin: 0;
  padding: var(--sp-4) var(--sp-3) var(--sp-1);
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: var(--ls-caps);
  text-transform: uppercase;
  color: var(--muted);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 10px var(--sp-3);
  font-size: var(--fs-md);
  font-weight: 500;
  color: var(--ink);
  text-decoration: none;
  border-radius: var(--r-md);
  border-left: 3px solid transparent;
  opacity: .85;
}
.nav-link:hover { background: var(--surface-1); opacity: 1; }
.nav-link[aria-current="page"] {
  background: linear-gradient(90deg, rgba(21, 101, 192, .35), transparent);
  border-left-color: var(--cyan);
  opacity: 1;
}
.nav-link .icon { width: 17px; height: 17px; flex: none; }

.spacer { flex: 1; }
.who { padding: var(--sp-2); font-size: var(--fs-sm); color: var(--muted); line-height: 1.5; }

main {
  grid-area: main;
  padding: var(--sp-6) var(--sp-8);
  overflow: auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-5);
}
.conn {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  font-size: var(--fs-sm);
  color: var(--muted);
}
.dot {
  display: inline-block;
  width: 9px; height: 9px;
  margin-right: var(--sp-1);
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px var(--ok-wash);
}
.dot.bad { background: var(--crit); box-shadow: 0 0 0 3px var(--crit-wash); }

.toggle {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  margin: 0;
  cursor: pointer;
  user-select: none;
  font-weight: 500;
  text-transform: none;
  font-size: var(--fs-sm);
}

.view { display: none; }
.view.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

/* ==========================================================================
   Footer  —  required on every surface
   ========================================================================== */
.app-footer {
  grid-area: foot;
  display: flex;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-8);
  font-size: var(--fs-sm);
  color: var(--muted);
  background: rgba(8, 18, 40, .45);
  border-top: 1px solid var(--line);
}
.app-footer strong { color: var(--ink); font-weight: 600; }

.login-footer {
  font-size: var(--fs-sm);
  color: var(--muted);
  text-align: center;
  line-height: 1.7;
}
.login-footer strong { color: var(--ink); font-weight: 600; }

/* ==========================================================================
   Grid + cards
   ========================================================================== */
.grid { display: grid; gap: var(--sp-4); }
.kpis  { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.cards { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.two   { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stack { margin-top: var(--sp-4); }

.card {
  padding: var(--sp-5);
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.card > h2 { font-size: var(--fs-lg); }

/* 700 is the heaviest weight shipped (see fonts.css). Asking for 800 makes the
   browser synthesise a faux-bold from the 700 face — smeared strokes on the
   largest numerals on screen. */
.kpi .n {
  font-size: var(--fs-3xl);
  font-weight: 700;
  line-height: var(--lh-tight);
  letter-spacing: var(--ls-tight);
}
.kpi .l {
  margin-top: var(--sp-1);
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--muted);
  letter-spacing: var(--ls-caps);
  text-transform: uppercase;
}
.kpi .n.ok   { color: var(--ok); }
.kpi .n.warn { color: var(--warn); }
.kpi .n.crit { color: var(--crit); }

.hero {
  display: flex;
  align-items: center;
  gap: var(--sp-6);
  padding: var(--sp-5) var(--sp-6);
  margin-bottom: var(--sp-5);
  background: linear-gradient(120deg, rgba(21, 101, 192, .25), rgba(77, 208, 225, .08));
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.hero img { width: 150px; }
.hero h2 { margin: 0 0 var(--sp-1); font-size: var(--fs-2xl); color: #fff; }
.hero p { margin: 0; color: var(--muted); }

/* ==========================================================================
   Tables
   ========================================================================== */
.tablewrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
}

caption {
  text-align: left;
  padding-bottom: var(--sp-2);
  font-size: var(--fs-xs);
  color: var(--muted);
}

th, td {
  text-align: left;
  padding: 10px var(--sp-3);
  border-bottom: 1px solid var(--line);
}

th {
  font-size: var(--fs-2xs);
  font-weight: 600;
  letter-spacing: var(--ls-caps);
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

tbody tr:hover { background: var(--surface-1); }

/* Threshold breaches in data cells — small text, so --crit-text not --crit. */
td .bad  { color: var(--warn); }
td .vbad { color: var(--crit-text); font-weight: 600; }

/* ==========================================================================
   Status — EEMUA 191 discipline
   Shape AND colour AND text. Never colour alone (WCAG 1.4.1).
   ========================================================================== */
.status {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 700;
  white-space: nowrap;
}
/* Status LABELS are small text -> --crit-text. The LED beside them keeps the
   vivid --crit fill (a graphic needs only 3:1), so the alarm still reads red. */
.status.ok   { color: var(--ok); }
.status.warn { color: var(--warn); }
.status.crit { color: var(--crit-text); }

.led {
  width: 12px;
  height: 12px;
  flex: none;
  display: inline-block;
}
/* Healthy = circle */
.led.ok { background: var(--ok); border-radius: 50%; }
/* Warning = triangle */
.led.warn { background: var(--warn); clip-path: polygon(50% 0, 100% 100%, 0 100%); }
/* Critical = square */
.led.crit { background: var(--crit); border-radius: 2px; }

/* Animation is reserved for UNACKNOWLEDGED alarms (EEMUA 191). A permanently
   pulsing critical LED trains operators to ignore movement. */
.led.unack { animation: ledpulse 1.1s infinite; }
@keyframes ledpulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

.pill {
  display: inline-block;
  padding: 2px 9px;
  font-size: var(--fs-xs);
  font-weight: 700;
  border-radius: var(--r-pill);
}
.pill.on       { background: var(--ok-wash);   color: var(--ok); }
.pill.off      { background: var(--crit-wash); color: var(--crit-text); }
.pill.info     { background: var(--info-wash); color: var(--cyan); }
.pill.warning  { background: var(--warn-wash); color: var(--warn); }
.pill.critical { background: var(--crit-wash); color: var(--crit-text); }

/* ==========================================================================
   Bars / charts
   ========================================================================== */
.track {
  display: flex;
  height: 12px;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: var(--r-sm);
}
.track.tall { height: 22px; }
.seg { height: 100%; }
.seg.ok   { background: var(--ok); }
.seg.warn { background: var(--warn); }
.seg.crit { background: var(--crit); }

.bar {
  height: 9px;
  border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--blue), var(--cyan));
}

.legend {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-top: var(--sp-2);
  font-size: var(--fs-sm);
}
.sev-row { margin: var(--sp-2) 0; }
.sev-row .legend { margin-top: 0; margin-bottom: var(--sp-1); }

.chartwrap { overflow-x: auto; }
.chartwrap svg { width: 100%; min-width: 420px; }
.chartwrap svg.topo { min-width: 660px; }

.chart-legend { display: flex; gap: var(--sp-3); flex-wrap: wrap; margin-top: var(--sp-1); font-size: var(--fs-xs); }
.chart-legend .key { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.chart-legend .swatch { width: 9px; height: 9px; border-radius: 2px; flex: none; }

/* ==========================================================================
   Layout helpers
   ========================================================================== */
.row { display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.top { align-items: flex-start; }
.push { margin-left: auto; }
.w-sel { max-width: 280px; }
.w-search { max-width: 230px; }
.scroll-y { max-height: 560px; overflow: auto; }

.empty {
  padding: var(--sp-6);
  text-align: center;
  color: var(--muted);
}

/* ==========================================================================
   Modal
   ========================================================================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);
  background: var(--scrim);
}
.modal.open { display: flex; }
.modal .card {
  width: 100%;
  max-width: 430px;
  background: var(--navy);
  box-shadow: var(--shadow-2);
}
.modal .card.wide { max-width: 680px; max-height: 88vh; overflow: auto; }
.modal h2 { margin: 0 0 var(--sp-1); }
.modal .actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-3);
  margin-top: var(--sp-5);
}

/* ==========================================================================
   Map
   ========================================================================== */
#leafmap { height: 480px; border-radius: var(--r-md); }

/* Leaflet popups render on a light chip; keep them readable. */
.leaflet-popup-content { font-family: var(--font-ui); font-size: var(--fs-md); }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1100px) {
  :root { --sidebar-w: 220px; }
  main { padding: var(--sp-5); }
  .app-footer { padding: var(--sp-3) var(--sp-5); }
}

@media (max-width: 820px) {
  #app { grid-template-columns: 1fr; grid-template-areas: "side" "main" "foot"; }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    flex-direction: row;
    flex-wrap: wrap;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .spacer, .who, .nav-group { display: none; }
  .hero { flex-direction: column; text-align: center; }
  .app-footer { flex-direction: column; gap: var(--sp-1); }
}
