/* ============ Theme tokens ============ */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e1e4ea;
  --text: #1c2230;
  --muted: #667085;
  --accent: #3b5bdb;
  --accent-contrast: #ffffff;
  --accent-soft: #e8edff;
  --green: #128c4a;
  --green-soft: #e3f6ec;
  --wa: #1fa855;
  --wa-contrast: #ffffff;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #c92a2a;
  --danger-soft: #fde8e8;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 12px rgba(16, 24, 40, 0.06);
  --radius: 10px;
  color-scheme: light;
}
:root[data-theme='dark'] {
  --bg: #0f131a;
  --surface: #171c26;
  --surface-2: #1f2633;
  --border: #2a3242;
  --text: #e8ecf3;
  --muted: #98a2b3;
  --accent: #7c93ff;
  --accent-contrast: #0f131a;
  --accent-soft: #232c4d;
  --green: #4cc38a;
  --green-soft: #153326;
  --wa: #2fbf6c;
  --wa-contrast: #08140d;
  --warn: #f5b64a;
  --warn-soft: #3a2c10;
  --danger: #ff7b7b;
  --danger-soft: #3b1a1d;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 16px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme='system'] {
    --bg: #0f131a;
    --surface: #171c26;
    --surface-2: #1f2633;
    --border: #2a3242;
    --text: #e8ecf3;
    --muted: #98a2b3;
    --accent: #7c93ff;
    --accent-contrast: #0f131a;
    --accent-soft: #232c4d;
    --green: #4cc38a;
    --green-soft: #153326;
    --wa: #2fbf6c;
    --wa-contrast: #08140d;
    --warn: #f5b64a;
    --warn-soft: #3a2c10;
    --danger: #ff7b7b;
    --danger-soft: #3b1a1d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 16px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

/* ============ Base ============ */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.pre-line { white-space: pre-line; }
.hidden { display: none !important; }
.right { margin-left: auto; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============ Layout ============ */
.shell { display: grid; grid-template-columns: 224px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 16px 12px; display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 4px 8px 16px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-contrast); display: grid; place-items: center; font-size: 15px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-weight: 500; border: 0; background: none; width: 100%; text-align: left; cursor: pointer;
}
.nav-link:hover { background: var(--surface-2); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); }
.nav-ico { width: 20px; text-align: center; }
.nav-badge { margin-left: auto; background: var(--danger); color: #fff; font-size: 0.72rem; border-radius: 999px; padding: 1px 7px; }
.nav-sep { flex: 1; }
.main { padding: 24px 28px 48px; min-width: 0; max-width: 1500px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .sub { color: var(--muted); }
.bottom-nav { display: none; }

@media (max-width: 899px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 16px 14px 96px; }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom-nav a, .bottom-nav button {
    display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; font-size: 0.7rem;
    color: var(--muted); text-decoration: none; background: none; border: 0; cursor: pointer; position: relative;
  }
  .bottom-nav .active { color: var(--accent); }
  .bottom-nav .ico { font-size: 1.2rem; line-height: 1; }
  .bottom-nav .add { color: var(--accent); font-weight: 700; }
}

/* ============ Controls ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 500; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-wa { background: var(--wa); color: var(--wa-contrast); border-color: var(--wa); }
.btn-wa:hover { background: var(--wa); filter: brightness(1.07); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); filter: brightness(1.08); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 0.87rem; }
.icon-btn { border: 0; background: none; cursor: pointer; padding: 6px 8px; border-radius: 8px; color: var(--muted); font-size: 1rem; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

input[type='text'], input[type='search'], input[type='email'], input[type='tel'], input[type='number'], input[type='password'],
input[type='datetime-local'], input[type='date'], select, textarea {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); min-width: 0;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .icon-btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent);
}
label.field { display: grid; gap: 4px; font-size: 0.85rem; color: var(--muted); font-weight: 500; }
label.field > input, label.field > select, label.field > textarea { color: var(--text); font-weight: 400; }
label.check { display: flex; align-items: center; gap: 8px; font-size: 0.92rem; }
label.check input { width: auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 599px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.stack { display: grid; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.gap { gap: 10px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type='search'] { max-width: 280px; }
.toolbar select { width: auto; max-width: 200px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 14px; }
.card-title { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }

.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.chip-accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip-green { background: var(--green-soft); color: var(--green); border-color: transparent; }
.chip-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
button.chip { cursor: pointer; }
button.chip:hover { border-color: var(--accent); color: var(--accent); }

.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 0.85rem; flex: none; }
.empty { text-align: center; color: var(--muted); padding: 40px 12px; }
.banner { border-radius: 8px; padding: 10px 12px; font-size: 0.9rem; }
.banner-warn { background: var(--warn-soft); color: var(--warn); }
.banner-info { background: var(--accent-soft); color: var(--accent); }
.banner-danger { background: var(--danger-soft); color: var(--danger); }
.banner-ok { background: var(--green-soft); color: var(--green); }

/* ============ Lists ============ */
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: var(--surface-2); }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .name { font-weight: 600; }

/* ============ Follow-up queue ============ */
.queue { display: grid; gap: 10px; }
.q-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 10px; }
.q-card.sent { border-color: var(--green); }
.q-top { display: flex; gap: 12px; align-items: center; }
.q-top .grow { flex: 1; min-width: 0; }
.q-name { font-weight: 650; cursor: pointer; }
.q-name:hover { text-decoration: underline; }
.q-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 2px; }
.q-msg { font-size: 0.93rem; min-height: 72px; }
.q-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.q-actions select { width: auto; padding: 6px 8px; }
.q-sent { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; flex: 1; min-width: 80px; }
.progress > span { display: block; height: 100%; background: var(--green); transition: width 0.3s; }
.newsbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 10px 12px; border-radius: 8px; background: var(--accent-soft); color: var(--text); margin-bottom: 14px; font-size: 0.9rem; }

