:root {
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --up: #006300;      /* rank improved / reviews gained */
  --down: #d03b3b;    /* rank dropped / reviews lost */
  --s1: #2a78d6; --s2: #1baf7a; --s3: #eda100; --s4: #008300;
  --s5: #4a3aa7; --s6: #e34948;
  --own: #2a78d6;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --surface-1: #1a1a19; --page: #0d0d0d; --text-primary: #fff;
    --text-secondary: #c3c2b7; --muted: #898781; --grid: #2c2c2a;
    --baseline: #383835; --border: rgba(255, 255, 255, 0.10);
    --up: #0ca30c; --down: #e66767;
    --s1: #3987e5; --s2: #199e70; --s3: #c98500; --s4: #008300;
    --s5: #9085e9; --s6: #e66767; --own: #3987e5;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--text-primary); font-size: 14px; }
a { color: inherit; }

header.top {
  position: sticky; top: 0; z-index: 10; background: var(--surface-1);
  border-bottom: 1px solid var(--border); padding: 14px 22px;
  display: flex; align-items: baseline; gap: 14px;
}
header.top h1 { font-size: 16px; margin: 0; font-weight: 650; }
header.top .meta { color: var(--muted); font-size: 12px; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 20px 22px 60px; }

.crumbs { font-size: 13px; color: var(--text-secondary); margin-bottom: 14px; }
.crumbs a { cursor: pointer; text-decoration: none; color: var(--s1); }
.crumbs a:hover { text-decoration: underline; }

/* overview table */
table.grid { width: 100%; border-collapse: collapse; background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
table.grid th, table.grid td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--grid); }
table.grid th { color: var(--muted); font-weight: 550; font-size: 12px; cursor: pointer;
  user-select: none; white-space: nowrap; text-transform: uppercase; letter-spacing: .03em; }
table.grid th:first-child, table.grid td:first-child { text-align: left; }
table.grid tbody tr { cursor: pointer; }
table.grid tbody tr:hover { background: color-mix(in srgb, var(--s1) 7%, transparent); }
table.grid td.num { font-variant-numeric: tabular-nums; }
.appname { font-weight: 600; }
.appcode { color: var(--muted); font-size: 12px; margin-left: 6px; font-variant-numeric: tabular-nums; }
.delta-up { color: var(--up); font-variant-numeric: tabular-nums; }
.delta-down { color: var(--down); font-variant-numeric: tabular-nums; }
.delta-flat { color: var(--muted); }

/* KPI tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 6px 0 22px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.tile .label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.tile .value { font-size: 26px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12px; margin-top: 2px; }

.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px 18px; margin-bottom: 18px; }
.card h3 { margin: 0 0 4px; font-size: 14px; font-weight: 620; }
.card .hint { color: var(--muted); font-size: 12px; margin-bottom: 10px; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text-secondary); margin: 8px 0 2px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 11px; height: 3px; border-radius: 2px; display: inline-block; }

.chartbox { position: relative; overflow-x: auto; }
svg.chart { display: block; width: 100%; height: auto; }
.tooltip { position: fixed; pointer-events: none; background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; font-size: 12px;
  box-shadow: 0 4px 14px rgba(0,0,0,.14); z-index: 50; display: none; font-variant-numeric: tabular-nums; }

/* keyword table sparkline cell */
.spark { width: 90px; }
.controls { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.controls input { padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-1); color: var(--text-primary); font-size: 13px; min-width: 180px; }
.pill { font-size: 11px; color: var(--muted); }
.empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

/* rank explorer pivot */
:root { --b1: #1baf7a; --b2: #7bc9a3; --b3: #eda100; --b4: #eb8a34; --b5: #e34948; }
@media (prefers-color-scheme: dark) { :root { --b1: #199e70; --b2: #4f9e7d; --b3: #c98500; --b4: #c96f26; --b5: #cc5150; } }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface-1); color: var(--text-secondary); padding: 6px 12px; font-size: 12px; cursor: pointer; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--s1); color: #fff; }
.pivot-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
table.pivot { border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.pivot th, table.pivot td { padding: 6px 9px; text-align: center; border-bottom: 1px solid var(--grid); }
table.pivot thead th { color: var(--muted); font-weight: 550; font-size: 11px; position: sticky; top: 0; background: var(--surface-1); }
table.pivot th.kw { text-align: left; position: sticky; left: 0; z-index: 2; background: var(--surface-1);
  cursor: pointer; min-width: 150px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
table.pivot thead th.kw { z-index: 3; }
table.pivot td.kwcell { color: var(--text-primary); font-weight: 500; }
table.pivot tr:hover th.kw { color: var(--s1); }
.pivot td.rk { color: var(--text-primary); font-weight: 600; border-radius: 3px; }
.legend-buckets { display: flex; gap: 12px; font-size: 11px; color: var(--text-secondary); margin: 8px 2px; flex-wrap: wrap; }
.legend-buckets span { display: inline-flex; align-items: center; gap: 5px; }
.legend-buckets i { width: 13px; height: 13px; border-radius: 3px; display: inline-block; }
.pivot td.neutral { color: var(--text-secondary); background: var(--surface-1); }
.seg button.disabled, .seg button:disabled { opacity: .4; cursor: not-allowed; }
table.pivot tr.selected th.kw { box-shadow: inset 3px 0 0 var(--s1); }
/* keyword detail panel below the pivot (fixed width, never stretches with the table) */
.kwpanel:empty { display: none; }
.kwpanel { margin-top: 14px; border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px;
  background: color-mix(in srgb, var(--s1) 3%, var(--surface-1)); }
.kwpanel-head { display: flex; align-items: baseline; gap: 6px; margin-bottom: 6px; }
.kwpanel-head .closebtn { margin-left: auto; border: 0; background: transparent; color: var(--muted);
  font-size: 15px; cursor: pointer; padding: 2px 6px; }
.kwpanel-head .closebtn:hover { color: var(--text-primary); }
.ctl-label { font-size: 11px; color: var(--muted); letter-spacing: .04em; margin-right: 2px; }
.controls input[type=date] { padding: 6px 8px; }

/* main keyword highlight */
.star { color: var(--s3); font-size: 12px; }
.nr { color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .03em; }
table.grid tr.mainrow td, table.grid tr.mainrow td:first-child { background: color-mix(in srgb, var(--s3) 8%, var(--surface-1)); font-weight: 600; }
table.pivot tr.mainrow th.kw { background: color-mix(in srgb, var(--s3) 12%, var(--surface-1)); font-weight: 650; }

/* distribution stacked bar */
.distbar { display: flex; width: 100%; height: 34px; border-radius: 8px; overflow: hidden; margin: 6px 0; border: 1px solid var(--border); }
.distseg { display: flex; align-items: center; justify-content: center; color: #fff; font-size: 12px;
  font-weight: 600; font-variant-numeric: tabular-nums; min-width: 0; }

/* section title (Competitors) */
.section-title { display: flex; align-items: baseline; gap: 10px; margin: 24px 2px 10px; }
.section-title span:first-child { font-size: 15px; font-weight: 650; }
.section-note { font-size: 12px; color: var(--muted); }
