/* Giao diện nền bộ ứng dụng doanh nghiệp KimQ (KQ-20261014-010), gốc từ KQ-20261011-011. Mobile-first; màn rộng là bản thích ứng. */
@font-face {
  font-family: 'Be Vietnam Pro';
  font-weight: 400;
  font-display: swap;
  src: url(/nen/fonts/bvp-vi-400.woff2) format('woff2');
  unicode-range:
    U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309,
    U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}
@font-face {
  font-family: 'Be Vietnam Pro';
  font-weight: 500;
  font-display: swap;
  src: url(/nen/fonts/bvp-vi-500.woff2) format('woff2');
  unicode-range:
    U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309,
    U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}
@font-face {
  font-family: 'Be Vietnam Pro';
  font-weight: 600;
  font-display: swap;
  src: url(/nen/fonts/bvp-vi-600.woff2) format('woff2');
  unicode-range:
    U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309,
    U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}
@font-face {
  font-family: 'Be Vietnam Pro';
  font-weight: 700;
  font-display: swap;
  src: url(/nen/fonts/bvp-vi-700.woff2) format('woff2');
  unicode-range:
    U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309,
    U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}
@font-face {
  font-family: 'Be Vietnam Pro';
  font-weight: 400;
  font-display: swap;
  src: url(/nen/fonts/bvp-la-400.woff2) format('woff2');
  unicode-range:
    U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191,
    U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Be Vietnam Pro';
  font-weight: 500;
  font-display: swap;
  src: url(/nen/fonts/bvp-la-500.woff2) format('woff2');
  unicode-range:
    U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191,
    U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Be Vietnam Pro';
  font-weight: 600;
  font-display: swap;
  src: url(/nen/fonts/bvp-la-600.woff2) format('woff2');
  unicode-range:
    U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191,
    U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Be Vietnam Pro';
  font-weight: 700;
  font-display: swap;
  src: url(/nen/fonts/bvp-la-700.woff2) format('woff2');
  unicode-range:
    U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191,
    U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #f9f8f5;
  --sunken: #ebe8e2;
  --line: #e1ddd5;
  --line-strong: #c9c3b8;
  --text: #1f1c18;
  --text-2: #5c564d;
  --text-3: #8a8378;
  --primary: #1d5c63;
  --primary-hover: #164a50;
  --primary-soft: #e3eeee;
  --on-primary: #ffffff;
  --accent: #b4532a;
  --accent-soft: #f6e6dd;
  --success: #2f7a3f;
  --success-soft: #e3f1e5;
  --warning: #9a6200;
  --warning-soft: #fbefd6;
  --danger: #b3261e;
  --danger-soft: #f9e2df;
  --focus: #2563eb;
  --chart-1: #1d5c63;
  --chart-2: #b4532a;
  --chart-3: #7a8b2f;
  --chart-4: #6b5aa6;
  --chart-5: #a37a1b;
  --chart-6: #8a8378;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(31, 28, 24, 0.06), 0 4px 16px rgba(31, 28, 24, 0.06);
  --shadow-lg: 0 12px 40px rgba(31, 28, 24, 0.18);
  --nav-h: 62px;
  --top-h: 54px;
  --gutter: 16px;
  --font: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
}
a {
  color: var(--primary);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}
