/* Gà Võ CRM — mobile-first, black / gold / red brand, light + dark */
:root {
  --gold: #F2B705; --gold-strong: #D9A300; --gold-soft: #FFF4CC;
  --red: #D62828; --red-soft: #FDE8E8;
  --green: #1E8E4E; --green-soft: #E3F5EA;
  --blue: #2563EB; --blue-soft: #E6EEFD;
  --purple: #7C3AED; --gray: #8A8F98;
  --bg: #F6F5F1; --surface: #FFFFFF; --surface-2: #FAF9F6; --line: #E7E4DC;
  --text: #17171A; --muted: #6B6F76; --ink: #111111;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --radius: 12px; --radius-sm: 8px;
  --nav-w: 232px; --bottom-h: 60px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --gold-soft: #3A3010; --red-soft: #3D1616; --green-soft: #12301F; --blue-soft: #15223F;
    --bg: #0E0E10; --surface: #17171B; --surface-2: #1D1D22; --line: #2A2A31;
    --text: #EDEDEF; --muted: #9A9CA4; --ink: #000;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --gold-soft: #3A3010; --red-soft: #3D1616; --green-soft: #12301F; --blue-soft: #15223F;
  --bg: #0E0E10; --surface: #17171B; --surface-2: #1D1D22; --line: #2A2A31;
  --text: #EDEDEF; --muted: #9A9CA4; --ink: #000;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.25);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
a { color: inherit; text-decoration-color: var(--gold); text-underline-offset: 2px; }
a:hover { color: var(--gold-strong); }
code { font: 13px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--surface-2); border: 1px solid var(--line); padding: 1px 6px; border-radius: 6px; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; } h2 { font-size: 16px; } h3 { font-size: 15px; }
p { margin: 0 0 8px; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.block { display: block; }
.center { text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.text-red { color: var(--red); } .text-green { color: var(--green); }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.row { display: flex; align-items: center; }
.row.gap, .gap { gap: 8px; }
.wrap { flex-wrap: wrap; }
.nowrap { flex-wrap: nowrap; }
.between { justify-content: space-between; }
.mt { margin-top: 12px; } .mb { margin-bottom: 12px; }
.stack-v { display: flex; flex-direction: column; gap: 14px; }
.pad { padding: 4px 12px 10px; display: block; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.main { padding: 14px 16px calc(var(--bottom-h) + 24px + env(safe-area-inset-bottom)); max-width: 1280px; width: 100%; margin: 0 auto; outline: none; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--ink); color: #fff; padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top));
  border-bottom: 2px solid var(--gold);
}
.topbar .icon-btn { color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { display: block; height: 36px; width: auto; flex-shrink: 0; filter: drop-shadow(0 1px 6px rgba(242,183,5,.18)); }
.sidebar .brand-logo { height: 58px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text b { font-size: 16px; letter-spacing: .3px; } .brand-text small { color: var(--gold); font-size: 11px; letter-spacing: 2px; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--nav-w); z-index: 40; background: var(--ink); color: #ddd;
  display: flex; flex-direction: column; padding: 16px 12px; transform: translateX(-100%); transition: transform .2s ease;
  overflow-y: auto;
}
.sidebar .brand { color: #fff; padding: 0 6px 16px; border-bottom: 1px solid #262626; margin-bottom: 10px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-link { display: flex; gap: 10px; align-items: center; padding: 10px 10px; border-radius: 8px; text-decoration: none; color: #cfcfcf; }
.nav-link:hover { background: #1c1c1c; color: #fff; }
.nav-link.active { background: var(--gold); color: #111; font-weight: 600; }
.nav-ico { width: 20px; text-align: center; font-size: 16px; }
.side-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid #262626; display: flex; flex-direction: column; gap: 10px; }
.side-foot .btn-ghost { color: #ddd; border-color: #333; }
.me { display: flex; flex-direction: column; color: #fff; padding: 0 6px; } .me small { color: #999; }
.backdrop { display: none; }
body.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.5); }
body.nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 35; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; 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(--line);
  display: grid; grid-template-columns: repeat(5, 1fr);
}
.bn-link { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; text-decoration: none; color: var(--muted); background: none; border: 0; cursor: pointer; }
.bn-link .nav-ico { font-size: 18px; }
.bn-link.active { color: var(--text); font-weight: 600; box-shadow: inset 0 3px 0 var(--gold); }

@media (min-width: 960px) {
  .sidebar { transform: none; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
  .topbar, .bottom-nav, .backdrop { display: none !important; }
  .main { padding: 22px 28px 40px; }
}

/* ---------- page ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.crumbs { margin-bottom: 8px; font-size: 14px; } .crumbs a { text-decoration: none; color: var(--muted); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.toolbar > .input[type="search"] { flex: 1 1 220px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 8px; }
.card > .card-head h2 { font-size: 15px; }
.grid-2 { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

/* ---------- buttons / inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { border-color: var(--gold); color: var(--text); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.is-busy { position: relative; color: transparent !important; }
.btn.is-busy::after { content: ""; position: absolute; width: 16px; height: 16px; border: 2px solid var(--muted); border-top-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.btn-sm { min-height: 34px; padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
:root[data-theme="dark"] .btn-primary { background: var(--gold); color: #111; border-color: var(--gold); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-primary { background: var(--gold); color: #111; border-color: var(--gold); } }
.btn-primary:hover { background: var(--gold); border-color: var(--gold); color: #111; }
.btn-gold { background: var(--gold); border-color: var(--gold); color: #111; font-weight: 600; }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover { color: #fff; filter: brightness(1.08); }
.btn-danger-ghost { color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, var(--line)); }
.btn-ghost { background: transparent; }
.icon-btn { min-width: 36px; height: 36px; border-radius: 8px; border: 0; background: transparent; cursor: pointer; font-size: 18px; display: inline-grid; place-items: center; text-decoration: none; color: inherit; }
.icon-btn:hover { background: color-mix(in srgb, var(--gold) 18%, transparent); }
.icon-btn.danger { color: var(--red); }

.input {
  width: 100%; min-height: 42px; padding: 8px 12px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px; /* 16px avoids iOS zoom */
}
.input:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 25%, transparent); }
textarea.input { resize: vertical; min-height: 64px; }
.input-sm { width: auto; min-height: 38px; }
.input.num { text-align: right; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; }
.form-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .form-grid:not(.one) { grid-template-columns: 1fr 1fr; } .form-grid .span-2 { grid-column: span 2; } }
.form-error { color: var(--red); font-size: 14px; min-height: 0; }
.form-error:empty { display: none; }

/* ---------- chips / badges ---------- */
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex-shrink: 0; border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; border-radius: 999px; cursor: pointer; font-size: 13px; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
:root[data-theme="dark"] .chip.on { background: var(--gold); color: #111; border-color: var(--gold); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip.on { background: var(--gold); color: #111; border-color: var(--gold); } }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; line-height: 1.6; }
.badge.xs { font-size: 10px; padding: 0 6px; }
.b-ok { background: var(--green-soft); color: var(--green); }
.b-bad { background: var(--red-soft); color: var(--red); }
.b-warn { background: var(--gold-soft); color: #8A6400; }
.b-info { background: var(--blue-soft); color: var(--blue); }
.b-gold { background: var(--gold); color: #111; }
.b-muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
:root[data-theme="dark"] .b-warn { color: var(--gold); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .b-warn { color: var(--gold); } :root:not([data-theme="light"]) .b-info { color: #8DB0FF; } }
:root[data-theme="dark"] .b-info { color: #8DB0FF; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tags a { text-decoration: none; }
.count { min-width: 20px; height: 20px; border-radius: 10px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; padding: 0 6px; }

/* ---------- states ---------- */
.state { display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 10px; padding: 36px 16px; color: var(--muted); text-align: center; }
.state.boot { min-height: 60vh; }
.state-icon { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); border: 1px solid var(--line); font-weight: 700; }
.state.error { color: var(--red); } .state.error .state-icon { background: var(--red-soft); border-color: transparent; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.notice { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 14px; }
.notice.warn { background: var(--gold-soft); color: inherit; border-left: 3px solid var(--gold); }
.notice.ok { background: var(--green-soft); border-left: 3px solid var(--green); }

/* ---------- KPIs ---------- */
.kpis { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 720px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } .kpis-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--line); }
.kpi-gold::before { background: var(--gold); } .kpi-red::before { background: var(--red); }
.kpi-title { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.kpi-value { font-size: 22px; font-weight: 750; font-variant-numeric: tabular-nums; margin-top: 2px; overflow-wrap: anywhere; }
.kpi-value.sm { font-size: 17px; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.mini-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.mini { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 10px; display: flex; flex-direction: column; }
.mini small { color: var(--muted); font-size: 12px; } .mini b { font-size: 16px; font-variant-numeric: tabular-nums; }

/* ---------- charts ---------- */
.hbars { display: flex; flex-direction: column; gap: 10px; }
.hbar-top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; margin-bottom: 4px; }
.hbar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-val { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; } .hbar-val small { color: var(--muted); font-weight: 400; }
.hbar-track { height: 10px; background: var(--surface-2); border-radius: 6px; overflow: hidden; border: 1px solid var(--line); }
.hbar-fill { height: 100%; border-radius: 6px; min-width: 2px; }
.f-gold { background: var(--gold); } .f-red { background: var(--red); } .f-green { background: var(--green); }
.f-blue { background: var(--blue); } .f-gray { background: var(--gray); } .f-purple { background: var(--purple); }
.stack { display: flex; height: 14px; border-radius: 8px; overflow: hidden; gap: 2px; }
.stack-seg { height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: 13px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.cols-wrap { overflow-x: auto; }
.cols { width: 100%; min-width: 280px; height: 170px; display: block; }
.cols .axis { stroke: var(--line); }
.cols .col { fill: var(--gold); } .cols .col:hover { fill: var(--gold-strong); }
.cols .col-label { fill: var(--muted); font-size: 10px; }

/* ---------- table (cards on phones) ---------- */
.table-wrap { overflow-x: auto; margin: -4px; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }
.table tr.row-low td, .table tr.row-bad td { background: color-mix(in srgb, var(--red) 7%, transparent); }
.table tr.row-warn td { background: color-mix(in srgb, var(--gold) 10%, transparent); }
.table th.num { text-align: right; }
@media (max-width: 719px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border: 1px solid var(--line); border-radius: var(--radius-sm); margin: 8px 4px; padding: 6px 10px; width: auto; background: var(--surface); }
  .table td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: right; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 600; text-align: left; flex-shrink: 0; }
  .table td[data-label=""]::before { display: none; }
  .table td > div { text-align: right; }
  .table td:first-child { text-align: left; } .table td:first-child > div { text-align: left; }
  .table td:first-child::before { display: none; }
  .table .hide-sm { display: none; }
  .table tr.row-low, .table tr.row-bad { border-color: color-mix(in srgb, var(--red) 45%, var(--line)); }
}
.stock.low { color: var(--red); font-weight: 700; }
.pager { display: flex; justify-content: center; align-items: center; gap: 10px; margin-top: 12px; font-size: 13px; color: var(--muted); }

/* ---------- key/value ---------- */
.kv { display: grid; grid-template-columns: minmax(96px, 34%) 1fr; gap: 6px 12px; margin: 0; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- modal / toast ---------- */
.overlay { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--surface); width: 100%; max-height: 92vh; border-radius: 16px 16px 0 0; display: flex; flex-direction: column; box-shadow: 0 -10px 40px rgba(0,0,0,.3); animation: up .18s ease; }
@media (min-width: 640px) { .overlay { align-items: center; padding: 20px; } .modal { max-width: 480px; border-radius: 16px; } .modal-wide { max-width: 760px; } }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); gap: 8px; }
.modal-body { padding: 16px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.toasts { position: fixed; z-index: 200; left: 50%; transform: translateX(-50%); bottom: calc(var(--bottom-h) + 16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
@media (min-width: 960px) { .toasts { bottom: 24px; left: auto; right: 24px; transform: none; } }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.25); border-left: 4px solid var(--green); transition: opacity .4s, transform .4s; font-size: 14px; }
.toast.t-bad { border-left-color: var(--red); } .toast.t-warn { border-left-color: var(--gold); }
.toast.out { opacity: 0; transform: translateY(8px); }

/* ---------- login: see "brand refresh" section at the end ---------- */

/* ---------- conversations ---------- */
.conv-layout { display: grid; gap: 14px; grid-template-columns: 1fr; }
.conv-layout .thread { display: none; }
.conv-layout.has-thread .conv-side { display: none; }
.conv-layout.has-thread .thread { display: block; }
@media (min-width: 960px) {
  .conv-layout { grid-template-columns: 340px 1fr; height: calc(100vh - 120px); }
  .conv-layout .conv-side, .conv-layout.has-thread .conv-side { display: flex; }
  .conv-layout .thread { display: block; min-height: 0; }
  .thread .back { display: none; }
}
.conv-side { flex-direction: column; padding: 0; overflow: hidden; display: flex; min-height: 0; }
.conv-tools { padding: 12px 12px 0; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.conv-list { overflow-y: auto; flex: 1; }
.conv-item { display: flex; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.conv-item:hover { background: var(--surface-2); color: inherit; }
.conv-item.on { background: var(--gold-soft); box-shadow: inset 3px 0 0 var(--gold); }
.conv-item.unread b { font-weight: 800; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--ink); color: var(--gold); display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.conv-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.conv-top, .conv-bottom { display: flex; align-items: center; gap: 6px; justify-content: space-between; min-width: 0; }
.conv-bottom .ellipsis { flex: 1; font-size: 13px; }
.thread-card { display: flex; flex-direction: column; padding: 0; height: calc(100vh - 150px - var(--bottom-h)); min-height: 420px; overflow: hidden; }
@media (min-width: 960px) { .thread-card { height: 100%; } }
.thread-empty { justify-content: center; }
.thread-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.thread-head .notice { flex-basis: 100%; }
.thread-title { flex: 1; min-width: 120px; display: flex; flex-direction: column; }
.msgs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; background: var(--surface-2); }
.msg { display: flex; flex-direction: column; max-width: 82%; }
.msg-in { align-self: flex-start; } .msg-out { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 8px 12px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-in .bubble { border-bottom-left-radius: 4px; }
.msg-out .bubble { background: var(--ink); color: #fff; border-color: var(--ink); border-bottom-right-radius: 4px; }
.msg-ai .bubble { background: var(--gold-soft); color: var(--text); border-color: var(--gold); }
.msg-system .bubble { background: transparent; color: var(--muted); font-style: italic; }
.msg-meta { font-size: 11px; color: var(--muted); margin-top: 2px; display: flex; gap: 4px; align-items: center; }
.msg-img { max-width: 220px; max-height: 260px; border-radius: 10px; display: block; margin-top: 4px; }
.composer { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); align-items: flex-end; }
.composer textarea { min-height: 44px; max-height: 160px; }
.runs { display: flex; flex-direction: column; gap: 8px; }
.thread .runs { max-height: 40%; overflow-y: auto; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.run { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px; background: var(--surface); display: flex; flex-direction: column; gap: 6px; }
.run-head { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; font-size: 13px; }
.run-tools { display: flex; gap: 4px; flex-wrap: wrap; }
.run-reply { white-space: pre-wrap; font-size: 14px; background: var(--surface-2); padding: 8px; border-radius: 6px; overflow-wrap: anywhere; }
.run-warn { color: #8A6400; font-size: 13px; } .run-err { color: var(--red); font-size: 13px; overflow-wrap: anywhere; }

/* ---------- timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.tl-item { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.tl-item:last-child { border-bottom: 0; }
.tl-ico { width: 28px; height: 28px; flex-shrink: 0; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); display: grid; place-items: center; font-size: 13px; }
.tl-order .tl-ico { background: var(--gold-soft); border-color: var(--gold); }
.timeline.compact .tl-ico { width: 16px; height: 16px; font-size: 10px; border: 0; background: none; }
.tl-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.tl-text { white-space: pre-wrap; font-size: 14px; color: var(--text); overflow-wrap: anywhere; }
.steps { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; border-top: 1px solid var(--line); padding-top: 10px; }

/* ---------- orders ---------- */
.order-form { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 1000px) { .order-form { grid-template-columns: 1fr 360px; align-items: start; } .order-form-side { position: sticky; top: 20px; } }
.order-form-main, .order-form-side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.picked { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; background: var(--gold-soft); border: 1px solid var(--gold); padding: 10px 12px; border-radius: var(--radius-sm); }
.pick-results { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.pick-item { text-align: left; border: 1px solid var(--line); background: var(--surface); padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; }
.pick-item:hover { border-color: var(--gold); }
.prod-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
@media (min-width: 720px) { .prod-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.prod-tile { position: relative; text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-sm); padding: 10px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.prod-tile:hover { border-color: var(--gold); }
.prod-tile.on { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); background: var(--gold-soft); }
.prod-tile.oos { opacity: .7; }
.prod-tile b { font-size: 14px; line-height: 1.3; padding-right: 26px; }
.prod-tile small { font-size: 12px; color: var(--muted); }
.prod-price { font-weight: 700; font-variant-numeric: tabular-nums; }
.prod-qty { position: absolute; top: 6px; right: 6px; background: var(--ink); color: var(--gold); font-size: 12px; font-weight: 700; padding: 1px 7px; border-radius: 999px; }
.lines { display: flex; flex-direction: column; margin-top: 12px; }
.line { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.lines.readonly .line:first-child { border-top: 0; }
.line-name { flex: 1 1 160px; min-width: 0; }
.line-ctl { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.line-ctl .qty { width: 64px; text-align: center; }
.line-ctl .input.num { width: 120px; }
.line-ctl > b { min-width: 96px; }
.totals { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; padding-top: 10px; border-top: 1px solid var(--line); }
.tot-row { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; font-size: 14px; }
.tot-row.grand { font-size: 18px; font-weight: 800; padding-top: 6px; border-top: 1px dashed var(--line); }
.tot-row.muted { color: var(--muted); }
.action-bar { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
@media (max-width: 719px) {
  .action-bar { position: sticky; bottom: calc(var(--bottom-h) + 8px + env(safe-area-inset-bottom)); z-index: 10; box-shadow: var(--shadow); }
  .action-bar .btn { flex: 1 1 140px; }
}
.big-code { font-size: 15px; font-weight: 700; letter-spacing: .5px; }

/* ---------- tasks ---------- */
.tasks { display: flex; flex-direction: column; gap: 8px; }
.task { display: flex; gap: 10px; align-items: center; justify-content: space-between; border: 1px solid var(--line); border-left: 4px solid var(--gray); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--surface); }
.task-bad { border-left-color: var(--red); } .task-warn { border-left-color: var(--gold); } .task-ok { border-left-color: var(--green); opacity: .8; }
.task-main { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.task-title { overflow-wrap: anywhere; }

/* ---------- daily ---------- */
.report-text { white-space: pre-wrap; font: 14px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--surface-2); padding: 12px; border-radius: var(--radius-sm); border: 1px solid var(--line); margin: 0; overflow-wrap: anywhere; max-height: 70vh; overflow-y: auto; }

/* ---------- packing slip / print ---------- */
.slip { background: #fff; color: #111; max-width: 760px; margin: 0 auto; padding: 24px; border: 1px solid #ddd; border-radius: 8px; font-size: 14px; }
.slip-head { display: flex; justify-content: space-between; gap: 12px; border-bottom: 3px solid #111; padding-bottom: 10px; margin-bottom: 14px; }
.slip-brand { font-size: 26px; font-weight: 900; letter-spacing: 2px; }
.slip-head small { color: #555; }
.slip-code { text-align: right; display: flex; flex-direction: column; }
.slip-code b { font-size: 20px; }
.slip-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 14px; }
.slip-grid h4 { font-size: 12px; text-transform: uppercase; color: #555; margin-bottom: 4px; letter-spacing: .5px; }
.slip-grid p { margin: 0 0 2px; }
.slip-cod { font-size: 18px; }
.slip-table { width: 100%; border-collapse: collapse; }
.slip-table th, .slip-table td { border: 1px solid #999; padding: 6px 8px; text-align: left; }
.slip-table th { background: #f1f1f1; font-size: 12px; text-transform: uppercase; }
.slip-table .num { text-align: right; }
.slip-table tfoot td { font-weight: 600; }
.slip-table tr.grand td { font-size: 16px; font-weight: 800; }
.slip-note { margin-top: 10px; padding: 8px; border: 1px dashed #999; }
.slip-foot { margin-top: 16px; font-size: 13px; }
.slip-foot .muted { color: #666; }
.slip-sign { display: flex; justify-content: space-around; margin-top: 24px; padding-bottom: 50px; font-weight: 600; }
@media (max-width: 560px) { .slip { padding: 14px; } .slip-grid { grid-template-columns: 1fr; } }
@media print {
  @page { size: A5; margin: 8mm; }
  body { background: #fff !important; }
  .sidebar, .topbar, .bottom-nav, .backdrop, .no-print, .toasts { display: none !important; }
  .main { padding: 0 !important; max-width: none; }
  .slip { border: 0; padding: 0; max-width: none; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---- Google login + staff ---- */
.google-login:empty { display: none; }
.google-login { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.gsi-btn { min-height: 44px; display: flex; justify-content: center; width: 100%; }
.login-sep { display: flex; align-items: center; gap: 10px; width: 100%; color: var(--muted); font-size: 12px; }
.login-sep::before, .login-sep::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.staff-inactive { opacity: .55; }

/* ---------- feedback (góp ý / báo lỗi) ---------- */
.fab {
  position: fixed; right: 16px; bottom: calc(var(--bottom-h) + 16px + env(safe-area-inset-bottom)); z-index: 32;
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: 999px; cursor: pointer;
  background: var(--gold); color: #111; border: 1px solid var(--gold-strong); font-weight: 700; font-size: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.fab:hover { background: var(--gold-strong); }
.fab-ico { font-size: 16px; line-height: 1; }
@media (max-width: 639px) { .fab { padding: 12px; } .fab-text { display: none; } }
@media (min-width: 960px) { .fab { bottom: 20px; right: 24px; } }
body.print-mode .fab, body.nav-open .fab { display: none; }
.nav-badge { margin-left: auto; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
.bn-link { position: relative; }
.nav-dot { position: absolute; top: 8px; right: calc(50% - 16px); width: 8px; height: 8px; border-radius: 50%; background: var(--red); }
.app-version { color: #777; font-size: 11px; padding: 0 6px; }
.fb-thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.fb-thumb { position: relative; width: 84px; height: 84px; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--line); background: var(--surface-2); }
.fb-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.fb-thumb-x { position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; cursor: pointer; font-size: 12px; line-height: 24px; padding: 0; }
.fb-ctx summary { cursor: pointer; font-size: 13px; color: var(--muted); }
.fb-ctx ul { margin: 6px 0; padding-left: 18px; }
.fb-list { display: flex; flex-direction: column; gap: 10px; }
.fb-item { display: flex; flex-direction: column; gap: 6px; padding: 12px; border: 1px solid var(--line); border-left: 4px solid var(--gray); border-radius: var(--radius-sm); background: var(--surface); text-decoration: none; color: inherit; }
.fb-item:hover { border-color: var(--gold); color: inherit; }
.fb-new { border-left-color: var(--gold); } .fb-reviewing { border-left-color: var(--blue); } .fb-fixed { border-left-color: var(--green); }
.fb-need_info { border-left-color: var(--red); } .fb-wontfix { opacity: .75; }
.fb-note { white-space: pre-wrap; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.fb-note.full { display: block; -webkit-line-clamp: unset; overflow: visible; margin-bottom: 12px; }
.fb-reply { background: var(--green-soft); border-radius: 6px; padding: 6px 8px; white-space: pre-wrap; overflow-wrap: anywhere; }
.fb-gallery { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.fb-shot { width: 140px; height: 140px; padding: 0; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2); cursor: zoom-in; display: grid; place-items: center; }
.fb-shot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.fb-full { max-width: 100%; height: auto; display: block; margin: 0 auto; }
.fb-log { margin: 6px 0; padding-left: 18px; font-size: 13px; overflow-wrap: anywhere; }
.fb-log li { margin-bottom: 4px; }
/* keep the last row of every page clear of the floating button */
.main { padding-bottom: calc(var(--bottom-h) + 84px + env(safe-area-inset-bottom)); }
@media (min-width: 960px) { .main { padding-bottom: 84px; } }
@media print { .fab { display: none !important; } }

/* ================= brand refresh (v1.4.0) ================= */
:root {
  --paper-glow: radial-gradient(900px 520px at 100% -10%, rgba(242,183,5,.10), transparent 60%),
                radial-gradient(700px 480px at -10% 110%, rgba(214,40,40,.05), transparent 60%);
  --pattern-opacity: .07;
  --grain-opacity: .35;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper-glow: radial-gradient(900px 560px at 100% -10%, rgba(242,183,5,.09), transparent 60%),
                  radial-gradient(700px 480px at -10% 110%, rgba(214,40,40,.07), transparent 60%);
    --pattern-opacity: .05; --grain-opacity: .5;
  }
}
:root[data-theme="dark"] {
  --paper-glow: radial-gradient(900px 560px at 100% -10%, rgba(242,183,5,.09), transparent 60%),
                radial-gradient(700px 480px at -10% 110%, rgba(214,40,40,.07), transparent 60%);
  --pattern-opacity: .05; --grain-opacity: .5;
}
/* light: warm paper; dark: deep charcoal with faint gold glow */
:root { --bg: #F5F2EA; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --bg: #0D0D0F; } }
:root[data-theme="dark"] { --bg: #0D0D0F; }

.content { position: relative; isolation: isolate; }
.content::before, .content::after { content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none; }
.content::before { background: var(--paper-glow); }
.content::after {
  background-image: url("../brand/bg-pattern.svg");
  background-size: 360px 360px; opacity: var(--pattern-opacity);
}
.main { position: relative; }
/* subtle paper grain over the whole page background (not over cards: cards are opaque surfaces) */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -2; pointer-events: none; opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5  0 0 0 0 .42  0 0 0 0 .3  0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
body { position: relative; isolation: isolate; }

/* sidebar: deep charcoal with a gold glow under the logo */
.sidebar {
  background:
    radial-gradient(260px 200px at 30% 0%, rgba(242,183,5,.14), transparent 70%),
    linear-gradient(180deg, #121212, #0b0b0b);
  border-right: 1px solid #1f1f1f;
}
.sidebar .brand { flex-direction: column; align-items: flex-start; gap: 6px; padding: 4px 6px 14px; border-bottom: 1px solid rgba(242,183,5,.18); }
.sidebar .brand .brand-text { flex-direction: row; align-items: baseline; gap: 6px; }
.sidebar .brand-text b { font-size: 17px; }
.topbar { background: linear-gradient(90deg, #0d0d0d, #1a1a1a); }
.topbar .brand-logo { height: 32px; }
.topbar .brand-text { flex-direction: row; align-items: baseline; gap: 6px; }

/* ---------- login ---------- */
.login-wrap {
  position: relative; isolation: isolate; overflow: hidden;
  min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: max(24px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  color: #EDEDEF;
  background:
    radial-gradient(620px 420px at 12% 8%, rgba(242,183,5,.20), transparent 62%),
    radial-gradient(700px 520px at 92% 96%, rgba(214,40,40,.18), transparent 62%),
    radial-gradient(500px 300px at 50% 45%, rgba(242,183,5,.06), transparent 70%),
    linear-gradient(160deg, #0f0f0f 0%, #151515 50%, #1a1a1a 100%);
}
.login-wrap::before {
  content: ""; position: absolute; inset: -40px; z-index: -1; pointer-events: none;
  background-image: url("../brand/bg-pattern.svg"); background-size: 360px 360px; opacity: .13;
  transform: rotate(-6deg);
}
.login-wrap::after { /* fine diagonal hairlines */
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background-image: repeating-linear-gradient(135deg, rgba(255,255,255,.022) 0 1px, transparent 1px 9px);
  mask-image: radial-gradient(ellipse at center, #000 30%, transparent 85%);
  -webkit-mask-image: radial-gradient(ellipse at center, #000 30%, transparent 85%);
}
.login-card {
  width: 100%; max-width: 420px; display: flex; flex-direction: column; overflow: hidden;
  border-radius: 20px; border: 1px solid rgba(242,183,5,.22);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  -webkit-backdrop-filter: blur(14px) saturate(140%); backdrop-filter: blur(14px) saturate(140%);
  box-shadow: 0 30px 80px rgba(0,0,0,.55), 0 0 0 1px rgba(255,255,255,.03) inset;
  color: var(--text);
}
.login-brand {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 4px;
  padding: 26px 22px 20px; color: #fff;
  background:
    radial-gradient(320px 160px at 50% 30%, rgba(242,183,5,.22), transparent 70%),
    linear-gradient(180deg, rgba(10,10,10,.92), rgba(22,22,22,.92));
  border-bottom: 2px solid var(--gold);
}
.login-logo { width: 200px; max-width: 70%; height: auto; display: block; filter: drop-shadow(0 6px 18px rgba(0,0,0,.6)); }
.wordmark { margin: 8px 0 0; font-size: 26px; font-weight: 900; letter-spacing: 3px; line-height: 1.1; }
.wordmark span { color: var(--gold); } .wordmark b { color: #fff; font-weight: 900; }
.login-tagline { margin: 2px 0 0; font-size: 13px; color: #B9B9BE; }
.login-body { display: flex; flex-direction: column; gap: 14px; padding: 22px 24px 18px; }
.login-body > .btn-ghost { align-self: center; }
.login-foot { margin: 0; font-size: 12px; color: rgba(255,255,255,.45); text-align: center; }
@media (max-width: 420px) {
  .login-brand { padding: 22px 16px 16px; }
  .login-logo { width: 170px; }
  .wordmark { font-size: 22px; }
  .login-body { padding: 18px 18px 14px; }
}

/* ---------- packing slip logo ---------- */
.slip-id { display: flex; align-items: center; gap: 12px; }
.slip-logo { width: 92px; height: auto; display: block; }
@media print {
  body::before, .content::before, .content::after { display: none !important; }
  .slip-logo { width: 80px; }
}
body.print-mode .content::after { opacity: 0; }
