:root {
  --bg: #f5f7fb; --panel: #ffffff; --ink: #172033; --muted: #5b6577; --line: #dfe4ee; --soft: #eef2f8;
  --brand: #1d4ed8; --brand-ink: #ffffff; --brand-soft: #e6edff; --ok: #0f7b47; --ok-soft: #e3f6ec;
  --warn: #9a5b00; --warn-soft: #fff3dc; --bad: #b42318; --bad-soft: #fdecea; --gold: #b7791f;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1420; --panel: #171d2b; --ink: #e8ecf4; --muted: #9aa4b6; --line: #2a3346; --soft: #1e2636;
    --brand: #5b8cff; --brand-ink: #0b1020; --brand-soft: #1c2a4d; --ok: #45c486; --ok-soft: #15301f;
    --warn: #f0b04a; --warn-soft: #33270f; --bad: #ff7a6b; --bad-soft: #3a1b18; --gold: #f0c05a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 1.25rem 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
p { margin: .4rem 0; }
.boot { padding: 2rem; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row > select, .row > input:not([type=checkbox]):not([type=radio]) { width: auto; min-width: 12rem; flex: 0 1 auto; }
.row > input.search, form.row > input { flex: 1 1 auto; }
.stack > * + * { margin-top: .75rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }

/* shell */
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.1rem; padding: .25rem .5rem .75rem; }
.brand img { width: 28px; height: 28px; }
.nav a { display: flex; justify-content: space-between; align-items: center; padding: .5rem .65rem; border-radius: 8px; color: var(--ink); text-decoration: none; margin-bottom: 2px; }
.nav a:hover { background: var(--soft); }
.nav a.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav .sep { border-top: 1px solid var(--line); margin: .5rem 0; }
.badge { background: var(--bad); color: #fff; border-radius: 999px; font-size: .72rem; padding: 0 .45rem; min-width: 1.3rem; text-align: center; font-weight: 700; }
.main { min-width: 0; }
.top { display: flex; gap: .75rem; align-items: center; padding: .6rem 1.25rem; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top .search { flex: 1; max-width: 460px; }
.page { padding: 1.25rem; max-width: 1280px; }
.menu-btn { display: none; }

/* panels */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.card + .card { margin-top: 1rem; }
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.kpi { font-size: 1.6rem; font-weight: 700; }
.pill { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .78rem; background: var(--soft); color: var(--muted); border: 1px solid var(--line); }
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.pill.brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.notice { border-radius: var(--radius); padding: .75rem 1rem; background: var(--brand-soft); border: 1px solid transparent; }
.notice.warn { background: var(--warn-soft); }
.notice.bad { background: var(--bad-soft); }
.notice.ok { background: var(--ok-soft); }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: 1.05rem; margin-bottom: .25rem; }
.progress { height: 12px; background: var(--soft); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.progress > div { height: 100%; background: var(--ok); }

/* forms */
label { display: block; font-weight: 600; font-size: .9rem; margin: .6rem 0 .2rem; }
label .hint { font-weight: 400; color: var(--muted); }
input, select, textarea { width: 100%; font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .6rem; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 40%, transparent); outline-offset: 1px; }
textarea { min-height: 90px; resize: vertical; }
input[type=checkbox], input[type=radio] { width: auto; }
.check { display: flex; gap: .5rem; align-items: flex-start; font-weight: 400; }
.field-help { color: var(--muted); font-size: .82rem; margin-top: .2rem; }
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 8px; padding: .45rem .8rem; cursor: pointer; text-decoration: none; display: inline-flex; gap: .35rem; align-items: center; white-space: nowrap; }
button:hover, .btn:hover { background: var(--soft); }
button.primary, .btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
button.primary:hover { filter: brightness(1.07); }
button.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
button.link { border: 0; background: none; color: var(--brand); padding: 0; }
button.small, .btn.small { padding: .2rem .5rem; font-size: .85rem; }
button:disabled { opacity: .55; cursor: not-allowed; }
.help-q { border: 1px solid var(--line); background: var(--soft); color: var(--brand); border-radius: 999px; width: 1.4rem; height: 1.4rem; padding: 0; justify-content: center; font-weight: 700; font-size: .8rem; }

/* tables and lists */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .55rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--soft); }
.table-wrap { overflow-x: auto; }
.list-item { padding: .65rem 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.overdue { color: var(--bad); font-weight: 600; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a, .tabs button { border: 0; background: none; border-bottom: 2px solid transparent; border-radius: 0; padding: .5rem .75rem; color: var(--muted); text-decoration: none; }
.tabs .on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

/* pipeline */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); gap: .75rem; overflow-x: auto; padding-bottom: .5rem; }
.col { background: var(--soft); border-radius: var(--radius); padding: .6rem; min-height: 200px; }
.col h3 { margin: 0 0 .5rem; font-size: .9rem; display: flex; justify-content: space-between; }
.deal { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .55rem; margin-bottom: .5rem; box-shadow: var(--shadow); }
.deal select { margin-top: .35rem; padding: .25rem; font-size: .85rem; }

