:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e2e5ea;
  --text: #1b1f27;
  --muted: #667085;
  --accent: #2f6fde;
  --accent-soft: #e8f0fd;
  --good: #1a7f4b;
  --good-soft: #e6f4ec;
  --warn: #a35d00;
  --warn-soft: #fdf1df;
  --bad: #c4322b;
  --bad-soft: #fbe9e8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  color-scheme: light;
}
/* dark theme: follows the system unless the user picked Light / Dark (data-theme on <html>, set by theme.js) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111318;
    --surface: #181b22;
    --surface-2: #20242d;
    --border: #2c313c;
    --text: #e7e9ee;
    --muted: #98a0b0;
    --accent: #6e9df0;
    --accent-soft: #1f2b42;
    --good: #4cc38a;
    --good-soft: #15291f;
    --warn: #e5a54b;
    --warn-soft: #2e2415;
    --bad: #f07067;
    --bad-soft: #321b1a;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111318;
  --surface: #181b22;
  --surface-2: #20242d;
  --border: #2c313c;
  --text: #e7e9ee;
  --muted: #98a0b0;
  --accent: #6e9df0;
  --accent-soft: #1f2b42;
  --good: #4cc38a;
  --good-soft: #15291f;
  --warn: #e5a54b;
  --warn-soft: #2e2415;
  --bad: #f07067;
  --bad-soft: #321b1a;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; font-weight: 650; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }
p { margin: 0 0 8px; }
code, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.break { word-break: break-all; }
[hidden] { display: none !important; }

/* layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex: 0 0 220px; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 16px 12px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; color: var(--text);
  padding: 4px 8px 16px; }
.brand:hover { text-decoration: none; }
.brand svg, .icon-btn svg { width: 22px; height: 22px; fill: none; stroke: var(--accent); stroke-width: 2.4;
  stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg { stroke: var(--text); }
.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.nav a { color: var(--text); padding: 7px 10px; border-radius: 8px; display: block; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  padding: 14px 10px 4px; }
.nav .sub { padding-left: 20px; font-size: 13px; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.view { padding: 24px 28px 48px; max-width: 1240px; width: 100%; outline: none; }



/* components */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap;
  margin-bottom: 18px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); margin-bottom: 16px; min-width: 0; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin-bottom: 16px; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 24px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .hint { color: var(--muted); font-size: 12px; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: 8px; padding: 7px 12px; font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--bad); }
.btn-sm { padding: 4px 9px; font-size: 12.5px; }
.btn-link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font: inherit; text-align: left; }
.icon-btn { background: none; border: 0; padding: 4px; cursor: pointer; display: inline-flex; }

form .row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
label { font-weight: 550; font-size: 13px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; width: 100%; min-width: 0;
}
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters > * { width: auto; }
.filters input { min-width: 200px; }
.form-grid { display: grid; gap: 0 14px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.url-cell { max-width: 420px; word-break: break-all; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 550;
  background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--accent-soft); color: var(--accent); }

.score { display: inline-flex; align-items: center; justify-content: center; width: 64px; height: 64px; border-radius: 50%;
  font-size: 22px; font-weight: 700; border: 5px solid var(--border); }
.score.good { border-color: var(--good); color: var(--good); }
.score.warn { border-color: var(--warn); color: var(--warn); }
.score.bad { border-color: var(--bad); color: var(--bad); }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto;
  scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.issue { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; background: var(--surface); }
.issue summary { padding: 10px 14px; cursor: pointer; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.issue summary::-webkit-details-marker { display: none; }
.issue .body { padding: 0 14px 12px; }
.issue ul { margin: 6px 0 0; padding-left: 18px; }

.list-plain { list-style: none; padding: 0; margin: 0; }
.list-plain li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.list-plain li:last-child { border-bottom: 0; }
.reasons li { padding: 3px 0; border: 0; }

.notice { padding: 10px 14px; border-radius: var(--radius); background: var(--accent-soft); color: var(--text);
  margin-bottom: 14px; border: 1px solid transparent; }
.notice.warn { background: var(--warn-soft); }
.notice.bad { background: var(--bad-soft); }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 8px 0; }
.progress > div { height: 100%; background: var(--accent); transition: width .4s; }
.kv { display: grid; grid-template-columns: minmax(120px, 200px) 1fr; gap: 6px 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; word-break: break-word; }
pre.report { white-space: pre-wrap; background: var(--surface-2); padding: 14px; border-radius: var(--radius);
  font-size: 12.5px; max-height: 70vh; overflow: auto; }

