:root {
  --bg: #0a0a0a;
  --bg-soft: #141414;
  --card: #161616;
  --card-border: #2b2b2b;
  --text: #f2f2f2;
  --muted: #a3a3a3;
  --primary: #ff2e7e;
  --primary-hover: #ff5c9d;
  --good: #3ddc97;
  --mid: #ffcc66;
  --bad: #ff6b6b;
  --chip: #232323;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 70% -10%, #2b0d1b 0%, var(--bg) 55%);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.wrap { max-width: 960px; margin: 0 auto; padding: 0 20px; }

/* ---------- Sidebar layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; flex-shrink: 0;
  background: var(--bg-soft); border-right: 1px solid var(--card-border);
  padding: 22px 16px; display: flex; flex-direction: column; gap: 18px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand { font-size: 1.25rem; font-weight: 800; letter-spacing: -0.02em; padding: 0 6px; }
.sidebar-note { color: var(--muted); font-size: 0.78rem; margin-top: auto; padding: 0 6px; line-height: 1.5; }

.tool-nav { display: flex; flex-direction: column; gap: 4px; }
.tool-tab {
  background: transparent; color: var(--muted); text-align: left;
  border: 1px solid transparent; border-radius: 10px;
  padding: 11px 14px; font-size: 0.95rem; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: all 0.15s ease; width: 100%;
}
.tool-tab:hover { color: var(--text); background: var(--chip); }
.tool-tab.active { background: var(--primary); color: #0a0a0a; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content { width: 100%; max-width: 960px; margin: 0 auto; padding: 4px 24px 48px; }
.tagline { margin: 22px 0 0; color: var(--muted); max-width: 660px; }

/* Topbar (mobile only) */
.topbar {
  display: none; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--card-border);
  position: sticky; top: 0; background: var(--bg); z-index: 40;
}
.menu-btn {
  background: var(--bg-soft); border: 1px solid var(--card-border); color: var(--text);
  font-size: 1.2rem; border-radius: 9px; padding: 7px 13px; cursor: pointer; line-height: 1;
}
.topbar-title { font-weight: 700; }
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 45; }

/* Quick-add keywords (Rank Tracker) */
.quickadd { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.quickadd input { flex: 1; min-width: 180px; padding: 10px 12px; }
.quickadd .btn-secondary { padding: 10px 14px; font-size: 0.92rem; white-space: nowrap; }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  .topbar { display: flex; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 50; height: 100dvh;
    transform: translateX(-100%); transition: transform 0.22s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 4px 14px 40px; }
  .card { padding: 16px 16px; }
  .tagline { margin-top: 14px; font-size: 0.95rem; }
  .btn-primary { width: 100%; }
  .tracker-actions .btn-primary, .tracker-actions .btn-secondary, .project-actions .btn-small { width: auto; }
  .overview-grid { grid-template-columns: repeat(2, 1fr); }
  h2 { font-size: 1.15rem; }
}

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin: 20px 0;
  box-shadow: var(--shadow);
}

.form-card { margin-top: 26px; }
.field { margin-bottom: 16px; }
label { display: block; font-weight: 600; margin-bottom: 6px; }
.hint { font-weight: 400; color: var(--muted); font-size: 0.85em; }

input[type='text'], textarea, select {
  width: 100%;
  background: var(--bg-soft);
  border: 1px solid var(--card-border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
}
select { appearance: none; cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23a3a3a3' d='M1 1l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 38px; }
select option { background: var(--card); color: var(--text); }
input[type='text']:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(255, 46, 126, 0.2);
}

.options { display: flex; flex-wrap: wrap; gap: 18px; margin: 6px 0 18px; }
.checkbox { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--primary); }

.btn-primary {
  background: var(--primary);
  color: #0a0a0a;
  border: none;
  padding: 12px 22px;
  font-size: 1rem;
  font-weight: 700;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.6; cursor: progress; }

