/* Hệ giao diện dùng chung. Màu thương hiệu (--brand, --accent) được ghi đè theo Cài đặt > Giao diện (xem BM.applyTheme). */
:root {
  --bg: #f4f6fb; --surface: #ffffff; --surface-2: #f6f8fc; --ink: #131f37; --muted: #5d6a82; --line: #dfe5f0;
  --brand: #1d4f9f; --brand-soft: #e9f0fc; --on-brand: #ffffff;
  --accent: #b9530b; --accent-soft: #fdf1e4; --accent-line: #f1b77f;
  --ok: #12784a; --ok-soft: #e2f6ea; --warn: #8a5a00; --warn-soft: #fff6d4; --warn-line: #f0c64a;
  --bad: #b8312a; --bad-soft: #fdecea; --room: #6a3cc4; --info: #0b6f8a; --info-soft: #e0f3f8;
  --shadow-sm: 0 1px 2px rgba(19, 31, 55, .05), 0 2px 8px rgba(19, 31, 55, .04);
  --shadow: 0 2px 4px rgba(19, 31, 55, .05), 0 12px 32px rgba(19, 31, 55, .10);
  --font: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --display: "Lora", Georgia, "Times New Roman", serif;
  --r: 14px; --r-sm: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1420; --surface: #171f30; --surface-2: #1d273b; --ink: #e9eef7; --muted: #9ba9c0; --line: #2c3951;
    --brand: #82b1ff; --brand-soft: #1c2d4d; --on-brand: #0c1830;
    --accent: #ffa868; --accent-soft: #382515; --accent-line: #875426;
    --ok: #62d394; --ok-soft: #153223; --warn: #f2ce62; --warn-soft: #382f10; --warn-line: #8c7220;
    --bad: #ff8d83; --bad-soft: #3d1b18; --room: #b9a0ff; --info: #70d1eb; --info-soft: #122f39;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35); --shadow: 0 2px 4px rgba(0, 0, 0, .3), 0 14px 34px rgba(0, 0, 0, .35); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1420; --surface: #171f30; --surface-2: #1d273b; --ink: #e9eef7; --muted: #9ba9c0; --line: #2c3951;
  --brand: #82b1ff; --brand-soft: #1c2d4d; --on-brand: #0c1830;
  --accent: #ffa868; --accent-soft: #382515; --accent-line: #875426;
  --ok: #62d394; --ok-soft: #153223; --warn: #f2ce62; --warn-soft: #382f10; --warn-line: #8c7220;
  --bad: #ff8d83; --bad-soft: #3d1b18; --room: #b9a0ff; --info: #70d1eb; --info-soft: #122f39;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35); --shadow: 0 2px 4px rgba(0, 0, 0, .3), 0 14px 34px rgba(0, 0, 0, .35); color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; overflow-x: clip; }
body { margin: 0; overflow-x: clip; max-width: 100%; touch-action: manipulation; background: var(--bg); color: var(--ink); font: 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3 { text-wrap: balance; line-height: 1.22; letter-spacing: -.01em; }
a { color: var(--brand); text-underline-offset: 3px; }
img { max-width: 100%; }
.wrap { max-width: 1160px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.muted { color: var(--muted); } .small { font-size: 13px; } .num { font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; } .row > .grow { flex: 1 1 0; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; } .stack.tight { gap: 6px; }
.between { justify-content: space-between; } .right { margin-left: auto; }

.btn { font: 600 14px/1 var(--font); padding: 11px 16px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; min-height: 42px; box-shadow: var(--shadow-sm); transition: border-color .15s, background-color .15s, transform .08s; }
.btn:hover { border-color: var(--brand); } .btn:active { transform: translateY(1px); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible, summary:focus-visible { outline: 3px solid var(--brand-soft); outline-offset: 0; border-color: var(--brand); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: var(--surface); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: var(--surface); }
.btn.primary:focus-visible, .btn.ok:focus-visible, .btn.danger:focus-visible { outline-color: var(--ink); outline-width: 2px; outline-offset: 2px; }
.btn.ghost { background: transparent; box-shadow: none; } .btn.sm { padding: 7px 12px; min-height: 34px; font-size: 13px; border-radius: 9px; } .btn.block { width: 100%; }
.btn.link { border: 0; background: none; color: var(--brand); padding: 4px; min-height: 0; box-shadow: none; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; } .field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
input, select, textarea { font: 15px/1.4 var(--font); color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 11px 13px; width: 100%; min-width: 0; transition: border-color .15s; }
input:hover, select:hover, textarea:hover { border-color: var(--muted); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .75; }
/* iPhone: ô ngày/giờ mặc định không co theo khung và tự phóng to trang khi chữ nhỏ hơn 16px */
input[type="date"], input[type="time"] { -webkit-appearance: none; appearance: none; min-height: 46px; display: block; max-width: 100%; } input::-webkit-date-and-time-value { text-align: left; }
@media (max-width: 860px) { input, select, textarea { font-size: 16px; } }
textarea { resize: vertical; } input[type="checkbox"], input[type="radio"] { width: auto; accent-color: var(--brand); }
input[type="color"] { padding: 3px; height: 42px; width: 56px; cursor: pointer; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; } .grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 560px) { .grid2.collapse, .grid3 { grid-template-columns: 1fr; } }
.form-err { color: var(--bad); font-weight: 600; font-size: 14px; background: var(--bad-soft); border-radius: var(--r-sm); padding: 9px 12px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow-sm); }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; line-height: 1.5; }
.badge.wait { color: var(--ink); } .badge.ok { background: var(--ok); color: var(--surface); border-color: var(--ok); }
.badge.okl { background: var(--ok-soft); color: var(--ok); border-color: transparent; } .badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; } .badge.warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); }
.badge.src { background: var(--brand-soft); color: var(--brand); border-color: transparent; } .badge.acc { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.room { color: var(--room); font-weight: 600; }

.important { background: var(--warn-soft); border: 1.5px solid var(--warn-line); border-radius: var(--r); padding: 13px 15px; }
.important h4 { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--warn); margin-bottom: 7px; }
.important p { background: var(--surface); border: 1px solid var(--warn-line); border-radius: var(--r-sm); padding: 9px 12px; font-weight: 600; white-space: pre-wrap; overflow-wrap: anywhere; }
.notebox { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 10px 13px; background: var(--surface); white-space: pre-wrap; overflow-wrap: anywhere; }
.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; } .kv dt { font-weight: 500; font-size: 13px; color: var(--muted); } .kv dd { margin: 2px 0 0; font-weight: 700; }
.kv .amber { color: var(--accent); } .kv .green { color: var(--ok); } .kv .red { color: var(--bad); }
.lines { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; } .lines li { overflow-wrap: anywhere; } .lines li::marker { color: var(--muted); }
.sec-title { font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.panel { background: var(--surface-2); border-radius: var(--r); padding: 15px; }

.overlay { position: fixed; inset: 0; background: rgba(8, 13, 24, .56); display: flex; align-items: flex-end; justify-content: center; z-index: 50; padding: 0; -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.dialog { background: var(--surface); color: var(--ink); width: 100%; max-width: 480px; border-radius: 22px 22px 0 0; padding: 22px max(20px, env(safe-area-inset-right, 0px)) calc(20px + env(safe-area-inset-bottom, 0px)) max(20px, env(safe-area-inset-left, 0px)); display: flex; flex-direction: column; gap: 14px; max-height: 93%; overflow: auto; box-shadow: var(--shadow); }
.dialog.wide { max-width: 780px; } .dialog h3 { font-size: 19px; }
.xclose { position: sticky; top: 0; align-self: flex-end; z-index: 3; flex: none; width: 40px; height: 40px; margin: -6px -6px -54px 0; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: 600 16px/1 var(--font); cursor: pointer; display: grid; place-items: center; box-shadow: var(--shadow-sm); }
.xclose:hover { border-color: var(--brand); color: var(--brand); } .xclose:focus-visible { outline: 3px solid var(--brand-soft); border-color: var(--brand); }
.xclose + * { padding-right: 48px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }
@media (min-width: 640px) { .overlay { align-items: center; padding: 24px; } .dialog { border-radius: 22px; } }
@media (prefers-reduced-motion: no-preference) { .dialog { animation: rise .22s cubic-bezier(.2, .8, .2, 1); } @keyframes rise { from { transform: translateY(18px); opacity: .6; } to { transform: none; opacity: 1; } } }
#toasts { position: fixed; left: 0; right: 0; bottom: calc(84px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 80; pointer-events: none; padding: 0 16px; }
.toast { background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 999px; font-weight: 600; font-size: 14px; box-shadow: var(--shadow); max-width: 480px; text-align: center; }
.toast.err { background: var(--bad); color: var(--surface); border-radius: 14px; } .toast.ok { background: var(--ok); color: var(--surface); }
.demo-bar { background: var(--warn-soft); color: var(--warn); border-bottom: 1px solid var(--warn-line); font-size: 13px; font-weight: 600; padding-block: 6px; }
.tablewrap { overflow-x: auto; } table.grid { border-collapse: collapse; width: 100%; font-size: 14px; }
table.grid th, table.grid td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: top; } table.grid th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; letter-spacing: .04em; text-transform: uppercase; }
table.grid tbody tr:last-child td { border-bottom: 0; } table.grid tbody tr:hover { background: var(--surface-2); }
.empty { text-align: center; color: var(--muted); padding: 40px 12px; }
.logo { width: 44px; height: 44px; border-radius: 12px; object-fit: cover; flex: none; background: var(--surface); }
@media (prefers-reduced-motion: no-preference) { .flash { animation: flash 1.6s ease-out; } @keyframes flash { from { box-shadow: 0 0 0 5px var(--accent-line); } to { box-shadow: 0 0 0 0 transparent; } } }
@media print { .noprint, #toasts, .overlay > .dialog .dialog-actions { display: none !important; } body { background: #fff; } }
