:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #1e222b;
  --line: #2a2f3a;
  --text: #e8eaf0;
  --muted: #8b93a5;
  --accent: #f5b942;
  --accent2: #4f8cff;
  --ok: #38c172;
  --warn: #f4a62a;
  --bad: #e35656;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
}
.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 230px; flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 18px 14px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; gap: 10px; align-items: center; margin-bottom: 24px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #e08b1e);
  color: #1a1a1a; font-weight: 800; font-size: 15px;
  display: grid; place-items: center;
}
.brand-name { font-weight: 700; }
.brand-sub { font-size: 12px; color: var(--muted); }
nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-btn {
  text-align: left; padding: 10px 12px; border-radius: 8px;
  background: none; border: none; color: var(--muted);
  font-size: 14px; cursor: pointer; transition: .15s;
}
.nav-btn:hover { background: var(--panel2); color: var(--text); }
.nav-btn.active { background: var(--panel2); color: var(--accent); font-weight: 600; }
.sidebar-foot { font-size: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
.db-badge { color: var(--warn); }
.db-badge.sb { color: var(--ok); }
.muted { color: var(--muted); }

/* Main */
.main { flex: 1; padding: 26px 30px; max-width: 100%; min-width: 0; }
.view { display: none; }
.view.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } }
.view-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.view-head h1 { font-size: 22px; margin: 0; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Buttons & inputs */
.btn {
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 14px; font-size: 13px; cursor: pointer; transition: .15s;
}
.btn:hover { border-color: var(--accent2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a1a1a; font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: 12px; }
input, select, textarea {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 11px; font-size: 13px; font-family: inherit;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent2); }
input[type="search"] { width: 230px; }
select { width: auto; }
option { background: var(--panel); }

/* Panels & stats */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.two-col .panel { margin-bottom: 18px; }
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px;
}
.panel h2 { font-size: 15px; margin: 0 0 14px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px;
}
.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat .value { font-size: 28px; font-weight: 800; margin-top: 4px; }
.stat .value.accent { color: var(--accent); }
.stat .value.ok { color: var(--ok); }
.stat .value.bad { color: var(--bad); }

/* Stage bars */
.stage-bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 120px 1fr 40px; align-items: center; gap: 12px; font-size: 13px; }
.bar-track { background: var(--panel2); height: 12px; border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; background: var(--accent2); transition: width .4s; }
.bar-row .count { text-align: right; color: var(--muted); font-size: 13px; }

/* Activity */
.activity { display: flex; flex-direction: column; gap: 8px; }
.activity .item { display: flex; justify-content: space-between; padding: 8px 10px; background: var(--panel2); border-radius: 8px; font-size: 13px; }
.activity .item .ts { color: var(--muted); font-size: 12px; }

/* Clif maintainer panel */
.clif-panel { border-color: rgba(245,185,66,.35); }
.clif-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.clif-head h2 { margin: 0; }
.clif-digest { font-size: 13px; }
.clif-digest .digest-stats { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; }
.clif-digest .digest-stats span { background: var(--panel2); padding: 4px 10px; border-radius: 10px; font-size: 12px; }
.clif-digest .digest-task { display: flex; gap: 8px; align-items: baseline; padding: 6px 8px; border-bottom: 1px dashed var(--line); }
.clif-digest .digest-task:last-child { border-bottom: none; }
.clif-digest .focus-callout { background: rgba(245,185,66,.1); border-left: 3px solid var(--accent); padding: 8px 12px; border-radius: 6px; margin-bottom: 10px; }

