:root {
  --navy: #14213d;
  --orange: #fca311;
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1c2333;
  --muted: #6b7385;
  --line: #e3e6ec;
  --danger: #c2372b;
  --warn: #b26a00;
  --ok: #1d7a46;
  --radius: 10px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11151d; --card: #1a202b; --text: #e6e9ef; --muted: #98a1b3; --line: #2b3240; --danger: #ff7b6e; --warn: #f2b04a; --ok: #5fd08f; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: #2457c5; text-decoration: none; }
@media (prefers-color-scheme: dark) { a { color: #8fb3ff; } }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 4px 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
h2 { font-size: 15px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 12px 0 6px; color: var(--muted); }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 14px; padding: 8px 16px;
  background: var(--navy); color: #fff; flex-wrap: wrap; }
.topbar[hidden], [hidden] { display: none !important; }
.topbar .brand { color: var(--orange); font-weight: 700; font-size: 16px; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { color: #d8deea; padding: 6px 10px; border-radius: 6px; }
.topbar nav a.active, .topbar nav a:hover { background: rgba(255,255,255,.12); color: #fff; text-decoration: none; }
.topbar .spacer { flex: 1; }
.topbar .me small { color: var(--orange); margin-left: 4px; }
.topbar select { background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.25); }
.topbar select option { color: #000; }
.topbar .ghost { color: #fff; border-color: rgba(255,255,255,.3); }

.page { max-width: 1280px; margin: 0 auto; padding: 16px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.pad { padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.strong { font-weight: 600; }
.danger { color: var(--danger); font-weight: 600; }
.warn { color: var(--warn); }
.error { color: var(--danger); }
.quote { color: var(--muted); border-left: 3px solid var(--line); padding-left: 6px; margin-top: 4px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
@media (max-width: 860px) { .grid2, .row2, .row3 { grid-template-columns: 1fr; } }

label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 13px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--orange); outline-offset: -1px; }
input:disabled, select:disabled, textarea:disabled { opacity: .75; }
textarea { resize: vertical; }
button, .button { font: inherit; cursor: pointer; border-radius: 7px; padding: 7px 14px; border: 1px solid var(--line); background: var(--card); color: var(--text); display: inline-flex; align-items: center; gap: 6px; }
button:disabled { opacity: .5; cursor: wait; }
.primary { background: var(--navy); color: #fff; border-color: var(--navy); font-weight: 600; }
.primary:hover { background: #1d2f57; text-decoration: none; }
.ghost { background: transparent; }
.ghost:hover { background: rgba(127,127,127,.1); }
.x { padding: 2px 8px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tab { border-radius: 999px; padding: 5px 12px; font-size: 13px; }
.tab b { color: var(--muted); font-weight: 600; margin-left: 2px; }
.tab.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.tab.active b { color: var(--orange); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; align-items: center; }
.filters input[type=search] { width: 260px; }

.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.list td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tbody tr[data-href] { cursor: pointer; }
table.list tbody tr:hover { background: rgba(127,127,127,.06); }
table.list tr.late td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
table.compact td, table.compact th { padding: 6px 6px; }
.num { text-align: right; white-space: nowrap; }
input.num { width: 120px; }
input.short { width: 64px; }
table.items input { width: 100%; }
table.items td { padding: 4px; }
.total { text-align: right; font-size: 15px; margin-top: 8px; }
.pager { display: flex; gap: 10px; justify-content: center; align-items: center; padding: 12px; }

.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eceff4; color: #3b4458; white-space: nowrap; }
.chip.lead-new { background: #e3ecff; color: #1f4fbf; }
.chip.lead-in_progress, .chip.order-processing { background: #fff1d6; color: #8a5300; }
.chip.lead-quoted, .chip.order-review { background: #efe4ff; color: #6430b8; }
.chip.lead-success, .chip.order-handed_over, .chip.ok { background: #dff5e7; color: #17663b; }
.chip.lead-churn, .chip.order-churned { background: #fde5e2; color: #a12d22; }
.chip.order-pending { background: #eceff4; color: #4a5468; }
.chip.order-deposited { background: #e0f2f7; color: #136680; }
.chip.order-repair, .chip.warn { background: #ffe6cc; color: #9b4a00; }
.chip.premium { background: var(--orange); color: var(--navy); }
.chip.brand-xlsl { background: var(--navy); color: #fff; }
.chip.brand-iform { background: #ffe8c2; color: #7a4a00; }

.timeline, .links, .chat { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.timeline li { border-left: 2px solid var(--line); padding-left: 10px; white-space: pre-wrap; }
.links li { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chat { max-height: 420px; overflow-y: auto; }
.bubble { padding: 7px 10px; border-radius: 10px; max-width: 85%; white-space: pre-wrap; }
.bubble.in { background: #eef1f6; }
.bubble.out { background: #e3ecff; margin-left: auto; margin-top: 4px; }
@media (prefers-color-scheme: dark) { .bubble.in { background: #232a37; } .bubble.out { background: #22345a; } }
.note-form { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; margin-bottom: 12px; }
@media (max-width: 600px) { .note-form { grid-template-columns: 1fr; } }
.balance { display: flex; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.balance div { background: var(--bg); border-radius: 8px; padding: 8px 12px; display: flex; flex-direction: column; font-size: 12px; color: var(--muted); }
.balance b { font-size: 16px; color: var(--text); }
.status-change select { max-width: 320px; }

.login { max-width: 640px; margin: 48px auto; }
.dev-staff button { margin: 0 6px 6px 0; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(10,15,25,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--card); border-radius: 12px; padding: 18px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 8px; transition: .2s; z-index: 100; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.error { background: var(--danger); }