h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
}
h1 {
  font-size: 20px;
  font-weight: 700;
}
h2 {
  font-size: 16px;
  font-weight: 600;
}
h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-2);
}
p {
  margin: 0;
}
.muted {
  color: var(--text-2);
}
.faint {
  color: var(--text-3);
  font-size: 13px;
}
.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.icon {
  width: 20px;
  height: 20px;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon.sm {
  width: 16px;
  height: 16px;
}

/* ---------- Khung ứng dụng ---------- */
.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.main {
  flex: 1;
  padding: 0 0 calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
}
.page {
  padding: 12px var(--gutter) 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-top: 6px;
}
.page-head .sub {
  color: var(--text-2);
  font-size: 13px;
  margin-top: 2px;
}
.page-head .actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.page-head .actions:empty {
  display: none;
}
@media (max-width: 639px) {
  .page-head {
    flex-direction: column;
    align-items: stretch;
  }
  .page-head .actions {
    justify-content: flex-start;
  }
  .topbar.root {
    display: none;
  }
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--top-h);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 8px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar .title {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .back {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 44px;
  padding: 0 10px 0 4px;
  border: 0;
  background: none;
  color: var(--primary);
  font-weight: 500;
  cursor: pointer;
  border-radius: 8px;
}
.topbar .back:hover {
  background: var(--primary-soft);
}

.bottom-nav {
  position: fixed;
  z-index: 30;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-3);
  font-size: 11.5px;
  font-weight: 500;
  text-decoration: none;
  position: relative;
}
.bottom-nav a .pill {
  display: grid;
  place-items: center;
  width: 52px;
  height: 28px;
  border-radius: 14px;
  transition: background 0.15s;
}
.bottom-nav a[aria-current='page'] {
  color: var(--primary);
  font-weight: 600;
}
.bottom-nav a[aria-current='page'] .pill {
  background: var(--primary-soft);
}
.bottom-nav .dot {
  position: absolute;
  top: 6px;
  left: calc(50% + 10px);
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  line-height: 16px;
  text-align: center;
}

.rail {
  display: none;
}

/* ---------- Bề mặt ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.card.pad {
  padding: 14px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px 0;
}
.card-head > a {
  flex: none;
  white-space: nowrap;
}
.card-body {
  padding: 12px 14px 14px;
}
.section-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 8px;
  margin-top: 4px;
}
/* Một cột co theo màn: không để chữ nowrap (tiêu đề dòng .item .t) kéo rộng cột quá khổ điện thoại. */
.grid {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr);
}
.grid > * {
  min-width: 0;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.wrap {
  flex-wrap: wrap;
}
.spacer {
  flex: 1;
}
.divider {
  height: 1px;
  background: var(--line);
  margin: 4px 0;
}

/* Chỉ số */
.kpis {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.kpi .label {
  color: var(--text-2);
  font-size: 12.5px;
}
.kpi .value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.kpi .value small {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  margin-left: 2px;
}
.kpi .hint {
  font-size: 12px;
  color: var(--text-3);
}
.kpi.alert {
  border-color: color-mix(in srgb, var(--danger) 35%, var(--line));
}
.kpi.alert .value {
  color: var(--danger);
}
.kpi.warn .value {
  color: var(--warning);
}
.kpi.hero {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}
.kpi.hero .value {
  color: var(--on-primary);
}
.kpi.hero .label,
.kpi.hero .hint,
.kpi.hero .value small {
  color: color-mix(in srgb, var(--on-primary) 78%, transparent);
}

/* Nút */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 14.5px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover {
  background: var(--surface-2);
  text-decoration: none;
}
.btn:active {
  transform: translateY(1px);
}
.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}
.btn.primary:hover {
  background: var(--primary-hover);
}
.btn.danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, var(--line));
}
.btn.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--primary);
}
.btn.ghost:hover {
  background: var(--primary-soft);
}
.btn.small {
  min-height: 36px;
  padding: 0 12px;
  font-size: 13.5px;
}
.btn.block {
  width: 100%;
}
.btn[disabled],
.btn[aria-busy='true'] {
  opacity: 0.55;
  cursor: default;
  pointer-events: none;
}
.btn.agent {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--line));
}
.btn.agent:hover {
  background: var(--accent-soft);
}
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--text-2);
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--sunken);
  color: var(--text);
}

/* Bộ lọc gọn 1 dòng */
.filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 calc(-1 * var(--gutter));
  padding: 2px var(--gutter);
}
.filters::-webkit-scrollbar {
  display: none;
}
.pick {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex: none;
  height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 19px;
  background: var(--surface);
  padding: 0 32px 0 14px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
}
.pick select {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  font-size: 16px;
}
.pick .chev {
  position: absolute;
  right: 10px;
  top: 50%;
  translate: 0 -50%;
  pointer-events: none;
  color: var(--text-2);
}
.pick.active {
  background: var(--primary-soft);
  border-color: color-mix(in srgb, var(--primary) 45%, var(--line));
  color: var(--primary);
}
.pick .k {
  color: var(--text-3);
  font-weight: 400;
  margin-right: 4px;
}
.search {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  min-width: 170px;
  border: 1px solid var(--line-strong);
  border-radius: 19px;
  background: var(--surface);
  padding: 0 12px;
  color: var(--text-2);
}
.search input {
  border: 0;
  outline: 0;
  background: none;
  width: 100%;
  font-size: 16px;
  color: var(--text);
}

