/* Competitor Watch — Data-Dense Dashboard (dark-first)
   Palette: blue data + amber highlights · Fira Sans / Fira Code */

:root, :root[data-theme="dark"] {
  --bg: #0B1220;
  --bg-raised: #101A2E;
  --bg-hover: #16233C;
  --bg-input: #0A1120;
  --border: #1E2C47;
  --border-strong: #2A3B5E;
  --text: #E4EAF4;
  --text-muted: #8A97B0;
  --placeholder: #4A5878;
  --primary: #3B82F6;
  --primary-strong: #2563EB;
  --on-primary: #FFFFFF;
  --accent: #F59E0B;
  --ok: #34D399;
  --ok-bg: rgba(52, 211, 153, .12);
  --danger: #F87171;
  --danger-bg: rgba(248, 113, 113, .12);
  --warn: #FBBF24;
  --add-bg: rgba(52, 211, 153, .13);
  --add-text: #6EE7B7;
  --del-bg: rgba(248, 113, 113, .13);
  --del-text: #FCA5A5;
  --ring: #60A5FA;
  --sidebar-1: #0D1526;
  --sidebar-2: #0A111F;
  --nav-active-bg: rgba(59, 130, 246, .14);
  --nav-active-text: #93C5FD;
  --chip-blue: #93C5FD;
  --chip-purple: #C4B5FD;
  --login-glow: rgba(59, 130, 246, .12);
  --radius: 10px;
  --radius-sm: 6px;
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 24px; --s-6: 32px;
  --font: 'Fira Sans', system-ui, -apple-system, sans-serif;
  --mono: 'Fira Code', ui-monospace, 'Cascadia Code', monospace;
  --shadow: 0 1px 2px rgba(0,0,0,.35), 0 8px 24px rgba(0,0,0,.25);
}

:root[data-theme="light"] {
  --bg: #F3F6FB;
  --bg-raised: #FFFFFF;
  --bg-hover: #EDF2F9;
  --bg-input: #FFFFFF;
  --border: #E3E9F2;
  --border-strong: #C9D5E5;
  --text: #16233A;
  --text-muted: #5A6A85;
  --placeholder: #94A3B8;
  --primary: #2563EB;
  --primary-strong: #1D4ED8;
  --on-primary: #FFFFFF;
  --accent: #B45309;
  --ok: #047857;
  --ok-bg: rgba(4, 120, 87, .1);
  --danger: #DC2626;
  --danger-bg: rgba(220, 38, 38, .08);
  --warn: #B45309;
  --add-bg: rgba(22, 163, 74, .12);
  --add-text: #166534;
  --del-bg: rgba(220, 38, 38, .1);
  --del-text: #991B1B;
  --ring: #2563EB;
  --sidebar-1: #FFFFFF;
  --sidebar-2: #F6F8FC;
  --nav-active-bg: rgba(37, 99, 235, .1);
  --nav-active-text: #1D4ED8;
  --chip-blue: #1D4ED8;
  --chip-purple: #6D28D9;
  --login-glow: rgba(37, 99, 235, .08);
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 6px 18px rgba(16,24,40,.07);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }
code, .mono { font-family: var(--mono); font-size: .86em; }
.mono-sm { font-family: var(--mono); font-size: .78rem; }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; border-radius: var(--radius-sm); }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100dvh; }
.sidebar {
  width: 224px; flex: none;
  background: linear-gradient(180deg, var(--sidebar-1) 0%, var(--sidebar-2) 100%);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: var(--s-4) var(--s-3);
  position: sticky; top: 0; height: 100dvh;
}
.brand {
  display: flex; align-items: center; gap: var(--s-2);
  font-size: 1.05rem; font-weight: 600; letter-spacing: -.01em;
  padding: var(--s-2) var(--s-2) var(--s-5);
  color: var(--text);
}
.brand svg { width: 24px; height: 24px; color: var(--primary); flex: none; }
.brand b { color: var(--accent); font-weight: 700; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 10px var(--s-3); border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 500; font-size: .92rem;
  transition: background .15s ease, color .15s ease;
}
.sidebar nav a svg { width: 18px; height: 18px; flex: none; }
.sidebar nav a:hover { background: var(--bg-hover); color: var(--text); }
.sidebar nav a.active {
  background: var(--nav-active-bg); color: var(--nav-active-text);
  box-shadow: inset 2px 0 0 var(--primary);
}
.sidebar-foot { display: flex; flex-direction: column; gap: var(--s-2); }
.scan-indicator {
  display: flex; align-items: center; gap: var(--s-2);
  font-size: .8rem; color: var(--accent);
  padding: var(--s-2) var(--s-3);
  background: rgba(245, 158, 11, .1); border-radius: var(--radius-sm);
}

