:root {
  /* Light theme palette. Surfaces are white-on-near-white with a subtle
     border + shadow; text is dark slate; the teal brand accent is kept but
     darkened slightly for contrast on white. */
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel2: #ffffff;
  --border: #e2e8f0;
  --text: #0b1120;
  --muted: #5b6b85;
  --accent: #0d9488;
  --accent2: #0f766e;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  /* Derived surfaces used to replace previously hardcoded dark values. */
  --input-bg: #f1f5f9;
  --row-hover: #f3f6fb;
  --code-bg: #f1f5f9;
  --code-text: #0f766e;
  --chip-bg: #eef2f7;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
  /* Readable status text colours on light translucent backgrounds. */
  --ok-text: #15803d;
  --down-text: #b91c1c;
  --warn-text: #b45309;
  --ready-text: #1d4ed8;
  --chart-grid: #e9eef5;
  color-scheme: light;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--code-bg); padding: 1px 6px; border-radius: 5px; font-size: .9em; color: var(--code-text); }

.topbar {
  display: flex; flex-direction: column; align-items: stretch; gap: 8px;
  padding: 10px 18px 12px; background: var(--panel2);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10;
  box-shadow: var(--shadow);
}
.topbar-main {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.topbar-tools { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar nav {
  display: flex; flex-wrap: wrap; gap: 4px;
}
.topbar nav a {
  color: var(--muted); font-size: 13px; font-weight: 600;
  padding: 6px 10px; border-radius: 8px; white-space: nowrap;
  text-decoration: none;
}
.topbar nav a:hover { background: var(--input-bg); color: var(--text); text-decoration: none; }
.topbar nav a.active {
  background: rgba(13,148,136,.12); color: var(--accent2);
}
.conn { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.conn .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--warn); flex: 0 0 auto; }
.conn.ok .dot { background: var(--ok); }
.conn.bad .dot { background: var(--danger); }
.user-menu { display: flex; align-items: center; gap: 9px; font-size: 12px; }
.user-menu > span { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.user-menu form { margin: 0; }

main { max-width: 1100px; margin: 0 auto; padding: 26px 22px 60px; }

.hero h1 { margin: 0 0 8px; font-size: 26px; }
.hero p { color: var(--muted); max-width: 760px; line-height: 1.5; }

.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 26px 0; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); }
.card-num { font-size: 30px; font-weight: 700; }
.card-label { color: var(--muted); font-size: 13px; margin-top: 4px; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 20px; margin: 18px 0; box-shadow: var(--shadow); }
.panel h2 { margin: 0 0 10px; font-size: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.muted { color: var(--muted); line-height: 1.5; }

.code {
  background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px; overflow: auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px; line-height: 1.5; color: var(--text); white-space: pre;
}
.output { margin-top: 12px; color: var(--code-text); }

.checklist { color: var(--muted); line-height: 1.8; }

table.sites { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 13.5px; }
table.sites th, table.sites td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
table.sites th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
table.sites tr:hover td { background: var(--row-hover); }
table.sites input {
  width: 100%; min-width: 110px; padding: 6px 8px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--input-bg); color: var(--text); font-size: 13px;
}

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.pill.done { background: rgba(34,197,94,.15); color: var(--ok-text); }
.pill.pending { background: rgba(245,158,11,.15); color: var(--warn-text); }
.pill.up { background: rgba(34,197,94,.15); color: var(--ok-text); }
.pill.down { background: rgba(239,68,68,.15); color: var(--down-text); }
.pill.na { background: var(--chip-bg); color: var(--muted); }

