/* SabAI Back Office — no CSS framework, no CDN (the server may be offline). Light + dark via tokens. */
:root {
    color-scheme: light;
    --bg: #f6f5f2;
    --surface: #ffffff;
    --surface-2: #f1efeb;
    --line: #e4e1db;
    --text: #1b1a18;
    --text-2: #52514e;
    --muted: #7b7973;
    --brand: #5a2ea6;
    --brand-ink: #ffffff;
    --brand-soft: #efe8fb;
    --data: #2a78d6;          /* single-series charts */
    --data-hl: #1c5cab;
    --funnel: #5a2ea6;
    --good: #0f7a3d; --good-soft: #e3f4ea;
    --warn: #9a6200; --warn-soft: #fdf1d8;
    --bad: #c0362c; --bad-soft: #fbe6e3;
    --info: #1d5fb4; --info-soft: #e3eefb;
    --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 1px 8px rgb(0 0 0 / .04);
    --radius: 12px;
    --font: "Noto Sans Thai", "Leelawadee UI", "Sarabun", "Tahoma", system-ui, sans-serif;
    --mono: "Cascadia Mono", "Consolas", ui-monospace, monospace;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --line: #33322f;
        --text: #f4f3ef; --text-2: #c3c2b7; --muted: #8f8d86;
        --brand: #9a7ae6; --brand-ink: #140b26; --brand-soft: #2a2240;
        --data: #3987e5; --data-hl: #86b6ef; --funnel: #9a7ae6;
        --good: #5cc98a; --good-soft: #17301f; --warn: #e5b04a; --warn-soft: #33280f;
        --bad: #ef7d73; --bad-soft: #3a1c19; --info: #7fb0f0; --info-soft: #172a42;
        --shadow: none;
    }
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --line: #33322f;
    --text: #f4f3ef; --text-2: #c3c2b7; --muted: #8f8d86;
    --brand: #9a7ae6; --brand-ink: #140b26; --brand-soft: #2a2240;
    --data: #3987e5; --data-hl: #86b6ef; --funnel: #9a7ae6;
    --good: #5cc98a; --good-soft: #17301f; --warn: #e5b04a; --warn-soft: #33280f;
    --bad: #ef7d73; --bad-soft: #3a1c19; --info: #7fb0f0; --info-soft: #172a42;
    --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 var(--font); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; line-height: 1.25; margin: 0 0 4px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h1:focus { outline: none; }
h2 { font-size: 15px; margin: 0 0 10px; font-weight: 650; }
.muted { color: var(--muted); } .small { font-size: 13px; } .mono { font-family: var(--mono); font-size: .92em; }
.good { color: var(--good); } .bad { color: var(--bad); }
p { margin: 0 0 8px; }

