/* MAD'R Ops Console — desktop-first web backend */
:root {
  --bg: #071018;
  --bg-2: #0c1520;
  --panel: rgba(255, 255, 255, 0.04);
  --panel-border: rgba(255, 255, 255, 0.09);
  --text: #eef2f5;
  --muted: rgba(240, 242, 245, 0.68);
  --accent: #ff9d31;
  --accent-2: #ffbf66;
  --teal: #5ed0c3;
  --green: #33d46c;
  --red: #ff5252;
  --yellow: #ffe033;
  --sidebar: 260px;
  --radius: 16px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
  font-family: "Barlow", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 158, 44, 0.12), transparent 30%),
    radial-gradient(circle at top right, rgba(94, 208, 195, 0.08), transparent 26%),
    linear-gradient(180deg, #071018 0%, #05080d 100%);
}
body { min-height: 100vh; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}
button { cursor: pointer; }
a { color: var(--accent-2); }

.hidden { display: none !important; }

/* ── Login ─────────────────────────────────────────── */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 18px;
}
.login-card {
  width: min(520px, 100%);
  background: linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.02));
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 28px;
}
.login-logo {
  display: block;
  width: 88px;
  height: auto;
  margin: 0 auto 6px;
}
.login-card .eyebrow {
  display: inline-flex;
  padding: 7px 11px;
  border-radius: 999px;
  background: rgba(255,158,44,.14);
  border: 1px solid rgba(255,158,44,.26);
  color: #ffd8a1;
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: 11px;
  font-weight: 700;
}
.login-card h1 {
  font-family: "Bebas Neue", "Barlow", sans-serif;
  font-size: 54px;
  letter-spacing: 3px;
  color: var(--accent-2);
  margin: 12px 0 8px;
  line-height: .95;
}
.login-card p { color: var(--muted); line-height: 1.55; margin: 0 0 18px; }
.login-form { display: grid; gap: 12px; }
.login-form label { font-size: 13px; color: var(--muted); display: grid; gap: 6px; }
.login-form input, .login-form select, .field, .ops-input, .ops-select, .ops-textarea {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.05);
  padding: 12px 14px;
  color: var(--text);
}
.ops-textarea { min-height: 110px; resize: vertical; }
.ops-select option {
  background: #0f171f;
  color: #e8eef3;
}
.demo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
}
.btn {
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.05);
  color: var(--text);
  padding: 11px 14px;
  font-family: "Rajdhani", "Barlow", sans-serif;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #091018;
  border: none;
}
.btn.danger { border-color: rgba(255,82,82,.35); color: #ffc9c9; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.login-error {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255,82,82,.12);
  border: 1px solid rgba(255,82,82,.28);
  color: #ffc9c9;
  display: none;
}
.login-error.show { display: block; }
.login-note {
  margin-top: 14px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

/* ── App shell ─────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  min-height: 100vh;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  border-right: 1px solid var(--panel-border);
  background: linear-gradient(180deg, rgba(12,21,32,.98), rgba(7,16,24,.98));
  padding: 20px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.brand-mark {
  padding: 8px 10px 4px;
}
.brand-mark .eyebrow {
  display: inline-flex;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(94,208,195,.12);
  border: 1px solid rgba(94,208,195,.24);
  color: #d9fff9;
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: 10px;
  font-weight: 700;
}
.brand-mark h1 {
  font-family: "Bebas Neue", sans-serif;
  font-size: 40px;
  letter-spacing: 2px;
  margin: 10px 0 0;
  color: var(--accent-2);
  line-height: .9;
}
.brand-mark p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}
.nav {
  display: grid;
  gap: 4px;
  margin-top: 8px;
}
.nav button {
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 12px;
  padding: 11px 12px;
  font-weight: 600;
}
.nav button:hover { background: rgba(255,255,255,.04); color: var(--text); }
.nav button.active {
  background: rgba(255,158,44,.12);
  border-color: rgba(255,158,44,.24);
  color: #ffe1b3;
}
.nav .nav-section {
  margin: 12px 8px 4px;
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: rgba(240,242,245,.42);
  font-weight: 700;
}

/* Collapsible nav groups (P3) */
.nav-group { display: grid; gap: 2px; }
.nav-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 12px 8px 4px;
  padding: 4px 6px;
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: rgba(240,242,245,.55);
  font-weight: 700;
  background: transparent;
  border: none;
  cursor: pointer;
  border-radius: 8px;
}
.nav-group-head:hover { background: rgba(255,255,255,.05); color: rgba(240,242,245,.85); }
.nav-group-head .ng-chev { transition: transform .2s ease; font-size: 10px; }
.nav-group:not(.open) .nav-group-head .ng-chev { transform: rotate(-90deg); }
.nav-group:not(.open) .nav-group-body { display: none; }
.nav-group-body { display: grid; gap: 4px; }

