:root {
  --bg: #fafafa;
  --panel: #ffffff;
  --border: #e3e3e8;
  --ink: #1a1a2e;
  --ink-mute: #5a5a72;
  --ink-faint: #9494a6;
  --critical: #cc0000;
  --critical-bg: #fdecec;
  --behind: #f57c00;
  --behind-bg: #fff4e6;
  --ahead: #0a8a0a;
  --ahead-bg: #e8f5e9;
  --primary: #1a73e8;
  --primary-ink: #ffffff;
  --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--ink);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.topbar .brand h1 { margin: 0; font-size: 18px; font-weight: 600; }
.topbar .brand .meta { color: #aaa; font-size: 12px; margin-top: 2px; }

.topnav { display: flex; gap: 4px; }
.topnav .navlink {
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
}
.topnav .navlink:hover { color: #fff; background: rgba(255,255,255,0.08); }
.topnav .navlink.active { color: #fff; background: rgba(255,255,255,0.16); border-color: rgba(255,255,255,0.25); }

.brand-actions { display: flex; gap: 6px; align-items: center; }
.brand-actions .btn-ghost {
  background: rgba(255,255,255,0.08);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.18);
  padding: 5px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
}
.brand-actions .btn-ghost:hover { background: rgba(255,255,255,0.16); }
.brand-actions .btn-ghost:disabled { opacity: 0.55; cursor: progress; }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
}

.loader, .empty { padding: 40px; text-align: center; color: var(--ink-mute); }
.error {
  background: var(--critical-bg);
  color: var(--critical);
  border: 1px solid #f5c2c2;
  padding: 14px;
  border-radius: 6px;
  margin: 20px 0;
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.tile {
  display: block;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 20px;
  text-decoration: none;
  color: var(--ink);
  box-shadow: var(--shadow);
  transition: transform 80ms ease, box-shadow 80ms ease;
}
.tile:hover { transform: translateY(-1px); box-shadow: 0 2px 6px rgba(0,0,0,0.07), 0 4px 12px rgba(0,0,0,0.05); }
.tile-title { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.tile-meta { font-size: 12px; color: var(--ink-mute); }

.briefing-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.briefing-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 18px;
  background: #f4f4f8;
  border-bottom: 1px solid var(--border);
}
.briefing-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.briefing-meta { font-size: 12px; color: var(--ink-mute); }
.briefing-frame { padding: 0; }
.briefing-frame iframe { display: block; width: 100%; border: none; }

.stale-banner {
  margin: 12px 18px 0;
  padding: 10px 14px;
  background: var(--behind-bg);
  color: var(--behind);
  border: 1px solid #f5d6a8;
  border-radius: 6px;
  font-size: 13px;
}

/* Audit page */
.audit-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}
.filter-group { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.group-label { color: var(--ink-faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; margin-right: 4px; }
.btn-pill {
  font: inherit;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--ink);
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
}
.btn-pill:hover { background: #f0f0f4; }
.btn-pill.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.audit-counts { font-size: 12px; color: var(--ink-mute); }

.audit-prop {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.audit-prop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #f4f4f8;
  border-bottom: 1px solid var(--border);
}
.audit-prop-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.audit-prop-head .pcode { color: var(--ink-faint); font-weight: 500; margin-left: 6px; font-size: 12px; }
.audit-prop-head .pcount { font-size: 12px; color: var(--ink-mute); }

.audit-row {
  display: grid;
  grid-template-columns: 110px 1fr auto;
  gap: 14px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  align-items: start;
}
.audit-row:last-child { border-bottom: none; }
.audit-row .sev {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-align: center;
}
.audit-row .sev.AUTO_APPLY { background: #e8f0ff; color: #2a4a8a; }
.audit-row .sev.QUICK_EDIT { background: #fff4e6; color: #f57c00; }
.audit-row .sev.DEEP_DIVE { background: #fdecec; color: #cc0000; }
.audit-row .sev.FYI       { background: #f0f0f4; color: #6a6a7e; }
.audit-row .body .field-name { font-weight: 600; font-size: 13px; }
.audit-row .body .field-name .label { color: var(--ink-faint); font-weight: 500; margin-right: 4px; }
.audit-row .body .delta { font-size: 12px; color: var(--ink-mute); margin-top: 2px; font-variant-numeric: tabular-nums; }
.audit-row .body .delta code { background: #f1f3f5; padding: 1px 4px; border-radius: 3px; font-size: 12px; }
.audit-row .body .reason { font-size: 12px; color: var(--ink-mute); margin-top: 4px; }
.audit-row .actions { display: flex; gap: 6px; align-items: flex-start; }
.audit-row .actions button {
  font: inherit;
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 5px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink);
}
.audit-row .actions .btn-apply {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.audit-row .actions .btn-apply:hover { filter: brightness(0.95); }
.audit-row .actions .btn-snooze:hover { background: #f0f0f4; }
.audit-row .actions button:disabled { opacity: 0.5; cursor: progress; }
.audit-row.applied .body { opacity: 0.4; }
.audit-row.applied .actions { display: none; }

/* Login overlay */
body.login-mode .topbar, body.login-mode #main { display: none; }
#loginOverlay {
  position: fixed; inset: 0;
  background: #f5f5f8;
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
#loginForm {
  background: #fff;
  padding: 32px 36px;
  border-radius: 8px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
#loginForm h2 { margin: 0 0 8px; font-size: 18px; color: var(--ink); }
#loginForm label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-mute); font-weight: 500; }
#loginForm input { padding: 8px 10px; border: 1px solid var(--border); border-radius: 4px; font-size: 14px; }
#loginForm input:focus { outline: none; border-color: var(--primary); }
#loginForm button {
  background: var(--primary);
  color: #fff;
  border: 0;
  padding: 10px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}
#loginForm button:hover { filter: brightness(0.95); }
.login-error { color: var(--critical); font-size: 12px; }

@media (max-width: 720px) {
  .topbar { flex-direction: column; align-items: stretch; }
  .topnav { justify-content: flex-start; }
  .audit-row { grid-template-columns: 1fr; }
  .audit-row .actions { justify-content: flex-end; }
}
