* { box-sizing: border-box; }

:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --border: #dde3ea;
  --border-strong: #c9d2dd;
  --text: #142033;
  --text-muted: #5f6b7a;
  --heading: #101828;
  --navy: #1e293b;
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #eef2f7 0%, var(--bg) 220px);
  line-height: 1.5;
}

a { color: #1d4ed8; text-decoration: none; }
a:hover { text-decoration: underline; }

.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 230px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 26px 18px;
  background: var(--navy);
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.sidebar .brand { color: #f8fafc; }
.sidebar .brand-subtitle { color: #94a3b8; }

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-group {
  margin: 14px 10px 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #64748b;
}

.side-nav a {
  color: #cbd5e1;
  font-size: 14px;
  font-weight: 500;
  padding: 9px 12px;
  border-radius: 10px;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.side-nav a:hover {
  background: rgba(148, 163, 184, 0.15);
  color: #f8fafc;
  text-decoration: none;
}

.side-nav a.active {
  background: rgba(59, 130, 246, 0.25);
  color: #ffffff;
  font-weight: 600;
}

.main-col {
  flex: 1;
  min-width: 0;
}

.brand-block {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-logo-frame,
.auth-logo-frame,
.config-logo-frame {
  position: relative;
  display: block;
  overflow: hidden;
}

.brand-logo-frame {
  width: 176px;
  height: 52px;
}

.brand-logo-frame img,
.auth-logo-frame img,
.config-logo-frame img {
  position: absolute;
  top: 50%;
  left: 50%;
  display: block;
  width: 100%;
  height: auto;
  transform: translate(-50%, -50%);
}

.brand-logo-frame img { width: 270px; }
.brand-logo-frame:hover { text-decoration: none; }

.brand {
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.02em;
  color: var(--heading);
}

.brand-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.container {
  max-width: 1180px;
  margin: 32px auto 48px;
  padding: 0 24px;
}

.app-shell {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

h1 {
  font-size: clamp(30px, 4vw, 38px);
  margin: 0;
  color: var(--heading);
  line-height: 1.1;
  letter-spacing: -0.03em;
}

h2 {
  font-size: 18px;
  margin: 0;
  color: var(--heading);
  line-height: 1.2;
}

.muted { color: var(--text-muted); font-size: 14px; }

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #475569;
}

.cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.card {
  padding: 24px;
  border-radius: 18px;
  color: var(--heading);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.card-label {
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.card-value {
  font-size: clamp(34px, 5vw, 46px);
  font-weight: 700;
  line-height: 1.05;
  margin: 10px 0 8px;
  letter-spacing: -0.03em;
}

.card-sub { font-size: 14px; color: var(--text-muted); }

.status-on_track {
  background: linear-gradient(180deg, #ffffff 0%, #f2fbf5 100%);
  border-color: #b7e2c0;
}

.status-at_risk  {
  background: linear-gradient(180deg, #ffffff 0%, #fff8ef 100%);
  border-color: #f3d3a5;
}

.status-behind   {
  background: linear-gradient(180deg, #ffffff 0%, #fff4f4 100%);
  border-color: #efc0c0;
}

.block { margin-top: 0; }

.section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.section-heading .muted {
  margin: 6px 0 0;
}

.chart-card canvas {
  display: block;
  width: 100%;
}

.qtd .badge {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  margin-left: 8px;
}

.badge.ok   { background: #dcfce7; color: #166534; }
.badge.warn { background: #ffedd5; color: #9a3412; }
.badge.bad  { background: #fee2e2; color: #b91c1c; }

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  font-size: 14px;
}

th, td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid #edf2f7;
}

th {
  background: #f8fafc;
  font-weight: 700;
  color: #475569;
  white-space: nowrap;
}

tbody tr:hover { background: #f8fbff; }
tr:last-child td { border-bottom: none; }

.pill {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  text-transform: capitalize;
}

.pill-on_track { background: #dcfce7; color: #166534; }
.pill-at_risk  { background: #ffedd5; color: #9a3412; }
.pill-behind   { background: #fee2e2; color: #b91c1c; }

.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 560px;
}

.form.row {
  flex-direction: row;
  align-items: flex-end;
  max-width: none;
}

.compact-form {
  max-width: none;
}

.form .row { display: flex; gap: 16px; }
.form .row label { flex: 1; }

.form label {
  display: flex;
  flex-direction: column;
  font-size: 13px;
  font-weight: 600;
  color: #334155;
  gap: 6px;
}

.form input[type=text],
.form input[type=email],
.form input[type=password],
.form input[type=date],
.form input[type=number],
.form input[type=file],
.form select {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
}

.form input[type=text]:focus,
.form input[type=email]:focus,
.form input[type=password]:focus,
.form input[type=date]:focus,
.form input[type=number]:focus,
.form input[type=file]:focus,
.form select:focus {
  outline: none;
  border-color: #93c5fd;
  box-shadow: 0 0 0 4px rgba(147, 197, 253, 0.25);
}

button {
  padding: 11px 18px;
  border: none;
  background: var(--navy);
  color: #fff;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background-color 0.15s ease, transform 0.15s ease;
}

button:hover {
  background: #334155;
  transform: translateY(-1px);
}

.link-button {
  background: none;
  color: #b91c1c;
  padding: 0;
  font-size: 13px;
  font-weight: 600;
  text-decoration: underline;
}

.link-button:hover {
  background: none;
  transform: none;
}

.inline-form { margin-top: 16px; }

.errors {
  background: #fff5f5;
  color: #b42318;
  padding: 14px 16px;
  border: 1px solid #f3c7c7;
  border-radius: 14px;
}

.errors ul { margin: 0; padding-left: 18px; }

.flash {
  background: #fffbeb;
  color: #92400e;
  padding: 12px 16px;
  border: 1px solid #f4df9b;
  border-radius: 14px;
}

.flash p {
  margin: 0;
}

.errors-list {
  font-size: 13px;
  background: #fff;
  border: 1px solid #f0d0d0;
  border-radius: 12px;
  padding: 12px 16px 12px 32px;
  max-height: 240px;
  overflow: auto;
  margin: 6px 0 14px;
}

.errors-list li { color: #842029; margin-bottom: 2px; }

.upload-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr);
  gap: 20px;
}

.upload-card .form {
  max-width: none;
}

.side-card {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.helper-details {
  font-size: 14px;
}

.helper-details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--heading);
  margin-bottom: 12px;
}

.helper-details p {
  margin: 0 0 10px;
}

.danger-zone {
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.danger-title {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 700;
  color: #7f1d1d;
}

.section-link {
  margin: -8px 4px 0;
}

@media (max-width: 900px) {
  .cards,
  .upload-layout {
    grid-template-columns: 1fr;
  }

  .form.row,
  .form .row {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 720px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    padding: 16px 20px;
    gap: 12px;
  }

  .side-nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
  }

  .nav-group {
    display: none;
  }

  .container {
    margin: 24px auto 36px;
    padding: 0 16px;
  }

  .section-card,
  .card {
    padding: 18px;
    border-radius: 16px;
  }

  th, td {
    padding: 10px 12px;
  }
}

/* ---------------------------------------------- authentication & admin */

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 32px;
  background:
    radial-gradient(circle at 15% 10%, rgba(59, 130, 246, .10), transparent 32%),
    linear-gradient(145deg, #eef3f8 0%, #f8fafc 55%, #edf2f7 100%);
}

.auth-shell {
  display: grid;
  grid-template-columns: minmax(300px, .9fr) minmax(380px, 1.1fr);
  width: min(920px, 100%);
  min-height: 570px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid rgba(148, 163, 184, .35);
  border-radius: 24px;
  box-shadow: 0 28px 80px rgba(15, 23, 42, .14);
}

.auth-intro {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 52px 48px;
  color: #dbeafe;
  background:
    radial-gradient(circle at 15% 10%, rgba(96, 165, 250, .24), transparent 35%),
    linear-gradient(155deg, #17243a 0%, #1e293b 58%, #263753 100%);
}

.auth-logo-frame { width: 252px; height: 68px; }
.auth-logo-frame img { width: 338px; }
.config-logo-frame { width: 190px; height: 60px; }
.config-logo-frame img { width: 292px; }

.auth-kicker {
  margin: 54px 0 12px;
  color: #93c5fd;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.auth-intro h2 {
  max-width: 360px;
  margin: 0 0 18px;
  color: #fff;
  font-size: clamp(28px, 4vw, 38px);
  line-height: 1.08;
  letter-spacing: -.035em;
}

.auth-intro p:not(.auth-kicker) {
  max-width: 355px;
  margin: 0;
  color: #cbd5e1;
  font-size: 15px;
}

.auth-assurances {
  display: flex;
  flex-direction: column;
  gap: 11px;
  margin: 44px 0 0;
  padding: 0;
  list-style: none;
  color: #e2e8f0;
  font-size: 13px;
}

.auth-assurances li::before {
  content: "✓";
  display: inline-block;
  margin-right: 10px;
  color: #86efac;
  font-weight: 800;
}

.auth-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 52px clamp(34px, 6vw, 72px);
  background: #fff;
}

.auth-panel-inner { width: 100%; max-width: 370px; }
.auth-panel h1 { margin: 0 0 10px; font-size: 34px; }
.auth-lead { margin: 0; color: var(--text-muted); }
.auth-form { max-width: none; margin-top: 30px; gap: 18px; }
.auth-form label { font-size: 14px; }

.auth-form input[type=email],
.auth-form input[type=password],
.auth-form input[type=text] {
  min-height: 48px;
  font-size: 15px;
}

.password-field { position: relative; display: block; }
.password-field input { width: 100%; padding-right: 68px !important; }

.password-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  padding: 7px 9px;
  color: #475569;
  background: transparent;
  font-size: 12px;
}

.password-toggle:hover {
  color: #0f172a;
  background: #f1f5f9;
  transform: translateY(-50%);
}

.auth-submit { min-height: 48px; margin-top: 4px; width: 100%; }
.auth-submit:disabled { cursor: wait; opacity: .72; transform: none; }
.auth-message { margin-top: 22px; }
.auth-message p { margin: 0; }

.auth-help {
  margin: 24px 0 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border: 1px solid #e4e6eb;
  border-radius: 12px;
  padding: 32px;
  box-shadow: 0 6px 24px rgba(16, 24, 40, .06);
}

.auth-card h1 { margin: 4px 0 8px; }
.auth-card .form { margin-top: 20px; }
.auth-card button[type="submit"] { width: 100%; }

@media (max-width: 760px) {
  .auth-body { padding: 18px; align-items: flex-start; }
  .auth-shell { grid-template-columns: 1fr; min-height: 0; border-radius: 20px; }
  .auth-intro { padding: 28px 30px; }
  .auth-kicker { margin-top: 28px; }
  .auth-intro h2 { font-size: 27px; max-width: 420px; }
  .auth-intro p:not(.auth-kicker), .auth-assurances { display: none; }
  .auth-panel { padding: 36px 30px 40px; }
}

@media (max-width: 420px) {
  .auth-body { padding: 0; background: #fff; }
  .auth-shell { border: 0; border-radius: 0; box-shadow: none; }
  .auth-intro { padding: 22px 24px; }
  .auth-kicker, .auth-intro h2 { display: none; }
  .auth-panel { padding: 34px 24px 40px; }
}

.user-block {
  margin-top: auto;
  padding: 16px 0 0;
  border-top: 1px solid rgba(255, 255, 255, .12);
  font-size: .85rem;
}
.user-block .user-name { margin: 0; font-weight: 600; color: #f8fafc; }
.user-block .user-role { margin: 2px 0 10px; color: #94a3b8; font-size: .78rem; }

/* The sidebar is dark, so these must not inherit the page's blue link colour
   or the red of .link-button — both are unreadable against the navy. */
.user-block a,
.user-block .link-button {
  display: block;
  color: #cbd5e1;
  font-weight: 500;
  font-size: .82rem;
  text-decoration: none;
  padding: 3px 0;
}
.user-block a:hover,
.user-block .link-button:hover {
  color: #ffffff;
  text-decoration: underline;
  background: none;
}

.data-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.data-table th, .data-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid #eceef2;
  vertical-align: middle;
}
.data-table th { font-weight: 600; color: #667085; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.data-table tr:last-child td { border-bottom: none; }
.data-table select { padding: 4px 6px; font-size: .85rem; }

.inline-form { display: inline; margin: 0; }

/* ------------------------------------------------------ facility switcher */

.facility-switcher {
  padding: 0 0 16px;
  border-bottom: 1px solid rgba(255, 255, 255, .12);
}
.facility-switcher .switcher-label {
  margin: 0 0 5px;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #64748b;
}
.facility-switcher select {
  width: 100%;
  padding: 6px 8px;
  font-size: .85rem;
  color: #f8fafc;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 6px;
}
.facility-switcher select:focus {
  outline: none;
  border-color: #93c5fd;
}
.facility-switcher select option { color: #0f172a; background: #ffffff; }
.facility-switcher .switcher-single {
  margin: 0;
  font-weight: 600;
  font-size: .9rem;
  color: #f8fafc;
}
.facility-switcher .inline-form { margin-top: 0; }

.facility-row { margin-top: 14px; }
.facility-active { border-left: 3px solid #2f9e44; }

/* ------------------------------------------------------- platform console */

.acting-banner {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 22px;
  background: #7c2d12;
  color: #ffedd5;
  font-size: .88rem;
}
.acting-banner strong { color: #ffffff; }
.acting-banner .inline-form { margin: 0; }
.acting-banner .link-button { color: #ffedd5; }
.acting-banner .link-button:hover { color: #ffffff; }

.platform-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.mini-metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.mini-metric span {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.mini-metric strong {
  display: block;
  color: var(--heading);
  font-size: 26px;
  margin-top: 6px;
}

.two-column-admin {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.table-actions {
  align-items: flex-start;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 125px;
}

.activity-list { display: flex; flex-direction: column; }

.activity-row {
  align-items: center;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding: 12px 0;
}

.activity-row:first-child { padding-top: 0; }
.activity-row:last-child { border-bottom: 0; padding-bottom: 0; }
.activity-row time { color: var(--text-muted); font-size: 12px; white-space: nowrap; }

.detail-list { margin: 0; }

.detail-list div {
  align-items: baseline;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 20px;
  justify-content: space-between;
  padding: 11px 0;
}

.detail-list div:first-child { padding-top: 0; }
.detail-list div:last-child { border-bottom: 0; padding-bottom: 0; }
.detail-list dt { color: var(--text-muted); }
.detail-list dd { margin: 0; max-width: 65%; text-align: right; word-break: break-word; }

@media (max-width: 900px) {
  .platform-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-column-admin { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .platform-metrics { grid-template-columns: 1fr; }
}

.data-table tr.row-active { background: #f0fdf4; }
.pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  background: #e2e8f0;
  color: #334155;
}

/* --------------------------------------------------------- destructive UI */

.danger-button {
  background: #b91c1c;
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
}
.danger-button:hover { background: #991b1b; transform: none; }

.confirm-form { margin-top: 10px; max-width: 320px; }
.confirm-form input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.row-danger > summary {
  cursor: pointer;
  color: #b91c1c;
  font-size: .82rem;
  font-weight: 600;
}
.row-danger[open] {
  padding: 10px;
  border: 1px solid #f3c7c7;
  border-radius: 8px;
  background: #fef6f6;
  min-width: 260px;
}
