:root {
  --bg: #0a0e1a;
  --bg-2: #0e1424;
  --panel: #131b30;
  --panel-2: #172038;
  --line: #24304f;
  --text: #e8edf7;
  --muted: #8b98b8;
  --dim: #5d6b8c;
  --accent: #6d8bff;
  --accent-2: #9a6dff;
  --client: #34d9a8;
  --comp: #ff8a5c;
  --danger: #ff5c7c;
  --warn: #ffcc57;
  --grad: linear-gradient(135deg, #6d8bff, #9a6dff);
  --grad-client: linear-gradient(135deg, #34d9a8, #2bb4d9);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --radius: 16px;
}

:root[data-theme="light"] {
  --bg: #eef1f8;
  --bg-2: #ffffff;
  --panel: #ffffff;
  --panel-2: #f2f5fc;
  --line: #dde4f1;
  --text: #141c33;
  --muted: #55637f;
  --dim: #8a97b4;
  --accent: #4f6fe8;
  --accent-2: #8250e6;
  --client: #10a97a;
  --comp: #e9702f;
  --danger: #e23b5b;
  --warn: #c1870c;
  --grad: linear-gradient(135deg, #5b78f0, #8a5cf0);
  --grad-client: linear-gradient(135deg, #14b98a, #1596c2);
  --shadow: 0 10px 30px rgba(30, 45, 90, 0.10);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", "Helvetica Neue", "Inter", system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #17203f 0%, transparent 55%),
              radial-gradient(900px 500px at -10% 20%, #1a1636 0%, transparent 50%),
              var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
:root[data-theme="light"] body {
  background: radial-gradient(1200px 600px at 80% -10%, #e6ecfb 0%, transparent 55%),
              radial-gradient(900px 500px at -10% 20%, #efe8fb 0%, transparent 50%),
              var(--bg);
}

.app { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }

/* Sidebar */
.sidebar {
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  border-right: 1px solid var(--line);
  padding: 22px 18px;
  display: flex; flex-direction: column; gap: 22px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  background: var(--grad); display: grid; place-items: center;
  font-size: 22px; color: white; box-shadow: 0 6px 20px rgba(109, 139, 255, 0.4);
}
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -0.2px; }
.brand-sub { font-size: 11px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 6px; }
.nav-btn {
  text-align: left; background: transparent; border: 1px solid transparent;
  color: var(--muted); padding: 10px 12px; border-radius: 10px; cursor: pointer;
  font-size: 13.5px; font-weight: 600; transition: all 0.15s;
}
.nav-btn:hover:not(:disabled) { background: var(--panel); color: var(--text); }
.nav-btn.active { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.nav-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.saved { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.saved-title { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--dim); margin-bottom: 10px; }
.saved-list { overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.saved-item {
  padding: 9px 11px; border-radius: 9px; background: var(--panel); border: 1px solid var(--line);
  cursor: pointer; transition: all 0.15s;
}
.saved-item:hover { border-color: var(--accent); background: var(--panel-2); }
.saved-item .si-name { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved-item .si-meta { font-size: 10.5px; color: var(--dim); display: flex; justify-content: space-between; margin-top: 2px; }
.saved-item .si-del { color: var(--dim); float: right; }
.saved-item .si-del:hover { color: var(--danger); }
.sidebar-foot { font-size: 11px; display: flex; align-items: center; gap: 10px; }
.theme-toggle {
  flex-shrink: 0; width: 34px; height: 34px; border-radius: 9px; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  font-size: 15px; display: grid; place-items: center; transition: all 0.15s;
}
.theme-toggle:hover { border-color: var(--accent); background: var(--panel-2); }
.badge { display: inline-block; padding: 4px 9px; border-radius: 20px; background: var(--panel); border: 1px solid var(--line); color: var(--muted); font-size: 10.5px; }
.badge.ok { color: var(--client); border-color: rgba(52, 217, 168, 0.4); }
.badge.err { color: var(--danger); border-color: rgba(255, 92, 124, 0.4); }

/* Main */
.main { padding: 34px 40px 80px; max-width: 1400px; width: 100%; }
.view.hidden, .hidden { display: none !important; }
.page-head h1 { font-size: 26px; font-weight: 750; letter-spacing: -0.5px; }
.lead { color: var(--muted); margin-top: 8px; max-width: 780px; font-size: 14px; }

/* Setup */
.setup-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 26px; }
.card {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow);
}
.card-h { font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.hint { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.domains-ta {
  width: 100%; height: 190px; resize: vertical; background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px; color: var(--text); font-size: 13.5px; font-family: "SF Mono", ui-monospace, monospace;
  line-height: 1.7;
}
.domains-ta:focus { outline: none; border-color: var(--accent); }
.roles-list { display: flex; flex-direction: column; gap: 8px; min-height: 150px; max-height: 260px; overflow-y: auto; }
.role-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 11px;
}
.role-row .rr-domain { flex: 1; font-size: 13.5px; font-weight: 600; }
.role-seg { display: flex; gap: 4px; background: var(--panel-2); border-radius: 9px; padding: 3px; }
.seg-btn {
  border: none; background: transparent; color: var(--muted); font-size: 11.5px; font-weight: 600;
  padding: 5px 11px; border-radius: 7px; cursor: pointer; transition: all 0.12s;
}
.seg-btn.client-on { background: var(--grad-client); color: #04231a; }
.seg-btn.comp-on { background: var(--comp); color: #2a1105; }
.seg-btn.off:hover { color: var(--text); }
.rr-remove { color: var(--dim); cursor: pointer; padding: 0 4px; font-size: 16px; }
.rr-remove:hover { color: var(--danger); }
.empty { color: var(--dim); font-size: 13px; text-align: center; padding: 40px 0; }

.setup-actions { display: flex; gap: 10px; margin-top: 16px; }
.text-in {
  flex: 1; background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 13px; color: var(--text); font-size: 13px;
}
.text-in:focus { outline: none; border-color: var(--accent); }

.btn { border: none; border-radius: 10px; padding: 11px 18px; font-size: 13px; font-weight: 700; cursor: pointer; transition: all 0.15s; white-space: nowrap; }
.btn-primary { background: var(--grad); color: white; box-shadow: 0 8px 24px rgba(109, 139, 255, 0.35); }
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 12px 30px rgba(109, 139, 255, 0.5); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); margin-top: 12px; }
.btn-ghost:hover { border-color: var(--accent); }

/* Progress */
.progress-card { margin-top: 22px; }
.progress-log {
  max-height: 320px; overflow-y: auto; font-family: "SF Mono", ui-monospace, monospace;
  font-size: 12px; line-height: 1.8; color: var(--muted);
  background: var(--bg); border-radius: 10px; padding: 14px; border: 1px solid var(--line);
}
.progress-log .pl-line { white-space: pre-wrap; }
.progress-log .pl-head { color: var(--accent); font-weight: 700; }
.progress-log .pl-ok { color: var(--client); }
.progress-log .pl-err { color: var(--danger); }
.spinner { width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; display: inline-block; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Dashboard */
.dash-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 8px; flex-wrap: wrap; }
.dash-title h1 { font-size: 24px; font-weight: 750; letter-spacing: -0.4px; }
.editable-title { cursor: text; border-radius: 8px; padding: 2px 8px; margin: -2px -8px; outline: none; transition: background 0.15s, box-shadow 0.15s; }
.editable-title:hover { background: var(--panel-2); }
.editable-title:focus { background: var(--panel-2); box-shadow: 0 0 0 2px var(--accent); }
.editable-title::after { content: ' ✎'; font-size: 15px; font-weight: 500; color: var(--dim); opacity: 0; transition: opacity 0.15s; }
.editable-title:hover::after { opacity: 0.7; }
.editable-title:focus::after { opacity: 0; }
.dash-domains { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.chip { font-size: 12px; padding: 5px 11px; border-radius: 20px; border: 1px solid var(--line); background: var(--panel); color: var(--muted); font-weight: 600; }
.chip.client { color: var(--client); border-color: rgba(52, 217, 168, 0.45); background: rgba(52, 217, 168, 0.08); }
.chip.comp { color: var(--comp); border-color: rgba(255, 138, 92, 0.35); background: rgba(255, 138, 92, 0.07); }
.dash-actions { display: flex; gap: 10px; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin: 22px 0; }
.kpi {
  background: linear-gradient(180deg, var(--panel), var(--bg-2)); border: 1px solid var(--line);
  border-radius: 14px; padding: 18px; position: relative; overflow: hidden;
}
.kpi::before { content: ''; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--grad); opacity: 0.8; }
.kpi.good::before { background: var(--grad-client); }
.kpi.warn::before { background: linear-gradient(90deg, var(--warn), var(--comp)); }
.kpi-label { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; font-weight: 600; }
.kpi-value { font-size: 30px; font-weight: 780; letter-spacing: -1px; margin-top: 8px; }
.kpi-sub { font-size: 12px; color: var(--dim); margin-top: 4px; }
.kpi-value.accent { background: var(--grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.kpi-value.client { color: var(--client); }
.kpi-value.danger { color: var(--danger); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 18px; }
.grid-2.wide { grid-template-columns: 1.4fr 1fr; }
.panel {
  background: linear-gradient(180deg, var(--panel), var(--bg-2)); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.panel-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.panel-h h3 { font-size: 15px; font-weight: 700; }
.panel-desc { font-size: 12px; color: var(--muted); margin-bottom: 16px; }
.chart-wrap { position: relative; height: 300px; }
.chart-wrap.tall { height: 360px; }

/* Tables */
.tbl-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.data th { text-align: left; color: var(--dim); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; position: sticky; top: 0; background: var(--panel); }
table.data td { padding: 9px 10px; border-bottom: 1px solid rgba(36, 48, 79, 0.5); }
table.data tr:hover td { background: rgba(109, 139, 255, 0.05); }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
.q-text { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-pill { font-variant-numeric: tabular-nums; color: var(--warn); font-weight: 700; }
.cov-pill { display: inline-block; font-size: 10.5px; padding: 2px 7px; border-radius: 10px; background: rgba(255, 92, 124, 0.12); color: var(--danger); font-weight: 700; }
.tbl-scroll { max-height: 420px; overflow-y: auto; }
.mini-tag { font-size: 10.5px; color: var(--dim); }

/* Forecast */
.forecast { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.fc-box { text-align: center; padding: 18px 12px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }
.fc-box .fc-val { font-size: 26px; font-weight: 780; letter-spacing: -0.5px; }
.fc-box .fc-lbl { font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.fc-box.hi { background: linear-gradient(180deg, rgba(52,217,168,0.12), var(--bg)); border-color: rgba(52,217,168,0.35); }
.fc-box.hi .fc-val { color: var(--client); }
.fc-note { font-size: 11.5px; color: var(--dim); margin-top: 14px; }

/* Insights */
.insights { margin-top: 18px; }
.verdict { font-size: 16px; font-weight: 650; line-height: 1.6; padding: 18px 20px; border-left: 3px solid var(--accent); background: rgba(109,139,255,0.06); border-radius: 0 12px 12px 0; }
.ins-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 18px; }
.ins-block h4 { font-size: 13px; font-weight: 700; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.ins-block ul { list-style: none; display: flex; flex-direction: column; gap: 9px; }
.ins-block li { font-size: 13px; color: var(--text); padding-left: 20px; position: relative; }
.ins-block li::before { content: '▹'; position: absolute; left: 0; color: var(--accent); }
.ins-block.client li::before { color: var(--client); }
.ins-block.comp li::before { color: var(--comp); }
.ins-block.why li::before { content: '⚡'; }

.plan { margin-top: 20px; display: flex; flex-direction: column; gap: 12px; }
.plan-phase { background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.plan-phase-h { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.plan-phase-h .pp-name { font-size: 14px; font-weight: 700; }
.plan-phase-h .pp-time { font-size: 11.5px; color: var(--accent); font-weight: 600; }
.plan-actions { list-style: none; margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.plan-actions li { font-size: 12.5px; color: var(--muted); padding-left: 18px; position: relative; }
.plan-actions li::before { content: '✓'; position: absolute; left: 0; color: var(--client); }
.plan-kpi { margin-top: 10px; font-size: 12px; color: var(--warn); font-weight: 600; }
.pitch { margin-top: 20px; padding: 22px 24px; border-radius: 14px; background: var(--grad); color: white; font-size: 14.5px; line-height: 1.65; font-weight: 500; box-shadow: 0 12px 34px rgba(109,139,255,0.4); }
.pitch-label { text-transform: uppercase; letter-spacing: 1px; font-size: 11px; opacity: 0.85; margin-bottom: 8px; font-weight: 700; }

.section-title { font-size: 17px; font-weight: 700; margin: 30px 0 14px; display: flex; align-items: center; gap: 10px; }
.section-title .st-line { flex: 1; height: 1px; background: var(--line); }

.gen-state { text-align: center; padding: 30px; color: var(--muted); font-size: 13px; }
.role-legend { font-size: 11px; color: var(--dim); }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 12px 20px; border-radius: 12px; font-size: 13px; box-shadow: var(--shadow); z-index: 100;
}
.toast.err { border-color: var(--danger); color: var(--danger); }

@media (max-width: 1080px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .setup-grid, .grid-2, .grid-2.wide, .ins-grid { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .forecast { grid-template-columns: 1fr; }
}