/* Segmented tabs */
.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--sunken);
  border-radius: 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs a,
.tabs button {
  flex: 1 0 auto;
  text-align: center;
  padding: 8px 12px;
  border-radius: 9px;
  color: var(--text-2);
  font-weight: 500;
  font-size: 13.5px;
  white-space: nowrap;
  text-decoration: none;
  border: 0;
  background: none;
  cursor: pointer;
}
.tabs [aria-current='page'],
.tabs [aria-selected='true'] {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow);
}

/* Danh sách dạng hàng (điện thoại) */
.list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
  min-height: 56px;
}
.item:first-child {
  border-top: 0;
}
a.item:hover {
  background: var(--surface-2);
  text-decoration: none;
}
.item .main-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.item .t {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item .s {
  color: var(--text-2);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item .end {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex: none;
}
.item .chev {
  color: var(--text-3);
}

/* Nhãn trạng thái */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: 11px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--sunken);
  color: var(--text-2);
}
.badge.ok {
  background: var(--success-soft);
  color: var(--success);
}
.badge.warn {
  background: var(--warning-soft);
  color: var(--warning);
}
.badge.bad {
  background: var(--danger-soft);
  color: var(--danger);
}
.badge.info {
  background: var(--primary-soft);
  color: var(--primary);
}
.badge.accent {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Bảng (màn rộng) */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.data th {
  text-align: left;
  font-weight: 600;
  font-size: 12.5px;
  color: var(--text-2);
  background: var(--surface-2);
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  position: sticky;
  top: 0;
}
table.data td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.data tr:last-child td {
  border-bottom: 0;
}
table.data tr.clickable {
  cursor: pointer;
}
table.data tr.clickable:hover td {
  background: var(--surface-2);
}
table.data tr.own td {
  background: var(--primary-soft);
  font-weight: 600;
}
table.data th.num,
table.data td.num {
  text-align: right;
}

/* Bảng chuyển thành thẻ trên điện thoại */
.rtable .cards {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.rtable .table-wrap {
  display: none;
}
.rcard {
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
}
.rcard:first-child {
  border-top: 0;
}
.rcard .t {
  font-weight: 600;
}
.rcard .kv {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 2px 14px;
  font-size: 13px;
  color: var(--text-2);
}
.rcard .kv b {
  color: var(--text);
  font-weight: 600;
}
.rcard.own {
  background: var(--primary-soft);
}

/* Biểu đồ */
.chart {
  width: 100%;
  height: auto;
  display: block;
}
.chart text {
  font: 11px var(--font);
  fill: var(--text-2);
}
.chart .grid-line {
  stroke: var(--line);
  stroke-width: 1;
}
.chart .axis {
  stroke: var(--line-strong);
}
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-size: 12.5px;
  color: var(--text-2);
}
.legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: -1px;
}

/* Form */
.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label {
  font-weight: 600;
  font-size: 13.5px;
}
.field .hint {
  font-size: 12.5px;
  color: var(--text-3);
}
.field .err {
  font-size: 12.5px;
  color: var(--danger);
}
.input,
.select,
textarea.input {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 16px;
}
.input:focus,
.select:focus {
  outline: 2px solid var(--focus);
  outline-offset: -1px;
  border-color: transparent;
}
.input[aria-invalid='true'] {
  border-color: var(--danger);
}
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235c564d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}
.form-grid {
  display: grid;
  gap: 12px;
}
.lines {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.line-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  display: grid;
  gap: 10px;
  background: var(--surface-2);
}
.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
}
.check input {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
}

/* Thông báo */
.note {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--primary-soft);
  color: var(--text);
  font-size: 13.5px;
}
.note.warn {
  background: var(--warning-soft);
}
.note.bad {
  background: var(--danger-soft);
}
.note.ok {
  background: var(--success-soft);
}
.note .icon {
  margin-top: 1px;
}
.note.warn .icon {
  color: var(--warning);
}
.note.bad .icon {
  color: var(--danger);
}
.note.ok .icon {
  color: var(--success);
}