.status {
  margin: 16px 0;
  padding: 14px 18px;
  border-radius: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--card-border);
}
.status.error { border-color: var(--bad); color: #ffd4d4; }
.spinner {
  display: inline-block; width: 16px; height: 16px; margin-right: 10px;
  border: 2px solid var(--muted); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -3px;
}
@keyframes spin { to { transform: rotate(360deg); } }

h2 { margin: 0 0 4px; font-size: 1.3rem; }
h3 { font-size: 1rem; margin: 0 0 10px; }
.section-note { color: var(--muted); margin: 0 0 16px; font-size: 0.92rem; }

.overview-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.scan-notice { margin: 14px 0 0; padding: 10px 14px; border-radius: 8px; background: rgba(255,204,102,0.12); border: 1px solid rgba(255,204,102,0.3); color: var(--mid); font-size: 0.88rem; }
.stat {
  background: var(--bg-soft); border: 1px solid var(--card-border);
  border-radius: 10px; padding: 12px 14px;
}
.stat .value { font-size: 1.4rem; font-weight: 700; }
.stat .value.small { font-size: 1rem; font-weight: 600; word-break: break-word; }
.stat .key { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }

/* Target keyword cards */
.target { border: 1px solid var(--card-border); border-radius: 12px; padding: 16px 18px; margin-bottom: 14px; background: var(--bg-soft); }
.target-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.target-kw { font-weight: 700; font-size: 1.05rem; }
.badge { padding: 3px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 700; }
.badge.Strong { background: rgba(61,220,151,0.18); color: var(--good); }
.badge.Moderate { background: rgba(255,204,102,0.18); color: var(--mid); }
.badge.Weak, .badge.Not { background: rgba(255,107,107,0.16); color: var(--bad); }

.score-bar { height: 8px; background: var(--chip); border-radius: 999px; overflow: hidden; margin: 12px 0; }
.score-bar > span { display: block; height: 100%; border-radius: 999px; }

.checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 4px 16px; margin: 8px 0; }
.check { font-size: 0.9rem; color: var(--muted); }
.check.pass::before { content: '✓ '; color: var(--good); font-weight: 700; }
.check.fail::before { content: '✕ '; color: var(--bad); font-weight: 700; }

.recs { margin: 10px 0 0; padding-left: 18px; }
.recs li { color: #e6e6e6; font-size: 0.9rem; margin-bottom: 4px; }

.serp { margin-top: 10px; font-size: 0.9rem; padding: 8px 12px; border-radius: 8px; background: var(--chip); }
.serp.hit { color: var(--good); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--card-border); }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: rgba(255,255,255,0.02); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--chip); font-size: 0.78rem; color: var(--muted); }
.placement { display: inline-block; margin-right: 6px; font-size: 0.78rem; color: var(--good); }

/* Suggestions */
.suggestions-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; }
.suggestion-col ul { list-style: none; margin: 0; padding: 0; }
.suggestion-col li { padding: 9px 12px; margin-bottom: 8px; background: var(--bg-soft); border: 1px solid var(--card-border); border-radius: 9px; }
.suggestion-col li .kw { font-weight: 600; }
.suggestion-col li .why { display: block; color: var(--muted); font-size: 0.8rem; margin-top: 2px; }
.copy-btn { float: right; background: transparent; border: 1px solid var(--card-border); color: var(--muted); border-radius: 6px; font-size: 0.75rem; padding: 2px 8px; cursor: pointer; }
.copy-btn:hover { color: var(--text); border-color: var(--primary); }

/* SERP Explorer */
.serp-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.serp-featured {
  margin-top: 14px; padding: 12px 16px; border-radius: 10px;
  background: rgba(255,46,126,0.1); border: 1px solid rgba(255,46,126,0.3);
}
.serp-featured .lbl { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--primary); font-weight: 700; }
.serp-featured .snip { color: var(--text); margin: 4px 0 2px; }
.serp-featured .src { color: var(--muted); font-size: 0.82rem; }