/* Mobile nav drawer */
.nav-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  font-size: 19px;
  cursor: pointer;
  flex-shrink: 0;
}
.nav-scrim {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 290;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
}

/* Sub-tab bar for consolidated views (P4) */
.subtab-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 10px;
}
.subtab {
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.subtab:hover { background: rgba(255,255,255,.05); color: var(--text); }
.subtab.active {
  background: rgba(255,158,44,.14);
  border-color: rgba(255,158,44,.32);
  color: #ffe1b3;
}

/* Checklist editor question rows (P4) */
.tmpl-q {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-radius: 12px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
  margin-bottom: 8px;
}
.tmpl-q .tmpl-q-text {
  flex: 1;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.05);
  color: var(--text);
  font: inherit;
}
.tmpl-q .tmpl-q-reqlbl {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}
@media (max-width: 720px) {
  .tmpl-q { flex-wrap: wrap; }
  .tmpl-q .tmpl-q-text { flex-basis: 100%; }
}
.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,.06);
}
.user-chip {
  padding: 12px;
  border-radius: 14px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.07);
}
.user-chip strong { display: block; font-size: 15px; }
.user-chip span { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--panel-border);
  background: rgba(7, 16, 24, 0.88);
  backdrop-filter: blur(12px);
}
.topbar h2 {
  margin: 0;
  font-family: "Rajdhani", sans-serif;
  font-size: 28px;
  letter-spacing: .5px;
}
.topbar p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.content {
  padding: 22px 24px 48px;
  display: grid;
  gap: 18px;
}

.panel {
  background: linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,.018));
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.panel h3 {
  margin: 0;
  font-family: "Rajdhani", sans-serif;
  font-size: 22px;
}
.panel .sub {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.metric {
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(255,255,255,.035);
  border: 1px solid rgba(255,255,255,.07);
}
.metric small {
  display: block;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .1em;
  font-size: 11px;
  font-weight: 700;
}
.metric strong {
  display: block;
  margin-top: 8px;
  font-family: "Rajdhani", sans-serif;
  font-size: 30px;
  line-height: 1;
}
.metric.alert strong { color: var(--red); }
.metric.warn strong { color: var(--accent-2); }
.metric.ok strong { color: var(--green); }

.split {
  display: grid;
  grid-template-columns: 1.15fr .85fr;
  gap: 16px;
}
.split-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.table-wrap { overflow: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}
table.data th, table.data td {
  text-align: left;
  padding: 11px 10px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  vertical-align: top;
  font-size: 14px;
}
table.data th {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  font-weight: 700;
}
table.data tr:hover td { background: rgba(255,255,255,.025); }
table.data tr.selected td { background: rgba(255,158,44,.08); }
table.data tr[data-ca-id],
table.data tr[data-sub-id],
table.data tr[data-review-id] { cursor: pointer; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  border: 1px solid rgba(255,255,255,.1);
  background: rgba(255,255,255,.05);
}
.badge.ok { color: #b8ffd0; border-color: rgba(51,212,108,.28); background: rgba(51,212,108,.12); }
.badge.warn { color: #ffe1b3; border-color: rgba(255,158,44,.28); background: rgba(255,158,44,.12); }
.badge.bad { color: #ffc9c9; border-color: rgba(255,82,82,.28); background: rgba(255,82,82,.12); }
.badge.teal { color: #d9fff9; border-color: rgba(94,208,195,.28); background: rgba(94,208,195,.12); }

/* Critical incident urgency (P2) */
.crit-banner {
  border: 1px solid rgba(255,82,82,.45);
  background: rgba(255,82,82,.14);
  color: #ffd9d9;
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 14px;
  font-size: 15px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}
.crit-banner .btn { margin-left: auto; }
table.data tr.crit-row td { background: rgba(255,82,82,.10); }
table.data tr.crit-row td:first-child { border-left: 3px solid rgba(255,82,82,.65); }
table.data tr.crit-row.selected td { background: rgba(255,82,82,.18); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 14px;
}
.form-grid .full { grid-column: 1 / -1; }
.form-grid label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}
.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}
.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 12px;
}
.toolbar .spacer { flex: 1; }
.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed rgba(255,255,255,.14);
  border-radius: 14px;
}
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  max-width: 380px;
  padding: 12px 16px;
  border-radius: 12px;
  background: #12202d;
  border: 1px solid rgba(255,158,44,.35);
  box-shadow: var(--shadow);
  display: none;
}
.toast.show { display: block; }
.detail-block {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}
.detail-block .row-line {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 10px;
  font-size: 14px;
}
.detail-block .row-line span:first-child { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  padding: 7px 11px;
  border-radius: 999px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.check-list {
  display: grid;
  gap: 8px;
}
.check-list label {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.06);
  color: var(--text);
  font-size: 14px;
}
.check-list input { margin-top: 3px; }

