:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f0f0f3;
  --text: #17171c;
  --muted: #686874;
  --border: #e2e2e8;
  --accent: #e5262f;
  --accent-hover: #c81e26;
  --accent-soft: #fdecec;
  --on-accent: #ffffff;
  --ok: #18804a;
  --ok-soft: #e6f4ec;
  --err: #c0262d;
  --err-soft: #fdecec;
  --shadow: 0 1px 2px rgba(20, 20, 30, 0.04), 0 2px 8px rgba(20, 20, 30, 0.04);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101014;
    --surface: #18181e;
    --surface-2: #22222a;
    --text: #ededf2;
    --muted: #9b9ba8;
    --border: #2c2c35;
    --accent: #ff4b53;
    --accent-hover: #ff6870;
    --accent-soft: #3a1c1f;
    --ok: #52c98a;
    --ok-soft: #173326;
    --err: #ff7076;
    --err-soft: #3a1c1f;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
html, body { overflow-x: hidden; }
body { font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
h1 { font-size: 26px; line-height: 1.2; margin: 0 0 6px; letter-spacing: -0.01em; }
h3 { font-size: 15px; margin: 0 0 12px; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 13px; }
.error { color: var(--err); margin: 8px 0 0; }
.error:empty { display: none; }
.grow { flex: 1; min-width: 0; }

/* ---- buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 600; font-size: 14px; padding: 9px 14px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger-ghost { color: var(--err); }
.btn-block { width: 100%; }
.btn-lg { padding: 12px 20px; font-size: 15px; }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 6px; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 18px; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---- layout ---- */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 280px; flex: 0 0 280px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: 12px; padding: 16px; position: sticky; top: 0; height: 100vh; }
.sidebar-top { display: flex; align-items: center; justify-content: space-between; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: var(--text); text-decoration: none; }
.brand-lg { font-size: 22px; }
.side-section { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-top: 8px; }
.history { flex: 1; overflow-y: auto; margin: 0 -8px; }
.history a { display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 9px; color: var(--text); text-decoration: none; }
.history a:hover { background: var(--surface-2); }
.history a.active { background: var(--accent-soft); }
.history img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex: 0 0 32px; background: var(--surface-2); }
.history .h-text { min-width: 0; }
.history .h-text b { display: block; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history .h-text span { font-size: 12px; color: var(--muted); }
.pad { padding: 0 8px; }
.sidebar-bottom { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.side-link { color: var(--text); text-decoration: none; font-weight: 500; padding: 6px 0; }
.side-link:hover { color: var(--accent); }
.user { display: flex; align-items: center; gap: 10px; }
.user-text { min-width: 0; flex: 1; }
.user-text b, .user-text span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-text b { font-size: 14px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; }
.main { flex: 1; min-width: 0; padding: 32px 40px 64px; max-width: 1100px; }
.topbar { display: none; }
.only-mobile { display: none; }

/* ---- cards & forms ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.hero { margin: 8px 0 22px; max-width: 680px; }
.form label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.form input, .form select { display: block; width: 100%; padding: 11px 12px; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 9px; margin-bottom: 16px; }
.form input:focus, .form select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.form-row { display: flex; gap: 14px; flex-wrap: wrap; }
.form-row > div:first-child { flex: 0 0 180px; }
.help { color: var(--muted); font-size: 13px; margin: -8px 0 18px; }
.pill { display: inline-block; margin-left: 6px; padding: 1px 9px; font-size: 12px; font-weight: 600; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.notice { background: var(--accent-soft); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; }

.progress { display: flex; gap: 16px; align-items: center; }
.progress p { margin: 2px 0 0; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin 0.9s linear infinite; flex: 0 0 28px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- report ---- */
.report-head { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.report-head h1 { font-size: 22px; margin: 0; }
.report-head p { margin: 2px 0 0; }
.avatar-lg { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; background: var(--surface-2); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; margin: 4px 0 16px; border-bottom: 1px solid var(--border); }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 14px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; margin-bottom: -1px; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.markdown { line-height: 1.65; padding: 24px 28px; overflow-wrap: anywhere; }
.markdown h1 { font-size: 24px; margin: 0 0 12px; }
.markdown h2 { font-size: 19px; margin: 30px 0 10px; padding-top: 18px; border-top: 1px solid var(--border); }
.markdown h2:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.markdown h3 { font-size: 16px; margin: 20px 0 8px; }
.markdown blockquote { margin: 12px 0; padding: 10px 16px; background: var(--surface-2); border-left: 3px solid var(--accent); border-radius: 6px; }
.markdown blockquote p { margin: 0; }
.markdown hr { border: 0; border-top: 1px solid var(--border); margin: 22px 0; }
.markdown table { margin: 12px 0; display: block; overflow-x: auto; }
.markdown code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 0.92em; overflow-wrap: anywhere; white-space: pre-wrap; }
.markdown li { margin: 4px 0; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.kpi b { display: block; font-size: 22px; letter-spacing: -0.01em; }
.kpi span { color: var(--muted); font-size: 13px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td a { color: var(--text); }
.scroll { overflow: auto; max-height: 560px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tags span { background: var(--surface-2); border-radius: 999px; padding: 3px 11px; font-size: 13px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: 14px; z-index: 50; }

/* ---- login ---- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 36px 32px; max-width: 400px; width: 100%; text-align: center; box-shadow: var(--shadow); }
.login-lead { color: var(--muted); margin: 14px 0 24px; }
.btn-google { width: 100%; padding: 12px; font-size: 15px; }

/* ---- mobile ---- */
@media (max-width: 860px) {
  .only-mobile { display: initial; }
  .topbar { display: flex; align-items: center; gap: 8px; margin: -16px -16px 16px; padding: 10px 12px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
  .main { padding: 16px 16px 48px; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 20; transform: translateX(-100%); transition: transform 0.2s; visibility: hidden; }
  .sidebar.open { transform: none; visibility: visible; box-shadow: 0 0 40px rgba(0, 0, 0, 0.2); }
  .scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 10; }
  h1 { font-size: 22px; }
  .markdown { padding: 18px 16px; }
  .form-row > div:first-child { flex: 1 1 100%; }
}

/* ---- print: just the report ---- */
@media print {
  .sidebar, .topbar, .no-print, .scrim, .toast, #tab-metrics { display: none !important; }
  body { background: #fff; color: #000; }
  .main { padding: 0; max-width: none; }
  .card { border: 0; box-shadow: none; padding: 0; }
  #tab-recs { display: block !important; }
}