.serp-list { list-style: none; margin: 0; padding: 0; counter-reset: serp; }
.serp-list li {
  position: relative; padding: 14px 16px 14px 52px; margin-bottom: 10px;
  background: var(--bg-soft); border: 1px solid var(--card-border); border-radius: 10px;
}
.serp-list li::before {
  counter-increment: serp; content: counter(serp);
  position: absolute; left: 14px; top: 14px;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--chip); color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.82rem; font-weight: 700;
}
.serp-list li.you { border-color: var(--good); background: rgba(61,220,151,0.08); }
.serp-list li.you::before { background: var(--good); color: #0a0a0a; }
.serp-result-title { font-weight: 600; color: var(--primary); text-decoration: none; }
.serp-result-title:hover { text-decoration: underline; }
.serp-result-domain { color: var(--good); font-size: 0.82rem; margin-left: 8px; }
.serp-result-snippet { color: var(--muted); font-size: 0.88rem; margin: 4px 0 0; }
.you-badge { display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 999px; background: var(--good); color: #0a0a0a; font-size: 0.72rem; font-weight: 700; }

/* Rank Tracker + Projects */
.btn-secondary {
  background: transparent; color: var(--text);
  border: 1px solid var(--card-border); padding: 12px 18px;
  font-size: 1rem; font-weight: 600; border-radius: 10px; cursor: pointer; font-family: inherit;
}
.btn-secondary:hover { border-color: var(--primary); }
.tracker-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.link-btn { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 0.85rem; text-decoration: underline; padding: 0; font-family: inherit; }
.project-bar {
  margin-bottom: 16px; padding: 10px 14px; border-radius: 9px;
  background: rgba(255,46,126,0.1); border: 1px solid rgba(255,46,126,0.3); font-size: 0.92rem;
}

.pos { display: inline-block; min-width: 26px; padding: 2px 8px; border-radius: 6px; background: var(--chip); font-weight: 700; }
.pos-top3 { background: rgba(61,220,151,0.2); color: var(--good); }
.pos-top10 { background: rgba(255,204,102,0.18); color: var(--mid); }
.pos-none { color: var(--muted); }
.pos-err { color: var(--bad); font-size: 0.82rem; }
.delta { font-weight: 700; font-size: 0.88rem; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.delta.flat { color: var(--muted); }

.storage-mode { font-size: 0.85rem; margin: 0 0 14px; padding: 8px 12px; border-radius: 8px; }
.storage-mode.neon { background: rgba(61,220,151,0.1); border: 1px solid rgba(61,220,151,0.3); color: var(--good); }
.storage-mode.memory { background: rgba(255,204,102,0.1); border: 1px solid rgba(255,204,102,0.3); color: var(--mid); }
.projects-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.project-card { background: var(--bg-soft); border: 1px solid var(--card-border); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.project-card-head { display: flex; justify-content: space-between; align-items: flex-start; }
.project-name { font-weight: 700; font-size: 1.05rem; }
.project-meta { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.project-lastrun { color: var(--muted); font-size: 0.82rem; }
.project-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.btn-small { background: var(--primary); color: #0a0a0a; border: none; border-radius: 8px; padding: 6px 12px; font-size: 0.82rem; font-weight: 700; cursor: pointer; font-family: inherit; }
.btn-small.ghost { background: transparent; color: var(--muted); border: 1px solid var(--card-border); }
.btn-small.ghost:hover { color: var(--text); border-color: var(--primary); }
.btn-small.danger:hover { color: var(--bad); border-color: var(--bad); }

code { background: var(--chip); padding: 1px 6px; border-radius: 5px; font-size: 0.85em; }

@media (max-width: 560px) { .serp-form-row { grid-template-columns: 1fr; } }

@media (max-width: 560px) {
  .site-header h1 { font-size: 1.6rem; }
}

/* Global project context selector */
.project-context { display: flex; align-items: center; gap: 8px; }
.project-context select {
  width: auto; min-width: 150px; padding: 7px 32px 7px 12px; font-size: 0.88rem;
}

/* Charts */
.chart-box { margin: 8px 0 4px; }
.chart-wrap { position: relative; }
.chart-tip {
  position: absolute; top: 8px; pointer-events: none;
  background: var(--card); border: 1px solid var(--card-border); border-radius: 8px;
  padding: 8px 12px; font-size: 0.82rem; box-shadow: var(--shadow); white-space: nowrap; z-index: 5;
}
.chart-tip-date { color: var(--muted); font-size: 0.75rem; margin-bottom: 4px; }
.chart-tip-row { display: flex; align-items: center; gap: 6px; }
.chart-tip-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; }
.chart-legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 0.82rem; color: var(--muted); }

/* AI insights */
.ai-card { border-color: rgba(255,46,126,0.4); }
.ai-out { margin-top: 14px; }
.ai-summary { font-size: 1.02rem; line-height: 1.55; color: var(--text); }
.ai-priorities { padding-left: 20px; }
.ai-priorities li { margin-bottom: 14px; }
.ai-priorities p { color: var(--muted); font-size: 0.92rem; margin: 4px 0 0; }
.ai-pri-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ai-badge { padding: 1px 9px; border-radius: 999px; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; background: var(--chip); color: var(--muted); }
.ai-badge.impact-high { background: rgba(61,220,151,0.16); color: var(--good); }
.ai-badge.impact-medium { background: rgba(255,204,102,0.16); color: var(--mid); }
.ai-badge.effort-low { background: rgba(255,46,126,0.16); color: var(--primary); }

/* ================= Modern SaaS polish ================= */
:root {
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.22);
}
.card { border-radius: 12px; }
h1 { font-size: 1.7rem; letter-spacing: -0.02em; margin: 0; }
.btn-primary:focus-visible, .btn-secondary:focus-visible, .tool-tab:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}
.nav-label {
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); padding: 10px 14px 4px; opacity: 0.8;
}

/* Dashboard */
.hero { text-align: left; padding: 34px 30px; margin-top: 26px; }
.hero h1 { font-size: 2.1rem; line-height: 1.15; margin-bottom: 12px; }
.hero-sub { color: var(--muted); max-width: 560px; margin: 0 0 22px; }
.hero-form { max-width: 640px; }
.dash-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 26px 0 4px; }
.dash-title { font-size: 1.55rem; }
.dash-sub { color: var(--muted); margin: 2px 0 0; font-size: 0.92rem; }
.dash-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.dash-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin: 18px 0 4px; }
.stat-tile {
  background: var(--card); border: 1px solid var(--card-border); border-radius: 12px;
  padding: 16px 18px; box-shadow: var(--shadow);
}
.stat-tile .label { color: var(--muted); font-size: 0.8rem; }
.stat-tile .value { font-size: 1.85rem; font-weight: 750; letter-spacing: -0.01em; margin: 2px 0; }
.stat-tile .delta { font-size: 0.82rem; font-weight: 700; }
.stat-tile .delta.up { color: var(--good); }
.stat-tile .delta.down { color: var(--bad); }
.stat-tile .delta.flat { color: var(--muted); font-weight: 500; }

/* Empty states */
.empty-state { text-align: center; padding: 40px 24px; }
.empty-icon { font-size: 2.4rem; margin-bottom: 8px; }
.empty-state .btn-primary { margin-top: 6px; width: auto; }

/* Toasts */
.toast-host { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--card); border: 1px solid var(--card-border); border-left: 3px solid var(--good);
  color: var(--text); border-radius: 10px; padding: 12px 16px; font-size: 0.92rem;
  box-shadow: var(--shadow); max-width: 340px; animation: toast-in 0.22s ease;
}
.toast.error { border-left-color: var(--bad); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 900px) {
  .hero h1 { font-size: 1.55rem; }
  .dash-actions .btn-primary, .dash-actions .btn-secondary { flex: 1; }
  .dash-stats { grid-template-columns: repeat(2, 1fr); }
  .toast-host { left: 14px; right: 14px; }
  .toast { max-width: none; }
}