/* timeline + chat */
.tl-item { border-left: 3px solid var(--line); padding: .35rem 0 .6rem .75rem; margin-left: .25rem; }
.tl-item.in { border-left-color: var(--ok); }
.tl-item.out { border-left-color: var(--brand); }
.tl-item.call { border-left-color: var(--gold); }
.tl-meta { font-size: .8rem; color: var(--muted); }
.chat { display: grid; grid-template-columns: 240px 1fr; gap: 1rem; min-height: 70vh; }
.chat-list a { display: flex; justify-content: space-between; padding: .45rem .6rem; border-radius: 8px; text-decoration: none; color: var(--ink); }
.chat-list a.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.chat-msgs { display: flex; flex-direction: column; gap: .5rem; max-height: 60vh; overflow-y: auto; padding: .25rem; }
.bubble { background: var(--soft); border-radius: 10px; padding: .5rem .7rem; max-width: 80%; white-space: pre-wrap; word-wrap: break-word; }
.bubble.me { background: var(--brand-soft); align-self: flex-end; }
.bubble .who { font-size: .78rem; color: var(--muted); font-weight: 600; }

/* modal + toast */
.modal-back { position: fixed; inset: 0; background: rgba(10,15,25,.5); display: grid; place-items: center; z-index: 50; padding: 1rem; }
.modal { background: var(--panel); border-radius: 12px; width: min(620px, 100%); max-height: 92vh; overflow-y: auto; padding: 1.25rem; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal h2 { margin-top: 0; }
.modal .actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
#toasts { position: fixed; bottom: 1rem; right: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 60; max-width: min(420px, calc(100vw - 2rem)); }
.toast { background: var(--ink); color: var(--panel); padding: .65rem .9rem; border-radius: 8px; box-shadow: var(--shadow); }
.toast.bad { background: var(--bad); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

/* auth */
.auth { max-width: 440px; margin: 8vh auto; padding: 0 16px; }
.auth .card { padding: 1.5rem; }
.auth .brand { justify-content: center; font-size: 1.4rem; padding-bottom: 1rem; }

/* help */
.help-layout { display: grid; grid-template-columns: 260px 1fr; gap: 1rem; }
.help-nav a { display: block; padding: .3rem .5rem; border-radius: 6px; text-decoration: none; color: var(--ink); font-size: .92rem; }
.help-nav a.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.help-nav h4 { margin: .9rem 0 .25rem; font-size: .78rem; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }
.help-article ol, .help-article ul { padding-left: 1.3rem; }
.help-article li { margin: .3rem 0; }
.tip { background: var(--ok-soft); border-radius: 8px; padding: .6rem .8rem; margin: .6rem 0; }
.warnbox { background: var(--warn-soft); border-radius: 8px; padding: .6rem .8rem; margin: .6rem 0; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .86em; background: var(--soft); padding: .05rem .3rem; border-radius: 4px; word-break: break-all; }
.copy-row { display: flex; gap: .4rem; }
.copy-row input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .82rem; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 30% 0 0; z-index: 40; transform: translateX(-105%); transition: transform .2s; height: 100vh; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.35); }
  .menu-btn { display: inline-flex; }
  .page { padding: 1rem; }
  .chat, .help-layout { grid-template-columns: 1fr; }
  .top { padding: .5rem 1rem; }
}
