:root {
  --bg-app: #0f172a;
  --bg-panel: #1e293b;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --bg-input: #0f172a;
  --border: #334155;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --purple: #8b5cf6;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  background: var(--bg-app);
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.5;
}

.app-layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 248px;
  background: #0b1120;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 10px 20px; border-bottom: 1px solid var(--border); }
.brand-logo {
  width: 36px; height: 36px; border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 18px; color: #fff;
}
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -0.02em; }
.brand-sub { font-size: 11px; color: var(--text-muted); }

.nav-list { display: flex; flex-direction: column; gap: 4px; margin-top: 16px; flex: 1; }
.nav-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 12px;
  border: none; border-radius: 8px;
  background: transparent; color: var(--text-muted);
  font-size: 13.5px; font-weight: 500; text-align: left; cursor: pointer;
  transition: all 0.15s;
}
.nav-btn:hover { background: var(--bg-panel); color: var(--text-main); }
.nav-btn.active { background: rgba(59, 130, 246, 0.16); color: #60a5fa; font-weight: 600; }
.nav-badge {
  margin-left: auto; background: var(--primary); color: #fff;
  font-size: 11px; padding: 1px 7px; border-radius: 99px; font-weight: 700;
}

.sidebar-footer { border-top: 1px solid var(--border); padding-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.playbook-pill {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--bg-panel); padding: 8px 12px; border-radius: 6px; font-size: 12px;
}
.autopilot-indicator { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); padding: 0 4px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.green { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot.amber { background: var(--amber); }
.dot.red { background: var(--red); }

/* Main area */
.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 68px; border-bottom: 1px solid var(--border);
  padding: 0 28px; display: flex; align-items: center; justify-content: space-between;
  background: rgba(15, 23, 42, 0.85);
}
.topbar h1 { font-size: 18px; font-weight: 700; }
.topbar-subtitle { font-size: 12px; color: var(--text-muted); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.filter-label { font-size: 12px; color: var(--text-muted); }

.view-container { padding: 24px 28px; display: flex; flex-direction: column; gap: 22px; overflow-y: auto; }

/* Cards & Grids */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 14px; }
.kpi-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px 18px;
}
.kpi-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 18px 20px;
}
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.card-title { font-size: 15px; font-weight: 600; }

/* Funnel bars */
.funnel-list { display: flex; flex-direction: column; gap: 10px; }
.funnel-row { display: grid; grid-template-columns: 150px 1fr 90px; align-items: center; gap: 12px; }
.funnel-stage { font-weight: 500; font-size: 13px; }
.funnel-track { background: #0f172a; height: 22px; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.funnel-fill { height: 100%; background: linear-gradient(90deg, #3b82f6, #10b981); border-radius: 4px; transition: width 0.3s; }
.funnel-num { text-align: right; font-weight: 600; font-size: 13px; }

/* Tables */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td {
  padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border);
}
.data-table th { color: var(--text-muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; }
.data-table tr.clickable-row { cursor: pointer; }
.data-table tr.clickable-row:hover { background: rgba(51, 65, 85, 0.45); }

/* Badges */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 99px;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
}
.badge-green { background: rgba(16, 185, 129, 0.18); color: #34d399; }
.badge-blue { background: rgba(59, 130, 246, 0.18); color: #60a5fa; }
.badge-amber { background: rgba(245, 158, 11, 0.18); color: #fbbf24; }
.badge-red { background: rgba(239, 68, 68, 0.18); color: #f87171; }
.badge-purple { background: rgba(139, 92, 246, 0.18); color: #c084fc; }
.badge-slate { background: rgba(148, 163, 184, 0.18); color: #cbd5e1; }

/* Controls & Forms */
.btn {
  padding: 8px 14px; border-radius: 7px; border: 1px solid transparent;
  font-size: 13px; font-weight: 600; cursor: pointer; transition: all 0.15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg-panel); color: var(--text-main); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-danger { background: rgba(239, 68, 68, 0.2); color: #f87171; border-color: rgba(239, 68, 68, 0.4); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.input-text, .input-select, .input-textarea {
  background: var(--bg-input); color: var(--text-main);
  border: 1px solid var(--border); border-radius: 7px;
  padding: 8px 11px; font-size: 13px;
}
.input-textarea { width: 100%; min-height: 76px; font-family: inherit; }
.form-row { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.form-row label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* Quota progress */
.quota-bar { height: 8px; background: #0f172a; border-radius: 99px; overflow: hidden; margin-top: 5px; }
.quota-fill { height: 100%; background: var(--primary); border-radius: 99px; }

/* Inbox Split Layout */
.inbox-split { display: grid; grid-template-columns: 320px 1fr; gap: 16px; min-height: 520px; }
.inbox-thread-list { border-right: 1px solid var(--border); padding-right: 12px; display: flex; flex-direction: column; gap: 8px; }
.inbox-item { padding: 12px; border-radius: 8px; border: 1px solid var(--border); cursor: pointer; background: #0f172a; }
.inbox-item.active { border-color: var(--primary); background: rgba(59, 130, 246, 0.12); }
.msg-bubble { padding: 10px 14px; border-radius: 10px; max-width: 78%; margin-bottom: 8px; }
.msg-inbound { background: #334155; align-self: flex-start; }
.msg-outbound { background: #1d4ed8; align-self: flex-end; margin-left: auto; }

/* Drawer & Modal */
.drawer-backdrop, .modal-backdrop {
  position: fixed; inset: 0; background: rgba(2, 6, 23, 0.72);
  display: flex; z-index: 100;
}
.drawer-panel {
  margin-left: auto; width: 540px; max-width: 95vw; height: 100vh;
  background: var(--bg-panel); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 20px; overflow-y: auto;
}
.drawer-header, .modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding-bottom: 14px; border-bottom: 1px solid var(--border); margin-bottom: 16px;
}
.modal-backdrop { align-items: center; justify-content: center; }
.modal-card {
  width: 640px; max-width: 95vw; max-height: 90vh; overflow-y: auto;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px; padding: 22px;
}
.toast-container { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: #1e293b; border: 1px solid var(--primary); color: #fff; padding: 10px 16px; border-radius: 8px; }
.text-muted { color: var(--text-muted); font-size: 12px; }
pre.code-block { background: #090d16; padding: 12px; border-radius: 8px; overflow-x: auto; font-size: 12px; color: #93c5fd; border: 1px solid var(--border); }
