/* =================== v5: enterprise layout polish, team features, dark mode. Loaded after theme.css =================== */
.sidebar { background: linear-gradient(180deg, #0b1b46 0%, #0f2560 60%, #11307a 100%); border-right: 0; color: #c9d6f2; }
.sidebar .brand-name { color: #fff; }
.sidebar .brand-tag { color: #8fb1ff; }
.nav a, .nav-toggle { color: #c9d6f2; }
.nav a:hover, .nav-toggle:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.nav a.active { background: rgba(255, 255, 255, .14); color: #fff; box-shadow: inset 3px 0 0 #6ea8ff; }
.nav a.sub { color: #a9bbe0; }
.nav-sub .sub-dot { background: #6b80b3; }
.nav a.sub.active .sub-dot { background: #8fb1ff; }
.nav-toggle svg:last-child { color: #8193bd; }
.nav .badge { background: #ff5c7a; color: #fff; }
.plan { border-color: rgba(255, 255, 255, .14); background: rgba(255, 255, 255, .06); color: #c9d6f2; }
.plan b { color: #fff; }
.plan .progress { background: rgba(255, 255, 255, .15); }
.plan-link { color: #8fb1ff; }
.sidebar .hint { color: #9fb2d8; }
.topbar { background: rgba(255, 255, 255, .82); backdrop-filter: blur(12px); }
.theme-btn { width: 38px; height: 38px; padding: 0; border-radius: 12px; font-size: 16px; }
.theme-btn .t-moon { display: none; }
[data-theme=dark] .theme-btn .t-sun { display: none; }
[data-theme=dark] .theme-btn .t-moon { display: inline; }

/* lead filters + list */
.lead-filters { display: flex; flex-direction: column; gap: 10px; padding: 14px 16px; }
.lf-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.lf-row select, .lf-row input { padding: 7px 10px; font-size: 13px; border-radius: 10px; }
.lf-label { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.lf-label svg { width: 15px; height: 15px; }
.lead-open { color: inherit; font-weight: 600; }
.lead-open:hover { color: var(--primary); text-decoration: underline; }
.fu-chip { display: inline-block; margin-top: 3px; font-size: 11.5px; font-weight: 600; color: #b45309; background: #fff7e6; border: 1px solid #fde3a7; border-radius: 999px; padding: 1px 8px; }
.fu-chip.late { color: #b91c1c; background: #fef2f2; border-color: #fecaca; }
.fu-box { border-top: 1px dashed var(--border); padding-top: 10px; }
.chips-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* dashboard mini lists */
.mini-list { display: flex; flex-direction: column; gap: 6px; }
.mini-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; border-radius: 12px; background: #f7f9fc; }
.mini-row.late { background: #fff5f5; }
.mini-row small { display: block; color: var(--muted); font-size: 12px; margin-top: 1px; }
.mini-row a { color: inherit; }
.task-strip { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.task-strip .ic { width: 42px; height: 42px; border-radius: 14px; display: grid; place-items: center; color: #fff; }
.task-strip .ic svg { width: 20px; }
.task-strip div { flex: 1; }
.task-strip small { display: block; color: var(--muted); }

/* sales summary strip */
.sale-sum { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.sale-kpi { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; }
.sale-kpi span { font-size: 12px; font-weight: 600; color: var(--muted); }
.sale-kpi > b { font-size: 26px; letter-spacing: -.03em; }
.sale-kpi small { color: var(--muted); font-size: 12px; }
.sale-kpi small b { color: #16a34a; }
.sale-kpi.today { background: linear-gradient(135deg, #eafff3, #fff); border-color: #bbf7d0; }
.sale-kpi.pend { background: linear-gradient(135deg, #fff8e6, #fff); border-color: #fde3a7; }
@media (max-width: 1100px) { .sale-sum { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 600px) { .sale-sum { grid-template-columns: repeat(2, 1fr); } }

/* lead drawer + journey */
.drawer-bg { position: fixed; inset: 0; z-index: 90; background: rgba(9, 16, 33, 0); transition: background .2s; }
.drawer-bg.open { background: rgba(9, 16, 33, .35); }
.drawer { position: absolute; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); background: var(--panel); box-shadow: -20px 0 60px rgba(9, 16, 33, .25); padding: 20px; overflow-y: auto; transform: translateX(100%); transition: transform .22s cubic-bezier(.2, .9, .3, 1); }
.drawer-bg.open .drawer { transform: none; }
.drawer-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.drawer-head h3 { margin: 0; font-size: 19px; }
.drawer-head .x { font-size: 26px; background: none; border: 0; cursor: pointer; color: var(--muted); }
.drawer-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0; }
.drawer-kv { margin-top: 6px; }
.drawer-notes { margin-top: 12px; white-space: pre-wrap; font-size: 13px; background: #f7f9fc; border-radius: 12px; padding: 10px 12px; max-height: 160px; overflow-y: auto; }
.fu-banner { background: #fff7e6; border: 1px solid #fde3a7; color: #92400e; border-radius: 12px; padding: 9px 12px; font-size: 13px; font-weight: 600; }
.fu-banner.late { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.timeline { position: relative; display: flex; flex-direction: column; gap: 4px; }
.timeline::before { content: ""; position: absolute; left: 17px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.tl-item { position: relative; display: flex; gap: 12px; padding: 6px 0; }
.tl-ic { position: relative; z-index: 1; width: 36px; height: 36px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--panel); border: 2px solid var(--border); font-size: 15px; }
.tl-sale .tl-ic { border-color: #86efac; }
.tl-call .tl-ic { border-color: #bfd3ff; }
.tl-body { flex: 1; min-width: 0; padding-top: 2px; }
.tl-top { display: flex; justify-content: space-between; gap: 8px; }
.tl-top b { font-size: 13.5px; }
.tl-top small { color: var(--muted); white-space: nowrap; font-size: 11.5px; }
.tl-detail { font-size: 12.5px; color: #334155; margin-top: 2px; white-space: pre-wrap; }
.tl-meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

/* reminders */
#reminders { position: fixed; top: 78px; right: 18px; z-index: 95; display: flex; flex-direction: column; gap: 10px; width: min(360px, calc(100vw - 36px)); }
.reminder { background: var(--panel); border: 1px solid #fde3a7; border-left: 5px solid #f59e0b; border-radius: 16px; padding: 12px 14px; box-shadow: 0 20px 40px -12px rgba(9, 16, 33, .3); transform: translateX(120%); transition: transform .25s cubic-bezier(.2, .9, .3, 1.2); }
.reminder.show { transform: none; }
.rem-body b { display: block; font-size: 14px; }
.rem-body small { color: var(--muted); font-size: 12.5px; }
.rem-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

/* tasks */
.task-list { display: flex; flex-direction: column; gap: 8px; }
.task { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 14px; background: var(--panel); }
.task.late { border-color: #fecaca; background: #fffafa; }
.task.pr-high { border-left: 4px solid #ef4444; }
.task.done .task-main b { text-decoration: line-through; color: var(--muted); }
.task-check { width: 24px; height: 24px; flex: none; border-radius: 8px; border: 2px solid #c7d2e3; background: none; cursor: pointer; color: #fff; font-weight: 800; margin-top: 1px; }
.task.done .task-check { background: #22b866; border-color: #22b866; }
.task-main { flex: 1; min-width: 0; }
.task-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 6px; font-size: 12px; color: #475569; }
.task-meta a { color: var(--primary); }

/* team chat */
.chat-wrap { display: grid; grid-template-columns: 290px 1fr; padding: 0; overflow: hidden; height: calc(100vh - 230px); min-height: 460px; }
.chat-side { border-right: 1px solid var(--border); overflow-y: auto; padding: 8px; }
.chat-th { display: flex; gap: 10px; align-items: center; width: 100%; border: 0; background: none; text-align: left; padding: 10px; border-radius: 12px; cursor: pointer; font: inherit; color: inherit; }
.chat-th:hover { background: #f5f8fd; }
.chat-th.on { background: var(--primary-50); }
.chat-th > div { flex: 1; min-width: 0; }
.chat-th small { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-th .badge { position: static; }
.chat-th .avatar { position: relative; }
.avatar.team { background: linear-gradient(135deg, #6ea8ff, #7c3aed); }
.on-dot { position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px; border-radius: 50%; background: #22c55e; border: 2px solid var(--panel); }
.chat-main { display: flex; flex-direction: column; min-width: 0; }
.chat-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; background: #f8fafd; }
.chat-day { align-self: center; font-size: 11.5px; color: var(--muted); background: var(--panel); border: 1px solid var(--border); padding: 2px 10px; border-radius: 999px; }
.cm { display: flex; gap: 8px; align-items: flex-end; max-width: 78%; }
.cm.mine { align-self: flex-end; flex-direction: row-reverse; }
.cm-bubble { background: var(--panel); border: 1px solid var(--border); padding: 9px 13px; border-radius: 16px 16px 16px 4px; white-space: pre-wrap; word-break: break-word; }
.cm.mine .cm-bubble { background: linear-gradient(135deg, #3b7bff, #1d5bf0); color: #fff; border-color: transparent; border-radius: 16px 16px 4px 16px; }
.cm small { font-size: 11px; color: var(--muted); }
.cm.mine small { display: block; text-align: right; }
.chat-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); }
.chat-form textarea { flex: 1; resize: none; }
@media (max-width: 800px) {
  .chat-wrap { grid-template-columns: 1fr; height: auto; }
  .chat-side { max-height: 200px; border-right: 0; border-bottom: 1px solid var(--border); }
  .chat-msgs { height: 55vh; }
}

/* webphone: lines + park in the party row */
.wp-lines { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 6px; font-size: 12px; }
.wp-lines > span { color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; font-size: 10.5px; }
.wp-lines b { display: inline-flex; align-items: center; gap: 4px; background: #eef4ff; color: #1e3a8a; border-radius: 999px; padding: 3px 10px; font-size: 12px; }
.wp-lines b small { color: #64748b; font-weight: 500; }
.party-btns { display: inline-flex; gap: 6px; margin-left: auto; }
.wp-parkbtn { min-width: 84px; }
.wp-hero.parked { background: radial-gradient(90% 80% at 50% 0%, rgba(255, 255, 255, .16), transparent 60%), linear-gradient(160deg, #7c2d12, #d97706 60%, #f59e0b); }

/* =================== Dark mode =================== */
[data-theme=dark] {
  color-scheme: dark;
  --bg: #0a1020; --panel: #111a2e; --border: #1f2b45; --text: #e6ecf7; --muted: #8ea0c0;
  --primary-50: #16244a; --green-50: #0f2a1e; --red-50: #2e1418;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -6px rgba(0, 0, 0, .45);
  --shadow-hover: 0 2px 4px rgba(0, 0, 0, .35), 0 16px 32px -8px rgba(0, 0, 0, .55);
}
[data-theme=dark] body { background: radial-gradient(1200px 500px at 85% -10%, #14224a 0%, transparent 60%), var(--bg); color: var(--text); }
[data-theme=dark] h1, [data-theme=dark] h2, [data-theme=dark] h3, [data-theme=dark] b, [data-theme=dark] .val { color: inherit; }
[data-theme=dark] .sidebar { background: linear-gradient(180deg, #070d1c 0%, #0b1530 100%); border-right: 1px solid var(--border); }
[data-theme=dark] .topbar, [data-theme=dark] .footer { background: rgba(17, 26, 46, .85); border-color: var(--border); }
[data-theme=dark] .card, [data-theme=dark] .modal, [data-theme=dark] .menu, [data-theme=dark] .wp-pop, [data-theme=dark] .drawer, [data-theme=dark] .reminder, [data-theme=dark] .task { background: var(--panel); border-color: var(--border); color: var(--text); }
[data-theme=dark] .modal-head, [data-theme=dark] .modal-foot { border-color: var(--border); }
[data-theme=dark] .btn, [data-theme=dark] input, [data-theme=dark] select, [data-theme=dark] textarea, [data-theme=dark] .search input, [data-theme=dark] .status-select { background: #0d1527; border-color: #26344f; color: var(--text); }
[data-theme=dark] .btn:hover, [data-theme=dark] .menu button:hover { background: #18233b; }
[data-theme=dark] .menu button { color: var(--text); }
[data-theme=dark] .btn-primary { background: linear-gradient(135deg, #3b7bff, #1d5bf0); color: #fff; border-color: transparent; }
[data-theme=dark] .btn-green { background: #16a34a; color: #fff; border-color: transparent; }
[data-theme=dark] .btn-red { background: #dc2626; color: #fff; border-color: transparent; }
[data-theme=dark] th { background: #0e1729; color: #8ea0c0; border-color: var(--border); }
[data-theme=dark] td { border-color: #18233b; }
[data-theme=dark] tbody tr:hover td { background: #142039; }
[data-theme=dark] .hint, [data-theme=dark] small { color: var(--muted); }
[data-theme=dark] .pill { background: #1b2742; color: #c7d3ea; }
[data-theme=dark] .range button, [data-theme=dark] .status-tabs button, [data-theme=dark] .chips span, [data-theme=dark] .qa-btn, [data-theme=dark] .head-date, [data-theme=dark] .status-chip,
[data-theme=dark] .my-grid div, [data-theme=dark] .flow-step, [data-theme=dark] .sale-box, [data-theme=dark] .meta-kpi, [data-theme=dark] .quote-grid div, [data-theme=dark] .rec-item, [data-theme=dark] .code, [data-theme=dark] code,
[data-theme=dark] .mini-row, [data-theme=dark] .drawer-notes, [data-theme=dark] .sms-msgs, [data-theme=dark] .chat-msgs, [data-theme=dark] .chat-day, [data-theme=dark] .lead-meta div, [data-theme=dark] .lead-notes,
[data-theme=dark] .wall-card, [data-theme=dark] .wall-callbox, [data-theme=dark] .info-i, [data-theme=dark] .margin-bar, [data-theme=dark] .imp-agents, [data-theme=dark] .dispo-now, [data-theme=dark] .rc-countries { background: #0e1729; border-color: var(--border); color: var(--text); }
[data-theme=dark] .range button.on, [data-theme=dark] .status-tabs button.on { background: var(--primary); color: #fff; }
[data-theme=dark] .notice, [data-theme=dark] .fu-banner, [data-theme=dark] .fu-chip, [data-theme=dark] .sale-kpi.pend { background: #2a2010; border-color: #5c4516; color: #fcd58a; }
[data-theme=dark] .sale-kpi.today { background: #0f2a1e; border-color: #1f5c3a; }
[data-theme=dark] .mini-row.late, [data-theme=dark] .task.late, [data-theme=dark] .fu-banner.late, [data-theme=dark] .fu-chip.late { background: #2e1418; border-color: #5b2329; color: #fca5a5; }
[data-theme=dark] .chat-th:hover, [data-theme=dark] .sms-conv:hover, [data-theme=dark] .rc-c:hover { background: #16213a; }
[data-theme=dark] .cm-bubble, [data-theme=dark] .sms-msg .bubble { background: #16213a; border-color: var(--border); color: var(--text); }
[data-theme=dark] .loc-badge { background: #16213a; border-color: #26344f; color: #b8c7e3; }
[data-theme=dark] .tl-detail { color: #c7d3ea; }
[data-theme=dark] .task-meta { color: #a9b8d4; }
[data-theme=dark] .wp-lines b { background: #16244a; color: #c7d8ff; }
[data-theme=dark] .drawer-bg.open { background: rgba(0, 0, 0, .55); }
/* webphone in dark mode */
[data-theme=dark] .phone { background: #0f1729; border-color: #1f2b45; }
[data-theme=dark] .wp-card, [data-theme=dark] .wp-key, [data-theme=dark] .wp-ctrl i, [data-theme=dark] .wp-party, [data-theme=dark] .wp-li, [data-theme=dark] .wp-from, [data-theme=dark] .wp-agent, [data-theme=dark] .wp-park-opt, [data-theme=dark] .wp-endall, [data-theme=dark] .wp-chip, [data-theme=dark] .wp-script-btn { background: #16213a; border-color: #26344f; color: var(--text); box-shadow: none; }
[data-theme=dark] .wp-key span, [data-theme=dark] .wp-display input { color: var(--text); }
[data-theme=dark] .wp-key:hover { background: #1d2b4a; }
[data-theme=dark] .wp-ctrl { color: #a9b8d4; }
[data-theme=dark] .wp-tabs button.on { background: #16213a; color: #fff; }
[data-theme=dark] .wp-alert { background: #13213f; border-color: #26344f; color: #c7d8ff; }
[data-theme=dark] .wp-alert.bad { background: #2e1418; border-color: #5b2329; color: #fca5a5; }
[data-theme=dark] .wp-alert.warn { background: #2a2010; border-color: #5c4516; color: #fcd58a; }
[data-theme=dark] .wp-parked-item { background: #2a2010; border-color: #5c4516; }
[data-theme=dark] .wp-parked-item .wp-li-main small { color: #fcd58a; }
[data-theme=dark] .status-tabs button span, [data-theme=dark] .badge-soft { background: #1f2b45; color: #c7d3ea; }
[data-theme=dark] .status-tabs button.on span { background: rgba(255, 255, 255, .25); color: #fff; }

/* paging, manager note, phone column */
.pager { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding-top: 12px; border-top: 1px solid var(--border); margin-top: 8px; }
.pager-ctl { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pager-ctl select { padding: 6px 8px; font-size: 13px; }
.pg-num { font-size: 13px; color: var(--muted); }
.pg-num input { width: 64px; padding: 5px 8px; margin: 0 4px; }
.mono { font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.mnote { background: #eef4ff; border: 1px solid #cfdcff; border-left: 4px solid #1d5bf0; color: #1e3a8a; border-radius: 12px; padding: 10px 12px; font-size: 13px; margin-top: 10px; }
.mnote small { color: #64748b; }
.mnote > div { margin-top: 4px; white-space: pre-wrap; color: var(--text); }
.mnote-edit textarea { border-color: #cfdcff; background: #f7faff; }
.mnote-dot { cursor: help; font-size: 12px; }
[data-theme=dark] .mnote { background: #13213f; border-color: #26407a; color: #c7d8ff; }
[data-theme=dark] .mnote-edit textarea { background: #0d1527; border-color: #26407a; }

/* client rate list */
.rl-table tbody tr { cursor: pointer; }
.rl-flag { font-size: 18px; vertical-align: -2px; }
.rl-flag.big { font-size: 34px; line-height: 1; }
.rl-badges { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 12px; }
.drawer.drawer-wide { width: min(860px, 100vw); }