.auth { max-width: 380px; margin: 9vh auto 0; }
.report-frame { width: 100%; height: 70vh; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.auth .brand { justify-content: center; font-size: 20px; padding-bottom: 20px; }

.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); display: flex; align-items: flex-start;
  justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; padding: 20px; width: 100%; max-width: 680px;
  border: 1px solid var(--border); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 12px; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; max-width: 360px;
  font-size: 13px; box-shadow: 0 4px 12px rgba(0, 0, 0, .2); }
.toast.bad { background: var(--bad); color: #fff; }
.spinner { width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%;
  display: inline-block; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; }

/* charts */
.spark { width: 100%; height: 70px; display: block; }
.bars { display: flex; align-items: flex-end; gap: 2px; border-bottom: 1px solid var(--border); }
.bars .bar { flex: 1; height: 100%; display: flex; align-items: flex-end; min-width: 2px; }
.bars .bar > div { width: 100%; border-radius: 2px 2px 0 0; min-height: 1px; }
.bars-axis { display: flex; justify-content: space-between; margin-top: 2px; }
pre.diff { max-height: 50vh; font-size: 12px; }

/* website panel */
.site-switch { margin: 6px 0 4px; font-weight: 600; }
.section-title { font-size: 18px; margin: -6px 0 14px; }
.role-switch { display: flex; gap: 4px; background: var(--surface-2); border-radius: 10px; padding: 4px; margin-bottom: 12px; }
.role-switch a { flex: 1; text-align: center; padding: 8px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.role-switch a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.role-switch a:hover { text-decoration: none; color: var(--text); }
.checklist { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.check-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); background: var(--surface); }
.check-item:hover { text-decoration: none; border-color: var(--accent); }
.check-dot { flex: 0 0 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; background: var(--warn-soft); color: var(--warn); }
.check-item.ok .check-dot { background: var(--good-soft); color: var(--good); }
.hub-item { display: flex; gap: 12px; justify-content: space-between; align-items: center; flex-wrap: wrap; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-bottom: 8px; }
.hub-item .hub-main { flex: 1 1 320px; min-width: 0; }
.hub-item.posted { border-left: 3px solid var(--good); }
.hub-item.skipped { opacity: .7; }
.todo { display: flex; gap: 10px; align-items: flex-start; }
.todo input[type=checkbox] { margin-top: 4px; }
.trend-up { color: var(--good); }
.trend-down { color: var(--bad); }

/* ---------- responsive (kept last so it overrides the base rules above) ---------- */
.tab-select { display: none; margin-bottom: 16px; font-weight: 600; }

@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 20; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s;
    width: min(280px, 85vw); flex-basis: auto; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35); }
  .topbar:not([hidden]) { display: flex; align-items: center; gap: 10px; padding: 10px 16px;
    background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
  .topbar-title { font-weight: 650; }
  .view { padding: 16px 16px 40px; }
  /* many tabs: a dropdown is easier than a sideways-scrolling bar */
  .tabs { display: none; }
  .tab-select { display: block; }
  h1 { font-size: 20px; }
  .page-head .actions { width: 100%; }
  .stat .value { font-size: 20px; }
  .modal-back { padding: 0; align-items: stretch; }
  .modal { border-radius: 0; min-height: 100%; max-width: none; }
  .filters > * { flex: 1 1 140px; }
  .filters input { min-width: 0; }
  .toasts { left: 16px; right: 16px; }
  .toast { max-width: none; }
}

/* phones: 16px inputs stop iOS from zooming in on focus */
@media (max-width: 600px) {
  input, select, textarea { font-size: 16px; }
  /* wide tables scroll sideways with the first column pinned, so you always see which row you are on */
  .table-wrap { -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
    background: linear-gradient(to left, var(--surface) 30%, transparent) right / 24px 100% no-repeat local,
      radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, .18), transparent) right / 10px 100% no-repeat scroll,
      var(--surface); }
  .table-wrap th:first-child, .table-wrap td:first-child { position: sticky; left: 0; z-index: 1;
    background: var(--surface); box-shadow: 1px 0 0 var(--border); max-width: 46vw; }
  .table-wrap th:first-child { background: var(--surface-2); }
  .table-wrap td, .table-wrap th { font-size: 13px; }
  .url-cell { max-width: 60vw; }
  .actions .btn-sm { flex: 0 0 auto; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .kv { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .kv dt { margin-top: 8px; }
  th, td { padding: 7px 8px; }
}

/* touch screens: comfortable tap targets */
@media (pointer: coarse) {
  .btn { min-height: 40px; padding: 8px 14px; }
  .btn-sm { min-height: 34px; }
  .nav a { padding: 10px 12px; }
  input[type=checkbox] { width: 20px !important; height: 20px; }
}

.form-error { color: var(--bad); font-size: 13px; margin: 0 0 10px; }
