:root {
  --bg: #0b1120;
  --bg-soft: #0f172a;
  --panel: #111827;
  --panel-2: #1a2333;
  --border: #1f2937;
  --border-soft: #263043;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --muted-2: #64748b;
  --accent: #3b82f6;
  --accent-soft: rgba(59, 130, 246, 0.14);
  --success: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --purple: #8b5cf6;
  --pink: #ec4899;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --sidebar-w: 248px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14.5px;
  line-height: 1.5;
}

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

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #263043; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

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

.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, #0c1424 0%, #0a0f1c 100%);
  border-right: 1px solid var(--border);
  position: fixed;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  z-index: 40;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; }
.brand .logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: grid; place-items: center; font-weight: 800; color: #fff; font-size: 16px;
}
.brand .name { font-weight: 700; font-size: 15px; letter-spacing: .2px; }
.brand .sub { font-size: 11px; color: var(--muted-2); }

.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav .section { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted-2); padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px;
  border-radius: var(--radius-sm); color: var(--muted); font-weight: 500; text-decoration: none;
  transition: background .15s, color .15s;
}
.nav a:hover { background: var(--panel); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: #bfdbfe; }
.nav a .ico { width: 18px; text-align: center; opacity: .9; }
.nav a .count {
  margin-left: auto; font-size: 11px; background: var(--panel-2); color: var(--muted);
  border-radius: 20px; padding: 1px 8px;
}

.sidebar .foot { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 10px; }
.sidebar .foot .who { font-size: 12px; color: var(--muted); }
.sidebar .foot .who b { color: var(--text); }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px;
  padding: 14px 24px; background: rgba(11, 17, 32, .85);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 650; }
.topbar .sub { color: var(--muted); font-size: 12.5px; }
.topbar .spacer { flex: 1; }

.content { padding: 22px 24px 60px; }

.live {
  display: inline-flex; align-items: center; gap: 7px; font-size: 12px;
  color: var(--muted); background: var(--panel); border: 1px solid var(--border);
  padding: 5px 11px; border-radius: 30px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted-2); }
.dot.on { background: var(--success); box-shadow: 0 0 0 0 rgba(34,197,94,.6); animation: pulse 1.8s infinite; }
.dot.busy { background: var(--warn); animation: pulse 1.2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(34,197,94,.5);} 70% { box-shadow: 0 0 0 8px rgba(34,197,94,0);} 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0);} }

/* ---------- Cards / panels ---------- */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px;
}
.card + .card { margin-top: 16px; }
.card h2, .card h3 { margin: 0 0 12px; font-weight: 620; }
.card h2 { font-size: 16px; }
.card h3 { font-size: 14px; }

.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
@media (max-width: 1100px) { .grid.cols-4 { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 820px) { .grid.cols-4, .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; } }

.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 28px; font-weight: 720; margin-top: 4px; }
.stat .value.small { font-size: 22px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border-soft);
  padding: 9px 14px; border-radius: var(--radius-sm); font-weight: 550; font-size: 13.5px;
  cursor: pointer; transition: filter .15s, background .15s, border-color .15s;
}
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.success { background: var(--success); border-color: transparent; color: #04220f; }
.btn.danger { background: rgba(239,68,68,.14); border-color: rgba(239,68,68,.4); color: #fca5a5; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 10px; font-size: 12.5px; }
.btn.block { width: 100%; }

/* ---------- Forms ---------- */
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; font-weight: 550; }
input, select, textarea {
  width: 100%; background: var(--bg-soft); color: var(--text);
  border: 1px solid var(--border-soft); border-radius: var(--radius-sm);
  padding: 10px 12px; font-size: 14px; font-family: inherit; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 110px; }
.check { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 13.5px; margin-bottom: 10px; }
.check input { width: auto; }
.inline { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.inline > * { flex: 1 1 160px; }
.hint { color: var(--muted-2); font-size: 12px; margin-top: 6px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tabs button {
  background: transparent; border: none; color: var(--muted); font: inherit; font-weight: 560;
  padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600;
  padding: 3px 9px; border-radius: 30px; background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--border-soft); white-space: nowrap;
}
.badge.ok { background: rgba(34,197,94,.14); color: #86efac; border-color: rgba(34,197,94,.3); }
.badge.warn { background: rgba(245,158,11,.14); color: #fcd34d; border-color: rgba(245,158,11,.3); }
.badge.danger { background: rgba(239,68,68,.14); color: #fca5a5; border-color: rgba(239,68,68,.3); }
.badge.info { background: rgba(59,130,246,.14); color: #93c5fd; border-color: rgba(59,130,246,.3); }
.badge.purple { background: rgba(139,92,246,.16); color: #c4b5fd; border-color: rgba(139,92,246,.32); }
.badge.muted { color: var(--muted-2); }

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted-2); padding: 11px 14px; background: var(--bg-soft);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 1;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: rgba(255,255,255,.02); }
tbody tr:last-child td { border-bottom: none; }
td.actions { text-align: right; white-space: nowrap; }
.mono { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 12.5px; }

/* ---------- Kanban / funnel ---------- */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 12px; }
.col { flex: 0 0 288px; background: var(--bg-soft); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; max-height: 68vh; }
.col .col-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg-soft); border-radius: var(--radius) var(--radius) 0 0; }
.col .col-head .name { font-weight: 620; font-size: 13.5px; }
.col .col-head .n { margin-left: auto; font-size: 11.5px; color: var(--muted); background: var(--panel-2); border-radius: 20px; padding: 1px 9px; }
.col .col-body { padding: 10px; display: flex; flex-direction: column; gap: 9px; overflow-y: auto; }
.lead-card { background: var(--panel); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); padding: 11px 12px; cursor: pointer; transition: border-color .15s, transform .1s; }
.lead-card:hover { border-color: var(--accent); }
.lead-card .t { font-weight: 580; font-size: 13.5px; margin-bottom: 3px; }
.lead-card .d { font-size: 12px; color: var(--muted); word-break: break-all; }
.lead-card .row { display: flex; align-items: center; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.lead-card .owner { margin-left: auto; font-size: 11px; color: var(--muted-2); }
.col-empty { color: var(--muted-2); font-size: 12.5px; text-align: center; padding: 16px 0; }

/* ---------- Progress ---------- */
.progress { height: 7px; background: var(--panel-2); border-radius: 20px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--purple)); border-radius: 20px; transition: width .4s ease; }
.progress.indet > i { width: 35% !important; animation: slide 1.2s infinite ease-in-out; }
@keyframes slide { 0% { margin-left: -35%; } 100% { margin-left: 100%; } }

