/* kamlai order dashboard — REFINED SOFT: tối giản, một màu trung tính, Lato */
@font-face { font-family: 'Lato'; font-weight: 400; font-style: normal; font-display: swap; src: url('../fonts/Lato-Regular.woff2') format('woff2'); }
@font-face { font-family: 'Lato'; font-weight: 600; font-style: normal; font-display: swap; src: url('../fonts/Lato-Semibold.woff2') format('woff2'); }
@font-face { font-family: 'Lato'; font-weight: 700; font-style: normal; font-display: swap; src: url('../fonts/Lato-Bold.woff2') format('woff2'); }

:root {
  --ink: #1c1c1c; --slate: #4a4a4a; --ash: #8e8e8e; --limestone: #c2c2c2; --mist: #e8e8e8; --white: #ffffff;
  --bg: #ffffff; --surface: #f6f6f5; --surface-2: #efefee;
  --text: var(--ink); --text-2: var(--slate); --text-3: var(--ash);
  --line: var(--mist); --line-strong: var(--limestone);
  --btn-bg: var(--ink); --btn-fg: #fff;
  --amber: #8a6a1f; --amber-bg: #f7f1e1; --green: #2d6a4f; --green-bg: #e8f2ec; --red: #a23b3b; --red-bg: #f7e9e9;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --radius: 12px;
  --nav-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
:root[data-theme='dark'] {
  --bg: #121212; --surface: #1a1a1a; --surface-2: #232323;
  --text: #ededed; --text-2: #b8b8b8; --text-3: #8a8a8a;
  --line: #2c2c2c; --line-strong: #444;
  --btn-bg: #ededed; --btn-fg: #121212;
  --amber: #d9b45b; --amber-bg: #2a2416; --green: #6fc29a; --green-bg: #17261f; --red: #e08a8a; --red-bg: #2c1b1b;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.5);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #121212; --surface: #1a1a1a; --surface-2: #232323;
    --text: #ededed; --text-2: #b8b8b8; --text-3: #8a8a8a;
    --line: #2c2c2c; --line-strong: #444;
    --btn-bg: #ededed; --btn-fg: #121212;
    --amber: #d9b45b; --amber-bg: #2a2416; --green: #6fc29a; --green-bg: #17261f; --red: #e08a8a; --red-bg: #2c1b1b;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 15px/1.5 'Lato', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
a { color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--text-3); }
.small { font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- Shell ---------- */
.shell { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: 220px 1fr; }
.side {
  position: sticky; top: 0; height: 100vh; height: 100dvh; padding: 28px 16px; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 28px;
}
.brand { font-size: 22px; font-weight: 700; letter-spacing: -.02em; padding: 0 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button {
  display: flex; align-items: center; gap: 12px; border: 0; background: none; text-align: left;
  padding: 10px 12px; border-radius: 10px; color: var(--text-2); font-weight: 600;
}
.nav button svg { width: 20px; height: 20px; flex: none; }
.nav button:hover { background: var(--surface); }
.nav button[aria-current='page'] { background: var(--surface-2); color: var(--text); }
.main { min-width: 0; padding: 28px 32px 80px; max-width: 1280px; width: 100%; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 24px; }
.topbar h1 { font-size: 24px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.brand-m { display: none; }

/* ---------- Buttons / inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 16px;
  border-radius: 10px; border: 1px solid var(--line-strong); background: transparent; font-weight: 600; white-space: nowrap;
}
.btn:hover { background: var(--surface); }
.btn.primary { background: var(--btn-bg); color: var(--btn-fg); border-color: var(--btn-bg); }
.btn.primary:hover { opacity: .88; }
.btn.danger { color: var(--red); border-color: transparent; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 13.5px; border-radius: 8px; }
.btn.icon { padding: 0; width: 40px; }
.btn svg { width: 18px; height: 18px; }
.btn[disabled] { opacity: .5; pointer-events: none; }

.input, .select {
  width: 100%; min-height: 42px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line-strong);
  background: var(--bg); outline: none;
}
.input:focus, .select:focus { border-color: var(--text); box-shadow: 0 0 0 3px var(--surface-2); }
.input[readonly] { background: var(--surface); color: var(--text-3); }
.select { appearance: none; padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238e8e8e' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
.field label { display: block; font-size: 12.5px; color: var(--text-3); margin: 0 0 4px; font-weight: 600; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 14px; border-radius: 8px; font-weight: 600; color: var(--text-2); min-height: 34px; }
.seg button[aria-pressed='true'] { background: var(--bg); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ---------- Cards ---------- */
.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; background: var(--bg); }
.card.flat { background: var(--surface); border-color: transparent; }
.section { margin-top: 32px; }
.section > h2 { font-size: 16px; margin-bottom: 12px; display: flex; align-items: baseline; gap: 8px; }
.section > h2 .count { color: var(--text-3); font-weight: 400; font-size: 14px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 16px; }
.kpis.k3 { grid-template-columns: repeat(3, 1fr); }
.kpi { background: var(--surface); border-radius: var(--radius); padding: 16px; min-width: 0; }
.kpi .l { font-size: 12.5px; color: var(--text-3); font-weight: 600; }
.kpi .v { font-size: 24px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; overflow-wrap: anywhere; }
.kpi .s { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }
.kpi .tag { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; float: right; }
.kpi.warn .v { color: var(--amber); } .kpi.bad .v { color: var(--red); }

.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--text); border-radius: 99px; transition: width .4s; }
.prog { display: grid; gap: 16px; }
.prog .row { display: grid; gap: 6px; }
.prog .head { display: flex; justify-content: space-between; gap: 12px; font-weight: 600; flex-wrap: wrap; }

/* ---------- Tables ---------- */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--text-3); font-weight: 600; background: var(--surface); position: sticky; top: 0; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.r, th.r { text-align: right; }
tr.total td { font-weight: 700; background: var(--surface); }
table.rows tbody tr { cursor: pointer; }
table.rows tbody tr:hover td { background: var(--surface); }
table.wide { min-width: 3400px; font-size: 13.5px; }
table.wide td { white-space: nowrap; }
table.wide td.wrap { white-space: normal; min-width: 240px; }
table.wide th:first-child, table.wide td:first-child { position: sticky; left: 0; background: var(--bg); z-index: 1; box-shadow: 1px 0 0 var(--line); }
table.wide th:first-child { background: var(--surface); z-index: 2; }
.lvl-warn { color: var(--amber); font-weight: 700; } .lvl-bad { color: var(--red); font-weight: 700; }

