:root {
  color-scheme: light;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #94a3b8;
  --brand: #16a34a;
  --brand-ink: #ffffff;
  --nav: #14324a;
  --nav-ink: #cfe0ee;
  --accent: #2563eb;
  --danger: #dc2626;
  --warn-bg: #fff7ed;
  --warn-ink: #9a3412;
  --in-bubble: #f1f5f9;
  --out-bubble: #dcfce7;
  --note-bubble: #fef9c3;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 2px 8px rgba(15, 23, 42, .05);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1418;
    --surface: #182027;
    --surface-2: #1d262e;
    --border: #2b3640;
    --text: #e8edf2;
    --text-2: #a9b5c0;
    --muted: #6b7a87;
    --nav: #0b1a26;
    --nav-ink: #b9cddd;
    --accent: #60a5fa;
    --in-bubble: #23303a;
    --out-bubble: #1e3a2a;
    --note-bubble: #3a3518;
    --warn-bg: #3a2414;
    --warn-ink: #fdba74;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
  }
}

* { box-sizing: border-box; }
html, body, #app { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.boot { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- Butoane și câmpuri ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(.95); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 8px 10px; outline: none; min-height: 36px;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
textarea.input { resize: vertical; min-height: 70px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); margin: 8px 0; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; word-break: break-all; }

/* ---------- Autentificare ---------- */
.auth-wrap { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; margin-bottom: 18px; }
.logo-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--brand); display: grid; place-items: center; }

