/* Wonzilla CRM - one stylesheet, light + dark, mobile first where it matters (the Android app). */

:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --border: #e3e6ef;
  --text: #161a2b;
  --muted: #6b7185;
  --primary: #4f46e5;
  --primary-600: #4338ca;
  --primary-soft: #eef0ff;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --success: #059669;
  --success-soft: #e6f6f0;
  --warning: #b45309;
  --warning-soft: #fdf3e2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 20px 50px rgba(16, 24, 40, .18);
  --sidebar-w: 248px;
  --topbar-h: 60px;
  --bottom-h: 62px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1120;
    --surface: #171b2e;
    --surface-2: #20253b;
    --border: #2b3150;
    --text: #e8eaf5;
    --muted: #9aa0b8;
    --primary: #818cf8;
    --primary-600: #6f7af5;
    --primary-soft: #252b52;
    --danger: #f87171;
    --danger-soft: #3a1c22;
    --success: #34d399;
    --success-soft: #133329;
    --warning: #fbbf24;
    --warning-soft: #3a2c14;
    --shadow: none;
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font: 15px/1.5 var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--primary); }
h1, h2, h3, h4 { line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.spacer { flex: 1; }

.icon {
  width: 20px; height: 20px; flex-shrink: 0;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- Shell ---------- */
.app { display: flex; min-height: 100vh; min-height: 100dvh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40;
  width: var(--sidebar-w);
  display: flex; flex-direction: column;
  padding: 16px 12px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-right: 1px solid var(--border);
  transition: transform .25s ease;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px 18px;
  font-weight: 700; font-size: 17px; color: var(--text); text-decoration: none;
}
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav a, .nav-btn {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px;
  color: var(--muted); text-decoration: none; font-weight: 500;
}
.nav a:hover, .nav-btn:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav a .count { margin-left: auto; }
.nav-btn { width: 100%; border: 0; background: none; font: inherit; cursor: pointer; text-align: left; }
.sidebar-foot { display: flex; flex-direction: column; gap: 4px; padding-top: 12px; border-top: 1px solid var(--border); }
.me { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; color: var(--text); text-decoration: none; }
.me:hover, .me.active { background: var(--surface-2); }
.me-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.me-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-text small { color: var(--muted); }
.scrim { display: none; }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 8px;
  padding: 0 24px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}
.page-title { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bell { margin-left: auto; }
.bell .count { position: absolute; top: 3px; right: 1px; }
.content { width: 100%; max-width: 1400px; padding: 8px 24px 40px; }

.bottom-nav {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  height: calc(var(--bottom-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.bottom-nav a, .bottom-nav button {
  position: relative; flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: none; font: 500 11px var(--font);
  color: var(--muted); text-decoration: none; cursor: pointer;
}
.bottom-nav .active { color: var(--primary); }
.bottom-nav .count { position: absolute; top: 6px; left: calc(50% + 6px); }
.only-mobile { display: none !important; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  body.menu-open .sidebar { transform: none; }
  .scrim {
    display: block; position: fixed; inset: 0; z-index: 30;
    background: rgba(10, 12, 25, .45);
    opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  body.menu-open .scrim { opacity: 1; pointer-events: auto; }
  .main { margin-left: 0; }
  .topbar { padding: 0 8px 0 6px; }
  .content { padding: 4px 14px calc(var(--bottom-h) + 28px + env(safe-area-inset-bottom)); }
  .bottom-nav { display: flex; }
  .only-mobile { display: inline-flex !important; }
  .hide-mobile { display: none !important; }
}

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font: 500 14px var(--font); white-space: nowrap; text-decoration: none; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn .icon { width: 18px; height: 18px; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); border-color: var(--primary-600); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn-danger-ghost { background: transparent; border-color: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-sm .icon { width: 16px; height: 16px; }
.btn-lg { height: 48px; font-size: 15px; }
.btn-block { width: 100%; }
.btn.icon-only { width: 44px; padding: 0; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.icon-btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border: 0; border-radius: 10px;
  background: transparent; color: var(--muted); cursor: pointer; text-decoration: none;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; line-height: 1;
}
.pill {
  display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 10px;
  background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600;
}
.badge {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 6px;
  background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-high { background: var(--danger-soft); color: var(--danger); }
.badge-progress { background: var(--primary-soft); color: var(--primary); }
.badge-ok { background: var(--success-soft); color: var(--success); }
.overdue { color: var(--danger); font-weight: 600; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; margin-bottom: 14px; }
.field > label { font-size: 13px; font-weight: 600; color: var(--muted); }
input, select, textarea {
  width: 100%; min-height: 40px; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { resize: vertical; min-height: 60px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--text); }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; min-height: 0; padding: 0; margin: 0; accent-color: var(--primary); flex-shrink: 0; }
input[type=color] { width: 64px; height: 40px; padding: 4px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; font-size: 14px; cursor: pointer; }
.input-group { display: flex; }
.input-group input { border-radius: 10px 0 0 10px; }
.input-group select { width: auto; border-left: 0; border-radius: 0 10px 10px 0; }
.select-sm { width: auto; }
.input-title { font-size: 18px; font-weight: 600; }
.search {
  width: 240px; padding-left: 36px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a90a6' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E") no-repeat 11px center / 16px;
}
@media (max-width: 560px) {
  .row { grid-template-columns: 1fr; gap: 0; }
  .search { width: 100%; }
}

.user-picks { display: flex; flex-wrap: wrap; gap: 6px; max-height: 190px; overflow-y: auto; }
.user-pick {
  position: relative;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 12px 3px 3px; border: 1px solid var(--border); border-radius: 20px;
  font-size: 13px; cursor: pointer; user-select: none;
}
.user-pick input { position: absolute; opacity: 0; pointer-events: none; }
.user-pick.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.user-pick.disabled { cursor: default; }

.tabs {
  display: inline-flex; gap: 4px; max-width: 100%; padding: 4px;
  background: var(--surface-2); border-radius: 12px; overflow-x: auto;
}
.tabs button {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border: 0; border-radius: 9px;
  background: transparent; color: var(--muted); font: 500 14px var(--font); white-space: nowrap; cursor: pointer;
}
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin: 8px 0 16px; }
.toolbar > p { margin: 0; }
.toolbar-right { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
@media (max-width: 560px) {
  .toolbar-right { width: 100%; }
  .toolbar-right .search { flex: 1 1 100%; }
  .toolbar-right .btn-primary { margin-left: auto; }
}

/* ---------- Cards & lists ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-head h3 { margin: 0; font-size: 15px; font-weight: 650; }
.card-body { padding: 18px; }
.link { font-size: 13px; font-weight: 500; text-decoration: none; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-2 > .span-2 { grid-column: 1 / -1; }
.stack { display: flex; flex-direction: column; gap: 12px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px; border-bottom: 1px solid var(--border);
  color: inherit; text-decoration: none;
}
.list > .item:last-child { border-bottom: 0; }
.item.clickable { cursor: pointer; }
.item.clickable:hover { background: var(--surface-2); }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; color: var(--muted); font-size: 13px; }
.item-sub span { display: inline-flex; align-items: center; gap: 4px; }
.item-sub .icon { width: 14px; height: 14px; }
.item-end { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.item.is-done .item-title { color: var(--muted); text-decoration: line-through; }
.item.unread { background: var(--primary-soft); }
.item .date-chip { min-width: 46px; text-align: center; line-height: 1.1; }
.date-chip b { display: block; font-size: 18px; }
.date-chip small { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.empty { padding: 32px 18px; text-align: center; color: var(--muted); }

.task-check {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 24px; height: 24px; padding: 0; border: 2px solid var(--border); border-radius: 50%;
  background: var(--surface); color: transparent; cursor: pointer;
}
.task-check:hover { border-color: var(--success); }
.task-check.done { background: var(--success); border-color: var(--success); color: #fff; }
.task-check .icon { width: 14px; height: 14px; stroke-width: 3; }

.avatar {
  --c: #4f46e5;
  position: relative; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--c); color: #fff; font-size: 12px; font-weight: 700; letter-spacing: .02em;
}
.avatar-sm { width: 24px; height: 24px; font-size: 10px; }
.avatar-lg { width: 52px; height: 52px; font-size: 18px; }
.avatar.online::after {
  content: ''; position: absolute; right: -1px; bottom: -1px;
  width: 10px; height: 10px; border-radius: 50%; background: #22c55e; border: 2px solid var(--surface);
}
.avatar.group { background: var(--surface-2); color: var(--muted); }

/* ---------- Dialogs & toasts ---------- */
dialog.modal {
  width: calc(100% - 24px); max-width: 560px; max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px);
  padding: 0; border: 0; background: transparent; color: var(--text);
}
dialog.modal::backdrop { background: rgba(10, 12, 25, .5); }
.modal-box {
  display: flex; flex-direction: column;
  max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px);
  background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-lg); overflow: hidden;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 14px 6px 22px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 8px 22px; overflow-y: auto; }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--border); }
@media (max-width: 560px) {
  dialog.modal { width: 100%; max-width: none; margin: auto 0 0; max-height: 94vh; max-height: 94dvh; }
  .modal-box { border-radius: 18px 18px 0 0; max-height: 94vh; max-height: 94dvh; padding-bottom: env(safe-area-inset-bottom); }
  .modal-body { padding: 8px 16px; }
  .modal-foot { padding: 12px 16px; }
}

.toasts {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 100;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  transform: translateX(-50%); pointer-events: none;
}
.toast {
  max-width: min(92vw, 420px); padding: 10px 16px; border-radius: 12px;
  background: #1d2237; color: #fff; font-size: 14px; box-shadow: var(--shadow-lg);
  pointer-events: auto; animation: toast-in .2s ease;
}
.toast.error { background: #b91c1c; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@media (max-width: 900px) { .toasts { bottom: calc(var(--bottom-h) + 16px + env(safe-area-inset-bottom)); } }

/* ---------- Dashboard ---------- */
.greeting h2 { margin: 8px 0 2px; font-size: 24px; letter-spacing: -.02em; }
.greeting p { margin: 0 0 16px; }
.banner { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; padding: 14px 16px; border-radius: var(--radius); background: var(--primary-soft); }
.banner > .icon { width: 28px; height: 28px; color: var(--primary); }
.banner > div { flex: 1; }
.banner p { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  display: flex; flex-direction: column; gap: 2px; padding: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  color: inherit; text-decoration: none;
}
.stat-label { color: var(--muted); font-size: 13px; font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.stat-note { color: var(--muted); font-size: 12px; }
.stat-note.bad { color: var(--danger); font-weight: 600; }
.pipeline { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 1px; background: var(--border); }
.pipe { padding: 14px 18px; background: var(--surface); }
.pipe-label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 600; }
.pipe-count { font-size: 22px; font-weight: 700; }
.pipe-value { color: var(--muted); font-size: 13px; }
@media (max-width: 900px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px) {
  .pipeline { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pipe:last-child:nth-child(odd) { grid-column: span 2; }
}

/* ---------- Leads board ---------- */
.stage-new { --stage: #64748b; }
.stage-contacted { --stage: #0ea5e9; }
.stage-qualified { --stage: #8b5cf6; }
.stage-demo { --stage: #ec4899; }
.stage-proposal { --stage: #f59e0b; }
.stage-won { --stage: #10b981; }
.stage-lost { --stage: #ef4444; }
.stage-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--stage); flex-shrink: 0; }
.stage-badge { background: var(--surface-2); background: color-mix(in srgb, var(--stage) 16%, transparent); color: var(--stage); }

.board {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 12px; align-items: start;
  overflow-x: auto; padding-bottom: 12px; scroll-snap-type: x mandatory;
}
.column { display: flex; flex-direction: column; min-height: 220px; padding: 10px; border-radius: var(--radius); background: var(--surface-2); scroll-snap-align: start; }
.column-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 4px 6px 10px; }
.column-head h3 { margin: 0; font-size: 14px; }
.column-total { width: 100%; }
.column-total:empty { display: none; }
.column-body { display: flex; flex: 1; flex-direction: column; gap: 8px; min-height: 60px; border-radius: 10px; transition: background .15s; }
.column-body.drag-over { background: var(--primary-soft); }
.lead-card {
  padding: 12px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); box-shadow: var(--shadow); cursor: pointer;
}
.lead-card[draggable=true] { cursor: grab; }
.lead-card.dragging { opacity: .5; }
.lead-card h4 { margin: 0 0 2px; font-size: 14px; font-weight: 600; word-break: break-word; }
.lead-card .muted { font-size: 13px; }
.lead-meta { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 13px; }
.lead-value { font-weight: 700; }
.lead-age { margin-left: auto; }
@media (max-width: 900px) { .board { grid-auto-columns: 82%; margin: 0 -14px; padding: 0 14px 12px; } }

/* ---------- Leads: stats, filters, cards, list ---------- */
.tabs button .icon { width: 16px; height: 16px; }
.stat-btn { font: inherit; text-align: left; cursor: pointer; transition: border-color .15s, background .15s; }
.stat-btn:hover { border-color: var(--primary); }
.stat-btn.active { border-color: var(--primary); background: var(--primary-soft); }
.filters { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: -4px 0 14px; }
.filters select { width: auto; min-height: 34px; padding: 5px 30px 5px 10px; font-size: 13px; }
.filters-count { margin-left: auto; }
@media (max-width: 560px) {
  .filters { flex-wrap: nowrap; overflow-x: auto; margin-right: -14px; padding-right: 14px; }
  .filters select, .filters .btn { flex-shrink: 0; }
  .filters-count { display: none; }
}
.icon-btn-sm { width: 28px; height: 28px; margin-left: auto; }
.icon-btn-sm .icon { width: 16px; height: 16px; }
.column-empty { padding: 14px 6px; color: var(--muted); font-size: 13px; text-align: center; }

.rating-hot { --rating: var(--danger); --rating-soft: var(--danger-soft); }
.rating-warm { --rating: var(--warning); --rating-soft: var(--warning-soft); }
.rating-cold { --rating: #0284c7; --rating-soft: #e0f2fe; }
@media (prefers-color-scheme: dark) { .rating-cold { --rating: #38bdf8; --rating-soft: #0c2a3d; } }
.badge[class*=rating-] { background: var(--rating-soft); color: var(--rating); }
.lead-card.is-hot { border-left: 3px solid var(--danger); }
.lead-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.lead-card-top .badge { flex-shrink: 0; }
.lead-who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lead-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.lead-chips:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 6px;
  background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 500; white-space: nowrap;
}
.chip .icon { width: 13px; height: 13px; }
.chip-warn { background: var(--warning-soft); color: var(--warning); }
.chip-bad { background: var(--danger-soft); color: var(--danger); font-weight: 600; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2);
  color: var(--muted); font-size: 12px; font-weight: 600; text-align: left; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap;
}
.table th[data-sort] { cursor: pointer; user-select: none; }
.table th[data-sort]:hover, .table th.sorted { color: var(--text); }
.table th.sorted::after { content: ' ↑'; }
.table th.sorted[data-dir=desc]::after { content: ' ↓'; }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr[data-id] { cursor: pointer; }
.table tbody tr[data-id]:hover { background: var(--surface-2); }
.table .num { text-align: right; white-space: nowrap; }
.table td.muted { white-space: nowrap; }
.cell-title { font-weight: 600; word-break: break-word; }
.cell-owner { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
/* Phones: each lead row becomes a compact card (title, then stage · follow-up · value). */
@media (max-width: 560px) {
  .table thead { display: none; }
  .table, .table tbody { display: block; }
  .table tr[data-id] { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
  .table tbody tr:last-child { border-bottom: 0; }
  .table tr[data-id] td { display: block; padding: 0; border: 0; }
  .table tr[data-id] td:first-child { flex: 1 1 100%; }
  .table tr[data-id] td.num { order: 1; margin-left: auto; font-weight: 700; }
}

/* Lead form & page */
.form-section { margin: 8px 0 12px; padding-top: 14px; border-top: 1px solid var(--border); font-size: 13px; font-weight: 700; color: var(--text); text-transform: uppercase; letter-spacing: .04em; }
.rating-picks { display: flex; flex-wrap: wrap; gap: 6px; }
.rating-picks label { position: relative; cursor: pointer; }
.rating-picks input { position: absolute; opacity: 0; pointer-events: none; }
.rating-picks span { display: inline-block; padding: 6px 14px; border: 1px solid var(--border); border-radius: 20px; font-size: 13px; font-weight: 500; }
.rating-picks input:checked + span { border-color: var(--rating, var(--primary)); background: var(--rating-soft, var(--primary-soft)); color: var(--rating, var(--primary)); }
.rating-picks input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
dialog.modal-sm { max-width: 420px; }
.lead-badges { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 0 18px 14px; }
.subscription {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px;
  margin: 0 18px 14px; padding: 8px 8px 8px 14px; border-radius: 10px; background: var(--success-soft); font-size: 14px;
}
.subscription b { color: var(--success); }
.subscription.is-cancelled { background: var(--surface-2); }
.subscription.is-cancelled b { color: var(--muted); }

/* ---------- Weekly scoreboard (Leads page) ---------- */
.scoreboard { margin-bottom: 16px; }
.score-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 10px 4px 18px; }
.score-title { min-width: 0; }
.score-title h3 { margin: 0; font-size: 15px; font-weight: 650; }
.score-title p { margin: 2px 0 0; }
.score-nav { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.score-nav .icon-btn:disabled { opacity: .35; cursor: default; background: none; }
.icon-btn.flip .icon { transform: rotate(180deg); }
.collapse-btn .icon { transform: rotate(90deg); transition: transform .2s; }
.scoreboard.collapsed .collapse-btn .icon { transform: rotate(-90deg); }
.scoreboard.collapsed #score-body { display: none; }
.scoreboard.collapsed .score-head { padding-bottom: 12px; }
.score-sunday { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin: 8px 18px 0; padding: 6px 6px 6px 12px; border-radius: 10px; background: var(--primary-soft); font-size: 14px; }
.score-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; margin-top: 12px; background: var(--border); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.score-tile { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: 14px 18px 12px; background: var(--surface); }
.score-value { overflow: hidden; font-size: 28px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; text-overflow: ellipsis; white-space: nowrap; }
.score-delta { color: var(--muted); font-size: 12px; font-weight: 600; }
.score-delta.up { color: var(--success); }
.score-delta.down { color: var(--danger); }
.score-delta .muted { font-weight: 400; }
.score-bars { width: 100%; height: 40px; margin-top: auto; padding-top: 10px; box-sizing: content-box; overflow: visible; }
.score-bars .mark { fill: var(--border); fill: color-mix(in srgb, var(--muted) 38%, transparent); transition: fill .15s; }
.score-bars .zero .mark { fill: var(--border); }
.score-bars .current .mark { fill: var(--primary); }
.score-bars .hit { fill: transparent; cursor: pointer; }
.score-bars .bar:not(.current):hover .mark { fill: color-mix(in srgb, var(--primary) 50%, transparent); }
.score-people summary { padding: 12px 18px; color: var(--muted); font-size: 14px; font-weight: 600; cursor: pointer; }
.score-people[open] summary { border-bottom: 1px solid var(--border); }
.score-people .table th { background: transparent; }
@media (max-width: 900px) {
  .score-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .score-tile { padding: 12px 14px 10px; }
  .score-value { font-size: 24px; }
}
.follow-when { display: flex; margin: 0 0 12px; font-size: 16px; font-weight: 600; }
.follow-when span { display: inline-flex; align-items: center; gap: 6px; }
.follow-pick { display: flex; gap: 8px; }
.follow-hint { margin: 12px 0 0; }

.stage-picker { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 18px 14px; }
.stage-picker button {
  padding: 6px 12px; border: 1px solid var(--border); border-radius: 20px;
  background: var(--surface); color: var(--muted); font: 500 13px var(--font); cursor: pointer;
}
.stage-picker button.active { background: var(--stage); border-color: var(--stage); color: #fff; }

/* ---------- Detail pages ---------- */
.back-link { display: inline-flex; align-items: center; gap: 6px; margin: 4px 0 12px; color: var(--muted); font-weight: 500; text-decoration: none; }
.detail {
  display: grid; gap: 16px; align-items: start;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
  grid-template-areas: "main side" "timeline side";
}
.detail-card { grid-area: main; }
.detail-side { grid-area: side; display: flex; flex-direction: column; gap: 16px; }
#timeline { grid-area: timeline; }
.detail-head { display: flex; align-items: center; gap: 14px; padding: 18px; }
.detail-title { flex: 1; min-width: 0; }
.detail-title h2 { margin: 0; font-size: 20px; word-break: break-word; }
.detail-title p { margin: 2px 0 0; }
.detail-actions { display: flex; gap: 6px; }
.quick-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 18px 14px; }
.facts { display: grid; grid-template-columns: 130px 1fr; gap: 10px 16px; margin: 0; padding: 16px 18px 18px; border-top: 1px solid var(--border); }
.facts dt { color: var(--muted); font-size: 13px; }
.facts dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
#lead-convert { margin: 0 18px 18px; width: calc(100% - 36px); }
@media (max-width: 900px) {
  .detail { grid-template-columns: 1fr; grid-template-areas: "main" "side" "timeline"; }
}
@media (max-width: 560px) {
  .facts { grid-template-columns: 1fr; gap: 0; }
  .facts dd { margin-bottom: 10px; }
}

.timeline-form { display: grid; grid-template-columns: auto 1fr auto; align-items: start; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.timeline-form select { width: auto; }
.timeline { padding: 4px 18px 12px; }
.tl-item { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px dashed var(--border); }
.tl-item:last-child { border-bottom: 0; }
.tl-body { flex: 1; min-width: 0; }
.tl-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; color: var(--muted); font-size: 13px; }
.tl-head strong { color: var(--text); }
.tl-text { margin-top: 2px; white-space: pre-wrap; word-break: break-word; }
.tl-item.update .tl-text { color: var(--muted); font-style: italic; }
@media (max-width: 560px) { .timeline-form { grid-template-columns: 1fr; } }

/* ---------- Chat ---------- */
.chat {
  display: grid; grid-template-columns: 300px minmax(0, 1fr);
  height: calc(100vh - var(--topbar-h) - 48px); height: calc(100dvh - var(--topbar-h) - 48px);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.chat-list { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); }
.chat-list-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.chat-list-head h3 { margin: 0; font-size: 15px; }
.conv-list { flex: 1; overflow-y: auto; }
.conv {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 16px; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.conv:hover { background: var(--surface-2); }
.conv.active { background: var(--primary-soft); }
.conv-main { flex: 1; min-width: 0; }
.conv-name { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.conv-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-name small { flex-shrink: 0; color: var(--muted); font-weight: 400; }
.conv-last { overflow: hidden; color: var(--muted); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.conv.unread .conv-last { color: var(--text); font-weight: 600; }
.chat-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 8px; min-height: 57px; padding: 8px 16px; border-bottom: 1px solid var(--border); }
.chat-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chat-title div { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.chat-title small { color: var(--muted); }
.messages { flex: 1; display: flex; flex-direction: column; gap: 3px; padding: 16px; overflow-y: auto; background: var(--bg); }
.msg { display: flex; align-items: flex-end; gap: 8px; max-width: 80%; }
.msg.me { align-self: flex-end; flex-direction: row-reverse; }
.msg.cont .avatar { visibility: hidden; }
.msg:not(.cont) { margin-top: 8px; }
.bubble {
  padding: 7px 12px; border: 1px solid var(--border); border-radius: 16px 16px 16px 4px;
  background: var(--surface); white-space: pre-wrap; word-break: break-word;
}
.msg.me .bubble { background: var(--primary); border-color: var(--primary); color: #fff; border-radius: 16px 16px 4px 16px; }
.msg.me .bubble a { color: #fff; }
.bubble-name { margin-bottom: 1px; color: var(--c); font-size: 12px; font-weight: 700; }
.bubble-time { float: right; display: inline-flex; align-items: center; gap: 3px; margin: 6px 0 0 10px; color: var(--muted); font-size: 11px; }
.msg.me .bubble-time { color: rgba(255, 255, 255, .75); }

/* Read receipts: ✓ sent, ✓✓ delivered, blue ✓✓ read, clock while sending */
:root { --tick-read: #7ef0ff; --tick-read-list: #0284c7; }
/* Dark mode: a deeper bubble for my messages so white text and blue ticks both stand out. */
@media (prefers-color-scheme: dark) {
  :root { --tick-read-list: #38bdf8; }
  .msg.me .bubble { background: #4338ca; border-color: #4338ca; }
}
.ticks { width: 17px; height: 14px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.ticks.pending { width: 14px; stroke-width: 1.4; }
.ticks.read { color: var(--tick-read); }
.conv-last .ticks { margin-right: 3px; vertical-align: -2px; color: var(--muted); }
.conv-last .ticks.read, .receipt-head .ticks.read { color: var(--tick-read-list); }
.messages.can-info .msg.me .bubble { cursor: pointer; }
.receipt-quote { margin: 0 0 14px; padding: 8px 12px; border-left: 3px solid var(--primary); border-radius: 6px; background: var(--surface-2); white-space: pre-wrap; word-break: break-word; max-height: 120px; overflow: auto; }
.receipt-head { display: flex; align-items: center; gap: 6px; margin: 14px 0 8px; font-size: 13px; color: var(--muted); }
.receipt-head .ticks { color: var(--muted); }
.receipt-head:first-child { margin-top: 0; }
.day-sep { align-self: center; margin: 12px 0 4px; padding: 3px 10px; border-radius: 10px; background: var(--surface-2); color: var(--muted); font-size: 12px; }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); background: var(--surface); }
.composer textarea { min-height: 44px; max-height: 140px; padding: 11px 16px; border-radius: 22px; resize: none; }
.composer .btn { height: 44px; border-radius: 22px; }
.people .item { cursor: pointer; }
@media (max-width: 900px) {
  body[data-page=chat] .content { padding-bottom: 0; }
  .chat {
    grid-template-columns: 1fr; margin: 0 -14px; border-width: 1px 0 0; border-radius: 0;
    height: calc(100vh - var(--topbar-h) - var(--bottom-h) - 4px);
    height: calc(100dvh - var(--topbar-h) - var(--bottom-h) - env(safe-area-inset-bottom) - 4px);
  }
  .chat .chat-pane { display: none; }
  .chat.open .chat-pane { display: flex; }
  .chat.open .chat-list { display: none; }
}

/* ---------- Notes ---------- */
.note-yellow { --note-bg: #fef9c3; }
.note-green { --note-bg: #dcfce7; }
.note-blue { --note-bg: #dbeafe; }
.note-pink { --note-bg: #fce7f3; }
.note-purple { --note-bg: #ede9fe; }
@media (prefers-color-scheme: dark) {
  .note-yellow { --note-bg: #3a3413; }
  .note-green { --note-bg: #16331f; }
  .note-blue { --note-bg: #172a47; }
  .note-pink { --note-bg: #3d1a2d; }
  .note-purple { --note-bg: #2b2148; }
}
.notes-grid { columns: 280px; column-gap: 14px; }
.note-card {
  display: block; width: 100%; margin-bottom: 14px; padding: 14px 16px; break-inside: avoid;
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  background: var(--note-bg, var(--surface)); color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.note-card h4 { margin: 0 0 6px; font-size: 15px; word-break: break-word; }
.note-card p {
  display: -webkit-box; margin: 0; overflow: hidden; font-size: 14px; white-space: pre-wrap; word-break: break-word;
  -webkit-line-clamp: 8; -webkit-box-orient: vertical;
}
.note-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; color: var(--muted); font-size: 12px; }
.note-foot .icon { width: 14px; height: 14px; }
.swatches { display: flex; gap: 8px; }
.swatch { position: relative; }
.swatch input { position: absolute; opacity: 0; }
.swatch span { display: block; width: 30px; height: 30px; border: 2px solid var(--border); border-radius: 50%; background: var(--note-bg, var(--surface)); cursor: pointer; }
.swatch input:checked + span { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* Handwriting (S Pen) on notes */
:root { --ink-blue: #2563eb; --ink-red: #dc2626; --ink-green: #16a34a; --ink-orange: #ea580c; --ink-yellow: #facc15; --ink-pink: #ec4899; }
@media (prefers-color-scheme: dark) {
  :root { --ink-blue: #60a5fa; --ink-red: #f87171; --ink-green: #4ade80; --ink-orange: #fb923c; --ink-yellow: #fde047; --ink-pink: #f472b6; }
}
.note-mode { margin-bottom: 12px; }
dialog.modal.is-ink { max-width: 900px; }
.ink-tools {
  position: sticky; top: -8px; z-index: 1; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px;
  margin: 0 0 8px; padding: 6px 0; background: var(--surface);
}
.ink-group { display: flex; align-items: center; gap: 2px; }
.ink-tools .icon-btn.on { background: var(--primary-soft); color: var(--primary); }
.ink-tools .icon-btn:disabled { opacity: .35; cursor: default; }
.ink-color, .ink-size {
  display: grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 2px solid transparent; border-radius: 50%;
  background: transparent; cursor: pointer;
}
.ink-color::before { content: ""; width: 20px; height: 20px; border-radius: 50%; background: var(--c); }
.ink-size span { width: var(--d); height: var(--d); border-radius: 50%; background: var(--text); }
.ink-color.on, .ink-size.on { border-color: var(--primary); }
.ink-hint { margin-left: auto; }
.ink-page {
  position: relative; overflow: hidden; border: 1px solid var(--border); border-radius: 12px;
  background-color: var(--note-bg, var(--surface));
  background-image: repeating-linear-gradient(to bottom, transparent 0 calc(var(--ink-line, 50px) - 1px), var(--border) calc(var(--ink-line, 50px) - 1px) var(--ink-line, 50px));
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.ink.is-readonly .ink-page { touch-action: auto; }
.ink-page canvas { position: absolute; top: 0; left: 0; width: 100%; }
.ink-msg { pointer-events: none; position: absolute; inset: 24px 16px auto; color: var(--muted); font-size: 14px; text-align: center; }
.note-ink { display: block; width: 100%; height: auto; max-height: 260px; margin-top: 6px; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.note-ink .hi { stroke-opacity: .35; }
.note-ink .c-ink { stroke: var(--text); }
.note-ink .c-blue { stroke: var(--ink-blue); }
.note-ink .c-red { stroke: var(--ink-red); }
.note-ink .c-green { stroke: var(--ink-green); }
.note-ink .c-orange { stroke: var(--ink-orange); }
.note-ink .c-yellow { stroke: var(--ink-yellow); }
.note-ink .c-pink { stroke: var(--ink-pink); }

/* ---------- Calendar ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 14px; color: var(--muted); font-size: 13px; }
.dot { display: inline-block; width: 9px; height: 9px; margin-right: 6px; border-radius: 50%; }
.dot-event { background: #4f46e5; }
.dot-task { background: #f59e0b; }
.dot-reminder { background: #10b981; }
.calendar-card { padding: 14px; }
.fc {
  --fc-border-color: var(--border);
  --fc-page-bg-color: var(--surface);
  --fc-neutral-bg-color: var(--surface-2);
  --fc-today-bg-color: var(--primary-soft);
  --fc-button-bg-color: var(--surface);
  --fc-button-border-color: var(--border);
  --fc-button-text-color: var(--text);
  --fc-button-hover-bg-color: var(--surface-2);
  --fc-button-hover-border-color: var(--border);
  --fc-button-active-bg-color: var(--primary-soft);
  --fc-button-active-border-color: var(--primary);
  --fc-list-event-hover-bg-color: var(--surface-2);
  --fc-event-border-color: transparent;
}
.fc .fc-button { font-weight: 500; text-transform: capitalize; box-shadow: none !important; }
.fc .fc-button-primary:not(:disabled).fc-button-active { color: var(--primary); }
.fc .fc-toolbar-title { font-size: 18px; }
.fc .fc-daygrid-event, .fc .fc-timegrid-event { cursor: pointer; }
.fc a { color: inherit; text-decoration: none; }
@media (max-width: 560px) {
  .calendar-card { padding: 8px; }
  .fc .fc-toolbar { flex-wrap: wrap; gap: 8px; }
  .fc .fc-toolbar-title { font-size: 16px; }
}

/* ---------- Announcements ---------- */
.ann { padding: 18px 20px; }
.ann.pinned { border-color: var(--primary); }
.ann-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.ann-head div { flex: 1; min-width: 0; }
.ann-head h3 { margin: 0; font-size: 16px; }
.ann-body { white-space: pre-wrap; word-break: break-word; }

/* ---------- Auth / setup ---------- */
body.auth {
  display: flex; align-items: center; justify-content: center; min-height: 100vh; min-height: 100dvh; padding: 24px 16px;
  background: radial-gradient(1000px 500px at 15% -10%, var(--primary-soft), transparent), var(--bg);
}
.auth-card { width: 100%; max-width: 400px; padding: 32px 28px; border: 1px solid var(--border); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow-lg); }
.auth-card.wide { max-width: 580px; }
.auth-brand { margin-bottom: 24px; text-align: center; }
.auth-brand h1 { margin: 12px 0 4px; font-size: 22px; }
.auth-brand p { margin: 0; }
.alert { margin-bottom: 16px; padding: 10px 14px; border-radius: 10px; background: var(--danger-soft); color: var(--danger); font-size: 14px; }
.alert.info { background: var(--primary-soft); color: var(--primary); }
.divider { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.auth-foot { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 20px; font-size: 14px; font-weight: 500; text-decoration: none; }
.checks { display: flex; flex-direction: column; gap: 8px; margin: 0 0 20px; padding: 0; list-style: none; }
.checks li { display: flex; gap: 10px; padding: 10px 12px; border-radius: 10px; font-size: 14px; font-weight: 700; }
.checks li span { color: var(--text); font-weight: 400; }
.checks .ok { background: var(--success-soft); color: var(--success); }
.checks .bad { background: var(--warning-soft); color: var(--warning); }
.section-title { margin: 18px 0 12px; font-size: 15px; }
.cred { margin: 0; padding: 14px; border-radius: 10px; background: var(--surface-2); font-size: 14px; white-space: pre-wrap; user-select: all; }

/* Inside the Android app: hide things that only make sense in a browser. */
.in-app .browser-only { display: none !important; }

/* ---------- Tasks: audience, assignees, progress ---------- */
.segmented { display: flex; width: 100%; }
.segmented button { flex: 1; justify-content: center; }
.segmented button .icon { width: 16px; height: 16px; }
.segmented button:disabled { cursor: default; opacity: .7; }
.field-hint { margin: 2px 0 0; }
.avatar-stack { display: inline-flex; align-items: center; }
.avatar-stack .avatar { box-shadow: 0 0 0 2px var(--surface); }
.avatar-stack .avatar + .avatar { margin-left: -6px; }
.avatar-stack .more { margin-left: 4px; font-size: 12px; font-weight: 600; }
.pill-ok { background: var(--success-soft); color: var(--success); }
.task-check.readonly { cursor: default; opacity: .5; }
.task-progress { display: flex; flex-direction: column; gap: 8px; }
.task-progress .person { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.task-progress .person .badge { margin-left: auto; }