/* Blueprint table */
.table-wrap { overflow: auto; padding: 0; max-height: calc(100vh - 190px); }
.leads-table { border-collapse: collapse; font-size: 12.5px; min-width: 2100px; }
.leads-table th {
  text-align: left; padding: 10px 12px; color: var(--muted);
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--line);
  background: var(--panel); position: sticky; top: 0; z-index: 2;
  white-space: nowrap;
}
.leads-table tr.group-row th {
  top: 0; z-index: 3; text-align: center;
  background: var(--panel2); color: var(--accent);
  border-bottom: 1px solid var(--line); font-size: 11.5px;
}
.leads-table thead tr:nth-child(2) th { top: 31px; }
.leads-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; max-width: 220px; }
.leads-table td:first-child { position: sticky; left: 0; background: var(--panel); z-index: 1; font-weight: 600; }
.leads-table tr:hover td { background: var(--panel2); }
.leads-table tr:hover td:first-child { background: var(--panel2); }
.cell-clip { display: block; max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pill { display: inline-block; font-size: 11px; padding: 2px 9px; border-radius: 10px; font-weight: 600; white-space: nowrap; }
.pill-neutral { background: rgba(139,147,165,.15); color: var(--muted); }
.pill-blue { background: rgba(79,140,255,.15); color: #79a8ff; }
.pill-gold { background: rgba(245,185,66,.15); color: var(--accent); }
.pill-purple { background: rgba(160,120,255,.15); color: #b79bff; }
.pill-green { background: rgba(56,193,114,.15); color: var(--ok); }
.pill-red { background: rgba(227,86,86,.15); color: var(--bad); }
.pill-teal { background: rgba(60,200,190,.15); color: #3cc8be; }

.row-actions { white-space: nowrap; }
.row-actions button { background: none; border: none; cursor: pointer; font-size: 14px; padding: 2px 5px; color: var(--muted); }
.row-actions button:hover { color: var(--text); }

/* Follow-ups */
.fu-list { display: flex; flex-direction: column; gap: 12px; }
.fu-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; gap: 14px; align-items: flex-start; }
.fu-card.overdue { border-left: 3px solid var(--bad); }
.fu-card.due { border-left: 3px solid var(--warn); }
.fu-card .fu-main { flex: 1; min-width: 0; }
.fu-card .fu-name { font-weight: 700; }
.fu-card .fu-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.fu-card .fu-note { color: var(--muted); font-size: 13px; margin-top: 6px; white-space: pre-wrap; }
.fu-date { font-size: 12px; padding: 3px 9px; border-radius: 10px; background: var(--panel2); white-space: nowrap; }
.fu-date.overdue { color: var(--bad); }
.fu-date.due { color: var(--warn); }

/* Settings */
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
label input, label select, label textarea { margin-top: 4px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
details { margin-top: 14px; font-size: 13px; }
summary { cursor: pointer; color: var(--accent2); }
pre {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px; overflow-x: auto; font-size: 12px; margin: 10px 0;
}

/* Modal */
dialog {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 14px;
  padding: 0; width: min(880px, 96vw);
  max-height: 92vh;
}
dialog.wide { width: min(920px, 96vw); }
dialog::backdrop { background: rgba(0,0,0,.6); backdrop-filter: blur(3px); }
.modal { padding: 22px 26px; overflow-y: auto; max-height: 92vh; }
.modal h2 { margin: 0 0 16px; font-size: 18px; }
fieldset {
  border: 1px solid var(--line); border-radius: 10px;
  margin: 0 0 16px; padding: 12px 16px 4px;
}
legend { font-size: 12px; color: var(--accent); font-weight: 700; padding: 0 6px; text-transform: uppercase; letter-spacing: .04em; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.modal-actions .muted { margin-right: auto; font-size: 12px; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--panel2); border: 1px solid var(--line);
  border-left: 3px solid var(--accent2);
  padding: 12px 18px; border-radius: 10px; font-size: 13px;
  opacity: 0; transform: translateY(10px); transition: .25s; pointer-events: none;
  max-width: 360px; z-index: 50;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.err { border-left-color: var(--bad); }
.toast.ok { border-left-color: var(--ok); }

/* Responsive */
@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; gap: 14px; padding: 10px 14px; }
  .sidebar nav { flex-direction: row; flex: 1; }
  .sidebar .brand { margin: 0; }
  .sidebar-foot { display: none; }
  .main { padding: 18px 14px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
}
