:root {
  --bg: #f4f6f9; --panel: #fff; --ink: #1b2430; --muted: #66707d; --line: #e1e5eb;
  --brand: #1f4e79; --brand-2: #2d6aa3; --side: #15283c;
  --good: #1e7b4f; --good-bg: #e3f3ea; --warn: #9a6400; --warn-bg: #fdf1dc; --bad: #a3322d; --bad-bg: #fbe5e3;
  --info-bg: #e6eef7;
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: var(--ink); background: var(--bg); display: flex; }
a { color: var(--brand-2); }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 24px 0 10px; }
h3 { font-size: 15px; margin: 16px 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.sidebar { width: 230px; flex: none; background: var(--side); color: #cfd8e3; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 18px; color: #fff; padding: 20px 20px 16px; }
.logo { color: #7fb3e6; }
nav a { display: block; padding: 9px 20px; color: #cfd8e3; text-decoration: none; border-left: 3px solid transparent; }
nav a:hover { background: rgba(255,255,255,.05); color: #fff; }
nav a.active { background: rgba(255,255,255,.08); color: #fff; border-left-color: #7fb3e6; }
.sidebar-foot { margin-top: auto; padding: 16px 20px; font-size: 12px; color: #7d8ea3; }

main { flex: 1; padding: 28px 36px 60px; overflow-x: auto; min-width: 0; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn { border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 7px 13px; border-radius: 6px; cursor: pointer; font: inherit; text-decoration: none; display: inline-block; }
.btn:hover { border-color: #b9c2cd; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 3px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .n { font-size: 26px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }

table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; background: #fafbfc; }
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
td.num, th.num { text-align: right; white-space: nowrap; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid #cdd3db; border-radius: 6px; background: #fff; color: var(--ink); }
textarea { width: 100%; min-height: 70px; resize: vertical; }
label { display: block; font-size: 12px; font-weight: 600; color: #3d4652; margin-bottom: 3px; }
.field { margin-bottom: 12px; }
.field input, .field select { width: 100%; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; background: #eef1f5; color: #3d4652; white-space: nowrap; }
.b-verified { background: var(--good-bg); color: var(--good); }
.b-estimated { background: var(--warn-bg); color: var(--warn); }
.b-inferred, .b-owner { background: var(--info-bg); color: var(--brand); }
.b-nodata { background: #eef1f5; color: var(--muted); }
.b-BUILD { background: var(--good-bg); color: var(--good); }
.b-INVESTIGATE { background: var(--warn-bg); color: var(--warn); }
.b-REJECT { background: var(--bad-bg); color: var(--bad); }
.b-rising { background: var(--good-bg); color: var(--good); }
.b-falling { background: var(--bad-bg); color: var(--bad); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px; cursor: pointer; }
.card:hover { border-color: #9fb6cf; box-shadow: 0 2px 8px rgba(21,40,60,.06); }
.card-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.card h3 { margin: 0; font-size: 15px; }
.score { flex: none; width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 18px; border: 4px solid; }
.score.hi { border-color: var(--good); color: var(--good); }
.score.mid { border-color: #d39b2a; color: var(--warn); }
.score.lo { border-color: #c9cfd7; color: var(--muted); }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; font-size: 13px; }
.kv span:nth-child(odd) { color: var(--muted); }

.bar { height: 8px; background: #eef1f5; border-radius: 4px; overflow: hidden; min-width: 80px; }
.bar > i { display: block; height: 100%; background: var(--brand-2); }
.bar.nodata > i { background: #c9cfd7; }

.notice { background: var(--info-bg); border-left: 3px solid var(--brand-2); padding: 10px 14px; border-radius: 4px; margin-bottom: 14px; font-size: 13px; }
.notice.warn { background: var(--warn-bg); border-color: #d39b2a; }
.notice.bad { background: var(--bad-bg); border-color: var(--bad); }
.ai-box { border: 1px dashed #9fb6cf; background: #f7fafd; border-radius: var(--radius); padding: 12px 14px; margin: 10px 0; }
.ai-box .ai-label { font-size: 11px; font-weight: 700; color: var(--brand); text-transform: uppercase; letter-spacing: .04em; }
.ai-box pre, .report pre { white-space: pre-wrap; font: inherit; margin: 6px 0 0; }
.evidence-list { margin: 6px 0 0; padding-left: 18px; }
.evidence-list li { margin-bottom: 4px; }
.quote { font-style: italic; color: #3d4652; }
.links-list a { display: inline-block; margin: 2px 8px 2px 0; }
.empty { text-align: center; padding: 30px; color: var(--muted); }
.steps { margin: 0; padding-left: 20px; }
.steps li { margin-bottom: 6px; }

.modal { position: fixed; inset: 0; background: rgba(15,25,40,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow: auto; z-index: 10; }
.modal.hidden, .toast.hidden { display: none; }
.modal-box { background: #fff; border-radius: 10px; width: min(760px, 100%); padding: 22px 24px; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.modal-box h2 { margin-top: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--side); color: #fff; padding: 10px 16px; border-radius: 6px; z-index: 20; max-width: 420px; }
.toast.error { background: var(--bad); }

.report h1 { font-size: 20px; } .report h2 { border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.report table { font-size: 13px; }

@media (max-width: 800px) {
  body { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  nav { display: flex; flex-wrap: wrap; } nav a { padding: 6px 10px; border-left: 0; }
  .sidebar-foot { display: none; }
  main { padding: 18px; }
  .form-grid { grid-template-columns: 1fr; }
}
@media print {
  .sidebar, .actions, .toolbar, .no-print { display: none !important; }
  main { padding: 0; } body { background: #fff; }
  .panel { border: 0; padding: 0; }
}

/* ---- Mission 008: sign-in page, backups, mobile reliability ---- */
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.btn.wide { width: 100%; }
.nav-signout { margin-top: 10px; border-top: 1px solid rgba(255,255,255,.1); }
.login-page { display: block; background: var(--side); min-height: 100vh; padding: 16px; }
.login-box { background: #fff; max-width: 400px; margin: 8vh auto 0; padding: 28px 26px; border-radius: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.login-box .brand { color: var(--brand); padding: 0 0 6px; }
.login-box h1 { margin-top: 6px; }
.login-box .field input { width: 100%; }
.login-box code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; }
.notice ul { margin: 6px 0 0; padding-left: 20px; }
.btn.danger.primary, #rs-go { background: var(--bad); border-color: var(--bad); color: #fff; }
#rs-go:disabled { opacity: .4; }

@media (max-width: 800px) {
  input, select, textarea { font-size: 16px; }            /* stops iPhone Safari zooming into fields */
  .btn { min-height: 44px; padding: 10px 14px; display: inline-flex; align-items: center; }
  .btn.sm { min-height: 36px; }
  .sidebar { position: sticky; top: 0; z-index: 5; }
  nav { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  nav::-webkit-scrollbar { display: none; }
  nav a { white-space: nowrap; flex: none; padding: 12px 14px; }
  .nav-signout { margin-top: 0; border-top: 0; color: #ffb4ae; }
  .modal { padding: 12px; }
  .modal-box { padding: 16px; max-width: 100%; }
  .modal-foot { flex-wrap: wrap; }
  .modal-foot .btn { flex: 1; justify-content: center; }
  .login-box { margin-top: 4vh; padding: 22px 18px; }
  .page-head .actions { width: 100%; }
  .kv { grid-template-columns: 1fr; gap: 0; } .kv span:nth-child(even) { margin-bottom: 6px; }
}

@media (max-width: 800px) {
  .stack-table thead { display: none; }
  .stack-table, .stack-table tbody, .stack-table tr, .stack-table td { display: block; width: 100%; }
  .stack-table tr { padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .stack-table td { border: 0; padding: 3px 0; text-align: left !important; }
  .stack-table td.num { white-space: normal; }
  .stack-table .actions-cell { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 8px; white-space: normal; }
  .stack-table .actions-cell .btn { flex: 1 1 auto; justify-content: center; }
}