/* Lớp phủ: sheet xem trước & xác nhận */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(20, 18, 15, 0.42);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade 0.15s ease-out;
}
.sheet {
  width: 100%;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow-lg);
  animation: rise 0.18s ease-out;
}
.sheet-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px 8px;
}
.sheet-head h2 {
  flex: 1;
  font-size: 17px;
}
.sheet-body {
  padding: 4px 16px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sheet-foot {
  display: flex;
  gap: 8px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.sheet-foot .btn {
  flex: 1;
}
.grabber {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--line-strong);
  margin: 8px auto 0;
}
@keyframes rise {
  from {
    transform: translateY(24px);
    opacity: 0.6;
  }
  to {
    transform: none;
    opacity: 1;
  }
}
@keyframes fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@media (prefers-reduced-motion: reduce) {
  .scrim,
  .sheet {
    animation: none;
  }
}

.change-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.change-table td {
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.change-table td + td {
  padding-left: 10px;
  text-align: right;
  white-space: nowrap;
}
.change-table .arrow {
  color: var(--text-3);
}

.toasts {
  position: fixed;
  z-index: 80;
  left: 50%;
  translate: -50% 0;
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(440px, calc(100% - 32px));
}
.toast {
  background: var(--text);
  color: #fff;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.toast.bad {
  background: var(--danger);
}

/* Trạng thái */
.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.empty .icon {
  width: 32px;
  height: 32px;
  color: var(--text-3);
}
.skeleton {
  background: linear-gradient(90deg, var(--sunken), var(--surface-2), var(--sunken));
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
  border-radius: 8px;
  min-height: 56px;
}
@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

/* Đăng nhập & bắt đầu */
.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px var(--gutter);
}
.auth .box {
  width: min(400px, 100%);
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.brandmark {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
}
.brandmark .logo {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
}
.steps {
  counter-reset: s;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.step {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.step::before {
  counter-increment: s;
  content: counter(s);
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  display: grid;
  place-items: center;
  font-size: 13px;
}

/* Thanh tiến độ */
.meter {
  height: 8px;
  border-radius: 4px;
  background: var(--sunken);
  overflow: hidden;
}
.meter > i {
  display: block;
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
}
.meter.warn > i {
  background: var(--warning);
}
.meter.bad > i {
  background: var(--danger);
}

/* Khung trợ lý (màn rộng) */
.assist {
  display: none;
}

/* ---------- Màn vừa ---------- */
@media (min-width: 640px) {
  .kpis {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .form-grid.two {
    grid-template-columns: 1fr 1fr;
  }
  .form-grid.three {
    grid-template-columns: 1fr 1fr auto;
    align-items: end;
  }
  .scrim {
    align-items: center;
    padding: 24px;
  }
  .sheet {
    max-width: 560px;
    border-radius: 16px;
    max-height: 86dvh;
  }
  .grabber {
    display: none;
  }
  .rtable .cards {
    display: none;
  }
  .rtable .table-wrap {
    display: block;
  }
  .rtable.list {
    border: 0;
    background: none;
  }
}

/* ---------- Màn rộng: thanh bên trái, không thanh dưới ---------- */
@media (min-width: 1024px) {
  :root {
    --gutter: 28px;
  }
  body {
    font-size: 14.5px;
  }
  .app {
    display: grid;
    grid-template-columns: 236px minmax(0, 1fr);
  }
  .app.with-assist {
    grid-template-columns: 236px minmax(0, 1fr) 400px;
  }
  .bottom-nav {
    display: none;
  }
  .main {
    padding-bottom: 32px;
    grid-column: 2;
    min-width: 0;
  }
  .rail {
    display: flex;
    flex-direction: column;
    gap: 2px;
    position: sticky;
    top: 0;
    height: 100dvh;
    overflow-y: auto;
    padding: 16px 12px;
    background: var(--surface);
    border-right: 1px solid var(--line);
    grid-column: 1;
    grid-row: 1 / span 3;
  }
  .rail .brandmark {
    padding: 4px 8px 16px;
  }
  .rail .group {
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-3);
    padding: 14px 10px 6px;
  }
  .rail a {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 40px;
    padding: 0 10px;
    border-radius: 8px;
    color: var(--text-2);
    font-weight: 500;
    text-decoration: none;
  }
  .rail a:hover {
    background: var(--surface-2);
    color: var(--text);
  }
  .rail a[aria-current='page'] {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 600;
  }
  .rail a .count {
    margin-left: auto;
    font-size: 12px;
    background: var(--accent);
    color: #fff;
    border-radius: 9px;
    padding: 0 6px;
    line-height: 18px;
  }
  .rail .me {
    margin-top: auto;
    padding: 12px 10px 0;
    border-top: 1px solid var(--line);
    font-size: 13px;
    color: var(--text-2);
  }
  .topbar {
    padding: 0 20px;
  }
  .topbar.root {
    display: none;
  }
  .topbar.from-more {
    display: none;
  }
  .page {
    padding-top: 20px;
    gap: 16px;
  }
  h1 {
    font-size: 24px;
  }
  .kpi .value {
    font-size: 26px;
  }
  .grid.cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .grid.cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .grid.main-side {
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
    align-items: start;
  }
  .filters {
    margin: 0;
    padding: 2px 0;
    flex-wrap: wrap;
    overflow: visible;
  }
  .toasts {
    bottom: 24px;
  }
  .assist {
    display: flex;
    flex-direction: column;
    grid-column: 3;
    grid-row: 1 / span 3;
    position: sticky;
    top: 0;
    height: 100dvh;
    border-left: 1px solid var(--line);
    background: var(--surface);
  }
  .assist-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    font-weight: 600;
  }
  .assist iframe {
    flex: 1;
    border: 0;
    width: 100%;
  }
}

/* ---------- Trợ lý (KQ-20261014-010) ---------- */
.chat {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: calc(100dvh - var(--nav-h) - env(safe-area-inset-bottom) - 48px);
}
.main:has(.chat-page) {
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
.page.chat-page {
  padding-bottom: 0;
}
.chat-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.chat-tools .spacer,
.assist-head .spacer {
  flex: 1;
}
.chat-log {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-empty {
  padding: 8px 2px;
}
.chat-suggest {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: inherit;
  font: inherit;
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
}
.chat-msg {
  display: flex;
}
.chat-msg.me {
  justify-content: flex-end;
}
.chat-msg .bubble {
  max-width: min(100%, 680px);
  padding: 10px 12px;
  border-radius: 14px;
  overflow-wrap: anywhere;
}
.chat-msg.me .bubble {
  background: var(--primary);
  color: var(--on-primary);
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}
.chat-msg.bot .bubble {
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-attached {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  font-size: 12.5px;
  opacity: 0.9;
}
.chat-text p {
  margin: 0 0 6px;
}
.chat-text p:last-child {
  margin-bottom: 0;
}
.chat-text ul {
  margin: 0 0 6px;
  padding-left: 20px;
}
.chat-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.chat-card .rtable {
  margin: 0;
}
.chat-card-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-3);
}
.chat-pending {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  background: var(--accent-soft);
}
.chat-kpis {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.bubble.typing {
  flex-direction: row;
  width: auto;
  gap: 4px;
}
.bubble.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-3);
  animation: chat-blink 1.2s infinite;
}
.bubble.typing span:nth-child(2) {
  animation-delay: 0.2s;
}
.bubble.typing span:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes chat-blink {
  0%,
  80%,
  100% {
    opacity: 0.25;
  }
  40% {
    opacity: 1;
  }
}
@media (prefers-reduced-motion: reduce) {
  .bubble.typing span {
    animation: none;
  }
}
.chat-composer {
  position: sticky;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px);
  background: var(--bg);
  padding-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chat-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chat-files:empty {
  display: none;
}
.chat-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.chat-input {
  flex: 1;
  min-height: 44px;
  max-height: 160px;
  resize: none;
  padding: 11px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  font: inherit;
  font-size: 16px;
  line-height: 1.35;
}
.chat-input:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}
.btn.icon-only {
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  justify-content: center;
}
.chat.embedded {
  flex: 1;
  min-height: 0;
  padding: 10px 12px 12px;
}
.chat.embedded .chat-log {
  overflow-y: auto;
  min-height: 0;
}
.chat.embedded .chat-composer {
  position: static;
}
@media (min-width: 1024px) {
  .chat {
    min-height: calc(100dvh - 120px);
  }
  .chat-composer {
    bottom: 12px;
  }
  .chat-input {
    font-size: 14.5px;
  }
}

@media print {
  .rail,
  .bottom-nav,
  .topbar,
  .filters,
  .actions,
  .btn {
    display: none !important;
  }
  body {
    background: #fff;
  }
  .app {
    display: block;
  }
}
.clamp2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

/* So sánh giá: chọn nhóm hàng + thanh khoảng giá theo hãng */
.seg {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--sunken);
  border-radius: 12px;
}
.seg button {
  flex: 1 1 0;
  min-height: 44px;
  border: 0;
  background: none;
  border-radius: 9px;
  color: var(--text-2);
  font: inherit;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  padding: 6px 10px;
}
.seg button[aria-selected='true'] {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow);
}
.seg button:disabled {
  opacity: 0.45;
  cursor: default;
}
.rbars {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.rbar {
  display: grid;
  grid-template-columns: minmax(0, 7.5em) minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 4px 6px;
  border-radius: 8px;
}
.rbar.own {
  background: var(--primary-soft);
  font-weight: 600;
}
.rbar-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rbar-track {
  position: relative;
  height: 14px;
  background: var(--sunken);
  border-radius: 7px;
}
.rbar-range {
  position: absolute;
  top: 4px;
  height: 6px;
  min-width: 2px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--text-3) 70%, transparent);
}
.rbar.own .rbar-range {
  background: var(--primary);
}
.rbar-median {
  position: absolute;
  top: 1px;
  width: 12px;
  height: 12px;
  margin-left: -6px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--text-2);
}
.rbar.own .rbar-median {
  border-color: var(--primary);
  background: var(--primary);
}
.rbar-market {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 0;
  border-left: 2px dashed var(--accent);
}
.rbar-value {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}
.src-list {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13.5px;
}
@media (min-width: 1024px) {
  .rbar {
    grid-template-columns: 14em minmax(0, 1fr) 7.5em;
    font-size: 13.5px;
  }
}