.main {
  flex: 1; min-width: 0;
  padding: var(--s-5) var(--s-6);
  max-width: 1440px;
}

/* ---------- Page head ---------- */
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--s-4); margin-bottom: var(--s-5); flex-wrap: wrap;
}
.page-head h1 { font-size: 1.45rem; font-weight: 700; letter-spacing: -.02em; display: flex; align-items: center; gap: var(--s-3); }
.page-head .sub { color: var(--text-muted); font-size: .9rem; margin-top: 2px; }
.crumb { font-size: .8rem; color: var(--text-muted); margin-bottom: 2px; }
.crumb a { color: var(--primary); }
.crumb a:hover { text-decoration: underline; }
.head-actions { display: flex; gap: var(--s-2); flex-wrap: wrap; }
.h-path { word-break: break-all; }
.accent-text { color: var(--accent); }

/* ---------- Cards ---------- */
.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s-4) var(--s-5);
  margin-bottom: var(--s-4);
  box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-3); margin-bottom: var(--s-3); flex-wrap: wrap;
}
.card-head h2 { font-size: .95rem; font-weight: 600; display: flex; align-items: center; gap: var(--s-2); }
.card-head .ic { width: 18px; height: 18px; color: var(--accent); }
.grid-2 { display: grid; grid-template-columns: 3fr 2fr; gap: var(--s-4); align-items: start; }
.grid-2 > .col { display: flex; flex-direction: column; }
.cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-4); }

/* ---------- KPI ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s-4); margin-bottom: var(--s-4); }
.kpi { display: flex; flex-direction: column; gap: 2px; }
.kpi-label { font-size: .74rem; text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); font-weight: 600; }
.kpi-value { font-family: var(--mono); font-size: 1.9rem; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi-accent .kpi-value { color: var(--accent); }
.kpi-hint { font-size: .78rem; color: var(--text-muted); }

/* ---------- Feed ---------- */
.feed { list-style: none; }
.feed-day {
  font-size: .76rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); padding: var(--s-3) 0 var(--s-2);
  border-bottom: 1px solid var(--border);
}
.feed-item {
  display: flex; gap: var(--s-3); justify-content: space-between;
  padding: var(--s-3) var(--s-2);
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: background .15s ease;
  cursor: pointer;
}
.feed li:last-child .feed-item { border-bottom: 0; }
.feed-item:hover { background: var(--bg-hover); }
.feed-main { min-width: 0; }
.feed-top { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; margin-bottom: 2px; }
.feed-summary { font-size: .87rem; color: var(--text); overflow: hidden; text-overflow: ellipsis; }
.feed-meta { display: flex; align-items: center; gap: var(--s-2); margin-top: var(--s-1); flex-wrap: wrap; }
.feed-item time { font-size: .76rem; color: var(--text-muted); white-space: nowrap; font-family: var(--mono); }
.comp-badge {
  font-size: .72rem; font-weight: 600; color: var(--chip-blue);
  background: var(--nav-active-bg);
  padding: 1px 8px; border-radius: 99px;
}
.path { font-size: .78rem; color: var(--text-muted); word-break: break-all; }