/* ---------- Structura aplicației ---------- */
.shell { display: grid; grid-template-columns: 76px 1fr; height: 100%; }
.nav { background: var(--nav); color: var(--nav-ink); display: flex; flex-direction: column; align-items: center; padding: 12px 0; gap: 4px; }
.nav .logo-mark { margin-bottom: 12px; }
.nav a {
  display: flex; flex-direction: column; align-items: center; gap: 3px; width: 64px; padding: 8px 0;
  color: var(--nav-ink); text-decoration: none; font-size: 11px; border-radius: 10px; position: relative;
}
.nav a svg { width: 22px; height: 22px; }
.nav a.active, .nav a:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.nav .spacer { flex: 1; }
.nav .badge { position: absolute; top: 4px; right: 10px; }
.main { min-width: 0; display: flex; flex-direction: column; height: 100%; overflow: hidden; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.topbar h1 { font-size: 17px; margin: 0 8px 0 0; }
.topbar .search { flex: 1; min-width: 160px; max-width: 360px; }
.topbar .grow { flex: 1; }
.content { flex: 1; overflow: auto; padding: 16px; }
.badge { display: inline-block; min-width: 18px; height: 18px; line-height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; text-align: center; font-weight: 600; }

/* ---------- Tabla Kanban ---------- */
.board { display: flex; gap: 12px; height: 100%; padding: 16px; overflow-x: auto; scroll-snap-type: x proximity; }
.column { flex: 0 0 272px; display: flex; flex-direction: column; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); max-height: 100%; scroll-snap-align: start; }
.column-head { padding: 10px 12px 8px; border-top: 4px solid var(--c, #64748b); border-radius: var(--radius) var(--radius) 0 0; }
.column-head .t { font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: .02em; }
.column-head .n { color: var(--text-2); font-size: 12px; }
.column-body { flex: 1; overflow-y: auto; padding: 4px 8px 10px; min-height: 80px; }
.column.drop { outline: 2px dashed var(--accent); outline-offset: -2px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; margin-top: 8px;
  cursor: pointer; box-shadow: var(--shadow); position: relative;
}
.card:hover { border-color: var(--accent); }
.card.dragging { opacity: .5; }
.card .name { font-weight: 600; padding-right: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .meta { color: var(--text-2); font-size: 12px; margin-top: 2px; }
.card .snippet { color: var(--text-2); font-size: 12.5px; margin-top: 6px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .foot { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; gap: 6px; }
.card .dot { position: absolute; top: 11px; right: 10px; width: 9px; height: 9px; border-radius: 50%; background: var(--danger); }
.src { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2); white-space: nowrap; }
.src i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.avatar { width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 10.5px; font-weight: 700; color: #fff; background: #64748b; flex: 0 0 auto; }
.empty-col { color: var(--muted); font-size: 12px; text-align: center; padding: 18px 0; }

/* ---------- Tabel ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; }
table.t { width: 100%; border-collapse: collapse; }
table.t th, table.t td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.t th { font-size: 12px; color: var(--text-2); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: var(--surface-2); }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; color: #fff; white-space: nowrap; }

/* ---------- Cardul leadului (panou lateral) ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .35); z-index: 20; display: flex; justify-content: flex-end; }
.drawer { width: min(980px, 100%); height: 100%; background: var(--bg); display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(0, 0, 0, .15); }
.drawer-head { background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px 16px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.drawer-head h2 { margin: 0; font-size: 18px; flex: 1; min-width: 160px; }
.drawer-body { flex: 1; display: grid; grid-template-columns: 340px 1fr; min-height: 0; }
.lead-side { overflow-y: auto; padding: 16px; border-right: 1px solid var(--border); background: var(--surface); }
.lead-feed { display: flex; flex-direction: column; min-height: 0; }
.feed { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.ev { max-width: 82%; }
.ev .bubble { padding: 8px 11px; border-radius: 10px; white-space: pre-wrap; word-wrap: break-word; }
.ev .who { font-size: 11.5px; color: var(--muted); margin-bottom: 2px; }
.ev.in { align-self: flex-start; }
.ev.in .bubble { background: var(--in-bubble); border-top-left-radius: 3px; }
.ev.out { align-self: flex-end; }
.ev.out .bubble { background: var(--out-bubble); border-top-right-radius: 3px; }
.ev.out .who { text-align: right; }
.ev.note { align-self: flex-end; }
.ev.note .bubble { background: var(--note-bubble); }
.ev.sys { align-self: center; max-width: 95%; text-align: center; font-size: 12px; color: var(--text-2); }
.ev.sys .bubble { padding: 2px 10px; white-space: pre-wrap; }
.composer { border-top: 1px solid var(--border); background: var(--surface); padding: 10px 12px; }
.tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.tab { border: 0; background: none; padding: 5px 10px; border-radius: 7px; cursor: pointer; color: var(--text-2); }
.tab.on { background: var(--surface-2); color: var(--text); font-weight: 600; box-shadow: inset 0 0 0 1px var(--border); }
.warn { background: var(--warn-bg); color: var(--warn-ink); padding: 8px 10px; border-radius: 8px; font-size: 13px; margin-bottom: 8px; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.section-t { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 14px 0 8px; font-weight: 600; }
.mobile-tabs { display: none; }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 40; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; padding: 20px; width: 100%; max-width: 440px; max-height: 90vh; overflow: auto; box-shadow: var(--shadow); }
.modal h3 { margin: 0 0 14px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* ---------- Rapoarte ---------- */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(12, 1fr); }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.panel h3 { margin: 0 0 12px; font-size: 14px; }
.span-3 { grid-column: span 3; } .span-4 { grid-column: span 4; } .span-6 { grid-column: span 6; } .span-8 { grid-column: span 8; } .span-12 { grid-column: span 12; }
.stat .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--text-2); font-size: 12.5px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-l { stroke: var(--border); stroke-width: 1; }
.chart .axis-t { fill: var(--muted); font-size: 10px; }
.tip { position: absolute; pointer-events: none; background: var(--text); color: var(--surface); font-size: 12px; padding: 6px 9px; border-radius: 6px; white-space: nowrap; z-index: 5; transform: translate(-50%, calc(-100% - 8px)); display: none; }
.hbar { display: grid; grid-template-columns: minmax(90px, 38%) 1fr 44px; align-items: center; gap: 8px; margin: 6px 0; font-size: 13px; }
.hbar .track { height: 14px; border-radius: 0 4px 4px 0; background: transparent; }
.hbar .fill { height: 100%; border-radius: 0 4px 4px 0; background: var(--series-1); min-width: 2px; }
.hbar .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.hbar .val { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Setări ---------- */
.settings { display: grid; grid-template-columns: 200px 1fr; gap: 16px; max-width: 1100px; }
.settings-nav { display: flex; flex-direction: column; gap: 2px; }
.settings-nav a { padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--text); }
.settings-nav a.on { background: var(--surface); box-shadow: inset 0 0 0 1px var(--border); font-weight: 600; }
.list-item { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 120px; }
.step { margin: 0 0 6px; }
.copy { display: flex; gap: 6px; align-items: center; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; margin: 4px 0 10px; }
.copy code { flex: 1; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 10px; z-index: 60; display: none; max-width: calc(100% - 32px); box-shadow: var(--shadow); }
#toast.err { background: var(--danger); color: #fff; }

/* ---------- Telefon ---------- */
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .nav { order: 2; flex-direction: row; justify-content: space-around; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
  .nav .logo-mark, .nav .spacer { display: none; }
  .nav a { width: auto; flex: 1; padding: 6px 0; }
  .topbar { padding: 10px 12px; }
  .topbar h1 { display: none; }
  .topbar .search { max-width: none; flex-basis: 100%; order: 5; }
  .board { padding: 12px; scroll-snap-type: x mandatory; }
  .column { flex-basis: calc(100vw - 48px); }
  .content { padding: 12px; }
  .drawer-body { grid-template-columns: 1fr; }
  .mobile-tabs { display: flex; background: var(--surface); border-bottom: 1px solid var(--border); padding: 6px 12px; gap: 4px; }
  .drawer-body[data-tab="feed"] .lead-side { display: none; }
  .drawer-body[data-tab="info"] .lead-feed { display: none; }
  .lead-side { border-right: 0; }
  .ev { max-width: 92%; }
  .span-3, .span-4, .span-6, .span-8 { grid-column: span 12; }
  .grid .stat-row { grid-column: span 6; }
  .settings { grid-template-columns: 1fr; }
  .settings-nav { flex-direction: row; overflow-x: auto; }
  .settings-nav a { white-space: nowrap; }
  .hide-m { display: none; }
}