/* Xu hướng mẫu: ảnh thật + bằng chứng hiện ngay trên thẻ */
.trend-grid {
  align-items: start;
}
.trend-pics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.trend-pics figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.trend-pics img {
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 8px;
  background: var(--sunken);
  border: 1px solid var(--line);
}
.trend-pics figcaption {
  font-size: 12px;
  color: var(--text-2);
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.trend-pics figcaption a {
  font-size: 12px;
}
.trend-h {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin: 4px 0 0;
  text-transform: none;
}
.trend-ev {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13.5px;
  overflow-wrap: anywhere;
}

/* Bảng thay đổi trong xem trước/thẻ chờ duyệt: giá trị dài xuống dòng, không tràn ngang ở 390px (v0.1.2). */
.change-table {
  width: 100%;
  table-layout: fixed;
}
.change-table td {
  white-space: normal;
  overflow-wrap: anywhere;
  vertical-align: top;
}
.change-table td:first-child {
  width: 38%;
}
.change-table td + td {
  white-space: normal;
}
/* Bảng markdown trong câu trả lời trợ lý: cuộn ngang trong khung, không đẩy cả trang (v0.1.5). */
.chat-md-table {
  overflow-x: auto;
  max-width: 100%;
  margin: 4px 0 8px;
}
.chat-md-table table {
  border-collapse: collapse;
  font-size: 13px;
  min-width: 100%;
}
.chat-md-table th,
.chat-md-table td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.chat-md-table th {
  color: var(--text-2);
  font-weight: 600;
  white-space: nowrap;
}
.chat-msg .bubble {
  min-width: 0;
}
.chat-log,
.chat {
  min-width: 0;
  max-width: 100%;
}

/* Bản demo công khai: thanh chọn vai + đặt lại dữ liệu (KQ-20261014-010). */
.demo-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 6px var(--gutter);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.demo-bar .spacer {
  flex: 1;
}
.demo-bar .demo-tag {
  flex: none;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 2px 8px;
}
.demo-bar .pick {
  min-width: 0;
  max-width: 100%;
  height: 40px;
}
.demo-bar .btn.small {
  flex: none;
  min-height: 40px;
}
@media (max-width: 359px) {
  .demo-bar .demo-reset-label {
    display: none;
  }
}

/* Dấu hiệu duy nhất cho tổ chức đang dùng dữ liệu mẫu (thanh bên, phần người dùng). */
.nhan-mau {
  display: inline-block;
  margin: 4px 0;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-2);
  background: var(--sunken);
}

