/*
 * Multi-Josh dashboard theme (2026-11-20). Loaded after styles.css and only restyles it:
 * colour tokens, sidebar layout, cards, KPIs, tables, pills, buttons, inputs, modals.
 * No element ids or script hooks depend on this file; removing its <link> restores the old look.
 */

:root {
  color-scheme: dark;
  --bg: #080d18;
  --bg-elevated: #0c1322;
  --bg-card: #101a2c;
  --bg-card-hover: #152238;
  --bg-inset: #0a1120;
  --border: #1d2a41;
  --border-strong: #2a3b5a;
  --text: #e8edf6;
  --text-muted: #a2afc4;
  --text-subtle: #74839b;
  --accent: #6f7dff;
  --accent-dim: #5a68f0;
  --accent-soft: rgba(111, 125, 255, 0.14);
  --accent-line: rgba(111, 125, 255, 0.45);
  --success: #34d399;
  --success-dim: #10b981;
  --success-soft: rgba(52, 211, 153, 0.12);
  --fail: #fb7185;
  --fail-dim: #f43f5e;
  --fail-soft: rgba(251, 113, 133, 0.12);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.12);
  --info: #38bdf8;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 14px 34px rgba(1, 4, 14, 0.38);
  --shadow-sm: 0 1px 0 rgba(255, 255, 255, 0.025) inset, 0 6px 18px rgba(1, 4, 14, 0.26);
  --sidebar-w: 252px;
}

/* ---------- Page canvas ---------- */
body {
  background:
    radial-gradient(1100px 620px at 92% -12%, rgba(111, 125, 255, 0.11), transparent 62%),
    radial-gradient(900px 520px at -8% 108%, rgba(52, 211, 153, 0.06), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  font-size: 15px;
  letter-spacing: 0.002em;
}

::selection { background: rgba(111, 125, 255, 0.35); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------- Layout: left sidebar ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

.header {
  grid-column: 1;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  gap: 1.6rem;
  padding: 1.3rem 0.95rem 1.1rem;
  background: linear-gradient(180deg, rgba(12, 19, 34, 0.97), rgba(8, 13, 24, 0.97));
  border-bottom: none;
  border-right: 1px solid var(--border);
  backdrop-filter: blur(10px);
  overflow-y: auto;
}

.main {
  grid-column: 2;
  max-width: 1480px;
  width: 100%;
  margin: 0 auto;
  padding: 1.9rem 2.2rem 3rem;
  min-width: 0;
}

/* Brand */
.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.15rem 0.45rem;
}

.brand-mark {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: linear-gradient(140deg, #8b95ff 0%, #5a68f0 55%, #2dd4bf 130%);
  box-shadow: 0 6px 18px rgba(90, 104, 240, 0.4), 0 1px 0 rgba(255, 255, 255, 0.35) inset;
}

.brand-mark svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: #fff;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-text { display: flex; flex-direction: column; min-width: 0; }

.logo {
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.2;
}

.brand-sub {
  font-size: 0.74rem;
  color: var(--text-subtle);
  letter-spacing: 0.02em;
}

/* Navigation */
.nav {
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 0.2rem;
}

.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.72rem;
  padding: 0.62rem 0.75rem;
  border-radius: 11px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-muted);
}

.nav-link:hover:not(.disabled) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.045);
}

.nav-link.active {
  color: #fff;
  background: linear-gradient(90deg, rgba(111, 125, 255, 0.22), rgba(111, 125, 255, 0.06));
  box-shadow: inset 0 0 0 1px rgba(111, 125, 255, 0.28);
}

.nav-link.active::before {
  content: "";
  position: absolute;
  left: -0.95rem;
  top: 22%;
  bottom: 22%;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
  box-shadow: 0 0 12px rgba(111, 125, 255, 0.8);
}

.nav-icon {
  flex: none;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.9;
}

.nav-link.active .nav-icon { color: #b9c0ff; opacity: 1; }

/* Sidebar footer: Pacific clock */
.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.85rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.02);
}