/* ---------- Chips ---------- */
.chip { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; border: 1px solid currentColor; white-space: nowrap; }
.chip.s-new { color: var(--amber); } .chip.s-done { color: var(--green); } .chip.s-ret { color: var(--red); }
.chip.plain { color: var(--text-3); }

/* ---------- Order cards (Cần xử lý / mobile list) ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.oc { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 8px; background: var(--bg); }
.oc.tap { cursor: pointer; }
.oc .top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.oc .top .id { font-weight: 700; }
.oc .name { font-weight: 700; font-size: 16px; }
.oc .meta { color: var(--text-2); font-size: 13.5px; display: grid; gap: 2px; }
.oc .meta a { text-decoration: none; font-weight: 600; }
.oc .act { display: flex; gap: 8px; margin-top: 4px; }
.oc .act .btn { flex: 1; }
.empty { color: var(--text-3); padding: 24px; text-align: center; border: 1px dashed var(--line-strong); border-radius: var(--radius); }

/* ---------- Modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 50; }
.modal {
  background: var(--bg); border-radius: 16px; width: 100%; max-width: 1100px; max-height: calc(100dvh - 48px);
  display: flex; flex-direction: column; box-shadow: var(--shadow); overflow: hidden;
}
.modal.narrow { max-width: 640px; }
.modal header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 24px; border-bottom: 1px solid var(--line); }
.modal header h2 { font-size: 18px; }
.modal .body { padding: 20px 24px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal footer { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 24px calc(14px + var(--safe-b)); border-top: 1px solid var(--line); background: var(--bg); }
.modal footer .spacer { flex: 1; }
.form { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 16px; }
.form .wide { grid-column: span 3; }
.calc { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 20px; padding: 14px; background: var(--surface); border-radius: var(--radius); }
.calc div b { display: block; font-size: 17px; }
.calc div span { font-size: 12px; color: var(--text-3); font-weight: 600; }
.errs { background: var(--red-bg); color: var(--red); border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-weight: 600; }
.note { font-size: 13px; color: var(--text-3); }

/* ---------- Toast / sync ---------- */
.toast-root { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 80; pointer-events: none; padding: 0 16px; }
@media (min-width: 801px) { .toast-root { bottom: 24px; } }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; box-shadow: var(--shadow); max-width: 480px; pointer-events: auto; }
.toast.err { background: var(--red); color: #fff; }
.sync { font-size: 12.5px; color: var(--text-3); display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; padding: 4px 8px; border-radius: 8px; }
.sync i { width: 8px; height: 8px; border-radius: 50%; background: var(--green); display: inline-block; }
.sync.busy i { background: var(--amber); animation: pulse 1s infinite; }
.sync.err { color: var(--red); } .sync.err i { background: var(--red); }
.sync.demo i { background: var(--limestone); }
@keyframes pulse { 50% { opacity: .3; } }

.fab { display: none; }

/* ---------- Connect screen ---------- */
.connect { max-width: 520px; margin: 10vh auto; padding: 0 20px; display: grid; gap: 16px; }
.connect h1 { font-size: 32px; letter-spacing: -.03em; }
.steps { padding-left: 18px; margin: 0; color: var(--text-2); display: grid; gap: 4px; }

/* ---------- Mobile ---------- */
@media (max-width: 1000px) { .kpis, .kpis.k3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 800px) {
  .shell { display: block; }
  .side { position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; top: auto; height: auto; padding: 0 0 var(--safe-b); border: 0; border-top: 1px solid var(--line); background: var(--bg); }
  .side .brand { display: none; }
  .nav { flex-direction: row; justify-content: space-around; gap: 0; }
  .nav button { flex: 1; flex-direction: column; gap: 2px; padding: 8px 2px; font-size: 11px; border-radius: 0; text-align: center; min-width: 0; height: var(--nav-h); justify-content: center; }
  .nav button[aria-current='page'] { background: none; box-shadow: inset 0 2px 0 var(--text); }
  .main { padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 90px); }
  .topbar { margin-bottom: 16px; }
  .topbar h1 { font-size: 20px; }
  .brand-m { display: block; font-weight: 700; font-size: 14px; color: var(--text-3); letter-spacing: -.01em; }
  .top-actions .label { display: none; }
  .top-actions .btn:not(.icon) { padding: 0 12px; }
  .hide-m { display: none !important; }
  .kpis.k3 { grid-template-columns: 1fr 1fr; }
  .kpis.k3 .kpi:last-child { grid-column: span 2; }
  .kpi .v { font-size: 20px; }
  .cards { grid-template-columns: 1fr; }
  .fab {
    display: inline-flex; position: fixed; right: 16px; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); z-index: 45;
    min-height: 52px; padding: 0 20px; border-radius: 99px; box-shadow: var(--shadow);
  }
  .overlay { padding: 0; align-items: flex-end; }
  .modal, .modal.narrow { max-width: none; border-radius: 16px 16px 0 0; max-height: 94dvh; }
  .modal header, .modal .body, .modal footer { padding-left: 16px; padding-right: 16px; }
  .form { grid-template-columns: 1fr 1fr; gap: 12px; }
  .form .wide { grid-column: span 2; }
  .calc { grid-template-columns: 1fr 1fr; }
  .input, .select { font-size: 16px; } /* tránh iOS tự zoom khi focus */
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media print { .side, .fab, .top-actions { display: none; } .shell { display: block; } }
