:root {
  --bg: #0f1117;
  --surface: #1a1d29;
  --surface2: #232838;
  --primary: #4f7cff;
  --primary-dark: #3b62d4;
  --accent: #00d4aa;
  --danger: #ff4757;
  --warning: #ffa502;
  --text: #e4e6ef;
  --text-muted: #8a8fa3;
  --border: #2d3142;
  --radius: 10px;
  --shadow: 0 4px 20px rgba(0,0,0,0.3);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ─────────────────────────────────────────────────────────────── */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 0;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 16px;
  color: var(--primary);
  font-weight: 700;
}

.sidebar-header small { color: var(--text-muted); font-size: 11px; }

.nav { padding: 12px 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text-muted);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all 0.15s;
  font-size: 13px;
}

.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active {
  background: var(--surface2);
  color: var(--primary);
  border-left-color: var(--primary);
}

.nav-item .icon { font-size: 16px; width: 20px; text-align: center; }

.main {
  flex: 1;
  padding: 24px;
  max-width: 100%;
  overflow-x: hidden;
}

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 14px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

/* ── KPI Grid ────────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  position: relative;
  overflow: hidden;
}

.kpi::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 4px; height: 100%;
  background: var(--primary);
}

.kpi.accent::before { background: var(--accent); }
.kpi.warning::before { background: var(--warning); }
.kpi.danger::before { background: var(--danger); }

.kpi-value { font-size: 28px; font-weight: 700; }
.kpi-label { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; text-transform: uppercase; font-size: 11px; }
tr:hover { background: var(--surface2); }
.rpn-high { color: var(--danger); font-weight: bold; }
.rpn-med { color: var(--warning); }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.badge-draft { background: #3a3a5a; color: #ccc; }
.badge-approved { background: #1a5e3a; color: #5ee893; }
.badge-dirty { background: #5e3a1a; color: #ffa502; }
.badge-active { background: #1a3a5e; color: #4f9eff; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%;
  padding: 8px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }

.btn {
  display: inline-block;
  padding: 8px 18px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s;
}
.btn:hover { background: var(--primary-dark); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-accent { background: var(--accent); }
.btn-accent:hover { background: #00b890; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #e03441; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); }

/* ── Grid ────────────────────────────────────────────────────────────────── */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ── Charts ──────────────────────────────────────────────────────────────── */
.chart-container {
  position: relative;
  height: 250px;
  margin-top: 12px;
}

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 700px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-title { font-size: 18px; margin-bottom: 16px; color: var(--primary); }