.sidebar-foot-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-subtle);
}

.pt-clock {
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 500;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.pt-date { font-size: 0.78rem; color: var(--text-muted); }

/* ---------- Page header ---------- */
.page-header {
  align-items: flex-end;
  margin-bottom: 1.6rem;
  padding-bottom: 1.1rem;
  border-bottom: 1px solid var(--border);
}

.page-title { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; }

.page-header h2 {
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

.page-sub {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-subtle);
}

.date-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.date-row label { font-size: 0.82rem; font-weight: 600; color: var(--text-muted); }

/* ---------- Cards ---------- */
.card,
.state-panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.022), rgba(255, 255, 255, 0) 120px), var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.card { padding: 1.35rem 1.45rem; margin-bottom: 1.25rem; }

.card h3 {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 1.05rem;
  font-size: 0.98rem;
  font-weight: 650;
  letter-spacing: 0.005em;
}

.card > h3::before,
.card > div > h3:first-child::before {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.state-panel { padding: 2.4rem 1.5rem; color: var(--text-muted); }
.state-panel.error { border-color: rgba(251, 113, 133, 0.35); background: linear-gradient(180deg, var(--fail-soft), transparent 140px), var(--bg-card); }

.spinner {
  border-color: rgba(111, 125, 255, 0.2) !important;
  border-top-color: var(--accent) !important;
}

/* ---------- KPIs ---------- */
.kpi-row {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.kpi-card {
  --kpi-accent: var(--accent);
  position: relative;
  overflow: hidden;
  padding: 1.2rem 1.35rem 1.15rem;
  border-radius: var(--radius);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0) 60%), var(--bg-card);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column-reverse;
  gap: 0.35rem;
}

.kpi-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, var(--kpi-accent), transparent 85%);
}

.kpi-card::after {
  content: "";
  position: absolute;
  right: -46px;
  top: -46px;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--kpi-accent) 22%, transparent), transparent);
  pointer-events: none;
}

.kpi-card.success,
.kpi-card.fail { border-left: 1px solid var(--border); }
.kpi-card.success { --kpi-accent: var(--success); }
.kpi-card.fail { --kpi-accent: var(--fail); }

.kpi-value {
  font-size: 2.15rem;
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.kpi-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-subtle);
}

/* ---------- Charts ---------- */
.charts-row { gap: 1.25rem; margin-bottom: 1.25rem; }
.chart-card .chart-wrap { height: 270px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  letter-spacing: 0.005em;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.08s ease, filter 0.15s ease;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(180deg, #7d8aff, #5d6bf2);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.22) inset, 0 6px 16px rgba(93, 107, 242, 0.32);
}

.btn-primary:hover { background: linear-gradient(180deg, #8794ff, #6573f6); filter: brightness(1.04); }

.btn-secondary {
  color: var(--text);
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--border-strong);
}

.btn-secondary:hover { background: rgba(255, 255, 255, 0.07); border-color: #3a4f75; }

.btn:disabled,
.btn[disabled] { opacity: 0.5; cursor: not-allowed; filter: grayscale(0.25); }

.btn-sm { padding: 0.32rem 0.65rem; font-size: 0.78rem; border-radius: 8px; }

/* ---------- Inputs ---------- */
input[type="date"],
input[type="text"],
input[type="number"],
input[type="password"],
input[type="search"],
select,
textarea {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-inset);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  padding: 0.48rem 0.7rem;
  font-size: 0.88rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea { font-family: var(--font-mono); font-size: 0.82rem; line-height: 1.55; }

input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; }

/* ---------- Tables ---------- */
.scaling-table,
.settings-table,
.browse-files-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.86rem;
}

.scaling-table th,
.settings-table th,
.browse-files-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #0f182a;
  color: var(--text-subtle);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.scaling-table td,
.settings-table td,
.browse-files-table td {
  padding: 0.62rem 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.045);
  vertical-align: top;
}