/* ---- shell ---- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); padding: 2px 6px; }
.brand:hover { text-decoration: none; }
.brand b { display: block; font-size: 17px; line-height: 1.1; }
.brand small { color: var(--muted); font-size: 12px; }
.logo { width: 34px; height: 34px; border-radius: 10px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; font-size: 18px; }
.brand.big .logo { width: 44px; height: 44px; font-size: 22px; }
.nav { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; color: var(--text-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: var(--brand); }
.nav .count { margin-left: auto; background: var(--bad); color: #fff; border-radius: 999px; font-size: 12px; padding: 0 8px; font-weight: 700; }
.me { margin-top: auto; border-top: 1px solid var(--line); padding: 12px 6px 0; }
.me-name { font-weight: 600; }
.me form { margin-top: 8px; }
.content { padding: 24px 28px 48px; min-width: 0; max-width: 1400px; }
.page-pad { padding: 24px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

/* ---- controls ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
       padding: 7px 14px; border-radius: 9px; font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.good { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, var(--line)); }
.btn.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.btn.good.on { background: var(--good-soft); border-color: var(--good); color: var(--good); }
.btn.bad.on { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.big { padding: 10px 18px; font-size: 16px; }
.btn.wide { width: 100%; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 1px; }
label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 10px; }
label > input, label > select, label > textarea { margin-top: 4px; }
label.check { display: flex; align-items: center; gap: 8px; }
label.check input { width: auto; margin: 0; }
.label { font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row-end { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.sep { height: 1px; background: var(--line); margin: 14px 0; }

.range { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: transparent; font: inherit; font-size: 13px; padding: 5px 10px; border-radius: 7px; color: var(--text-2); cursor: pointer; }
.seg button.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.dates { display: flex; align-items: center; gap: 4px; margin: 0; }
.dates input { width: 140px; padding: 5px 8px; font-size: 13px; margin: 0; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 8px 12px; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.tabs a:hover { text-decoration: none; color: var(--text); }
.tabs a.on { color: var(--brand); border-color: var(--brand); font-weight: 600; }
.tabs .n { font-size: 12px; background: var(--surface-2); border-radius: 999px; padding: 0 7px; color: var(--muted); }
.filters { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.filters .search { max-width: 420px; }
.filters select { width: auto; min-width: 200px; }

/* ---- cards & layout ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 16px; min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.pad { padding: 14px 18px; margin: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-2 > .card, .grid-3 > .card { margin-bottom: 0; }
section.grid-2, section.grid-3 { margin-bottom: 16px; }
.detail { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(300px, 1fr); gap: 16px; align-items: start; }
.loading, .empty { padding: 28px; text-align: center; color: var(--muted); }
.empty.ok { color: var(--good); display: flex; gap: 8px; justify-content: center; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi.accent { border-color: color-mix(in srgb, var(--good) 35%, var(--line)); }
.kpi-label { color: var(--text-2); font-size: 13px; }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -.01em; margin: 2px 0; font-variant-numeric: tabular-nums; }
.kpis.small .kpi-value { font-size: 20px; }
.kpi-sub { font-size: 12.5px; color: var(--muted); }
.kpi-sub .delta + span::before { content: " · "; }
.delta { font-weight: 600; } .delta.up { color: var(--good); } .delta.down { color: var(--bad); }

.callout { display: flex; align-items: center; gap: 10px; background: var(--info-soft); color: var(--info); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; }
.callout.warn { background: var(--bad-soft); color: var(--bad); }
.callout .go { margin-left: auto; font-weight: 600; }
.callout:hover { text-decoration: none; filter: brightness(.98); }
.alert { border-radius: 9px; padding: 10px 14px; margin-bottom: 12px; }
.alert.err { background: var(--bad-soft); color: var(--bad); }
.alert.ok { background: var(--good-soft); color: var(--good); }

/* ---- tables ---- */
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-weight: 600; font-size: 12.5px; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface); }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl.click tbody tr { cursor: pointer; }
.tbl.click tbody tr:hover, .tbl.click tbody tr:focus-within { background: var(--surface-2); }
.tbl tr.late td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
.tbl tr.dim { opacity: .55; }
.tbl.compact td, .tbl.compact th { padding: 5px 6px; font-size: 13px; }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge i, .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }
.dot { background: var(--muted); }
.st-new { background: var(--brand-soft); color: var(--brand); } .dot.st-new { background: var(--brand); }
.st-contacted { background: var(--info-soft); color: var(--info); } .dot.st-contacted { background: var(--info); }
.st-quoted { background: var(--warn-soft); color: var(--warn); } .dot.st-quoted { background: var(--warn); }
.st-booked { background: var(--good-soft); color: var(--good); } .dot.st-booked { background: var(--good); }
.st-lost { background: var(--surface-2); color: var(--muted); } .dot.st-lost { background: var(--muted); }
.pill { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--info-soft); color: var(--info); white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good); } .pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.muted { background: var(--surface-2); color: var(--muted); }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 14px; border-top: 1px solid var(--line); }
.pager span { margin-right: auto; }

/* ---- charts (single series: one hue, no legend; hover = tooltip) ---- */
.vbars { position: relative; height: calc(var(--h) + 26px); padding-left: 40px; }
.vb-grid { position: absolute; inset: 0 0 26px 40px; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
.vb-line { border-top: 1px solid var(--line); position: relative; height: 0; }
.vb-line span { position: absolute; right: calc(100% + 6px); top: -8px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.vb-plot { position: absolute; inset: 0 0 0 40px; display: flex; align-items: flex-end; gap: 2px; padding-bottom: 26px; }
.vb-col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; position: relative; min-width: 0; outline: none; }
.vb-bar { background: var(--data); border-radius: 4px 4px 0 0; min-height: 0; max-width: 36px; width: 100%; margin: 0 auto; transition: filter .1s; }
.vb-bar.hl { background: var(--data-hl); }
.vb-col:hover .vb-bar, .vb-col:focus .vb-bar { filter: brightness(1.15); }
.vb-x { position: absolute; bottom: -22px; left: 50%; transform: translateX(-50%); font-size: 11px; color: var(--muted); white-space: nowrap; }
.vb-tip { display: none; position: absolute; bottom: calc(100% - 20px); left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); font-size: 12px; padding: 6px 9px; border-radius: 7px; white-space: nowrap; z-index: 5; pointer-events: none; }
.vb-col:hover .vb-tip, .vb-col:focus .vb-tip { display: block; }
.vb-col:first-child .vb-tip { left: 0; transform: none; }
.vb-col:last-child .vb-tip { left: auto; right: 0; transform: none; }