/* Liên kết bỏ qua điều hướng (bàn phím): ẩn tới khi được focus */
.bo-qua {
  position: absolute;
  left: 8px;
  top: -60px;
  z-index: 100;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.bo-qua:focus {
  top: 8px;
}
main.main:focus {
  outline: none;
}

/* ---------- v0.2: vỏ không cuộn ngang ở 320 px ---------- */
.main,
.page,
.page > *,
.topbar .title {
  min-width: 0;
}
.page {
  overflow-wrap: break-word;
}
.bottom-nav {
  grid-auto-columns: minmax(0, 1fr);
}
.bottom-nav a {
  min-width: 0;
  padding: 0 2px;
  text-align: center;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.bottom-nav a .pill {
  width: min(52px, 100%);
}
.demo-bar {
  min-width: 0;
}
.demo-bar .pick {
  flex: 0 1 auto;
  overflow: hidden;
  white-space: nowrap;
}
@media (max-width: 399px) {
  .demo-bar {
    gap: 6px;
  }
  .demo-bar .pick .k {
    display: none;
  }
  .demo-bar .pick {
    padding-left: 12px;
  }
}

/* ---------- v0.2: đăng nhập nhanh bằng mã QR quán + PIN ---------- */
.auth .hien-mk {
  min-height: 44px;
}
.auth .lien-ket-phu {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  justify-content: center;
}
.auth .lien-ket-phu a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 4px;
}
.vao-quan .ten-quan {
  font-size: 22px;
  line-height: 1.25;
}
.chon-ten {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chon-ten .btn {
  min-height: 44px;
  min-width: 44px;
  max-width: 100%;
  border-radius: 22px;
  white-space: normal;
  text-align: left;
}
.chon-ten .btn[aria-pressed='true'] {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary, #fff);
}
.pin-cham {
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 6px 0;
}
.pin-cham span {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
}
.pin-cham span.da {
  background: var(--primary);
  border-color: var(--primary);
}
.ban-phim {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.ban-phim button {
  min-height: 56px;
  min-width: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  touch-action: manipulation;
}
.ban-phim button:active {
  background: var(--primary-soft);
}
.ban-phim button.phu {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-2);
}
.ban-phim button.vao {
  font-size: 16px;
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary, #fff);
}
.ban-phim button:disabled {
  opacity: 0.5;
  cursor: default;
}
.loi-pin {
  min-height: 20px;
  color: var(--danger);
  font-size: 14px;
  text-align: center;
}
.qr-khung {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}
.qr-khung .qr-hinh {
  width: min(280px, 100%);
  aspect-ratio: 1;
  background: #fff;
  border-radius: 12px;
  padding: 8px;
  box-shadow: inset 0 0 0 1px var(--line);
}
.qr-khung .qr-hinh svg {
  display: block;
  width: 100%;
  height: 100%;
}
.qr-khung .qr-link {
  font-size: 12.5px;
  color: var(--text-2);
  word-break: break-all;
}
.qr-khung .nut-hang {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.qr-khung .nut-hang .btn,
.pin-nguoi .btn {
  min-height: 44px;
}
.buoc-dung {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--text-2);
}
.pin-nguoi .item {
  flex-wrap: wrap;
}
.pin-nguoi .item .end {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 6px;
}
@media print {
  .rail,
  .bottom-nav,
  .topbar,
  .demo-bar,
  .bo-qua,
  .khong-in {
    display: none !important;
  }
  .qr-khung .qr-hinh {
    width: 70vmin;
    box-shadow: none;
  }
}
