/* ASO Toolkit design system */
:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #ffffff;
  --surface-2: #f8f8f6;
  --sidebar: #fbfbfa;
  --border: #e6e5e1;
  --border-strong: #d4d3ce;
  --text: #121211;
  --text-2: #4f4e4a;
  --muted: #84837d;
  --accent: #2a78d6;
  --accent-soft: #e6f0fc;
  --accent-ink: #ffffff;
  --grid: #eeede9;
  --good: #0a8a0a; --good-soft: #e5f5e3;
  --warn: #9a6700; --warn-soft: #fdf3dc;
  --bad: #c93636; --bad-soft: #fde8e8;
  --info-soft: #eef1f6;
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 2px 8px rgb(0 0 0 / .04);
  --shadow-lg: 0 12px 40px rgb(0 0 0 / .14);
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #5598e7; --seq-4: #256abf; --seq-5: #104281;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110; --surface: #1a1a19; --surface-2: #20201e; --sidebar: #161615;
    --border: #2c2c2a; --border-strong: #3a3a37; --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e88;
    --accent: #3987e5; --accent-soft: #1b2c42; --grid: #262624;
    --good: #3cc23c; --good-soft: #15301a; --warn: #f0b429; --warn-soft: #33290f; --bad: #ef7070; --bad-soft: #3a1c1c; --info-soft: #23262c;
    --shadow: 0 1px 2px rgb(0 0 0 / .3); --shadow-lg: 0 12px 40px rgb(0 0 0 / .5);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --s8: #e66767;
    --seq-1: #184f95; --seq-2: #1c5cab; --seq-3: #2a78d6; --seq-4: #5598e7; --seq-5: #9ec5f4;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #20201e; --sidebar: #161615;
  --border: #2c2c2a; --border-strong: #3a3a37; --text: #f0efec; --text-2: #c3c2b7; --muted: #8f8e88;
  --accent: #3987e5; --accent-soft: #1b2c42; --grid: #262624;
  --good: #3cc23c; --good-soft: #15301a; --warn: #f0b429; --warn-soft: #33290f; --bad: #ef7070; --bad-soft: #3a1c1c; --info-soft: #23262c;
  --shadow: 0 1px 2px rgb(0 0 0 / .3); --shadow-lg: 0 12px 40px rgb(0 0 0 / .5);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --s8: #e66767;
  --seq-1: #184f95; --seq-2: #1c5cab; --seq-3: #2a78d6; --seq-4: #5598e7; --seq-5: #9ec5f4;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }
.nowrap { white-space: nowrap; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar); border-right: 1px solid var(--border); padding: 16px 12px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; padding: 4px 8px 14px; font-size: 15px; }
.brand .logo { width: 26px; height: 26px; border-radius: 8px; background: linear-gradient(135deg, var(--s1), var(--s7)); display: grid; place-items: center; color: #fff; font-size: 13px; }
.mine { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); margin-bottom: 10px; cursor: pointer; }
.mine:hover { border-color: var(--border-strong); }
.mine .t { font-weight: 600; font-size: 13px; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mine .s { font-size: 11px; color: var(--muted); }
.nav-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; padding: 12px 10px 4px; font-weight: 600; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.nav a svg { width: 17px; height: 17px; flex: none; }
.nav .count { margin-left: auto; font-size: 11px; color: var(--muted); }
.sidebar .foot { margin-top: auto; padding: 10px; font-size: 11px; color: var(--muted); }
.sidebar .foot .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--good); margin-right: 5px; }