/* ---------- Chips & severity ---------- */
.chip {
  display: inline-flex; align-items: center;
  font-size: .7rem; font-weight: 600; letter-spacing: .02em;
  padding: 1px 8px; border-radius: 99px;
  background: var(--bg-hover); color: var(--text-muted);
  border: 1px solid var(--border-strong);
}
.chip-content { color: var(--chip-blue); border-color: rgba(59,130,246,.4); }
.chip-seo_meta { color: var(--warn); border-color: rgba(251,191,36,.4); }
.chip-structure { color: var(--chip-purple); border-color: rgba(196,181,253,.4); }
.chip-page_added { color: var(--ok); border-color: rgba(52,211,153,.4); }
.chip-page_removed { color: var(--danger); border-color: rgba(248,113,113,.4); }
.chip-ai { color: var(--accent); border-color: rgba(245,158,11,.4); }
.chip-ok { color: var(--ok); border-color: rgba(52,211,153,.4); }
.chip-err { color: var(--danger); border-color: rgba(248,113,113,.4); }
.chip-run { color: var(--accent); border-color: rgba(245,158,11,.4); }
.chip-paused { color: var(--text-muted); }
.sev { display: inline-flex; align-items: center; gap: 5px; font-size: .72rem; color: var(--text-muted); }
.sev .dot { width: 8px; height: 8px; border-radius: 50%; }
.sev-major .dot { background: var(--danger); box-shadow: 0 0 6px var(--danger); }
.sev-moderate .dot { background: var(--accent); }
.sev-minor .dot { background: var(--text-muted); }

.stat-chip {
  display: inline-flex; font-family: var(--mono); font-size: .76rem; font-weight: 500;
  padding: 2px 8px; border-radius: var(--radius-sm);
}
.stat-chip.add { background: var(--add-bg); color: var(--add-text); }
.stat-chip.del { background: var(--del-bg); color: var(--del-text); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.table td { padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: rgba(59, 130, 246, .04); }
.table .th td {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); font-weight: 600; border-bottom: 1px solid var(--border-strong);
}
.table .th:hover td { background: none; }
.trunc { max-width: 320px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-dim { opacity: .55; }
.ta-r { text-align: right; }
.fw-600 { font-weight: 600; }
.muted { color: var(--text-muted); }
.link { color: var(--primary); }
.link:hover { text-decoration: underline; }
.pin { font-size: .72rem; margin-left: 4px; }

/* ---------- Diff viewer ---------- */
.diff-view {
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--s-3); overflow-x: auto;
  font-size: .8rem; line-height: 1.6;
  max-height: 640px; overflow-y: auto;
}
.diff-view.preview { white-space: pre-wrap; max-height: 400px; }
.diff-line { padding: 1px var(--s-2); border-radius: 3px; white-space: pre-wrap; word-break: break-word; font-family: var(--mono); font-size: .8rem; }
.diff-line.add { background: var(--add-bg); color: var(--add-text); }
.diff-line.del { background: var(--del-bg); color: var(--del-text); }
.diff-line.ctx { color: var(--text-muted); }
.diff-line.gap { color: var(--border-strong); text-align: center; font-style: italic; }
.diff-fields td { font-size: .84rem; }
.diff-del { background: var(--del-bg); color: var(--del-text); border-radius: 4px; }
.diff-add { background: var(--add-bg); color: var(--add-text); border-radius: 4px; }
.add-text { color: var(--add-text); }
.del-text { color: var(--del-text); }
.legend { display: flex; gap: var(--s-2); }
.mini-h { font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin: var(--s-3) 0 var(--s-2); }

/* ---------- AI card ---------- */
.ai-card { border-left: 3px solid var(--accent); }
.ai-body p { font-size: .9rem; margin-bottom: var(--s-2); }
.ai-body b { color: var(--accent); }

