/* BMS Accounting theme — one file for tokens, layout and every shared control.
   Visual source: BMSInventory (QuanlyVoBinh.Web wwwroot/app.css, app-ui.css, Layout/*.razor.css; App* controls
   ported from frontend/shared/components) and beos.vn (BEOSWorkspace/public/theme.css).
   Change a token or a control rule here and every screen follows. */

:root {
  /* Brand: TIHA red + orange (BMSInventory). Inside BEOS the host palette is used (see .beos-hosted). */
  --link: #0b57d0;
  --link-hover: #083f9a;
  --brand: #d71920;
  --brand-dark: #b5121b;
  --accent: #ef8b22;
  --accent-light: rgba(243, 154, 36, .1);
  --accent-glow: 0 0 0 .18rem rgba(243, 154, 36, .18);
  --ink: #27313d;
  --muted: #6b7580;
  --head-fg: #6b7280;
  --border: #e1e5ea;
  --border-strong: #d1d5db;
  --control-border: #b8bfc8;
  --row-line: rgba(0, 0, 0, .08);
  --canvas: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --surface-muted: #f1f5f9;
  --sidebar-bg: #202932;
  --sidebar-fg: #c6ced6;
  --sidebar-fg-muted: #aeb8c2;
  --hover-row: #fff7f1;
  --total-bg: #fff8f0;
  --total-line: #f0c28f;
  --ok: #16834a;
  --warn: #9a4408;
  --error: #ef4444;
  --radius: 6px;
  --radius-lg: 10px;
  --control-h: 30px;
  --fs: .82rem;
  --fs-head: .72rem;
  --fast: .15s ease;
  font-family: "Segoe UI", Inter, Arial, sans-serif;
  font-size: 14px;
  color-scheme: light;
}
/* BEOS host palette (theme.css): brand maroon + orange, near-black sidebar. Applied only after adoption. */
.beos-hosted {
  --brand: #7a1734;
  --brand-dark: #61122a;
  --accent: #f47a22;
  --accent-light: rgba(244, 122, 34, .1);
  --accent-glow: 0 0 0 .18rem rgba(244, 122, 34, .18);
  --hover-row: #faf2f5;
  --canvas: #f5f6f8;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--canvas); color: var(--ink); line-height: 1.4; }
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ── Layout: dark sidebar + white top row (BMSInventory MainLayout/NavMenu) ── */
.layout { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--sidebar-bg); box-shadow: 3px 0 18px rgba(25, 35, 45, .10); display: flex; flex-direction: column; }
.nav-brand { min-height: 84px; padding: 1rem 1rem .8rem; display: flex; flex-direction: column; justify-content: center; border-bottom: 1px solid rgba(255, 255, 255, .09); color: #fff; text-decoration: none; }
.nav-brand:hover { text-decoration: none; }
.nav-brand-mark { display: flex; align-items: center; gap: .6rem; font-size: 1.05rem; font-weight: 700; letter-spacing: .02em; }
.nav-logo { width: 34px; height: 36px; display: grid; place-items: center; border-radius: 7px; background: var(--brand); border-bottom: 3px solid var(--accent); font-size: .78rem; font-weight: 800; }
.nav-brand small { margin-top: .4rem; color: var(--sidebar-fg-muted); font-size: .66rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
.nav-section { padding: .7rem .65rem 1.2rem; }
.nav-label { margin: .2rem .7rem .5rem; color: #75818d; font-size: .65rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.sidebar ul { list-style: none; margin: 0; padding: 0; display: grid; gap: .18rem; }
.nav-item { display: flex; align-items: center; gap: .62rem; min-height: 39px; padding: .55rem .72rem; border-radius: 7px; color: var(--sidebar-fg); font-size: .86rem; line-height: 1.2; text-decoration: none; transition: background var(--fast), color var(--fast); }
.nav-item:hover { color: #fff; background: rgba(255, 255, 255, .09); text-decoration: none; }
.nav-item.active { color: #fff; background: var(--brand); box-shadow: 0 3px 8px rgba(215, 25, 32, .22); font-weight: 650; }
.nav-item.disabled { color: #6b7684; cursor: not-allowed; }
.nav-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .55; flex: 0 0 7px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; height: 34px; display: flex; align-items: center; gap: .9rem; padding: 0 1.25rem; background: rgba(255, 255, 255, .98); border-bottom: 1px solid #e5e8ed; box-shadow: 0 2px 10px rgba(31, 41, 55, .05); }
.topbar .company { color: var(--ink); font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.topbar .btn { height: 26px; padding: 0 .6rem; font-size: .8rem; }
.topbar .company { font-size: .9rem; }
.topbar .user { color: #66717d; font-size: .82rem; padding-left: .9rem; border-left: 1px solid #e6e9ed; white-space: nowrap; }
.content { width: 100%; max-width: 1700px; margin: 0 auto; padding: 1.1rem 1.25rem 2rem; min-width: 0; }

/* Hosted in BEOS: chrome hidden only after adoption (setHosted(true)). */
.beos-hosted [data-native-sidebar], .beos-hosted [data-native-topbar], .beos-hosted [data-native-logout] { display: none !important; }
.beos-hosted .layout { grid-template-columns: minmax(0, 1fr); }
.beos-hosted .content { padding: .8rem; }
.print-mode [data-native-sidebar], .print-mode [data-native-topbar] { display: none !important; }
.print-mode .layout { grid-template-columns: minmax(0, 1fr); }

/* ── Page header (AppPageHeader) ── */
.app-page-header { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin: 0 0 .4rem; flex-wrap: wrap; }
.app-page-header-title { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.app-page-header h1 { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.app-page-header-bare { margin: 0; height: 0; overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.app-page-subtitle { font-size: .78rem; color: var(--muted); }
.app-page-back { width: 28px; height: 28px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--ink); font-size: 1.1rem; line-height: 1; }
.app-page-back:hover { border-color: var(--accent); color: var(--brand); text-decoration: none; }
.app-page-header-actions { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; height: var(--control-h); padding: 0 .8rem; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); color: var(--ink); font-size: .84rem; font-weight: 600; white-space: nowrap; cursor: pointer; text-decoration: none; transition: border-color var(--fast), color var(--fast), background var(--fast); }
.btn:hover { border-color: var(--accent); color: var(--brand); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn-outline { color: var(--brand); border-color: #e5a0a3; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 24px; padding: 0 .55rem; font-size: .76rem; border-radius: 5px; }

/* ── Cards / KPIs / badges / states ── */
.app-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: 0 2px 8px rgba(31, 41, 55, .045); margin-bottom: .8rem; }
.app-card-header { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .55rem .85rem; border-bottom: 1px solid var(--border); }
.app-card-header h2 { margin: 0; font-size: .92rem; font-weight: 650; color: var(--ink); }
.app-card-body { padding: .75rem .85rem; }
.app-card-flush .app-card-body { padding: 0; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .5rem; margin-bottom: .55rem; }
.kpi-card { display: grid; gap: .1rem; padding: .45rem .75rem; background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--brand); border-radius: var(--radius-lg); }
.kpi-card.kpi-orange { border-top-color: var(--accent); }
.kpi-label { color: var(--muted); font-size: .78rem; font-weight: 650; }
.kpi-value { font-size: 1.2rem; font-weight: 750; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi-hint { color: var(--muted); font-size: .74rem; }
.badge { display: inline-block; padding: 2px 8px; border: 1px solid var(--border); border-radius: 999px; font-size: .72rem; font-weight: 600; color: var(--muted); white-space: nowrap; background: var(--surface); }
.badge-demo { color: var(--warn); background: #fff2e8; border-color: #f7d7bc; letter-spacing: .04em; }
.badge-ok { color: var(--ok); border-color: #b7dfc8; background: #eaf5ee; }
.status { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin: .4rem 0; padding: .5rem .7rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); font-size: .84rem; }
.status-error { border-color: #fca5a5; background: #fff1f2; color: #b91c1c; }
.status-loading, .status-empty { color: var(--muted); }
.status-info { border-color: #b7dfc8; background: #eaf5ee; color: var(--ok); }
.note, .meta, .muted { color: var(--muted); font-size: .76rem; }
.meta { margin: .2rem 0 .45rem; }
.warn { color: #b91c1c; font-size: .8rem; margin: .3rem 0; }
.row { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ── AppInput / AppNumber / AppDate ── */
.app-input, .app-combobox { position: relative; min-width: 0; }
.app-input-label, .combobox-label { display: block; font-size: .78rem; font-weight: 500; color: var(--head-fg); margin-bottom: 2px; }
.app-input-label span, .combobox-required { color: var(--error); margin-left: 2px; }
.app-input-wrapper { position: relative; width: 100%; }
.app-input-control { width: 100%; height: var(--control-h); padding: 0 .55rem; background: #fff; border: 1px solid var(--control-border); box-shadow: inset 0 1px 1px rgba(16, 24, 40, .04); border-radius: var(--radius); color: var(--ink); font-size: .85rem; line-height: 1.25; outline: none; transition: border-color var(--fast), box-shadow var(--fast); }
textarea.app-input-control { height: auto; min-height: 52px; padding: .35rem .55rem; resize: vertical; }
.app-input-control::placeholder { color: #7b8490; }
.app-input-control:focus { border-color: var(--accent); box-shadow: var(--accent-glow); }
.app-input-control:disabled, .app-input-control[readonly] { background: var(--surface-muted); color: var(--muted); }
.app-input-control.is-invalid, .combobox-trigger.is-invalid { border-color: var(--error); }
.app-number-control { text-align: right; font-variant-numeric: tabular-nums; }
.app-input-right { position: absolute; top: 50%; right: 6px; transform: translateY(-50%); display: flex; align-items: center; }
.app-input-control.has-right { padding-right: 28px; }
.app-input-error, .field-error { display: block; color: var(--error); font-size: .75rem; margin-top: 2px; }
.app-date .app-input-control { min-width: 7.6rem; }
.app-date-native { position: absolute; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: 0; padding: 0; }
.app-date-button { background: transparent; border: 0; padding: 2px 3px; border-radius: 4px; cursor: pointer; color: #6b7280; }
.app-date-button:hover { color: var(--brand); background: var(--accent-light); }
.app-date-icon { display: block; width: 14px; height: 14px; border: 2px solid currentColor; border-top-width: 4px; border-radius: 3px; }
.picker { display: flex; gap: 4px; }
.picker .app-input-control { cursor: pointer; }
.picker .app-input-control:not(:placeholder-shown) { font-weight: 650; color: #111827; }
td .app-input-label, td .combobox-label { display: none; }

/* ── AppCombobox ── */
.combobox-trigger { display: flex; align-items: center; width: 100%; height: var(--control-h); padding: 0 1.8rem 0 .55rem; text-align: left; background: var(--surface) url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e") no-repeat right .55rem center / 11px 11px; background-color: #fff; border: 1px solid var(--control-border); border-radius: var(--radius); color: var(--ink); font-size: .85rem; line-height: 1.25; cursor: pointer; transition: border-color var(--fast), box-shadow var(--fast); }
.combobox-trigger:hover:not(:disabled) { border-color: #8f98a3; }
.combobox-trigger:focus, .combobox-trigger.open { border-color: var(--accent); box-shadow: var(--accent-glow); outline: none; }
.combobox-trigger:disabled { background-color: var(--surface-muted); color: var(--muted); cursor: not-allowed; }
.combobox-trigger.is-empty { color: #7b8490; }
.combobox-trigger-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combobox-backdrop { position: fixed; inset: 0; z-index: 1990; background: transparent; }
.combobox-dropdown { position: fixed; z-index: 2000; display: flex; flex-direction: column; max-height: 340px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 12px 24px -4px rgba(0, 0, 0, .12), 0 4px 8px -2px rgba(0, 0, 0, .06); overflow: hidden; }
.combobox-local-search { display: flex; align-items: center; margin: 6px; padding: 0 8px; height: 28px; background: #f9fafb; border: 1px solid var(--border); border-radius: 6px; }
.combobox-local-search:focus-within { border-color: var(--accent); }
.combobox-search-icon { color: #9ca3af; margin-right: 6px; }
.combobox-local-search input { flex: 1; min-width: 0; height: 100%; background: transparent; border: 0; outline: none; color: var(--ink); font-size: .82rem; }
.combobox-items { overflow-y: auto; padding: 2px 4px 4px; }
.combobox-item { display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 5px; font-size: .82rem; color: var(--ink); cursor: pointer; }
.combobox-item.active { background: var(--surface-muted); }
.combobox-item.selected { color: var(--brand); font-weight: 600; background: var(--accent-light); }
.combobox-item-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combobox-check-icon { color: var(--brand); }
.combobox-empty, .combobox-more { padding: 8px; font-size: .78rem; color: var(--muted); text-align: center; }
.combobox-clear-btn { padding: 6px 10px; border-top: 1px solid var(--border); font-size: .78rem; color: var(--error); text-align: center; cursor: pointer; }
.combobox-clear-btn:hover { background: #fff1f2; }

/* ── Filter bar (document-filter-row) ── */
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .5rem .6rem; align-items: end; padding: 0 0 .1rem; margin-bottom: .5rem; background: transparent; border: 0; }
.field-wide { grid-column: span 2; }
.field-action { display: flex; align-items: end; gap: .4rem; }
.field-action .btn { min-width: 4.5rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .5rem .75rem; align-items: start; }
.total { display: flex; align-items: center; justify-content: flex-end; height: var(--control-h); font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--brand-dark); }

/* ── AppTable ── */
.app-table-block { display: flex; flex-direction: column; min-width: 0; }
.app-table-toolbar { display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; margin: .15rem 0 .3rem; position: relative; }
.app-table-count { margin-left: auto; font-size: .75rem; color: var(--muted); white-space: nowrap; }
.app-table-tool-btn { height: 24px; padding: 0 .55rem; font-size: .76rem; border: 1px solid var(--border); border-radius: 5px; background: var(--surface); color: var(--ink); cursor: pointer; white-space: nowrap; }
.app-table-tool-btn:hover { border-color: var(--accent); color: var(--brand); }
.app-table-tool-btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.app-table-config-anchor { position: relative; display: inline-flex; }
.app-table-config-backdrop { position: fixed; inset: 0; z-index: 40; }
.app-table-config { position: absolute; right: 0; top: 100%; z-index: 50; width: min(320px, 92vw); max-height: 65vh; overflow: auto; margin-top: .2rem; padding: .6rem; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 10px 24px rgba(39, 49, 61, .14); font-size: .8rem; }
.app-table-config-title { display: flex; justify-content: space-between; align-items: center; padding-bottom: .4rem; margin-bottom: .4rem; border-bottom: 1px solid var(--border); }
.app-table-config-close { border: 0; background: none; font-size: 1.1rem; line-height: 1; cursor: pointer; color: var(--muted); }
.app-table-config-freeze { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .4rem; }
.app-table-config-freeze select { height: 24px; border: 1px solid var(--border); border-radius: 5px; padding: 0 .3rem; }
.app-table-config-list { display: grid; gap: 1px; }
.app-table-config-item { display: flex; align-items: center; gap: .25rem; }
.app-table-config-item label { flex: 1; display: flex; align-items: center; gap: .4rem; cursor: pointer; }
.app-table-config-item button { width: 22px; height: 22px; border: 1px solid var(--border); background: var(--surface); border-radius: 4px; font-size: .75rem; cursor: pointer; }
.app-table-config-item button:disabled { opacity: .35; cursor: default; }
.app-table-config-actions { display: flex; justify-content: flex-end; gap: .4rem; margin-top: .5rem; padding-top: .45rem; border-top: 1px solid var(--border); }
.app-table-wrap { overflow: auto; max-width: 100%; max-height: min(68vh, calc(100vh - 230px)); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; overscroll-behavior: contain; scrollbar-width: thin; }
.app-table-wrap.app-table-notoolbar { max-height: 60vh; }
.app-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs); color: var(--ink); }
.app-table thead th { position: sticky; top: 0; z-index: 5; background: var(--surface-soft); }
.app-table thead tr:first-child th { padding: .32rem .45rem; font-weight: 600; font-size: var(--fs-head); color: var(--head-fg); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; border-bottom: 1px solid var(--border); text-align: left; user-select: none; }
.app-table thead tr.app-table-filter-row th { top: 25px; padding: 3px 4px; border-bottom: 1px solid var(--border); }
.app-table th.th-sortable { cursor: pointer; }
.app-table th.th-sortable:hover { color: var(--ink); }
.app-table-th-inner { display: inline-flex; align-items: center; gap: 4px; }
.app-table th.td-num .app-table-th-inner { justify-content: flex-end; width: 100%; }
.app-table-sort { opacity: .35; font-size: .8em; }
.app-table-sort.active { opacity: 1; color: var(--brand); }
.app-table td { padding: .14rem .45rem; height: 28px; line-height: 1.3; border-bottom: 1px solid var(--row-line); vertical-align: middle; background: var(--surface); white-space: nowrap; max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
.app-table td.td-wrap { white-space: normal; }
.app-table tbody tr:hover td, .app-table tbody tr.active td { background: var(--hover-row); }
.app-table tbody tr:focus { outline: none; }
.app-table tbody tr:focus td { box-shadow: inset 0 1px 0 var(--accent), inset 0 -1px 0 var(--accent); }
.app-table tbody tr:last-child td { border-bottom: 0; }
.app-table td.td-num, .app-table th.td-num { text-align: right; font-variant-numeric: tabular-nums; }
.app-table td.td-center, .app-table th.td-center { text-align: center; }
.app-table-clickable { cursor: pointer; }
.app-table tr.row-opening td { font-style: italic; background: var(--surface-soft); }
.app-table tr.row-mismatch td { color: #b91c1c; }
.app-table tr.row-overdue td:nth-child(4) { color: #b91c1c; }
.app-table td .app-input-control, .app-table td .combobox-trigger { height: 26px; }
.app-table td:has(.app-input, .app-combobox) { overflow: visible; }
.app-table-filter-input { width: 100%; min-width: 3rem; height: 22px; background: var(--surface); border: 1px solid var(--border); border-radius: 4px; color: var(--ink); padding: 1px 5px; font-size: .72rem; outline: none; }
.app-table-filter-input:focus { border-color: var(--accent); box-shadow: var(--accent-glow); }
.app-table-tfoot td { position: sticky; bottom: 0; z-index: 4; padding: .22rem .45rem; background: var(--total-bg); font-weight: 700; border-top: 2px solid var(--total-line); white-space: nowrap; }
.app-table-state-row td { background: var(--surface) !important; }
.app-table-state-msg { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 28px 12px; color: var(--muted); white-space: normal; }
.app-table-state-msg.error { color: var(--error); }
.app-table-spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: app-table-spin .7s linear infinite; }
@keyframes app-table-spin { to { transform: rotate(360deg); } }
.app-table .app-table-sticky { position: sticky; left: 0; z-index: 3; }
.app-table thead .app-table-sticky { z-index: 7; }
.app-table-sticky-left-last { box-shadow: inset -1px 0 0 var(--border), 4px 0 6px -4px rgba(0, 0, 0, .18); }
.w-sm { width: 6rem; } .w-md { width: 10rem; } .w-lg { width: 16rem; } .w-xl { width: 24rem; }
.pager { display: flex; gap: .4rem; align-items: center; justify-content: flex-end; margin-top: .4rem; font-size: .8rem; color: var(--muted); }

/* ── Search dialog (AppModal) ── */
.search-dialog { width: min(900px, 96vw); height: min(620px, 90vh); padding: 0; border: 0; border-radius: 10px; box-shadow: 0 16px 40px rgba(0, 0, 0, .18); resize: both; overflow: hidden; background: var(--surface); color: var(--ink); }
.search-dialog::backdrop { background: rgba(15, 23, 42, .4); }
.dialog-frame { display: grid; grid-template-rows: auto auto 1fr auto; height: 100%; }
.dialog-head, .dialog-foot { display: flex; align-items: center; gap: 8px; padding: .5rem .8rem; border-bottom: 1px solid var(--border); }
.dialog-head strong { font-size: .95rem; }
.dialog-head .btn-ghost { margin-left: auto; }
.dialog-foot { border-top: 1px solid var(--border); border-bottom: 0; font-size: .8rem; }
.dialog-search { padding: .5rem .8rem; }
.dialog-results { overflow: auto; padding: 0 .8rem; }
.dialog-results .app-table-wrap { max-height: none; }
.hint { margin-left: auto; color: var(--muted); font-size: .74rem; }

/* ── Detail facts / sticky form actions ── */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; margin: 0; font-size: .86rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.status-pill { display: inline-block; margin-bottom: .5rem; font-size: .72rem; font-weight: 600; color: var(--ok); border: 1px solid #b7dfc8; background: #eaf5ee; border-radius: 999px; padding: 1px 8px; }
.sticky-actions { position: sticky; bottom: 0; z-index: 6; display: flex; gap: .4rem; justify-content: flex-end; align-items: center; padding: .5rem .7rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: 0 -4px 12px rgba(31, 41, 55, .06); }
.save-state { margin-right: auto; color: var(--muted); font-size: .82rem; }
.save-state.dirty { color: var(--warn); }
.save-state.saving { color: var(--brand); }
.crumbs { display: none; }

/* ── Login (BMSInventory login-shell) ── */
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(145deg, #f5f6f8 0%, #fff 58%, #fff6ed 100%); }
.login-card { width: min(100%, 440px); display: grid; gap: .7rem; padding: 22px 32px 22px; border-radius: 18px; background: rgba(255, 255, 255, .96); box-shadow: 0 10px 30px rgba(39, 49, 61, .12); }
.login-card h1 { margin: 0 0 .2rem; text-align: center; color: var(--brand); font-size: 1.6rem; font-weight: 800; }
.login-card .app-input-control, .login-card .combobox-trigger { height: 42px; font-size: .95rem; }
.login-submit { height: 46px; margin-top: .4rem; border: 0; border-radius: 9px; color: #fff; background: linear-gradient(110deg, var(--brand), #ee3549); font-size: 1rem; font-weight: 800; letter-spacing: .03em; box-shadow: 0 6px 15px rgba(215, 25, 32, .2); cursor: pointer; }
.login-submit:disabled { opacity: .6; }
.form-error { color: #9b1118; min-height: 1em; margin: 0; font-size: .85rem; }

/* ── Session entry inside BEOS ── */
body.session-entry { display: grid; place-items: center; text-align: center; padding: 16px; }
body.session-entry h1 { font-size: 1.1rem; }

/* ── Print-page toolbar (documents themselves are in print.css) ── */
.print-toolbar { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; margin-bottom: .8rem; position: sticky; top: 0; z-index: 2; background: var(--canvas); padding: .4rem 0; }
.print-toolbar .app-combobox { width: 9rem; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav-brand { min-height: 0; padding: .6rem .8rem; }
  .nav-brand small, .nav-label { display: none; }
  .nav-section { padding: .3rem .4rem; }
  .sidebar ul { display: flex; overflow-x: auto; }
  .nav-item { min-height: 32px; padding: .35rem .6rem; white-space: nowrap; }
  .topbar { height: auto; min-height: 48px; flex-wrap: wrap; padding: .3rem .8rem; }
  .topbar .company, .topbar .user { display: none; }
  .content { padding: .7rem; }
  .field-wide { grid-column: auto; }
}
@media print {
  .sidebar, .topbar, .filters, .app-page-header-actions, .pager, .sticky-actions, .app-table-toolbar, .app-table-filter-row { display: none !important; }
  .layout { display: block; }
  .app-table-wrap { max-height: none; overflow: visible; border: 0; }
  body { background: #fff; }
}

/* Danh mục (views/catalogs.mjs) */
.catalog-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .8rem; }
.catalog-groups .app-card { margin-bottom: 0; }
.catalog-links { list-style: none; margin: 0; padding: 0; display: grid; gap: .3rem; font-size: .86rem; }
.catalog-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .9rem; margin-bottom: .5rem; }
.catalog-toolbar .catalog-search { flex: 0 1 380px; min-width: 220px; margin: 0; }
.catalog-toolbar .meta { margin: 0; }
.catalog-evidence { margin-top: .8rem; font-size: .8rem; color: var(--muted); }
.catalog-evidence summary { cursor: pointer; }
.catalog-evidence .facts { margin: .4rem 0; }

/* ---- Tổng hợp reports (views/tonghop.mjs) ---- */
.app-table tr.row-parent td { font-weight: 600; background: #f3f4f6; }
.app-check { display: inline-flex; align-items: center; gap: 6px; height: var(--control-h, 30px); align-self: flex-end; white-space: nowrap; }
.status-line { margin: 4px 0 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.badge-warn { background: #fdecea; color: #b5121b; border-color: #f5c2c0; }
.th-kpi-link { color: inherit; text-decoration: none; display: block; }
.th-kpi-link:hover .kpi-card, .th-kpi-link:focus-visible .kpi-card { border-color: var(--accent, #ef8b22); }

/* Giá vốn – Lãi lỗ (views/inventory/gia-von.mjs): tabs, options, simple bar chart. */
.gv-tabs { display: flex; flex-wrap: wrap; gap: .25rem; margin: .4rem 0 .6rem; border-bottom: 1px solid var(--border); }
.gv-tab { height: var(--control-h); padding: 0 .85rem; border: 1px solid transparent; border-bottom: 0; border-radius: var(--radius) var(--radius) 0 0; background: none; color: var(--muted); font-size: .84rem; font-weight: 600; cursor: pointer; margin-bottom: -1px; }
.gv-tab:hover:not(:disabled) { color: var(--brand); }
.gv-tab[aria-selected="true"] { color: var(--brand); background: var(--surface); border-color: var(--border); border-bottom: 2px solid var(--surface); box-shadow: inset 0 3px 0 var(--accent); }
.gv-tab:disabled { opacity: .45; cursor: not-allowed; }
.gv-option { display: inline-flex; align-items: center; gap: .35rem; margin: 0 0 .5rem; font-size: .82rem; color: var(--muted); }
.gv-h2 { font-size: .9rem; margin: .45rem 0 .2rem; }
.gv-legend { display: flex; align-items: center; gap: .35rem; font-size: .78rem; color: var(--muted); }
.gv-key { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.gv-bars { display: grid; gap: .45rem; }
.gv-bar-row { display: grid; grid-template-columns: minmax(90px, 220px) 1fr; gap: .6rem; align-items: center; }
.gv-bar-label { font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gv-bar-group { display: grid; gap: 2px; }
.gv-bar-line { display: flex; align-items: center; gap: .4rem; min-width: 0; }
.gv-bar { display: block; height: 9px; border-radius: 0 3px 3px 0; flex: none; max-width: 80%; }
.gv-bar-value { font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.gv-rev { background: var(--brand); }
.gv-cost { background: #94a3b8; }
.gv-margin { background: var(--accent); }
.gv-bar.gv-neg { background: var(--error); }
@media (max-width: 640px) { .gv-bar-row { grid-template-columns: 1fr; gap: .15rem; } }
.gv-calc-box { border: 1px solid var(--border, #d0d7de); border-radius: 6px; padding: .6rem .8rem; margin: 0 0 .8rem; background: var(--surface, #fff); }
.gv-calc-box p { margin: 0 0 .4rem; }
.gv-calc-actions { display: flex; gap: .4rem; margin-top: .4rem; }
.gv-calc-bar { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin: -.3rem 0 .8rem; }
.app-table-more { display: flex; align-items: center; justify-content: center; gap: .4rem; padding: .5rem; font-size: .8rem; color: var(--muted); position: sticky; left: 0; }
.app-table-busy table { opacity: .6; transition: opacity .15s; }

/* Gọn: chú thích vào tooltip, nút Tính cạnh nút Xem */
.gv-actions { display: flex; gap: .4rem; align-items: end; flex-wrap: nowrap; grid-column: span 2; }
.gv-info { font-size: .78rem; color: var(--muted); padding: .15rem .55rem; border: 1px solid var(--border); border-radius: 999px; cursor: help; white-space: nowrap; }
.gv-hint { cursor: help; color: var(--muted); font-size: .9rem; padding: 0 .2rem; }
.app-table-toolbar .gv-option { margin: 0 .4rem 0 0; }
.app-hint { cursor: help; color: var(--muted); font-size: .9rem; padding: 0 .25rem; }
.meta-short { cursor: help; margin: 0 0 .25rem; }
/* Thanh tab các trang đang mở (giữ trạng thái khi chuyển qua lại) */
.tabbar { position: sticky; top: 34px; z-index: 19; display: flex; gap: 2px; padding: 3px .8rem 0; background: #eef1f5; border-bottom: 1px solid #dde2e8; overflow-x: auto; scrollbar-width: thin; }
.beos-hosted .tabbar { top: 0; }
.tabbar .tab { display: flex; align-items: center; max-width: 220px; min-width: 0; border: 1px solid #dde2e8; border-bottom: 0; border-radius: 6px 6px 0 0; background: #f7f8fa; font-size: .8rem; }
.tabbar .tab.active { background: var(--surface); border-color: #cfd5dd; box-shadow: inset 0 2px 0 var(--brand); }
.tabbar .tab-link { padding: .28rem .2rem .28rem .6rem; color: var(--muted); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabbar .tab.active .tab-link { color: var(--ink); font-weight: 600; }
.tabbar .tab-close { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 0 .4rem; font-size: 1rem; line-height: 1; }
.tabbar .tab-close:hover { color: var(--brand); }
.print-mode .tabbar { display: none; }
@media print { .tabbar { display: none !important; } }

/* Mã khách hàng / NCC → Lịch sử mua bán; mã hàng → Thẻ kho (ui/links.mjs) */
.code-link { color: var(--link); text-decoration: none; border-bottom: 1px dotted currentColor; }
.code-link:hover, .code-link:focus-visible { color: var(--link-hover); }
@media print { .code-link { color: inherit; border: 0; } }
/* Lịch sử mua bán: dải tổng hợp gọn một hàng, chi tiết phiếu ngay dưới lưới chính */
.kpis-compact { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .35rem; margin-bottom: .35rem; }
.kpis-compact .kpi-card { padding: .25rem .55rem; border-top-width: 2px; }
.kpis-compact .kpi-label { font-size: .72rem; }
.kpis-compact .kpi-value { font-size: .95rem; }
.lsmb-detail:empty { display: none; }
.lsmb-detail { margin-top: .3rem; }
.lsmb-detail-title { font-size: .82rem; white-space: nowrap; margin-right: .3rem; }
.lsmb-missing { align-self: center; margin-left: .3rem; }
.lsmb-report { min-width: 210px; }
.lsmb-report .app-input-label:empty { display: none; }
.lsmb-tabs { align-items: center; }
.lsmb-tools { margin-left: auto; display: flex; align-items: center; gap: .4rem; padding-bottom: .2rem; }
.lsmb-tools .app-table-toolbar { margin: 0; }
.lsmb-info { align-self: center; cursor: help; }
.filters .lsmb-party { grid-column: span 3; }
.lsmb-view .filters .gv-actions { grid-column: auto; }
@media (max-width: 1500px) { .filters .lsmb-party { grid-column: span 2; } }
@media (max-width: 760px) { .filters .lsmb-party { grid-column: 1 / -1; } }
.lsmb-view .kpis-compact .kpi-card { justify-items: center; text-align: center; }

/* Lịch sử mua bán: ô tổng hợp bấm được, chia 2 cột Nhập–Xuất | Chi–Thu */
.lsmb-kpi { cursor: pointer; transition: border-color var(--fast), box-shadow var(--fast); }
.lsmb-kpi:hover, .lsmb-kpi:focus-visible { border-color: var(--accent); outline: none; }
.lsmb-kpi.is-active { box-shadow: 0 0 0 2px var(--accent-light), inset 0 -2px 0 var(--accent); }
.lsmb-split { display: grid; grid-template-columns: minmax(0, var(--lsmb-left, 60%)) 8px minmax(0, 1fr); align-items: start; }
.lsmb-split[data-max] { grid-template-columns: minmax(0, 1fr); }
.lsmb-split[data-max] .lsmb-splitter, .lsmb-split[data-max="left"] .lsmb-pane-right, .lsmb-split[data-max="right"] .lsmb-pane-left { display: none; }
.lsmb-split.is-dragging { user-select: none; cursor: col-resize; }
.lsmb-pane { min-width: 0; }
.lsmb-pane-head { display: flex; align-items: center; gap: .4rem; min-height: 28px; margin-bottom: .2rem; }
.lsmb-pane-head strong { font-size: .82rem; white-space: nowrap; }
.lsmb-pane-head .app-table-toolbar { flex: 1; margin: 0; }
.lsmb-splitter { align-self: stretch; cursor: col-resize; position: relative; }
.lsmb-splitter::after { content: ''; position: absolute; left: 3px; top: 0; bottom: 0; width: 2px; border-radius: 2px; background: var(--border-strong); }
.lsmb-splitter:hover::after, .lsmb-splitter:focus-visible::after, .lsmb-split.is-dragging .lsmb-splitter::after { background: var(--accent); }

/* ── Viền (02/11/2026, theo yêu cầu người dùng): không vẽ viền một phần (viền trên/dưới/trái, gạch chân chấm).
   Khối, ô nhập, nút: không viền, chỉ bóng mềm kiểu Windows 11 / iOS. Chỉ khi được chọn hoặc focus mới có viền mỏng màu cam.
   Đặt cuối file để đè các quy tắc cũ ở trên. ── */
:root {
  --elev: 0 0 0 1px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .09);
  --elev-hover: 0 0 0 1px rgba(15, 23, 42, .09), 0 2px 6px rgba(15, 23, 42, .12);
  --ring: 0 0 0 1px var(--accent), 0 1px 3px rgba(15, 23, 42, .09);
}
.topbar { border-bottom: 0; }
.topbar .user { border-left: 0; }
.nav-logo { border-bottom: 0; }
.app-card, .app-table-wrap, .status, .combobox-dropdown, .app-table-config { border: 0; box-shadow: var(--elev); }
.app-card-header, .app-table-config-title, .app-table-config-actions, .dialog-head, .dialog-foot, .combobox-clear-btn { border-top: 0; border-bottom: 0; }
.kpi-card, .kpis-compact .kpi-card { border: 0; box-shadow: var(--elev); }
.kpi-card.kpi-orange { background: #fffaf3; }
.lsmb-kpi:hover { box-shadow: var(--elev-hover); }
.lsmb-kpi:focus-visible, .lsmb-kpi.is-active { box-shadow: var(--ring); }
/* Ô nhập, combobox, nút */
.app-input-control, .combobox-trigger { border-color: transparent; box-shadow: var(--elev); }
.combobox-trigger:hover:not(:disabled), .app-input-control:hover:not(:disabled) { border-color: transparent; box-shadow: var(--elev-hover); }
.app-input-control:focus, .combobox-trigger:focus, .combobox-trigger.open { border-color: transparent; box-shadow: var(--ring); }
.app-input-control.is-invalid, .combobox-trigger.is-invalid { border-color: transparent; box-shadow: 0 0 0 1px var(--error); }
.app-input-control:disabled, .app-input-control[readonly], .combobox-trigger:disabled { box-shadow: none; }
.btn:not(.btn-primary), .app-table-tool-btn:not(.primary) { border-color: transparent; box-shadow: var(--elev); }
.btn:not(.btn-primary):hover, .app-table-tool-btn:not(.primary):hover { border-color: transparent; box-shadow: var(--elev-hover); }
.btn:focus-visible, .app-table-tool-btn:focus-visible { outline: none; box-shadow: var(--ring); }
/* Tab trong trang và thanh tab trên cùng: tab chọn = nền trắng + viền mỏng cam, không viền trên/dưới. */
.gv-tabs { border-bottom: 0; }
.gv-tab { border: 0; border-radius: var(--radius); }
.gv-tab[aria-selected="true"] { border: 0; box-shadow: var(--ring); }
.gv-tab:focus-visible { outline: none; box-shadow: var(--ring); }
.tabbar { border-bottom: 0; padding-bottom: 3px; }
.tabbar .tab { border: 0; border-radius: 6px; background: transparent; }
.tabbar .tab.active { background: var(--surface); box-shadow: var(--ring); }
/* Lưới: dòng tổng tách bằng bóng, dòng đang chọn có viền cam mỏng bao quanh. */
.app-table-tfoot td { border-top: 0; }
.app-table tbody tr:focus td { box-shadow: none; }
.app-table tbody tr:focus { outline: 1px solid var(--accent); outline-offset: -1px; }
/* Link: chỉ màu xanh, gạch chân khi rê chuột. */
.code-link { border-bottom: 0; }
.code-link:hover { text-decoration: underline; }

/* ── Bộ lọc một hàng (02/11/2026): ô có độ rộng vừa đủ, ô Tìm giãn ra, nút Xem và nút thao tác nằm cuối cùng hàng. ── */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .4rem .5rem; }
.filters > * { flex: 0 1 175px; min-width: 120px; }
.filters > .field-wide { flex: 1 1 240px; }
.filters > .field-action, .filters > .gv-actions, .filters > .filters-end { flex: 0 0 auto; min-width: 0; }
.filters > .lsmb-party { flex: 2 1 380px; }
.filters-end { margin-left: auto; display: flex; align-items: center; gap: .4rem; min-height: var(--control-h); }
.filters-end .app-page-header-actions { flex-wrap: nowrap; }
.meta-dock { margin: 0 .4rem 0 0; color: var(--muted); font-size: .76rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: help; max-width: 60%; }
.meta-dock .app-hint { padding: 0 .1rem; }
.meta-dock.meta-plain { cursor: auto; color: var(--ink); }
@media (max-width: 760px) { .filters > * { flex: 1 1 100%; } }

/* Ô KPI gọn trên mọi trang; tab có việc cần xử lý tô chữ đỏ. */
.kpis { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .35rem; margin-bottom: .35rem; }
.kpis .kpi-card { padding: .25rem .55rem; justify-items: center; text-align: center; }
.kpis .kpi-label { font-size: .72rem; }
.kpis .kpi-value { font-size: .98rem; }
.gv-tab.gv-tab-warn { color: var(--error); }

/* Giá vốn: nút Tính giá vốn / Định khoản. Nút tắt (thiếu quyền) không nhận chuột để tooltip của khung bọc hiện lý do. */
.gv-write { display: inline-flex; }
.gv-write .btn:disabled { pointer-events: none; }
.gv-calc-ask { margin: .35rem 0; }
.gv-calc-ask p { margin: 0 0 .3rem; }