.summary { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.chip { display: inline-block; padding: 4px 11px; border-radius: 8px; font-size: 12px; font-weight: 600; background: var(--chip-bg); color: var(--muted); }
.chip b { font-weight: 800; }
.chip.up { background: rgba(34,197,94,.15); color: var(--ok-text); }
.chip.ready { background: rgba(59,130,246,.18); color: var(--ready-text); }
.chip.warn { background: rgba(245,158,11,.15); color: var(--warn-text); }
.chip.pending { background: rgba(245,158,11,.12); color: var(--warn-text); }
.chip.down { background: rgba(239,68,68,.15); color: var(--down-text); }
.chip.na { background: var(--chip-bg); color: var(--muted); }
.chip.btnish { cursor: pointer; user-select: none; border: 1px solid transparent; }
.chip.btnish.active { box-shadow: inset 0 0 0 1.5px currentColor; }
table.sites tr.row-down td { background: rgba(239,68,68,.05); }
table.sites tr.row-5g td { background: rgba(245,158,11,.06); }

.btn {
  border: 0; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 13px;
}
.btn:hover { background: var(--accent2); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.filter { width: 220px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text); }

.modal { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal.hidden { display: none; }
.modal-box { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; width: min(760px, 92vw); max-height: 88vh; overflow: auto; padding: 20px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { margin: 0; }
.modal .x { background: none; border: 0; color: var(--muted); font-size: 26px; cursor: pointer; line-height: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.hidden { display: none; }

.cmd-line { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.cmd-line code { background: var(--input-bg); padding: 3px 8px; border-radius: 6px; border: 1px solid var(--border); font-size: 12.5px; }
.cmd-line .pill { flex: 0 0 auto; min-width: 56px; text-align: center; }

/* clickable dashboard ops cards (force-5G / natural failover / no-SIM) */
.card.clickable { cursor: pointer; transition: border-color .12s, transform .12s; }
.card.clickable:hover { border-color: var(--accent2); transform: translateY(-1px); }
.card.ops-forced .card-num { color: var(--warn-text); }
.card.ops-nat .card-num { color: var(--down-text); }
.card.ops-nosim .card-num { color: var(--ready-text); }
.card.ops-ok .card-num { color: var(--ok-text); }
#opsDrill h3, #opsDrill h4 { margin: 12px 0 6px; font-size: 15px; }
.cmd-line .muted { font-size: 12px; }
code.bad { color: var(--down-text); }

.cred-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.cred-row input { flex: 1; min-width: 160px; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text); font-size: 13px; }

/* ---------------------------------------------------------------------------
   Authentication and user administration.
   --------------------------------------------------------------------------- */
.auth-page { min-height: 100vh; background: var(--bg); }
.auth-shell {
  min-height: 100vh; display: grid; place-items: center;
  max-width: none; padding: 28px 16px;
}
.auth-card {
  width: min(420px, 100%); background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px; box-shadow: var(--shadow);
}
.auth-brand { color: var(--accent2); font-size: 12px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; }
.auth-card h1 { margin: 10px 0 6px; font-size: 26px; line-height: 1.2; }
.auth-form {
  display: flex; flex-direction: column; gap: 6px; margin-top: 22px;
}
.auth-form label, .invite-form label span { font-size: 13px; font-weight: 650; margin-top: 8px; display: block; }
.auth-form input, .invite-form input, .invite-form select, .user-access-form select {
  display: block; width: 100%; padding: 11px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--input-bg); color: var(--text); font: inherit;
}
.auth-submit { margin-top: 14px; min-height: 44px; width: 100%; }
.auth-help, .field-help { color: var(--muted); font-size: 12px; line-height: 1.5; }
.auth-help { margin: 18px 0 0; text-align: center; }
.auth-secondary-form { margin-top: 10px; text-align: center; }
.otp-input { text-align: center; font-size: 24px !important; letter-spacing: .35em; font-variant-numeric: tabular-nums; }
.notice { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin: 14px 0; font-size: 13px; }
.notice.error { color: var(--down-text); background: rgba(239,68,68,.08); }
.notice.success { color: var(--ok-text); background: rgba(34,197,94,.08); }
.invite-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px; align-items: end;
}
.invite-form label { display: grid; gap: 6px; }
.user-access-form { display: flex; align-items: center; gap: 7px; }

/* ---------------------------------------------------------------------------
   Monitoring / charts (light-theme aware; charts read CSS vars at runtime).
   --------------------------------------------------------------------------- */
.mon-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin: 18px 0; }
.mon-grid .panel { margin: 0; }
.chart-box { width: 100%; }
.ee-chart { display: block; width: 100%; }
.chart-empty { padding: 28px 6px; text-align: center; font-size: 13px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.chart-key { display: inline-flex; align-items: center; gap: 6px; }
.chart-key i { width: 11px; height: 3px; border-radius: 2px; display: inline-block; }
.chart-key b { color: var(--text); font-weight: 700; }

/* Horizontal-scroll wrapper for wide data tables (keeps the table inside its
   own box on narrow screens instead of forcing full-page horizontal scroll). */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------------------------------------------------------------------------
   Main lines staff monitor
   --------------------------------------------------------------------------- */
body.ml-page main { max-width: 1280px; }
.ml-hero {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 16px;
  margin-bottom: 8px;
}
.ml-hero h1 { margin: 0 0 6px; font-size: 28px; }
.ml-hero p { margin: 0; color: var(--muted); max-width: 640px; line-height: 1.5; }
.ml-kicker {
  margin: 0 0 6px; font-size: 12px; font-weight: 700; letter-spacing: .7px;
  text-transform: uppercase; color: var(--accent2);
}
.ml-live {
  display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
  color: var(--muted); font-size: 13px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 999px; padding: 8px 14px;
  box-shadow: var(--shadow);
}
.ml-live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.ml-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 18px 0; }
.ml-stat {
  text-align: left; cursor: pointer; border: 1px solid var(--border);
  background: var(--panel); border-radius: 14px; padding: 16px 18px;
  box-shadow: var(--shadow); color: inherit; font: inherit;
}
.ml-stat:hover { border-color: var(--accent); }
.ml-stat.active { box-shadow: inset 0 0 0 2px var(--accent); }
.ml-stat .n { display: block; font-size: 34px; font-weight: 800; line-height: 1; }
.ml-stat .l { display: block; margin-top: 6px; color: var(--muted); font-size: 13px; font-weight: 600; }
.ml-stat.ok .n { color: var(--ok-text); }
.ml-stat.warn .n { color: var(--warn-text); }
.ml-stat.down .n { color: var(--down-text); }
.ml-alerts { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.ml-alert {
  border-radius: 14px; padding: 16px 18px; border: 1px solid var(--border);
  background: var(--panel); box-shadow: var(--shadow);
}
.ml-alert h3 { margin: 0 0 6px; font-size: 18px; }
.ml-alert p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.ml-alert .ip { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.ml-alert.down { background: rgba(239,68,68,.07); border-color: rgba(185,28,28,.25); }
.ml-alert.warn { background: rgba(245,158,11,.08); border-color: rgba(180,83,9,.22); }
.ml-alert.ok-all { background: rgba(34,197,94,.08); border-color: rgba(22,163,74,.22); }
.ml-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ml-empty { padding: 28px 8px; text-align: center; color: var(--muted); }

/* ---------------------------------------------------------------------------
   Mobile responsiveness (additive — desktop layout above is unchanged).
   --------------------------------------------------------------------------- */
@media (max-width: 640px) {
  /* Top bar already wraps; just tighten padding on small screens. */
  .topbar { padding: 10px 12px 12px; gap: 8px; }
  .brand { font-size: 15px; }
  .topbar nav a { padding: 8px 10px; font-size: 13px; }
  .conn { font-size: 12px; }
  .user-menu > span { display: none; }

  main { padding: 16px 14px 60px; }

  .hero h1 { font-size: 21px; }

  /* Stat cards: two-up instead of four-up. */
  .cards { grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 18px 0; }
  /* Monitoring charts: single column on narrow screens. */
  .mon-grid { grid-template-columns: 1fr; gap: 12px; }
  .card { padding: 14px; }
  .card-num { font-size: 24px; }

  .panel { padding: 14px; border-radius: 12px; }
  .panel-head { flex-wrap: wrap; align-items: stretch; }

  /* Data tables scroll inside their own container and keep cells readable. */
  table.sites { font-size: 13px; min-width: 560px; }
  table.sites th, table.sites td { padding: 8px 8px; }

  /* Controls: comfortable tap targets, full-width filters/buttons. */
  .filter { width: 100%; }
  .btn { min-height: 44px; padding: 10px 16px; font-size: 14px; }
  .btn.small { min-height: 38px; padding: 8px 12px; font-size: 13px; }
  .cred-row { gap: 8px; }
  .cred-row .btn { flex: 1 1 auto; }
  .auth-card { padding: 22px 18px; }
  .invite-form { grid-template-columns: 1fr; }
  .user-access-form { min-width: 360px; }

  /* Modals: use the full viewport with safe scrolling and a sticky close. */
  .modal { align-items: flex-end; }
  .modal-box {
    width: 100vw;
    max-width: 100vw;
    max-height: 92vh;
    border-radius: 14px 14px 0 0;
    padding: 16px;
  }
  .modal-head { position: sticky; top: -16px; background: var(--panel); padding-top: 4px; }
  .modal .x { min-width: 44px; min-height: 44px; }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions .btn { flex: 1 1 auto; }
  .code { font-size: 11.5px; }
  .ml-hero { flex-direction: column; align-items: flex-start; }
  .ml-stats { grid-template-columns: 1fr; }
  .ml-stat .n { font-size: 28px; }
}