.hbars { display: flex; flex-direction: column; gap: 7px; }
.hb-row { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; gap: 10px; align-items: center; font-size: 13.5px; }
.hb-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.hb-track { height: 14px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hb-bar { height: 100%; background: var(--data); border-radius: 0 4px 4px 0; }
.hb-bar.funnel { background: var(--funnel); }
.hb-bar.warn { background: var(--warn); }
.hb-val { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 92px; text-align: right; white-space: nowrap; }
.hbars + p { margin-top: 12px; }
.hb-val small { font-weight: 400; color: var(--muted); }

/* ---- lead / call detail ---- */
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; margin: 0; }
.kv dt { color: var(--muted); font-size: 13.5px; }
.kv dd { margin: 0; }
.trip { display: flex; align-items: center; gap: 18px; margin-bottom: 12px; }
.trip .code { font-size: 26px; font-weight: 700; letter-spacing: .02em; }
.trip .arrow { color: var(--brand); text-align: center; }
.airline { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.airline img { width: 32px; height: 32px; border-radius: 6px; }
.flights { margin: 4px 0 10px; padding-left: 18px; }
.action h2 { margin-bottom: 12px; }
.status-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.subform { margin-top: 12px; padding: 12px; border: 1px dashed var(--line); border-radius: 10px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 12px 8px; }
.timeline li::before { content: ""; position: absolute; left: -21px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--muted); }
.timeline li.status::before { border-color: var(--brand); background: var(--brand); }
.timeline li.call_attempt::before { border-color: var(--info); }
.timeline li.created::before { border-color: var(--good); }
.t-head { font-size: 13px; }
.plain { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.transcript { display: flex; flex-direction: column; gap: 6px; max-height: 70vh; overflow: auto; }
.transcript.mini { max-height: none; margin-top: 10px; }
.tl { padding: 7px 10px; border-radius: 8px; background: var(--surface-2); font-size: 14px; }
.tl b { margin: 0 4px; }
.tl.customer { background: var(--info-soft); }
.tl.customer b { color: var(--info); }
.tl.sabai { background: var(--brand-soft); }
.tl.sabai b { color: var(--brand); }
.tl.system { background: transparent; color: var(--muted); font-size: 12.5px; padding: 2px 10px; }
.search-row { padding: 8px 0; border-bottom: 1px solid var(--line); }
.search-row:last-child { border-bottom: 0; }

/* ---- modal ---- */
.modal-bg { position: fixed; inset: 0; background: rgb(0 0 0 / .35); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; padding: 20px; width: min(460px, 100%); box-shadow: 0 10px 40px rgb(0 0 0 / .25); }

/* ---- login ---- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(1200px 600px at 20% -10%, var(--brand-soft), transparent), var(--bg); }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.login-card h1 { margin: 20px 0 16px; font-size: 20px; }
.validation-message { color: var(--bad); font-size: 13px; margin: -6px 0 10px; }

.ico { flex: none; }
#blazor-error-ui { background: var(--warn-soft); color: var(--warn); bottom: 0; box-shadow: 0 -1px 2px rgba(0,0,0,.2); display: none; left: 0; padding: .6rem 1.25rem; position: fixed; width: 100%; z-index: 1000; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }
.blazor-error-boundary { background: var(--bad); padding: 1rem; color: white; }

/* ---- small screens: sidebar becomes a top bar ---- */
@media (max-width: 1100px) {
    .grid-3 { grid-template-columns: 1fr 1fr; }
    .detail { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
    .shell { grid-template-columns: minmax(0, 1fr); }
    .side { min-width: 0; }
    .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; gap: 10px; }
    .nav { flex-direction: row; overflow-x: auto; width: 100%; order: 3; }
    .nav a { white-space: nowrap; padding: 7px 9px; }
    .me { margin: 0 0 0 auto; border: 0; padding: 0; display: flex; align-items: center; gap: 8px; }
    .me .muted { display: none; }
    .me form { margin: 0; }
    .content { padding: 16px 16px 40px; }
    .grid-2, .grid-3, .form-grid { grid-template-columns: 1fr; }
    .kv { grid-template-columns: 110px 1fr; }
    .dates input { width: 128px; }
    .filters select { min-width: 0; width: 100%; }
}

/* customers (2026-09-29) */
.who-cell { display: flex; align-items: center; gap: 10px; }
.who-cell img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex: none; }
.btn.danger { background: #d93025; border-color: #d93025; color: #fff; margin-top: 8px; }
.btn.danger:hover { background: #b3261e; }