.scaling-table tbody tr:hover td,
.settings-table tbody tr:hover td,
.browse-files-table tbody tr:hover td { background: rgba(111, 125, 255, 0.05); }

.scaling-table-wrap {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow-x: auto;
}

/* ---------- Pills and badges (shape only; colours stay per state) ---------- */
.badge,
.scaling-pill,
.cron-pill,
.ec2-badge,
.bot-badge,
.server-badge,
.census-server-badge,
.census-status,
.pw-sync-badge,
.versions-item-status {
  border-radius: 999px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

/* ---------- Settings page ---------- */
.cron-row,
.settings-server-card,
.settings-facility-card,
.server-block,
.census-row,
.failed-reason-item,
.versions-item {
  border-radius: 13px;
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.018);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.cron-row:hover,
.settings-server-card:hover,
.settings-facility-card:hover,
.server-block:hover,
.census-row:hover,
.failed-reason-item:hover {
  border-color: var(--border-strong);
  background: rgba(255, 255, 255, 0.032);
}

.settings-server-name,
.server-header strong { letter-spacing: -0.01em; }

/* The EC2 column was a fixed 8.75rem, so a "Running: Intervisit · 48m" badge spilled over the server line */
@media (min-width: 901px) {
  .settings-server-header { grid-template-columns: minmax(0, 1fr) auto 12.5rem 13.5rem; }
}
.settings-server-header-ec2 { flex-direction: column; align-items: flex-end; gap: 0.3rem; }

/* Per-server stats: .server-url holds the server name there */
.server-header .server-url {
  font-family: var(--font);
  font-size: 0.92rem;
  font-weight: 650;
  color: var(--text);
}

/* ---------- Browse files / terminal ---------- */
.browse-files-terminal-output,
.browse-files-viewer-content,
.browse-files-editor-ta,
.settings-editor-ta {
  background: #060b15 !important;
  border: 1px solid var(--border) !important;
  border-radius: 12px !important;
}

/* ---------- Modals ---------- */
.modal-backdrop {
  background: rgba(2, 6, 16, 0.62);
  backdrop-filter: blur(5px);
}

.modal-content {
  border-radius: 18px;
  border-color: var(--border-strong);
  box-shadow: 0 32px 90px rgba(0, 0, 0, 0.55);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 140px), var(--bg-card);
}

.modal-header { padding: 1.05rem 1.35rem; }
.modal-title { font-size: 1.05rem; font-weight: 650; }
.modal-close { border-radius: 8px; width: 32px; height: 32px; }
.modal-close:hover { background: rgba(255, 255, 255, 0.06); }

/* ---------- Scrollbars ---------- */
* { scrollbar-width: thin; scrollbar-color: #26344f transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: #26344f; border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: #33466a; background-clip: padding-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ---------- Narrow screens: sidebar becomes a top bar ---------- */
@media (max-width: 980px) {
  .app { grid-template-columns: minmax(0, 1fr); }

  .header {
    grid-column: 1;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 0.9rem;
    padding: 0.65rem 1rem;
    border-right: none;
    border-bottom: 1px solid var(--border);
    z-index: 50;
  }

  .brand-sub, .sidebar-foot { display: none; }
  .brand-mark { width: 32px; height: 32px; }

  .nav {
    flex-direction: row;
    overflow-x: auto;
    gap: 0.25rem;
    scrollbar-width: none;
  }

  .nav-link { padding: 0.5rem 0.7rem; white-space: nowrap; }
  .nav-link.active::before { display: none; }

  .main { grid-column: 1; padding: 1.2rem 1rem 2.5rem; }
  .page-header { align-items: flex-start; }
  .page-header h2 { font-size: 1.4rem; }
}

@media (max-width: 560px) {
  .nav-link span { display: none; }
  .nav-link { padding: 0.55rem; }
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.7rem; }
  .kpi-card { padding: 0.95rem 1rem; }
  .kpi-value { font-size: 1.6rem; }
}

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