:root {
  --bg: #f4f6f8; --card: #fff; --ink: #1d2733; --muted: #66727f; --line: #dfe4ea;
  --brand: #a8740a; --brand-ink: #fff; --brand-soft: #fbf3e2;
  --empty: #e7f6ec; --empty-ink: #1f7a3e;
  --partial: #fff6d9; --partial-ink: #8a6200;
  --full: #e3eefc; --full-ink: #1d5bb8;
  --over: #fde5e5; --over-ink: #b42323;
  --maint: #eceef1; --maint-ink: #5b6570;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--brand); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 17px; }
h3 { font-size: 14px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }

/* Header */
.topbar { position: sticky; top: 0; z-index: 20; background: #1d2733; color: #fff; }
.topbar-inner { display: flex; align-items: center; gap: 16px; padding: 10px 20px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .02em; }
.brand-mark { width: 28px; height: 28px; border-radius: 7px; background: var(--brand); display: grid; place-items: center; font-size: 15px; }
.brand small { display: block; font-weight: 400; color: #aab4bf; font-size: 12px; letter-spacing: 0; }
.datebox { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.datebox label { color: #aab4bf; font-size: 12px; }
.datebox input { background: #2b3746; color: #fff; border: 1px solid #3c4a5c; border-radius: 6px; padding: 5px 8px; color-scheme: dark; }
.tabs { display: flex; gap: 2px; padding: 0 12px; overflow-x: auto; }
.tabs button { background: none; border: 0; color: #c3ccd6; padding: 10px 14px; font: inherit; cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs button:hover { color: #fff; }
.tabs button.active { color: #fff; border-bottom-color: var(--brand); font-weight: 600; }
.tabs .badge { background: var(--over-ink); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; margin-left: 4px; }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }

/* Cards & grid */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-bottom: 14px; }
.kpi .label { color: var(--muted); font-size: 12.5px; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; }
.kpi.warn .value { color: var(--over-ink); }
.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); margin-bottom: 14px; }
.charts { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); margin-bottom: 14px; }
.chart-box { position: relative; height: 220px; }
.card h3 { margin-bottom: 10px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; position: sticky; top: 0; }
tr:hover td { background: #fafbfc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.empty-state { color: var(--muted); text-align: center; padding: 24px; }

/* Pills */
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.s-EMPTY { background: var(--empty); color: var(--empty-ink); }
.s-PARTIAL { background: var(--partial); color: var(--partial-ink); }
.s-FULL { background: var(--full); color: var(--full-ink); }
.s-OVERBOOK { background: var(--over); color: var(--over-ink); }
.s-MAINTENANCE { background: var(--maint); color: var(--maint-ink); }
.b-Confirmed { background: var(--full); color: var(--full-ink); }
.b-Checked-out { background: var(--maint); color: var(--maint-ink); }
.b-Cancelled { background: var(--over); color: var(--over-ink); }
.g-Nam { color: #1d5bb8; } .g-Nữ { color: #b4237a; }

/* Visual board */
.legend { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.block-group { margin-bottom: 18px; }
.block-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.block-head .muted { font-size: 12.5px; }
.rooms-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.room-tile { border-radius: var(--radius); border: 1px solid var(--line); padding: 10px 12px; cursor: pointer; transition: transform .08s; min-height: 120px; display: flex; flex-direction: column; gap: 4px; }
.room-tile:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.room-tile .rt-head { display: flex; justify-content: space-between; align-items: center; }
.room-tile .rt-id { font-size: 18px; font-weight: 700; }
.room-tile .rt-cap { font-size: 12px; font-weight: 600; }
.room-tile .beds { display: flex; gap: 3px; margin: 2px 0 4px; flex-wrap: wrap; }
.room-tile .bed { width: 14px; height: 8px; border-radius: 2px; background: rgba(0,0,0,.12); }
.room-tile .bed.on { background: currentColor; }
.room-tile .guest { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-tile .warn { margin-top: auto; font-size: 12px; font-weight: 700; color: var(--over-ink); }
.room-tile.s-EMPTY { border-color: #bfe5cb; } .room-tile.s-PARTIAL { border-color: #f0dc9a; }
.room-tile.s-FULL { border-color: #b9d2f5; } .room-tile.s-OVERBOOK { border-color: #f2b1b1; } .room-tile.s-MAINTENANCE { border-color: #d3d8de; }
.room-tile.alert { outline: 2px solid var(--over-ink); outline-offset: -1px; }

/* Calendar */
.cal { border-collapse: separate; border-spacing: 0; font-size: 12.5px; }
.cal th, .cal td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 0; text-align: center; }
.cal th { padding: 6px 4px; min-width: 44px; }
.cal th.weekend { background: #f3f0e8; }
.cal th.today { background: var(--brand); color: #fff; }
.cal td.room { text-align: left; padding: 6px 10px; position: sticky; left: 0; background: #fff; font-weight: 600; white-space: nowrap; z-index: 1; }
.cal td.cell { height: 32px; cursor: pointer; font-variant-numeric: tabular-nums; }
.cal td.cell:hover { outline: 2px solid var(--brand); outline-offset: -2px; }
.cal tr.block-row td { background: #f7f8fa; text-align: left; padding: 5px 10px; font-weight: 600; color: var(--muted); position: static; }

/* Forms & buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 7px; padding: 7px 12px; font: inherit; cursor: pointer; text-decoration: none; }
.btn:hover { background: #f5f7f9; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--over-ink); border-color: #f0c4c4; }
.btn.small { padding: 3px 8px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; background: #fff; color: var(--ink); min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid #e9c97f; border-color: var(--brand); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.hint { font-size: 12px; color: var(--muted); }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(17,24,39,.45); display: none; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; }
.modal-bg.open { display: flex; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 640px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal .body { padding: 18px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.modal footer .left { margin-right: auto; display: flex; gap: 8px; }
.close-x { background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.warnings { background: var(--over); color: var(--over-ink); border-radius: 8px; padding: 10px 14px; margin-top: 12px; }
.warnings ul { margin: 6px 0 0; padding-left: 18px; }
.files { margin-top: 16px; border-top: 1px dashed var(--line); padding-top: 12px; }
.file-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.file-row a { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.alert-list { list-style: none; margin: 0; padding: 0; }
.alert-list li { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.alert-list li:last-child { border-bottom: 0; }
.alert-list .room { font-weight: 700; min-width: 40px; }
.ok-banner { background: var(--empty); color: var(--empty-ink); border-radius: 8px; padding: 10px 14px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1d2733; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 100; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }
.toast.error { background: var(--over-ink); }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: #1d2733; }
.login-card { background: #fff; border-radius: 14px; padding: 28px; width: 100%; max-width: 360px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.login-card h1 { font-size: 19px; margin: 12px 0 4px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.login-card .err { color: var(--over-ink); min-height: 1.2em; font-size: 13px; }

@media (max-width: 640px) {
  main { padding: 14px; }
  .topbar-inner { padding: 10px 14px; }
  .datebox { margin-left: 0; width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .two, .charts { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}

.user-btn { background: #2b3746; color: #fff; border-color: #3c4a5c; }
.user-btn:hover { background: #34425a; }
.role-admin { background: var(--brand-soft); color: var(--brand); }
.role-staff { background: var(--full); color: var(--full-ink); }
.role-viewer { background: var(--maint); color: var(--maint-ink); }
[hidden] { display: none !important; }

/* ---------- Datepicker ---------- */
.dp-native { display: none !important; }
.dp-wrap { display: inline-flex; align-items: stretch; gap: 0; width: 100%; }
.datebox .dp-wrap { width: auto; }
.dp-trigger {
  flex: 1; display: inline-flex; align-items: center; gap: 9px; min-width: 0;
  font: inherit; text-align: left; cursor: pointer; color: var(--ink);
  background: #fff; border: 1px solid var(--line); border-radius: 7px; padding: 6px 10px;
  transition: border-color .12s, box-shadow .12s;
}
.dp-trigger svg { color: var(--brand); flex: none; }
.dp-trigger:hover { border-color: #c9ced6; }
.dp-trigger.open, .dp-trigger:focus-visible { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(168,116,10,.18); }
.dp-text { display: flex; align-items: baseline; gap: 7px; white-space: nowrap; overflow: hidden; }
.dp-text b { font-weight: 600; font-variant-numeric: tabular-nums; }
.dp-text small { color: var(--muted); font-size: 12px; }
.dp-ph { color: var(--muted); }
.dp-step {
  font: inherit; font-size: 18px; line-height: 1; width: 32px; cursor: pointer;
  background: #fff; border: 1px solid var(--line); color: var(--ink);
}
.dp-step:first-child { border-radius: 7px 0 0 7px; border-right: 0; }
.dp-step:last-child { border-radius: 0 7px 7px 0; border-left: 0; }
.dp-wrap:has(.dp-step) .dp-trigger { border-radius: 0; }
.dp-step:hover { background: #f5f7f9; }

/* biến thể trên thanh tiêu đề tối */
.dp-dark .dp-trigger, .dp-dark .dp-step { background: #2b3746; border-color: #3c4a5c; color: #fff; }
.dp-dark .dp-trigger svg { color: #e9c97f; }
.dp-dark .dp-text small { color: #aab4bf; }
.dp-dark .dp-trigger:hover, .dp-dark .dp-step:hover { background: #34425a; }

.dp-pop {
  position: fixed; z-index: 80; width: 296px; padding: 12px;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 12px 32px rgba(16,24,40,.18), 0 2px 6px rgba(16,24,40,.08);
  animation: dp-in .12s ease-out; color: var(--ink);
}
@keyframes dp-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.dp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.dp-title { font: inherit; font-weight: 700; font-size: 14.5px; background: none; border: 0; padding: 5px 10px; border-radius: 7px; cursor: pointer; color: var(--ink); }
.dp-title:hover { background: var(--brand-soft); color: var(--brand); }
.dp-nav { width: 32px; height: 32px; border-radius: 8px; border: 0; background: none; font-size: 20px; line-height: 1; cursor: pointer; color: var(--muted); }
.dp-nav:hover { background: #f1f3f5; color: var(--ink); }
.dp-dow, .dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.dp-dow span { text-align: center; font-size: 11.5px; font-weight: 600; color: var(--muted); padding: 4px 0 6px; }
.dp-dow span.wkd { color: #c0563f; }
.dp-day {
  position: relative; height: 36px; border: 0; background: none; font: inherit; font-size: 13.5px;
  cursor: pointer; color: var(--ink); border-radius: 8px; font-variant-numeric: tabular-nums;
}
.dp-day:hover:not(:disabled):not(.sel) { background: #f1f3f5; }
.dp-day.wkd { color: #c0563f; }
.dp-day.out { color: #b9c0c8; }
.dp-day:disabled { color: #d3d8de; cursor: not-allowed; text-decoration: line-through; }
.dp-day.today::after { content: ''; position: absolute; left: 50%; bottom: 4px; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: var(--brand); }
.dp-day.in-range { background: var(--brand-soft); border-radius: 0; }
.dp-day.r-start:not(.sel), .dp-day.r-end:not(.sel) { background: #f3dfb3; }
.dp-day.r-start { border-radius: 8px 0 0 8px; }
.dp-day.r-end { border-radius: 0 8px 8px 0; }
.dp-day.sel { background: var(--brand); color: #fff; font-weight: 700; }
.dp-day.sel.r-start { border-radius: 8px 0 0 8px; } .dp-day.sel.r-end { border-radius: 0 8px 8px 0; }
.dp-day.sel.today::after { background: #fff; }
.dp-day:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.dp-months { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.dp-month { font: inherit; padding: 12px 0; border: 0; border-radius: 8px; background: none; cursor: pointer; color: var(--ink); }
.dp-month:hover { background: #f1f3f5; }
.dp-month.today { box-shadow: inset 0 0 0 1px var(--brand); }
.dp-month.sel { background: var(--brand); color: #fff; font-weight: 700; }
.dp-foot { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.dp-info { font-size: 12.5px; color: var(--muted); }
.dp-info b { color: var(--brand); }
.dp-quick { display: flex; gap: 6px; align-items: center; justify-content: flex-end; }
.dp-quick-label { font-size: 12px; color: var(--muted); margin-right: auto; }
.dp-chip { font: inherit; font-size: 12.5px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: #fff; cursor: pointer; color: var(--ink); }
.dp-chip:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); }
.dp-chip.primary { background: var(--brand-soft); border-color: #ecd6a6; color: var(--brand); font-weight: 600; }
.dp-chip:disabled { opacity: .45; cursor: not-allowed; }
@media (max-width: 640px) { .datebox .dp-wrap { flex: 1; } }