.main { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  display: flex; align-items: center; gap: 12px; padding: 14px 28px; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.topbar .crumbs { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar .crumbs .back { color: var(--muted); }
.topbar .right { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.page { padding: 24px 28px 80px; max-width: 1280px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
td:has(> .kw), td:has(> a.kw) { min-width: 170px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3, .g-2-1 { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; overflow-x: auto; }
  .sidebar .nav-label, .sidebar .foot, .mine { display: none; }
  .nav { display: flex; gap: 2px; flex-wrap: wrap; }
  .g2, .g4 { grid-template-columns: 1fr; }
  .page, .topbar { padding-left: 16px; padding-right: 16px; }
}

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > .card-head { padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card-head .right { margin-left: auto; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.card.hero { background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 10%, var(--surface)), var(--surface) 60%); }

.kpi .label { color: var(--text-2); font-size: 12px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 30px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.15; margin-top: 4px; }
.kpi .value small { font-size: 14px; color: var(--muted); font-weight: 500; }
.kpi .delta { font-size: 12px; font-weight: 600; }
.kpi .foot { font-size: 12px; color: var(--muted); margin-top: 6px; }
.up { color: var(--good); } .down { color: var(--bad); }

button, .btn {
  font: inherit; font-weight: 500; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 8px; padding: 7px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; line-height: 1.3;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.06); }
button.ghost { background: none; border-color: transparent; color: var(--text-2); }
button.ghost:hover { background: var(--surface-2); }
button.sm { padding: 4px 9px; font-size: 12px; border-radius: 7px; }
button.ai { background: linear-gradient(135deg, var(--s7), var(--s1)); border: 0; color: #fff; }
button:disabled { opacity: .5; cursor: default; }
button svg { width: 15px; height: 15px; }
input, textarea, select {
  font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
input:focus, textarea:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 0; border-color: var(--accent); }
textarea { resize: vertical; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); font-weight: 500; }
label.field .row-between { display: flex; justify-content: space-between; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.tight { gap: 4px; }
.row > .grow { flex: 1 1 220px; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: none; border-radius: 7px; padding: 5px 11px; color: var(--text-2); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 3px 10px; font-size: 12px; color: var(--text-2); cursor: pointer; }
.chip.on { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 600; }
.chip .n { color: var(--muted); margin-left: 4px; font-weight: 500; }

.pill { display: inline-flex; align-items: center; justify-content: center; min-width: 34px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.mid { background: var(--info-soft); color: var(--text-2); }
.pill.low { background: var(--surface-2); color: var(--muted); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); margin: 1px 2px 1px 0; white-space: nowrap; }
.tag.ai { background: color-mix(in srgb, var(--s7) 14%, var(--surface)); color: var(--s7); border-color: transparent; }
.tag.brand { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tag.own { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.rank { font-weight: 700; font-variant-numeric: tabular-nums; }
.rank.r1 { color: var(--good); } .rank.r2 { color: var(--accent); } .rank.r3 { color: var(--text); } .rank.r4 { color: var(--muted); }

.bar { height: 6px; background: var(--grid); border-radius: 3px; overflow: hidden; min-width: 50px; }
.bar > i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.meter-cell { display: flex; align-items: center; gap: 8px; }
.meter-cell .bar { flex: 1; }
.meter-cell span { width: 26px; text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; color: var(--text-2); }

/* tables */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; background: var(--surface); position: sticky; top: 0; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
tr.sel td { background: var(--accent-soft); }
td .kw { font-weight: 600; color: var(--text); }
td .kw:hover { color: var(--accent); }
.check { width: 16px; height: 16px; accent-color: var(--accent); }

.app-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.app-cell .meta { min-width: 0; }
.app-cell .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; }
.app-cell .d { font-size: 12px; color: var(--muted); }
.icon { width: 36px; height: 36px; border-radius: 9px; flex: none; object-fit: cover; background: var(--surface-2); border: 1px solid var(--border); }
.icon.sm { width: 26px; height: 26px; border-radius: 7px; }
.icon.lg { width: 76px; height: 76px; border-radius: 18px; }
.icon.ph { display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 13px; }

/* insights */
.insight { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.insight:last-child { border-bottom: 0; }
.insight .ico { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; flex: none; }
.insight .ico svg { width: 16px; height: 16px; }
.insight.high .ico { background: var(--bad-soft); color: var(--bad); }
.insight.medium .ico { background: var(--warn-soft); color: var(--warn); }
.insight.good .ico { background: var(--good-soft); color: var(--good); }
.insight.info .ico { background: var(--info-soft); color: var(--text-2); }
.insight .t { font-weight: 600; }
.insight .d { color: var(--text-2); font-size: 13px; }
.insight .go { margin-left: auto; align-self: center; }

/* empty + onboarding */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .big { font-size: 16px; color: var(--text); font-weight: 600; margin-bottom: 6px; }
.onboard { max-width: 640px; margin: 40px auto; }
.steps { counter-reset: s; list-style: none; padding: 0; margin: 16px 0; }
.steps li { counter-increment: s; display: flex; gap: 12px; padding: 10px 0; }
.steps li::before { content: counter(s); width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; display: grid; place-items: center; flex: none; font-size: 12px; }

/* progress */
.progress { height: 8px; background: var(--grid); border-radius: 4px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--s1), var(--s7)); border-radius: 4px; transition: width .3s; }
.job { padding: 14px 16px; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; }
.job .msg { font-size: 12px; color: var(--muted); margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--grid), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 8px; min-height: 16px; }
@keyframes sk { to { background-position: -200% 0; } }

/* toast + modal */
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 13px; max-width: 380px; animation: tin .2s ease-out; }
.toast.err { background: var(--bad); color: #fff; }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }
.modal-bg { position: fixed; inset: 0; background: rgb(0 0 0 / .35); z-index: 90; display: grid; place-items: center; padding: 20px; }
.modal { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); width: min(560px, 100%); max-height: 86vh; overflow: auto; padding: 22px; }

/* charts */
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid-l { stroke: var(--grid); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { opacity: .1; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .cross { stroke: var(--muted); stroke-dasharray: 3 3; }
.chart .bub { stroke: var(--surface); stroke-width: 1.5; cursor: pointer; transition: opacity .15s; }
.chart .bub:hover { opacity: 1 !important; stroke: var(--text); }
.chart .zone { fill: var(--good-soft); }
.chart .zone-label { fill: var(--good); font-size: 11px; font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.legend i, .tip i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 8px 10px; font-size: 12px; box-shadow: var(--shadow-lg); min-width: 150px; z-index: 5; }
.tip div { display: flex; align-items: center; gap: 2px; }
.tip span { margin-left: auto; padding-left: 12px; font-variant-numeric: tabular-nums; font-weight: 600; }
.table-view summary { font-size: 12px; color: var(--muted); cursor: pointer; margin-top: 8px; }
.spark { display: block; }
.hbar { display: grid; grid-template-columns: 22px 1fr 44px; align-items: center; gap: 8px; font-size: 12px; margin: 4px 0; }
.hbar .bar { height: 10px; }

/* heatmap matrix */
.heat td.cell { text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; font-size: 12px; padding: 6px; }
.heat .h1 { background: var(--seq-5); color: #fff; } .heat .h2 { background: var(--seq-4); color: #fff; }
.heat .h3 { background: var(--seq-3); color: #fff; } .heat .h4 { background: var(--seq-2); } .heat .h5 { background: var(--seq-1); }
.heat .h0 { color: var(--muted); font-weight: 400; }
:root[data-theme="dark"] .heat .h4, :root[data-theme="dark"] .heat .h5 { color: #fff; }

/* misc */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }
.desc { white-space: pre-wrap; font-size: 13px; color: var(--text-2); max-height: 260px; overflow: auto; background: var(--surface-2); padding: 12px; border-radius: 8px; }
.copy-box { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: 8px; padding: 8px 10px; }
.copy-box code { flex: 1; overflow-x: auto; white-space: nowrap; font-size: 13px; }
.counter { font-variant-numeric: tabular-nums; }
.counter.over { color: var(--bad); font-weight: 700; }
.counter.ok { color: var(--good); }
.hl { background: color-mix(in srgb, var(--s4) 35%, transparent); border-radius: 3px; padding: 0 1px; }
.divider { height: 1px; background: var(--border); margin: 14px 0; }
.review { padding: 12px 0; border-bottom: 1px solid var(--border); }
.review .stars { color: var(--s4); letter-spacing: 1px; }
.ai-box { border: 1px solid color-mix(in srgb, var(--s7) 35%, var(--border)); background: color-mix(in srgb, var(--s7) 5%, var(--surface)); }
.ai-badge { display: inline-flex; gap: 4px; align-items: center; font-size: 11px; font-weight: 700; color: var(--s7); text-transform: uppercase; letter-spacing: .05em; }
.report { white-space: pre-wrap; font-size: 13px; line-height: 1.6; }
