/* =====================================================================
   Sổ Thu Chi — giao diện ưu tiên điện thoại
   - Tông xanh ngọc Inliti
   - Dark mode: theo hệ thống, hoặc chọn tay (html[data-theme])
   ===================================================================== */

:root {
  --font: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --radius: 18px;
  --radius-sm: 12px;

  /* Nền & chữ (sáng) */
  --bg: #f7f5f9;
  --surface: #ffffff;
  --surface-2: #f2eff5;
  --border: #e7e2ec;
  --text: #1f1b24;
  --muted: #6e6778;
  --shadow: 0 1px 2px rgba(30, 20, 40, .05), 0 6px 20px rgba(30, 20, 40, .06);

  /* Thu xanh lá, chi đỏ */
  --income: #16a34a;
  --income-soft: #dcfce7;
  --expense: #dc2626;
  --expense-soft: #fee2e2;
  --warn: #d97706;

  /* Màu nhấn: xanh ngọc Inliti */
  --accent: #0d9488;
  --accent-2: #06b6d4;
  --accent-soft: #dff7f4;
  --accent-text: #ffffff;
  --grad: linear-gradient(135deg, #0f766e 0%, #0d9488 45%, #06b6d4 100%);
}


/* Dark mode theo hệ thống */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121015;
    --surface: #1c1920;
    --surface-2: #26222b;
    --border: #332e39;
    --text: #f1edf5;
    --muted: #a39cad;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    --income: #4ade80;
    --income-soft: rgba(74, 222, 128, .14);
    --expense: #f87171;
    --expense-soft: rgba(248, 113, 113, .14);
  }
  :root:not([data-theme="light"]) body[data-biz="inliti"] { --accent: #2dd4bf; --accent-soft: rgba(45, 212, 191, .14); }
}
/* Dark mode chọn tay */
:root[data-theme="dark"] {
  --bg: #121015;
  --surface: #1c1920;
  --surface-2: #26222b;
  --border: #332e39;
  --text: #f1edf5;
  --muted: #a39cad;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  --income: #4ade80;
  --income-soft: rgba(74, 222, 128, .14);
  --expense: #f87171;
  --expense-soft: rgba(248, 113, 113, .14);
}
:root[data-theme="dark"] body[data-biz="inliti"] { --accent: #2dd4bf; --accent-soft: rgba(45, 212, 191, .14); }

/* ---------- Nền tảng ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.income { color: var(--income); }
.expense { color: var(--expense); }
.error-text { color: var(--expense); font-size: 14px; margin: 8px 0 0; }

/* ---------- Đăng nhập ---------- */
.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: linear-gradient(160deg, #e6fbf8 0%, #f2fbff 50%, #dff7f4 100%);
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .login { background: var(--bg); } }
:root[data-theme="dark"] .login { background: var(--bg); }
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border-radius: 24px;
  padding: 32px 24px;
  box-shadow: var(--shadow);
  text-align: center;
  display: grid;
  gap: 12px;
}
.login-logo {
  width: 64px; height: 64px; margin: 0 auto 4px;
  border-radius: 20px;
  background: linear-gradient(135deg, #0f766e, #0d9488 50%, #06b6d4);
  color: #fff; font-size: 34px; font-weight: 700;
  display: grid; place-items: center;
}
.login-card h1 { font-size: 22px; }
.login-card p { margin: 0 0 8px; }

/* ---------- Thanh trên ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
}

/* ---------- Khung nội dung ---------- */
.view {
  max-width: 560px; margin: 0 auto;
  padding: 4px 16px calc(env(safe-area-inset-bottom) + 150px);
}
.section { margin-top: 20px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.section-head h2 { font-size: 17px; }
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card + .card { margin-top: 12px; }

/* Thẻ lợi nhuận lớn (hero) */
.hero {
  background: var(--grad);
  color: #fff;
  border-radius: 22px;
  padding: 18px;
  box-shadow: 0 10px 30px color-mix(in srgb, var(--accent) 30%, transparent);
}
.hero-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.hero-label { opacity: .9; font-size: 14px; }
.hero-value { font-size: 30px; font-weight: 700; margin: 6px 0 2px; letter-spacing: -.5px; }
.hero-sub { font-size: 13px; opacity: .92; }
.month-step { display: flex; align-items: center; gap: 2px; background: rgba(255, 255, 255, .2); border-radius: 12px; padding: 2px; font-weight: 600; font-size: 14px; white-space: nowrap; }
.month-step button { border: 0; background: transparent; color: inherit; width: 32px; height: 32px; border-radius: 10px; font-size: 20px; line-height: 1; }
.month-step button:disabled { opacity: .35; }
.month-step span { padding: 0 4px; }
.hero .month-input { background: rgba(255, 255, 255, .2); color: #fff; border: 0; }
.hero .month-input::-webkit-calendar-picker-indicator { filter: invert(1); }
.hero-split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.hero-split > div { background: rgba(255, 255, 255, .16); border-radius: 14px; padding: 10px 12px; }
.hero-split .k { font-size: 12.5px; opacity: .9; }
.hero-split .v { font-weight: 700; font-size: 17px; }
.hero-split .d { font-size: 12px; opacity: .9; }

.month-input {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 10px; padding: 6px 8px; font-size: 14px;
}

.chip-delta { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: rgba(255, 255, 255, .22); }


/* Biểu đồ */
.chart-box { position: relative; height: 230px; }
.chart-box.pie { height: 250px; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; font-size: 14px; }

/* ---------- Danh sách giao dịch ---------- */
.filters { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 8px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters select, .filters input {
  flex: 0 0 auto;
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 99px; padding: 7px 12px; font-size: 13.5px;
  max-width: 180px;
}
.totals-bar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.totals-bar > div { background: var(--surface); border-radius: 14px; padding: 10px; box-shadow: var(--shadow); }
.totals-bar .k { font-size: 12px; color: var(--muted); }
.totals-bar .v { font-weight: 700; font-size: 15px; }

.day-group { margin-top: 14px; }
.day-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); padding: 0 4px 6px; }
.tx-list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.tx {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; width: 100%;
  border: 0; background: transparent; text-align: left;
}
.tx + .tx { border-top: 1px solid var(--border); }
.tx:active { background: var(--surface-2); }
.tx-ico {
  flex: 0 0 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center; font-weight: 700; font-size: 16px;
}
.tx-ico.thu { background: var(--income-soft); color: var(--income); }
.tx-ico.chi { background: var(--expense-soft); color: var(--expense); }
.tx-main { flex: 1; min-width: 0; }
.tx-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-meta { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-amt { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.badge {
  display: inline-block; font-size: 11px; font-weight: 600;
  padding: 1px 7px; border-radius: 99px;
  background: var(--surface-2); color: var(--muted);
  vertical-align: 1px;
}
.badge.shopee { background: #ffede6; color: #d9480f; }
.badge.zalo { background: #e6f0ff; color: #1d5fd1; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"])   :root:not([data-theme="light"])   :root:not([data-theme="light"]) .badge.shopee { background: rgba(249, 115, 22, .16); color: #fdba74; }
  :root:not([data-theme="light"]) .badge.zalo { background: rgba(59, 130, 246, .18); color: #93c5fd; }
}
:root[data-theme="dark"] :root[data-theme="dark"] :root[data-theme="dark"] .badge.shopee { background: rgba(249, 115, 22, .16); color: #fdba74; }
:root[data-theme="dark"] .badge.zalo { background: rgba(59, 130, 246, .18); color: #93c5fd; }

/* Sản phẩm bán chạy */
.rank { display: grid; gap: 10px; }
.rank-row { display: grid; grid-template-columns: 24px 1fr auto; gap: 10px; align-items: center; }
.rank-no { font-weight: 700; color: var(--accent); text-align: center; }
.rank-name { font-weight: 500; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-bar { height: 6px; border-radius: 99px; background: var(--surface-2); margin-top: 4px; overflow: hidden; }
.rank-bar i { display: block; height: 100%; background: var(--grad); border-radius: 99px; }
.rank-val { text-align: right; font-size: 13px; }

/* ---------- Nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface);
  padding: 11px 16px; border-radius: 14px; font-weight: 600;
  min-height: 44px;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--grad); color: #fff; border: 0; box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 30%, transparent); }
.btn-danger { color: var(--expense); border-color: color-mix(in srgb, var(--expense) 35%, var(--border)); }
.btn-ghost { background: transparent; border: 0; color: var(--accent); padding: 6px 8px; min-height: 0; }
.btn-sm { padding: 6px 12px; min-height: 34px; font-size: 13.5px; border-radius: 10px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; }
.btn-row > .btn { flex: 1; }
.link { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 0; font-size: 14px; }

/* ---------- Thanh điều hướng dưới ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 4px calc(env(safe-area-inset-bottom) + 6px);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--border);
}
.tabbar button {
  border: 0; background: none; color: var(--muted);
  display: grid; justify-items: center; gap: 2px;
  font-size: 11.5px; font-weight: 600; padding: 6px 0;
}
.tabbar svg { width: 24px; height: 24px; fill: currentColor; }
.tabbar button.active { color: var(--accent); }

/* ---------- Nút nổi (FAB) ---------- */
.fab-wrap {
  position: fixed; z-index: 45;
  right: max(16px, calc(50% - 264px));
  bottom: calc(env(safe-area-inset-bottom) + 78px);
  display: flex; flex-direction: column; align-items: flex-end; gap: 12px;
}
.fab {
  width: 58px; height: 58px; border-radius: 20px; border: 0;
  background: var(--grad); color: #fff;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 45%, transparent);
  display: grid; place-items: center;
  transition: transform .2s;
}
.fab svg { width: 28px; height: 28px; fill: currentColor; transition: transform .2s; }
.fab[aria-expanded="true"] svg { transform: rotate(45deg); }
.fab-menu { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; animation: pop .18s ease-out; }
.fab-menu button {
  display: flex; align-items: center; gap: 10px;
  border: 0; background: var(--surface); color: var(--text);
  padding: 11px 16px 11px 12px; border-radius: 16px;
  font-weight: 600; box-shadow: var(--shadow);
}
.fab-ico { width: 30px; height: 30px; border-radius: 10px; background: var(--accent-soft); display: grid; place-items: center; font-size: 16px; }
.fab-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(20, 10, 30, .35); animation: fade .15s; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.97); } }
@keyframes fade { from { opacity: 0; } }

/* ---------- Bảng trượt từ dưới (sheet) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(20, 10, 30, .45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s;
}
.sheet {
  width: 100%; max-width: 560px;
  max-height: 92dvh;
  background: var(--bg);
  border-radius: 24px 24px 0 0;
  display: flex; flex-direction: column;
  animation: slideup .22s cubic-bezier(.2, .8, .2, 1);
}
.sheet.full { height: 96dvh; max-height: 96dvh; }
@keyframes slideup { from { transform: translateY(40px); opacity: .4; } }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}
.sheet-head h3 { font-size: 17px; }
.sheet-close { border: 0; background: var(--surface-2); width: 34px; height: 34px; border-radius: 50%; font-size: 18px; line-height: 1; }
.sheet-body { overflow-y: auto; padding: 16px; flex: 1; -webkit-overflow-scrolling: touch; }
.sheet-foot { padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px); border-top: 1px solid var(--border); background: var(--surface); }
@media (min-width: 700px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 24px; max-height: 88dvh; }
  .sheet.full { height: 88dvh; }
}

/* ---------- Form ---------- */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field > label, .label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea, .input {
  width: 100%;
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 12px; padding: 11px 12px;
  font-size: 16px; /* 16px để iPhone không tự zoom */
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus, .input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field textarea { min-height: 70px; resize: vertical; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.amount-input { font-size: 26px !important; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.amount-wrap { position: relative; }
.amount-wrap::after { content: '₫'; position: absolute; right: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 600; }
.amount-wrap .amount-input { padding-right: 36px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 14px; }
.seg button { border: 0; background: transparent; padding: 9px; border-radius: 11px; font-weight: 600; color: var(--muted); }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, .08); }
.seg.type button.active[data-v="thu"] { background: var(--income); color: #fff; }
.seg.type button.active[data-v="chi"] { background: var(--expense); color: #fff; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  border: 1px solid var(--border); background: var(--surface);
  padding: 7px 12px; border-radius: 99px; font-size: 14px;
}
.chips button.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.inliti-box { display: grid; gap: 14px; padding: 14px; border-radius: 16px; background: var(--accent-soft); }
.inliti-box { background: color-mix(in srgb, #0d9488 9%, var(--surface)); }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; }
.switch-row + .switch-row { border-top: 1px solid var(--border); }
.switch-row .t { font-weight: 600; }
.switch-row .s { font-size: 13px; color: var(--muted); }
.toggle { position: relative; flex: 0 0 48px; height: 28px; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle span { position: absolute; inset: 0; background: var(--border); border-radius: 99px; transition: .2s; }
.toggle span::before { content: ''; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
.toggle input:checked + span { background: var(--accent); }
.toggle input:checked + span::before { transform: translateX(20px); }

/* ---------- Màn hình xem lại đơn ---------- */
.review-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.review-summary > div { background: var(--surface); border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow); }
.review-summary .k { font-size: 12px; color: var(--muted); }
.review-summary .v { font-weight: 700; font-size: 16px; }
.notice { border-radius: 14px; padding: 10px 12px; font-size: 13.5px; background: var(--surface-2); margin-top: 10px; }
.notice.warn { background: color-mix(in srgb, var(--warn) 14%, var(--surface)); }
.order-card { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); margin-top: 10px; overflow: hidden; }
.order-card.off { opacity: .5; }
.order-head { display: flex; align-items: center; gap: 10px; padding: 12px; }
.order-head input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); flex: 0 0 auto; }
.order-head .oh-main { flex: 1; min-width: 0; }
.order-head .oh-code { font-weight: 700; font-size: 14px; }
.order-head .oh-meta { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.order-head .oh-net { text-align: right; font-weight: 700; white-space: nowrap; }
.order-head .oh-net small { display: block; font-weight: 500; font-size: 11.5px; color: var(--muted); }
.order-toggle { border: 0; background: var(--surface-2); border-radius: 10px; width: 32px; height: 32px; flex: 0 0 auto; transition: transform .2s; }
.order-card.open .order-toggle { transform: rotate(180deg); }
.order-body { border-top: 1px solid var(--border); padding: 12px; display: grid; gap: 10px; background: color-mix(in srgb, var(--surface-2) 45%, var(--surface)); }
.mini { display: grid; gap: 4px; }
.mini label { font-size: 11.5px; font-weight: 600; color: var(--muted); }
.mini input { width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 9px; padding: 7px 9px; font-size: 16px; }
.mini select { width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 9px; padding: 7px 9px; font-size: 16px; }
.mini input.money { text-align: right; font-variant-numeric: tabular-nums; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.item-row { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px; display: grid; gap: 8px; }
.item-row .item-top { display: flex; gap: 8px; align-items: flex-end; }
.item-row .item-top .mini { flex: 1; }
.icon-btn { border: 0; background: var(--expense-soft); color: var(--expense); width: 34px; height: 34px; border-radius: 10px; flex: 0 0 auto; font-size: 16px; }
.calc-line { display: flex; justify-content: space-between; font-size: 13px; }
.calc-line.total { font-weight: 700; font-size: 14px; border-top: 1px dashed var(--border); padding-top: 6px; }

/* Bảng ghép cột */
.map-row { display: grid; grid-template-columns: 1fr 1.2fr; gap: 10px; align-items: center; padding: 10px 0; }
.map-row + .map-row { border-top: 1px solid var(--border); }
.map-row .t { font-weight: 600; font-size: 14px; }
.map-row .t .req { color: var(--expense); }
.map-row .s { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.map-row select { width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 8px; font-size: 14px; }
.map-row.missing select { border-color: var(--warn); }

/* Danh mục trong cài đặt */
.cat-list { display: grid; }
.cat-item { display: flex; align-items: center; gap: 8px; padding: 10px 0; }
.cat-item + .cat-item { border-top: 1px solid var(--border); }
.cat-item .name { flex: 1; }
.cat-item .lock { font-size: 12px; color: var(--muted); }

.settings-list { display: grid; }
.settings-list > * + * { border-top: 1px solid var(--border); }
.settings-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 13px 0; width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; }
.settings-item:first-child { border-top: 0; }

/* Đang tải */
.loading { display: grid; place-items: center; padding: 60px 0; color: var(--muted); gap: 12px; }
.spinner { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.overlay-busy { position: fixed; inset: 0; z-index: 90; background: rgba(20, 10, 30, .45); display: grid; place-items: center; }
.overlay-busy .box { background: var(--surface); border-radius: 20px; padding: 24px 28px; display: grid; justify-items: center; gap: 12px; box-shadow: var(--shadow); max-width: 280px; text-align: center; }

/* Thông báo nhỏ */
.toast-root { position: fixed; left: 0; right: 0; top: calc(env(safe-area-inset-top) + 12px); z-index: 100; display: grid; justify-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast {
  pointer-events: auto;
  max-width: 520px; background: #1f1b24; color: #fff;
  padding: 11px 16px; border-radius: 14px; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  animation: pop .2s ease-out;
}
.toast.ok { background: #15803d; }
.toast.err { background: #b91c1c; }

/* ---------- Đơn hàng ---------- */
.order-row { display: grid; gap: 4px; width: 100%; padding: 12px 14px; border: 0; background: transparent; text-align: left; }
.order-row + .order-row { border-top: 1px solid var(--border); }
.order-row:active { background: var(--surface-2); }
.or-top, .or-mid { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.or-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.or-amt { font-weight: 700; white-space: nowrap; }
.or-badges { display: flex; flex-wrap: wrap; gap: 4px; }
.or-items { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge.late { background: var(--expense-soft); color: var(--expense); }
.badge.soon { background: color-mix(in srgb, var(--warn) 18%, var(--surface)); color: var(--warn); }
.badge.st-cho_coc { background: color-mix(in srgb, var(--warn) 14%, var(--surface)); color: var(--warn); }
.badge.st-dang_in { background: var(--accent-soft); color: var(--accent); }
.badge.st-da_giao { background: #e6f0ff; color: #1d5fd1; }
.badge.st-da_thanh_toan { background: var(--income-soft); color: var(--income); }
.badge.st-da_huy { background: var(--surface-2); color: var(--muted); text-decoration: line-through; }
.tabbar button span { white-space: nowrap; }

/* ---------- Ô tìm kiếm ---------- */
.search {
  width: 100%;
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 12px; padding: 10px 12px; font-size: 16px; outline: none;
}
.search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* Các phần chỉ dùng trên máy tính */
.brand, .top-actions, .nav-spacer { display: none; }
.page-title { font-size: 20px; max-width: 560px; margin: 0 auto; padding: 2px 0; }
.icon-round { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); display: grid; place-items: center; color: var(--muted); }
.icon-round svg { width: 20px; height: 20px; fill: currentColor; }
.icon-round:active svg { transform: rotate(-90deg); transition: transform .2s; }

/* Hiệu ứng rê chuột (chỉ máy có chuột) */
@media (hover: hover) {
  .tx:hover, .order-row:hover { background: var(--surface-2); }
  .btn:hover { filter: brightness(.97); }
  .btn-primary:hover { filter: brightness(1.06); }
  .chips button:hover, .seg button:not(.active):hover { color: var(--text); }
  .icon-round:hover { color: var(--accent); border-color: var(--accent); }
}

/* ===================== Máy tính bảng (≥ 700px) ===================== */
@media (min-width: 700px) {
  .view, .page-title { max-width: 760px; }
  .fab-wrap { right: max(16px, calc(50% - 364px)); }
  .review-summary { grid-template-columns: repeat(4, 1fr); }
  .review-summary > div[style*="grid-column"] { grid-column: auto !important; }
}

/* ===================== Máy tính (≥ 900px): full màn hình ===================== */
@media (min-width: 900px) {
  :root { --side: 248px; }
  body { font-size: 15px; }
  #app { padding-left: var(--side); }

  /* Thanh điều hướng → cột bên trái */
  .tabbar {
    top: 0; bottom: 0; right: auto; width: var(--side);
    display: flex; flex-direction: column; gap: 4px;
    padding: 20px 14px 20px;
    border-top: 0; border-right: 1px solid var(--border);
    background: var(--surface);
    backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  .tabbar button {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 14px; border-radius: 12px;
    font-size: 14.5px; font-weight: 600; text-align: left;
  }
  .tabbar button:hover { background: var(--surface-2); color: var(--text); }
  .tabbar button.active { background: var(--accent-soft); color: var(--accent); }
  .tabbar svg { width: 20px; height: 20px; flex: 0 0 auto; }
  .brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; }
  .brand-logo { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 22px; background: linear-gradient(135deg, #0f766e, #0d9488 50%, #06b6d4); flex: 0 0 auto; }
  .brand b { display: block; font-size: 15.5px; }
  .brand small { display: block; font-size: 11.5px; color: var(--muted); }
  .nav-spacer { display: block; flex: 1; }

  /* Thanh trên: tiêu đề + chọn mảng + nút thao tác */
  .topbar { padding: 14px 32px; border-bottom: 1px solid var(--border); }
  .topbar-inner { display: flex; align-items: center; gap: 20px; max-width: 1560px; margin: 0 auto; }
  .page-title { display: block; font-size: 22px; white-space: nowrap; margin: 0; max-width: none; }
  .lbl-long { display: none; }
  .top-actions { display: flex; gap: 8px; margin-left: auto; align-items: center; }
  .top-actions .btn { white-space: nowrap; }
  .fab-wrap, .fab-backdrop { display: none !important; }

  /* Nội dung trải rộng */
  .view { max-width: 1560px; padding: 24px 32px 48px; }
  .section-head h2 { font-size: 18px; }

  /* Tổng quan: lưới 2 cột */
  .dash { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; align-items: start; }
  .dash > * { margin-top: 0 !important; }
  .dash > .wide { grid-column: 1 / -1; }
  .d-side > .section:first-child, .d-side > .notice:first-child { margin-top: 0; }
  .hero { padding: 24px; }
  .hero-value { font-size: 38px; }
  .chart-box, .chart-box.pie { height: 300px; }

  /* Giao dịch: bộ lọc bên trái, danh sách bên phải */
  .tx-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 24px; align-items: start; }
  .tx-side { position: sticky; top: 92px; display: grid; gap: 12px; }
  .tx-side .filters { flex-direction: column; overflow: visible; padding: 0; margin: 0 !important; }
  .tx-side .filters select { max-width: none; width: 100%; border-radius: 12px; padding: 10px 12px; }
  .tx-side .totals-bar { grid-template-columns: 1fr; margin: 0; }
  .tx-col > .day-group:first-child { margin-top: 0; }

  /* Danh sách dạng thẻ nhiều cột (đơn hàng, vật liệu, sản phẩm) */
  .card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 12px; background: transparent; box-shadow: none; overflow: visible; }
  .card-grid > .tx, .card-grid > .order-row { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); border-top: 0 !important; }
  .card-grid > .tx:hover, .card-grid > .order-row:hover { background: var(--surface); box-shadow: 0 0 0 2px var(--accent-soft), var(--shadow); }
  #ord-tab, #inv-tab { max-width: 520px; }
  #ord-new, #mat-new { max-width: 260px; }
  .totals-bar { max-width: 760px; }
  .tx-side .totals-bar { max-width: none; }

  /* Cài đặt */
  .cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; align-items: start; }
  .cat-grid .card + .card { margin-top: 0; }

  /* Form: khung trượt từ bên phải; hộp xác nhận ở giữa */
  .sheet-backdrop { justify-content: flex-end; align-items: stretch; }
  .sheet { max-width: 520px; height: 100dvh; max-height: none; border-radius: 0; animation: slidein .22s cubic-bezier(.2, .8, .2, 1); box-shadow: -10px 0 40px rgba(0, 0, 0, .15); }
  .sheet.full { max-width: 780px; height: 100dvh; max-height: none; }
  .sheet-backdrop.is-small { justify-content: center; align-items: center; }
  .sheet.small { max-width: 440px; height: auto; border-radius: 20px; animation: pop .18s ease-out; }
  .sheet-head { padding: 18px 24px 14px; }
  .sheet-body { padding: 20px 24px; }
  .sheet-foot { padding: 14px 24px; }
}
@keyframes slidein { from { transform: translateX(40px); opacity: .4; } }

/* Màn hình rộng: hiện đủ nhãn nút */
@media (min-width: 1380px) {
  .lbl-long { display: inline; }
}

/* Máy tính màn hình nhỏ: thu gọn thanh trên để không bị tràn */
@media (min-width: 900px) and (max-width: 1099px) {
  .top-actions .lbl { display: none; }
  .top-actions .btn { min-width: 40px; padding: 6px 10px; font-size: 16px; }
}