/* ---------- Forms ---------- */
.form-row { display: flex; gap: var(--s-3); align-items: flex-end; flex-wrap: wrap; }
.form-col { display: flex; flex-direction: column; gap: var(--s-3); }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.grow { flex: 1; min-width: 220px; }
.field.w-100 { width: 110px; }
.field label { font-size: .8rem; font-weight: 500; color: var(--text-muted); }
.field.check label { display: flex; align-items: center; gap: var(--s-2); color: var(--text); font-size: .88rem; cursor: pointer; }
.req { color: var(--danger); }
input[type="text"], input[type="password"], input[type="number"], input[type="url"], input:not([type]), select, textarea {
  background: var(--bg-input); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 9px var(--s-3); font-size: .9rem; min-height: 40px;
  transition: border-color .15s ease;
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px rgba(59,130,246,.18); }
input::placeholder, textarea::placeholder { color: var(--placeholder); }
.inline-form { display: flex; gap: var(--s-2); }
.inline-form input { min-width: 260px; }
.sep { border: 0; border-top: 1px solid var(--border); margin: var(--s-2) 0; }
.self-end { align-self: flex-end; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  background: var(--bg-hover); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 9px var(--s-4); font-size: .88rem; font-weight: 500;
  min-height: 40px;
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}
.btn:hover { background: var(--border); border-color: var(--primary); }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary-strong); border-color: var(--primary-strong); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary); border-color: var(--primary); }
.btn-block { width: 100%; }
.btn-sm { padding: 5px var(--s-3); font-size: .8rem; min-height: 32px; }
.btn-ghost {
  display: inline-flex; align-items: center; gap: var(--s-2);
  background: none; border: 0; color: var(--text-muted);
  padding: 7px var(--s-3); border-radius: var(--radius-sm);
  font-size: .85rem; transition: background .15s ease, color .15s ease;
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-ghost svg { width: 16px; height: 16px; }
.btn-ghost.danger:hover { color: var(--danger); background: var(--danger-bg); }
button[disabled] { opacity: .45; cursor: not-allowed; }

/* ---------- Alerts / banners ---------- */
.alert { padding: var(--s-3) var(--s-4); border-radius: var(--radius-sm); font-size: .88rem; margin-bottom: var(--s-4); }
.alert-error { background: var(--danger-bg); color: var(--del-text); border: 1px solid rgba(248,113,113,.35); }
.alert-ok { background: var(--ok-bg); color: var(--add-text); border: 1px solid rgba(52,211,153,.35); }
.running-banner {
  display: flex; align-items: center; gap: var(--s-3);
  background: rgba(245,158,11,.08); border: 1px solid rgba(245,158,11,.3);
  color: var(--accent); border-radius: var(--radius-sm);
  padding: var(--s-3) var(--s-4); margin-bottom: var(--s-4); font-size: .88rem;
}
.pulse {
  width: 9px; height: 9px; border-radius: 50%; background: var(--accent); flex: none;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1);} 50% { opacity: .4; transform: scale(.8);} }

.hint { font-size: .78rem; color: var(--text-muted); margin-top: var(--s-2); }
.hint.warn { color: var(--warn); }
.hint code { background: var(--bg-hover); padding: 1px 5px; border-radius: 4px; }

/* ---------- Empty states ---------- */
.empty { padding: var(--s-5) var(--s-3); text-align: center; color: var(--text-muted); }
.empty.big { padding: var(--s-6); }
.empty .sub { font-size: .84rem; margin-top: var(--s-1); }