/* ---------- Job cards ---------- */
.job { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.job .head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.job .title { font-weight: 620; }
.job .meta { color: var(--muted-2); font-size: 12px; }
.job .body { margin-top: 10px; }
.job .items { margin-top: 12px; display: flex; flex-direction: column; gap: 5px; max-height: 220px; overflow-y: auto; }
.job .item { display: flex; align-items: center; gap: 8px; font-size: 12.5px; padding: 4px 8px; border-radius: 7px; background: var(--bg-soft); }
.job .item .lbl { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job .item .det { color: var(--muted-2); font-size: 11.5px; }

/* ---------- Console ---------- */
.console {
  background: #05080f; border: 1px solid var(--border); border-radius: var(--radius);
  font-family: ui-monospace, Consolas, monospace; font-size: 12.3px; padding: 12px 14px;
  height: 340px; overflow-y: auto; line-height: 1.65;
}
.console .ln { white-space: pre-wrap; word-break: break-word; }
.console .ts { color: var(--muted-2); margin-right: 8px; }
.console .info { color: #cbd5e1; }
.console .success { color: #86efac; }
.console .warn { color: #fcd34d; }
.console .error { color: #fca5a5; }

/* ---------- Modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(3,7,18,.72); backdrop-filter: blur(3px);
  display: none; align-items: flex-start; justify-content: center; z-index: 80; padding: 40px 16px;
}
.modal-back.open { display: flex; }
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  width: min(680px, 100%); max-height: 86vh; overflow-y: auto; box-shadow: var(--shadow);
}
.modal .modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--panel); }
.modal .modal-head h3 { margin: 0; font-size: 16px; }
.modal .modal-head .x { margin-left: auto; background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; }
.modal .modal-body { padding: 20px; }
.modal .modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; position: sticky; bottom: 0; background: var(--panel); }

/* ---------- Toast ---------- */
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 120; }
.toast { background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 10px; padding: 12px 16px; min-width: 260px; box-shadow: var(--shadow); animation: fadein .2s; }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
@keyframes fadein { from { opacity: 0; transform: translateY(8px);} to { opacity: 1; transform: none; } }

/* ---------- Misc ---------- */
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.muted-2 { color: var(--muted-2); }
.small { font-size: 12.5px; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }
.pill { font-size: 11.5px; padding: 2px 8px; border-radius: 20px; background: var(--panel-2); color: var(--muted); }
.empty { text-align: center; color: var(--muted-2); padding: 40px 10px; }
.timeline { position: relative; padding-left: 20px; }
.timeline::before { content: ""; position: absolute; left: 6px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.timeline .entry { position: relative; padding: 0 0 16px; }
.timeline .entry::before { content: ""; position: absolute; left: -18px; top: 5px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); }
.timeline .entry .when { font-size: 11.5px; color: var(--muted-2); }
.timeline .entry .what { font-size: 13.5px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: #bfdbfe; display: inline-grid; place-items: center; font-size: 11px; font-weight: 700; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; font-size: 13.5px; }
.kv .k { color: var(--muted-2); }
.score-pill { font-weight: 700; }
.score-pill.ok { color: #86efac; }
.score-pill.warn { color: #fcd34d; }
.score-pill.danger { color: #fca5a5; }
.score-pill.muted { color: var(--muted-2); }

@media (max-width: 780px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .content { padding: 16px; }
  .menu-btn { display: inline-flex !important; }
}
.menu-btn { display: none; }