/* ── AI Panel ─────────────────────────────────────────────────────────────── */
.ai-panel {
  background: linear-gradient(135deg, #1a1d29, #232838);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.ai-panel h3 { color: var(--accent); font-size: 14px; margin-bottom: 8px; }
.ai-response {
  background: var(--bg);
  border-radius: 6px;
  padding: 12px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  white-space: pre-wrap;
  max-height: 300px;
  overflow-y: auto;
  margin-top: 8px;
}

/* ── Phase tracker ────────────────────────────────────────────────────────── */
.phase-tracker {
  display: flex;
  gap: 0;
  margin: 16px 0;
  overflow-x: auto;
}
.phase-step {
  flex: 1;
  min-width: 140px;
  text-align: center;
  padding: 12px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-right: none;
  font-size: 12px;
  position: relative;
}
.phase-step:last-child { border-right: 1px solid var(--border); }
.phase-step.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.phase-step.completed {
  background: #1a5e3a;
  color: #5ee893;
}
.phase-step .phase-num { font-size: 18px; font-weight: 700; display: block; }
.phase-step .phase-name { font-size: 10px; opacity: 0.8; }

/* ── Tree ─────────────────────────────────────────────────────────────────── */
.tree-node { padding: 6px 0; }
.tree-children { margin-left: 20px; border-left: 1px solid var(--border); padding-left: 12px; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .nav { display: flex; overflow-x: auto; padding: 8px; }
  .nav-item { white-space: nowrap; border-left: none; border-bottom: 3px solid transparent; }
  .nav-item.active { border-left: none; border-bottom-color: var(--primary); }
  .main { padding: 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .phase-tracker { flex-direction: column; }
  .phase-step { border-right: 1px solid var(--border) !important; border-bottom: none; }
}

/* ── Toast ────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  padding: 12px 20px;
  border-radius: 6px;
  box-shadow: var(--shadow);
  z-index: 2000;
  max-width: 350px;
  animation: slideIn 0.3s ease;
}
@keyframes slideIn { from { transform: translateX(400px); } to { transform: translateX(0); } }

/* ── Scrollbar ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ── Login Screen ─────────────────────────────────────────────────────────── */
.login-screen {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0f1117 0%, #1a1d29 50%, #0f3460 100%);
}
.login-screen.hidden { display: none; }
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 380px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-logo {
  width: 80px; height: 80px;
  margin-bottom: 12px;
  border-radius: 16px;
}
.login-brand h1 {
  font-size: 32px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -1px;
}
.login-brand h1 span { color: var(--accent); }
.login-brand small { color: var(--text-muted); display: block; margin-top: 4px; }
.login-divider {
  text-align: center;
  color: var(--text-muted);
  margin: 16px 0;
  position: relative;
}
.login-divider::before, .login-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: var(--border);
}
.login-divider::before { left: 0; }
.login-divider::after { right: 0; }
.demo-accounts {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
}
.demo-accounts small {
  display: block;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.6;
}

/* ── Sidebar Footer ───────────────────────────────────────────────────────── */
.sidebar-logo {
  width: 48px; height: 48px;
  border-radius: 10px;
  margin-bottom: 8px;
  display: block;
}
.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}
.sidebar-footer .copyright {
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 8px;
}
.user-menu-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: white;
}
.user-name { font-size: 12px; }
.user-role { font-size: 10px; color: var(--text-muted); }

/* ── Funnel ───────────────────────────────────────────────────────────────── */
.funnel-container {
  overflow-x: auto;
  padding-bottom: 16px;
}
.funnel-board {
  display: flex;
  gap: 12px;
  min-width: max-content;
}
.funnel-column {
  width: 260px;
  flex-shrink: 0;
  background: var(--surface2);
  border-radius: var(--radius);
  border-top: 3px solid var(--primary);
  display: flex;
  flex-direction: column;
}
.funnel-column-header {
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.funnel-column-count {
  background: var(--surface);
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 11px;
  color: var(--text-muted);
}
.funnel-column-items {
  padding: 8px;
  flex: 1;
  min-height: 200px;
}
.funnel-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.funnel-item:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}
.funnel-item-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}
.funnel-item-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
}
.funnel-item-value {
  color: var(--accent);
  font-weight: 600;
}
.funnel-item-priority {
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 10px;
}
.priority-high { background: #5e1a1a; color: #ff6b6b; }
.priority-medium { background: #5e4a1a; color: #ffa502; }
.priority-low { background: #1a3a5e; color: #4f9eff; }
.priority-critical { background: #5e1a1a; color: #ff4757; font-weight: bold; }

.funnel-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.funnel-stat {
  background: var(--surface2);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
}
.funnel-stat-value { font-size: 22px; font-weight: 700; color: var(--accent); }
.funnel-stat-label { font-size: 11px; color: var(--text-muted); }

/* ── Billing ──────────────────────────────────────────────────────────────── */
.plan-card {
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  position: relative;
  transition: border-color 0.15s;
}
.plan-card:hover { border-color: var(--primary); }
.plan-card.current { border-color: var(--accent); }
.plan-card.featured { border-color: var(--primary); }
.plan-badge {
  position: absolute;
  top: -12px; left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: white;
  padding: 2px 12px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
}
.plan-price { font-size: 36px; font-weight: 800; margin: 12px 0; }
.plan-price small { font-size: 14px; color: var(--text-muted); font-weight: 400; }
.plan-features { text-align: left; margin: 16px 0; }
.plan-features li {
  list-style: none;
  padding: 4px 0;
  font-size: 13px;
  color: var(--text-muted);
}
.plan-features li::before { content: '✓ '; color: var(--accent); }