.prose {
  white-space: pre-wrap;
  line-height: 1.55;
  color: var(--text);
  font-size: 14px;
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(0,0,0,.22);
  border: 1px solid rgba(255,255,255,.06);
}
.kv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 14px;
}
.kv-item {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.06);
}
.kv-item .k {
  display: block;
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 4px;
}
.kv-item .v { font-size: 14px; line-height: 1.4; }
.list-item-btn {
  width: 100%;
  text-align: left;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.03);
  padding: 12px 14px;
  color: var(--text);
  display: grid;
  gap: 6px;
  cursor: pointer;
  pointer-events: auto;
  -webkit-appearance: none;
  appearance: none;
}
.list-item-btn:hover { background: rgba(255,255,255,.05); }
.list-item-btn.selected {
  border-color: rgba(255,158,44,.35);
  background: rgba(255,158,44,.1);
}
.list-item-btn .title-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}
.list-item-btn .meta { color: var(--muted); font-size: 12px; line-height: 1.4; }
.stack-list { display: grid; gap: 8px; max-height: 70vh; overflow: auto; }
.filter-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.filter-bar input, .filter-bar select {
  min-width: 160px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.05);
  padding: 10px 12px;
}
.ppe-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.ppe-pill.yes { background: rgba(51,212,108,.14); color: #b8ffd0; border: 1px solid rgba(51,212,108,.3); }
.ppe-pill.partial { background: rgba(255,158,44,.14); color: #ffe1b3; border: 1px solid rgba(255,158,44,.3); }
.ppe-pill.no { background: rgba(255,82,82,.14); color: #ffc9c9; border: 1px solid rgba(255,82,82,.3); }
.reason-list { margin: 8px 0 0; padding-left: 18px; color: #ffd0d0; font-size: 13px; line-height: 1.45; }
.reason-list.ok { color: #c8ffd8; }
.section-label {
  margin: 16px 0 8px;
  font-size: 12px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}
.scan-items {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}
.scan-box {
  padding: 12px;
  border-radius: 12px;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.07);
}
.scan-box h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.scan-box ul { margin: 0; padding-left: 18px; font-size: 14px; line-height: 1.5; }
.worker-card {
  padding: 14px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.03);
  display: grid;
  gap: 8px;
}
.worker-card.flagged { border-color: rgba(255,82,82,.35); background: rgba(255,82,82,.06); }
.worker-card.warn { border-color: rgba(255,158,44,.35); background: rgba(255,158,44,.06); }
.worker-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

@media (max-width: 1180px) {
  .metrics, .split, .split-3, .form-grid, .worker-grid, .kv-grid, .scan-items { grid-template-columns: 1fr; }
  .app-shell { grid-template-columns: 1fr; }
  /* Sidebar becomes an off-canvas drawer (was: 24-button wall above content) */
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(300px, 85vw);
    height: auto;
    z-index: 300;
    transform: translateX(-102%);
    transition: transform .25s ease;
    border-right: 1px solid var(--panel-border);
    border-bottom: none;
    overflow-y: auto;
    box-shadow: 12px 0 40px rgba(0,0,0,.4);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .nav-scrim { opacity: 1; pointer-events: auto; }
  .nav-menu-btn { display: inline-flex; }
  .topbar { gap: 10px; }
}
@media (max-width: 720px) {
  .demo-grid { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .detail-block .row-line { grid-template-columns: 1fr; }
}

/* Evidence / Safety Vision photo strip */
.evidence-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 10px 0 6px;
}
.evidence-thumb {
  display: block;
  width: 96px;
  height: 96px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--panel-border);
  background: rgba(0, 0, 0, 0.25);
  flex-shrink: 0;
}
.evidence-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.evidence-thumb:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(255, 157, 49, 0.35);
}
.evidence-links {
  margin: 0 0 12px;
  padding-left: 1.2rem;
  color: var(--muted);
  font-size: 13px;
}
.evidence-links a { word-break: break-all; }
.evidence-empty {
  margin: 6px 0 12px;
  font-style: italic;
}