/* ---------- Competitors grid ---------- */
.comp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--s-4); }
.comp-card.paused { opacity: .6; }
.comp-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-2); }
.comp-name { font-size: 1.02rem; font-weight: 600; }
.comp-name:hover { color: var(--primary); }
.comp-domain { font-size: .78rem; color: var(--text-muted); word-break: break-all; }
.comp-domain:hover { color: var(--primary); }
.comp-stats { display: flex; gap: var(--s-5); margin: var(--s-3) 0; }
.comp-stats .num { display: block; font-family: var(--mono); font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.comp-stats .num.accent { color: var(--accent); }
.comp-stats .lbl { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.comp-actions { display: flex; gap: var(--s-2); flex-wrap: wrap; align-items: center; }
.meta-strip {
  display: flex; gap: var(--s-5); flex-wrap: wrap; align-items: center;
  font-size: .84rem; color: var(--text-muted);
  padding: var(--s-3) 0; margin-bottom: var(--s-4);
  border-bottom: 1px solid var(--border);
}
.meta-strip b { color: var(--text); font-weight: 500; }

/* ---------- Sparkline ---------- */
.spark { display: flex; align-items: flex-end; gap: 5px; height: 84px; padding-top: var(--s-2); }
.spark-col { flex: 1; display: flex; align-items: flex-end; height: 100%; cursor: default; }
.spark-bar {
  width: 100%; border-radius: 3px 3px 0 0;
  background: linear-gradient(180deg, var(--primary), var(--primary-strong));
  min-height: 4px; transition: opacity .15s ease;
}
.spark-col:hover .spark-bar { opacity: .75; }

/* ---------- Filters ---------- */
.filters .form-row { align-items: flex-end; }
.filters select { min-width: 160px; }

/* ---------- How-it-works ---------- */
.how { padding-left: var(--s-5); font-size: .87rem; display: flex; flex-direction: column; gap: var(--s-2); color: var(--text-muted); }
.how b { color: var(--text); }

/* ---------- Login ---------- */
.login-body {
  display: grid; place-items: center; min-height: 100dvh;
  background: radial-gradient(1200px 600px at 50% -10%, var(--login-glow), transparent), var(--bg);
  padding: var(--s-4);
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: 14px; padding: var(--s-6);
  box-shadow: var(--shadow);
}
.login-brand { text-align: center; margin-bottom: var(--s-5); }
.login-brand svg { width: 40px; height: 40px; color: var(--primary); margin-bottom: var(--s-2); }
.login-brand h1 { font-size: 1.3rem; letter-spacing: -.02em; }
.login-brand h1 b { color: var(--accent); }
.login-brand p { font-size: .82rem; color: var(--text-muted); margin-top: 2px; }
.login-card label { display: block; font-size: .8rem; font-weight: 500; color: var(--text-muted); margin: var(--s-3) 0 4px; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 42px; }
.pw-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  background: none; border: 0; color: var(--text-muted);
  width: 34px; height: 34px; display: grid; place-items: center; border-radius: var(--radius-sm);
}
.pw-toggle:hover { color: var(--text); }
.pw-toggle svg { width: 18px; height: 18px; }
.login-card .btn-block { margin-top: var(--s-5); }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .grid-2 { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .main { padding: var(--s-4); }
}
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: static;
    flex-direction: row; align-items: center;
    padding: var(--s-2) var(--s-3);
  }
  .brand { padding: 0 var(--s-2); font-size: .95rem; }
  .brand span { display: none; }
  .sidebar nav { flex-direction: row; gap: 0; overflow-x: auto; }
  .sidebar nav a { padding: var(--s-2) var(--s-3); font-size: .82rem; white-space: nowrap; }
  .sidebar-foot { flex-direction: row; margin-left: auto; }
  .scan-indicator .scan-text { display: none; }
  .cols-2 { grid-template-columns: 1fr; }
  .inline-form input { min-width: 0; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: var(--s-2); }
  .card { padding: var(--s-3); }
}

/* ---------- Theme toggle ---------- */
[data-theme-toggle] .ic-moon { display: none; }
[data-theme-toggle] .ic-sun { display: block; }
:root[data-theme="light"] [data-theme-toggle] .ic-moon { display: block; }
:root[data-theme="light"] [data-theme-toggle] .ic-sun { display: none; }
.theme-float {
  position: fixed; top: var(--s-4); right: var(--s-4);
  background: var(--bg-raised); border: 1px solid var(--border);
  color: var(--text-muted);
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  box-shadow: var(--shadow);
  transition: color .15s ease, border-color .15s ease;
}
.theme-float:hover { color: var(--text); border-color: var(--primary); }
.theme-float svg { width: 18px; height: 18px; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