/* ============ Pipeline board ============ */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 14px; padding-bottom: 2px; }
.tab { padding: 7px 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; white-space: nowrap; font-weight: 500; }
.tab.active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
.board { display: flex; gap: 12px; overflow-x: auto; align-items: flex-start; padding-bottom: 16px; scroll-snap-type: x proximity; min-height: 60vh; }
.col { flex: 0 0 272px; background: var(--surface-2); border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 230px); scroll-snap-align: start; }
.col-head { padding: 10px 12px 6px; display: flex; align-items: center; gap: 8px; }
.col-head .title { font-weight: 650; flex: 1; min-width: 0; }
.col-sum { padding: 0 12px 6px; color: var(--muted); font-size: 0.8rem; }
.col-list { padding: 4px 8px 10px; overflow-y: auto; display: grid; gap: 8px; min-height: 52px; align-content: start; flex: 1; }
.col.won { box-shadow: inset 0 3px 0 var(--green); }
.col.lost { box-shadow: inset 0 3px 0 var(--danger); }
.deal-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 11px; cursor: grab; box-shadow: var(--shadow); }
.deal-card:active { cursor: grabbing; }
.deal-card .t { font-weight: 600; margin-bottom: 4px; overflow-wrap: anywhere; }
.deal-card .m { font-size: 0.82rem; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; }
.sortable-ghost { opacity: 0.35; }
.sortable-chosen { box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2); }
.col-add { margin: 0 8px 10px; }
@media (max-width: 599px) { .col { flex-basis: 84vw; max-height: calc(100vh - 260px); } }

/* ============ Drawer + modal ============ */
.drawer-wrap { position: fixed; inset: 0; z-index: 50; }
.drawer-backdrop, .modal-backdrop { position: absolute; inset: 0; background: rgba(8, 12, 20, 0.5); opacity: 0; transition: opacity 0.2s; }
.drawer-wrap.open .drawer-backdrop, .modal-wrap .modal-backdrop { opacity: 1; }
.drawer { position: absolute; top: 0; right: 0; bottom: 0; width: min(580px, 100%); background: var(--bg); box-shadow: var(--shadow); display: flex; flex-direction: column; transform: translateX(100%); transition: transform 0.22s ease; }
.drawer-wrap.open .drawer { transform: none; }
.drawer-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.drawer-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-body { padding: 16px; overflow-y: auto; flex: 1; display: grid; gap: 14px; align-content: start; }
.drawer-body .card + .card { margin-top: 0; }
.modal-wrap { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 16px; }
.modal { position: relative; background: var(--surface); border-radius: 14px; width: min(480px, 100%); max-height: 92vh; overflow: auto; box-shadow: var(--shadow); }
.modal-wide { width: min(720px, 100%); }
.modal-head { display: flex; align-items: center; padding: 14px 16px 6px; }
.modal-head h2 { flex: 1; }
.modal-body { padding: 8px 16px 16px; display: grid; gap: 12px; }
#toast-root { position: fixed; left: 50%; transform: translateX(-50%); bottom: 84px; z-index: 90; display: grid; gap: 8px; width: min(440px, calc(100% - 24px)); pointer-events: none; }
@media (min-width: 900px) { #toast-root { bottom: 24px; } }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); transition: opacity 0.3s; pointer-events: auto; }
.toast-error { background: var(--danger); color: #fff; }
.toast-success { background: var(--green); color: var(--bg); }
.toast.out { opacity: 0; }

/* ============ Timeline / deal chat ============ */
.timeline { display: grid; gap: 10px; }
.tl-item { display: grid; grid-template-columns: 28px 1fr; gap: 10px; }
.tl-ico { width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: 0.8rem; }
.tl-body { min-width: 0; }
.tl-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.tl-meta { font-size: 0.78rem; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chat-note { background: var(--accent-soft); border-radius: 12px 12px 12px 3px; padding: 8px 12px; }
.chat-box { display: flex; gap: 8px; align-items: flex-end; }
.chat-box textarea { min-height: 44px; }
.kv-row { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 8px; margin-bottom: 8px; }

/* ============ Auth ============ */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: min(400px, 100%); }
.auth-card .brand { justify-content: center; padding-bottom: 18px; font-size: 1.2rem; }

/* ============ Misc ============ */
.drop { border: 2px dashed var(--border); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--muted); }
.drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumb { position: relative; }
.thumb img { height: 92px; border-radius: 8px; border: 1px solid var(--border); display: block; }
.thumb button { position: absolute; top: -6px; right: -6px; border-radius: 50%; width: 22px; height: 22px; border: 0; background: var(--danger); color: #fff; cursor: pointer; line-height: 1; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.t { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
table.t th, table.t td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
table.t th { background: var(--surface-2); font-weight: 600; }
.stage-row { display: grid; grid-template-columns: 22px 1fr 110px 80px auto; gap: 8px; align-items: center; margin-bottom: 6px; }
.handle { cursor: grab; color: var(--muted); text-align: center; user-select: none; }
@media (max-width: 599px) { .stage-row { grid-template-columns: 22px 1fr 96px auto; } .stage-row .prob { display: none; } }
details > summary { cursor: pointer; font-weight: 600; }

/* ============ Additions ============ */
.picker-results { margin-top: 6px; }
.picker-results .list-row { cursor: pointer; }
.hide-sm { display: inline-flex; }
@media (max-width: 599px) { .hide-sm { display: none; } }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 0.88em; }
.toolbar select, .toolbar input[type='number'] { width: auto; }
@media (max-width: 599px) { .toolbar input[type='search'] { max-width: none; flex: 1 1 100%; } }
