/* =========================================================
   Homestay bookings — cream and night navy
   Cream paper (#F2EDDB) and deep navy ink (#171F3C), with one clay (#B07156)
   for the standout action, today's date and new changes.
   The calendar's booking ribbons carry the other colours; everything else stays calm.
   ========================================================= */
:root {
  --bg: #f2eddb;          /* cream */
  --surface: #fffcf3;
  --surface-2: #f8f4e6;
  --border: #e3dbc2;
  --border-strong: #cfc5a5;
  --text: #171f3c;        /* night navy */
  --muted: #5e6378;
  --accent: #171f3c;      /* buttons and selected things are navy */
  --accent-ink: #0d1230;
  --accent-soft: #e6e3d6;
  --hl: #b07156;          /* clay: the one highlight */
  --hl-ink: #8e5741;
  --hl-soft: #ead9c4;
  --on-navy: #f2eddb;
  --on-navy-muted: rgba(242, 237, 219, .68);
  --danger: #c0392b;
  --weekend: #f8f4e6;
  --hl-line: rgba(176, 113, 86, .45);
  --shadow: 0 1px 2px rgba(23, 31, 60, .06);
  --lift: 0 10px 30px rgba(23, 31, 60, .16);

  --st-pending: #d9952a;
  --st-confirmed: #3f66c9;
  --st-checked_in: #2f8f6f;
  --st-checked_out: #9a978a;
  --st-cancelled: #c8463d;
  --st-blocked: #6f7388;

  --r-card: 16px;
  --r-ctl: 10px;
  --label-w: 168px;
  --cell-w: 46px;
  --row-h: 52px;
  --tabbar-h: 0px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
h2 { font-size: 20px; line-height: 1.25; margin: 0; font-weight: 700; letter-spacing: -.01em; }
h3 { font-size: 16px; margin: 0 0 10px; font-weight: 700; }
h4 { font-weight: 700; }
.muted { color: var(--muted); font-weight: normal; }
.spacer { flex: 1; }
.num, .kpi .value, .tl-day b, .pill b { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 3px solid var(--hl); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 24px;
  background: var(--text);
  color: var(--on-navy);
  border-bottom: 1px solid var(--accent-ink);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
/* logo and New booking share one shape: 40px tall, 12px corners, line icons */
.logo {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; flex: none;
  background: rgba(242, 237, 219, .1); border: 1px solid rgba(242, 237, 219, .22); color: var(--on-navy);
}
.logo svg, .btn.cta .plus { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.property-select {
  font-weight: 700; font-size: 16px; border-color: transparent; background-color: transparent; color: var(--on-navy);
  max-width: 260px; min-width: 0; cursor: pointer; padding-left: 6px;
}
.property-select:hover { background-color: rgba(242, 237, 219, .1); border-color: rgba(242, 237, 219, .25); }
.property-select option { background: var(--surface); color: var(--text); }
.tabs { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: 7px;
  border: 0; background: none; padding: 9px 13px; border-radius: var(--r-ctl); cursor: pointer;
  color: var(--on-navy-muted); font-weight: 600; white-space: nowrap;
}
.tab-ic { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.tab .short, .segmented .short { display: none; }
.tab:hover { background: rgba(242, 237, 219, .1); color: var(--on-navy); }
.tab.active { background: var(--on-navy); color: var(--text); }

.btn.cta {
  background: var(--hl); border-color: var(--hl); color: var(--text); height: 40px; min-height: 40px;
  padding: 0 16px 0 12px; border-radius: 12px; display: inline-flex; align-items: center; gap: 6px;
}
.btn.cta:hover { background: #c08068; border-color: #c08068; }

main { padding: 24px; max-width: 1600px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }

/* ---------- controls ---------- */
.btn {
  border: 1px solid var(--border-strong); background: var(--surface); padding: 8px 15px; min-height: 40px;
  border-radius: var(--r-ctl); cursor: pointer; font-weight: 600; white-space: nowrap; color: var(--text);
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-navy); }
.btn.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.btn.danger:hover { background: #f8e3dc; }
.btn.icon { padding: 6px 12px; font-size: 20px; line-height: 1; min-width: 40px; }
.btn.small { padding: 5px 11px; min-height: 32px; font-size: 13px; }
input, select, textarea {
  border: 1px solid var(--border-strong); background-color: var(--surface); border-radius: var(--r-ctl);
  padding: 9px 12px; min-height: 42px; color: var(--text);
}
textarea { line-height: 1.5; resize: vertical; }
input[type=checkbox] { min-height: 0; width: 18px; height: 18px; accent-color: var(--text); }
input[type=color] { padding: 4px; height: 42px; }
input::placeholder, textarea::placeholder { color: #9a9786; }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--hl-soft); border-color: var(--hl-ink); }
.check { display: flex; align-items: center; gap: 8px; color: var(--muted); white-space: nowrap; min-height: 40px; }

.segmented { display: inline-flex; background: #e6dfc8; border-radius: 12px; padding: 3px; gap: 2px; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.segmented::-webkit-scrollbar { display: none; }
.segmented button {
  border: 0; background: none; padding: 7px 13px; border-radius: 9px; cursor: pointer;
  font-weight: 600; color: var(--muted); white-space: nowrap;
}
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(23, 31, 60, .15); }

/* ---------- calendar ---------- */
.cal-toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.cal-nav, .cal-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cal-nav h2 { margin-left: 8px; min-width: 220px; font-size: 22px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 10px; color: var(--muted); font-size: 13px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend i { width: 14px; height: 8px; border-radius: 4px; display: inline-block; }
.cal-stats { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.pill {
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 13px; font-size: 13px; color: var(--muted); white-space: nowrap;
}
.pill b { color: var(--text); }
.cal-body {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card);
  overflow: auto; box-shadow: var(--shadow); max-height: calc(100vh - 250px);
  overscroll-behavior: contain;
}
.hint { color: var(--muted); font-size: 13px; margin-top: 10px; }

/* timeline (week / 2 weeks / month) */
.timeline { min-width: max-content; user-select: none; -webkit-user-select: none; }
.tl-row { display: grid; grid-template-columns: var(--label-w) 1fr; border-bottom: 1px solid var(--border); }
.tl-row:last-child { border-bottom: 0; }
.tl-label {
  position: sticky; left: 0; z-index: 3; background: var(--surface);
  border-right: 1px solid var(--border); padding: 6px 14px;
  display: flex; flex-direction: column; justify-content: center; min-height: var(--row-h); min-width: 0;
}
.tl-label .name { font-weight: 700; display: flex; align-items: center; gap: 8px; min-width: 0; }
.tl-label .name i { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.tl-label .meta { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-track {
  position: relative; display: grid;
  grid-template-columns: repeat(var(--days), minmax(var(--cell-w), 1fr));
}
.tl-head { position: sticky; top: 0; z-index: 5; background: var(--surface); }
.tl-head .tl-label { z-index: 6; font-weight: 600; color: var(--muted); font-size: 13px; }
.tl-day {
  text-align: center; padding: 7px 2px 6px; border-right: 1px solid var(--border);
  font-size: 12px; color: var(--muted); line-height: 1.25;
}
.tl-day b { display: block; font-size: 16px; color: var(--text); margin-top: 1px; }
.tl-day.weekend { background: var(--weekend); }
.tl-day.today { box-shadow: inset 0 3px 0 var(--hl); color: var(--hl-ink); font-weight: 600; }
.tl-day.today b { color: var(--hl-ink); }
.tl-day .occ { display: block; font-size: 10px; margin-top: 2px; }
.tl-cell { border-right: 1px solid var(--border); min-height: var(--row-h); cursor: cell; }
.tl-cell.weekend { background: var(--weekend); }
.tl-cell.today { box-shadow: inset 1px 0 0 var(--hl-line), inset -1px 0 0 var(--hl-line); }
@media (hover: hover) { .tl-cell:hover { background: var(--accent-soft); } }
.tl-cell.selecting { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }

/* booking ribbons: the one bold thing */
.bar {
  position: absolute; top: 8px; bottom: 8px; z-index: 2;
  border-radius: 999px; padding: 0 12px; color: #fff; font-size: 13px; font-weight: 700;
  display: flex; align-items: center; gap: 6px; overflow: hidden; white-space: nowrap;
  cursor: pointer; box-shadow: 0 2px 6px rgba(23, 31, 60, .18);
  transition: transform .1s, box-shadow .1s;
}
@media (hover: hover) { .bar:hover { transform: translateY(-1px); box-shadow: 0 6px 14px rgba(23, 31, 60, .25); z-index: 4; } }
.bar span:first-child { overflow: hidden; text-overflow: ellipsis; }
.bar .sub { font-weight: 500; opacity: .9; overflow: hidden; text-overflow: ellipsis; }
.bar.clip-start { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.bar.clip-end { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.bar.st-pending { background: var(--st-pending); }
.bar.st-confirmed { background: var(--st-confirmed); }
.bar.st-checked_in { background: var(--st-checked_in); }
.bar.st-checked_out { background: var(--st-checked_out); }
.bar.st-blocked {
  background: repeating-linear-gradient(-45deg, #6f7388 0 7px, #878ba0 7px 14px);
  box-shadow: none;
}
.bar.st-cancelled {
  background: repeating-linear-gradient(-45deg, var(--st-cancelled) 0 6px, #db7068 6px 12px);
  opacity: .6; top: auto; bottom: 4px; height: 16px; font-size: 10px; box-shadow: none;
}
.bar.conflict { outline: 2px dashed var(--danger); outline-offset: 1px; }
.timeline.compact .bar .sub { display: none; }

/* day view */
.day-view { padding: 16px; display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.day-room {
  border: 1px solid var(--border); border-left: 5px solid var(--c); border-radius: 14px; padding: 14px 16px;
  background: var(--surface);
}
.day-room .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.day-room .head b { font-size: 16px; }
.day-room .entry {
  display: block; width: 100%; text-align: left; border: 1px solid var(--border); background: var(--surface-2);
  border-radius: var(--r-ctl); padding: 10px 12px; margin-top: 6px; cursor: pointer;
}
.day-room .entry:hover { border-color: var(--accent); }
.day-room .entry small { color: var(--muted); display: block; }
.day-room .free { color: var(--muted); }

/* month grid */
.mgrid { display: grid; grid-template-columns: repeat(7, minmax(120px, 1fr)); min-width: 840px; }
.mgrid .dow {
  padding: 9px 8px; font-size: 13px; font-weight: 600; color: var(--muted);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 2;
}
.mcell {
  min-height: 120px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  padding: 6px; cursor: pointer; display: flex; flex-direction: column; gap: 3px; min-width: 0;
}
.mcell:nth-child(7n) { border-right: 0; }
@media (hover: hover) { .mcell:hover { background: var(--surface-2); } }
.mcell.other { opacity: .45; }
.mcell.weekend { background: var(--weekend); }
.mcell.today { box-shadow: inset 0 0 0 2px var(--hl); }
.mcell .top { display: flex; justify-content: space-between; align-items: center; font-size: 12px; }
.mcell .top b { font-size: 14px; }
.mcell.today .top b { color: var(--hl-ink); }
.occbar { height: 4px; border-radius: 4px; background: #e6dfc8; overflow: hidden; }
.occbar span { display: block; height: 100%; background: var(--accent); }
.chip {
  font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px; color: #fff; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; border: 0; text-align: left; cursor: pointer; min-height: 0;
}
.chip.arrive::before { content: "→ "; }
.chip.depart { opacity: .6; }
.chip.depart::before { content: "← "; }
.more { font-size: 11px; color: var(--muted); }

/* ---------- overview ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 13px; font-weight: 600; }
.kpi .value { font-size: 28px; font-weight: 800; margin-top: 2px; letter-spacing: -.02em; line-height: 1.2; }
.kpi .sub { color: var(--muted); font-size: 12px; }
.kpi:first-child { background: var(--text); border-color: var(--text); color: var(--on-navy); }
.kpi:first-child .label, .kpi:first-child .sub { color: var(--on-navy-muted); }
.kpi:first-child .value { color: var(--hl); }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; margin-bottom: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); padding: 18px; box-shadow: var(--shadow); }
.mini {
  display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); cursor: pointer;
}
.mini:first-child { border-top: 0; }
.mini:hover .who { color: var(--accent-ink); }
.mini .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.mini .who { font-weight: 600; }
.mini .info { color: var(--muted); font-size: 13px; }
.mini .right { margin-left: auto; text-align: right; font-size: 12px; color: var(--muted); }
.empty { color: var(--muted); padding: 6px 0; }

/* ---------- tables ---------- */
.list-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.list-toolbar input[type=search] { min-width: 260px; }
.list-toolbar label { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); overflow: auto; box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 14px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.table th { font-size: 13px; color: var(--muted); font-weight: 600; background: var(--surface-2); }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { cursor: pointer; }
@media (hover: hover) { .table tbody tr:hover { background: var(--surface-2); } }
.table .num { text-align: right; }
.table .owed { color: var(--danger); font-weight: 700; }
.room-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; vertical-align: 1px; }
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; color: #fff; white-space: nowrap;
}
.badge.st-pending { background: var(--st-pending); }
.badge.st-confirmed { background: var(--st-confirmed); }
.badge.st-checked_in { background: var(--st-checked_in); }
.badge.st-checked_out { background: var(--st-checked_out); }
.badge.st-cancelled { background: var(--st-cancelled); }
.badge.st-blocked { background: var(--st-blocked); }

/* ---------- DD/MM/YYYY date fields ---------- */
.date-field { position: relative; display: flex; gap: 6px; }
.date-field .date-text { flex: 1; min-width: 0; color: var(--text); font-weight: normal; }
.date-field .date-native { position: absolute; left: 0; top: 0; width: calc(100% - 52px); height: 100%; padding: 0; border: 0; opacity: 0; pointer-events: none; z-index: -1; }
.date-pick { border: 1px solid var(--border-strong); border-radius: var(--r-ctl); background: var(--surface-2); padding: 0 12px; min-width: 46px; cursor: pointer; }

/* ---------- guest lookup ---------- */
.guest-field { position: relative; }
.suggest {
  position: absolute; left: 0; top: 100%; margin-top: 4px; z-index: 10;
  width: calc(200% + 12px); max-height: 260px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--lift); padding: 4px;
}
.suggest button {
  display: flex; width: 100%; justify-content: space-between; gap: 10px; align-items: baseline;
  border: 0; background: none; padding: 10px 12px; border-radius: 9px; cursor: pointer; text-align: left;
}
.suggest button:hover, .suggest button.hl { background: var(--accent-soft); }
.suggest small { color: var(--muted); white-space: nowrap; }
.suggest .head { font-size: 12px; font-weight: 600; color: var(--muted); padding: 6px 12px 2px; }

/* ---------- homestay info ---------- */
.prop-card { margin-bottom: 22px; border-top: 5px solid var(--hl); }
.prop-card h2 { font-size: 24px; margin-bottom: 4px; }
.prop-card .desc { white-space: pre-line; margin: 10px 0 0; max-width: 72ch; }
.prop-facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px 20px; margin-top: 16px; }
.prop-facts div { font-size: 14px; overflow-wrap: anywhere; }
.prop-facts span { display: block; color: var(--muted); font-size: 13px; font-weight: 600; }
.prop-facts a { color: var(--accent-ink); }
.section-title { margin: 0; font-size: 18px; }

/* ---------- rooms ---------- */
.room-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.room-card {
  background: var(--surface); border: 1px solid var(--border); border-top: 5px solid var(--c);
  border-radius: var(--r-card); padding: 16px 18px; cursor: pointer; box-shadow: var(--shadow);
}
.room-card:hover { border-color: var(--c); }
.room-card h4 { margin: 0 0 4px; font-size: 18px; }
.room-card .meta { color: var(--muted); font-size: 13px; }
.room-card .now { margin-top: 10px; font-size: 14px; }

/* ---------- dialogs ---------- */
dialog {
  border: 0; border-radius: 20px; padding: 0; width: min(580px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px); overflow: auto;
  background: var(--surface); color: var(--text); box-shadow: 0 24px 60px rgba(23, 31, 60, .3);
}
dialog::backdrop { background: rgba(23, 31, 60, .5); }
.form { padding: 22px 24px; position: relative; }
.form h2 { margin-bottom: 16px; padding-right: 48px; min-height: 36px; display: flex; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: end; } /* fields line up even when one label wraps */
.grid2 label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); }
.grid2 label > input, .grid2 label > select, .grid2 label > textarea { color: var(--text); font-weight: normal; }
.grid2 > * { min-width: 0; }
.grid2 label > :is(input, select, textarea) { width: 100%; min-width: 0; }
.span2 { grid-column: span 2; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.error { color: var(--danger); margin: 10px 0 0; min-height: 1em; font-weight: 600; }
.error:empty { min-height: 0; margin: 0; }

.dialog-x {
  position: absolute; top: 22px; right: 20px; width: 36px; height: 36px; padding: 0; /* top = form padding, so it lines up with the title */
  border: 1px solid var(--border); border-radius: var(--r-ctl); background: var(--surface); color: var(--muted);
  font-size: 0; cursor: pointer;
}
.dialog-x::before, .dialog-x::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 14px; height: 1.8px; border-radius: 2px;
  background: currentColor; transform: translate(-50%, -50%) rotate(45deg);
}
.dialog-x::after { transform: translate(-50%, -50%) rotate(-45deg); }
.dialog-x:hover { background: var(--accent-soft); border-color: var(--border-strong); color: var(--text); }
.confirm-dialog { width: min(420px, calc(100vw - 32px)); }
.confirm-dialog p { margin: 0; white-space: pre-line; color: var(--muted); }
.btn.danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }

.toast {
  position: fixed; bottom: calc(20px + var(--tabbar-h)); left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--on-navy); padding: 11px 18px; border-radius: 12px; max-width: calc(100vw - 32px);
  opacity: 0; pointer-events: none; transition: .2s; z-index: 100; font-weight: 600; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- messages ---------- */
.msg-layout { display: grid; grid-template-columns: 290px 1fr; gap: 14px; align-items: start; }
.msg-layout > * { min-width: 0; }
.msg-list-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.msg-list-head h3 { margin: 0; }
.tpl-item {
  display: block; width: 100%; text-align: left; border: 1px solid transparent; background: none;
  border-radius: 12px; padding: 10px 12px; cursor: pointer;
}
.tpl-item:hover { background: var(--surface-2); }
.tpl-item.active { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }
.tpl-item small { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  border: 1px dashed var(--border-strong); background: var(--surface-2); border-radius: 999px;
  padding: 5px 11px; font-size: 13px; cursor: pointer;
}
.chips button:hover { border-color: var(--accent); color: var(--accent-ink); }
.chips button.custom { border-style: solid; border-color: var(--accent); color: var(--accent-ink); background: var(--accent-soft); }
.small-note { font-size: 13px; margin: 10px 0 8px; }
.sep { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
.inline-label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 10px; }
.booking-pick { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 8px; }
.booking-pick > * { min-width: 0; font-weight: normal; color: var(--text); }
#tplBookingCount { font-weight: normal; min-height: 1em; }
.msg-preview {
  white-space: pre-wrap; font: inherit; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px; margin: 0; min-height: 80px; overflow-wrap: anywhere;
}
.msg-preview mark { background: var(--hl-soft); color: inherit; border-radius: 4px; padding: 0 2px; }

/* custom placeholders */
.custom-ph { margin-top: 16px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2); }
.custom-ph h4 { margin: 0; font-size: 15px; }
.custom-ph h4 .muted { font-weight: 400; }
.ph-row { display: grid; grid-template-columns: minmax(120px, 1fr) 2fr auto; gap: 8px; align-items: center; margin-top: 8px; }
.ph-row code { font-size: 13px; color: var(--accent-ink); overflow-wrap: anywhere; }
.ph-row .ph-value { overflow-wrap: anywhere; }
.ph-row input { min-width: 0; }

/* ---------- linked calendars ---------- */
.cal-links { margin-top: 18px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2); }
.cal-links h4 { margin: 0; font-size: 15px; }
.cal-links h4 .muted { font-weight: 400; }
.cal-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--border); }
.cal-item:first-child { border-top: 0; }
.cal-item .chan { font-weight: 700; font-size: 14px; }
.cal-item .url { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-item .stat { grid-column: 2 / -1; font-size: 12px; color: var(--muted); }
.cal-item .stat.err { color: var(--danger); }
.cal-add { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; margin-top: 8px; }
.cal-export .cal-add { grid-template-columns: minmax(0, 1fr) auto; }
.cal-add > * { min-width: 0; }
.cal-sync { display: flex; align-items: center; gap: 8px; }
.cal-sync .small-note { margin: 0; }
.cal-export { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 12px; }
.cal-export summary { cursor: pointer; font-size: 14px; }
.cal-export summary .muted { font-weight: 400; font-size: 13px; }
.small-note.warn { color: var(--danger); }
.small-note.warn:empty { display: none; }
.import-note { margin: -6px 0 16px; padding: 10px 12px; border-radius: 12px; background: var(--accent-soft); font-size: 13px; }
.room-card .links { margin-top: 8px; font-size: 12px; color: var(--muted); }
.room-card .links .err { color: var(--danger); }

/* ---------- calendar changes (Bookings tab) ---------- */
.tab-badge { display: inline-block; min-width: 19px; padding: 0 5px; border-radius: 10px; background: var(--hl); color: var(--text); font-size: 11px; font-weight: 700; line-height: 19px; text-align: center; }
.tab-badge[hidden] { display: none; }
.sync-changes { margin-bottom: 14px; padding: 12px 16px; border: 1px solid var(--border); border-left: 5px solid var(--hl); border-radius: var(--r-card); background: var(--surface); }
.sync-changes summary { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; cursor: pointer; }
.sync-changes summary .btn { margin-left: auto; }
.sync-changes ul { list-style: none; margin: 8px 0 0; padding: 0; }
.sync-changes li { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 8px; align-items: baseline; padding: 8px 4px; border-top: 1px solid var(--border); font-size: 14px; border-radius: 8px; }
.sync-changes li[data-booking] { cursor: pointer; }
.sync-changes li[data-booking]:hover { background: var(--surface-2); }
.sync-changes li.new { font-weight: 600; }
.sync-changes li .ic { text-align: center; color: var(--accent); }
.sync-changes li.k-cancelled .ic { color: var(--danger); }
.sync-changes li.k-unblocked .ic { color: var(--st-checked_in); }
.sync-changes li.k-blocked .ic { color: var(--st-blocked); }
.table tr.changed td { background: var(--hl-soft); }
.table tbody tr.changed { background: var(--hl-soft); }
.change-pill { display: inline-block; margin-top: 4px; font-size: 12px; font-weight: 600; color: #8e5741; white-space: normal; }

/* ---------- accounts ---------- */
/* nothing shows until we know who is signed in; signed out shows only the sign-in card */
body.booting .topbar, body.booting main, body.signed-out .topbar, body.signed-out main { display: none; }
/* controls this account isn't allowed to use are hidden (the server refuses them too) */
.no-perm { display: none !important; }
body.one-tab .tabs { display: none; }

.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; background: var(--text); }
.auth[hidden] { display: none; }
.auth-card {
  width: min(400px, 100%); background: var(--surface); border-radius: 20px; padding: 28px 24px 24px;
  display: flex; flex-direction: column; gap: 14px; box-shadow: 0 24px 60px rgba(0, 0, 0, .35);
}
.auth-card h1 { margin: 4px 0 0; font-size: 24px; letter-spacing: -.01em; }
.auth-card > p.muted { margin: -8px 0 4px; font-size: 14px; }
.auth-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); }
.auth-card label input { color: var(--text); font-weight: normal; width: 100%; }
.no-admin { background: var(--hl-soft); border-radius: 12px; padding: 12px 14px; font-size: 14px; line-height: 1.5; }
.no-admin code { display: block; margin: 8px 0; padding: 8px 10px; background: var(--text); color: var(--on-navy); border-radius: 8px; font-size: 13px; overflow-wrap: anywhere; }
.auth-logo { background: var(--text); border: 0; color: var(--on-navy); }
.auth-submit { min-height: 46px; font-size: 16px; }

.user-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px 0 4px; flex: none;
  border: 1px solid rgba(242, 237, 219, .22); border-radius: 12px; background: rgba(242, 237, 219, .1);
  color: var(--on-navy); cursor: pointer; text-align: left;
}
.user-btn:hover { background: rgba(242, 237, 219, .18); }
.avatar {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: var(--hl); color: var(--text); font-size: 12px; font-weight: 700;
}
.avatar.big { width: 48px; height: 48px; border-radius: 14px; font-size: 17px; }
.user-text { display: flex; flex-direction: column; line-height: 1.15; }
.user-text b { font-size: 13px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-text small { font-size: 11px; color: var(--on-navy-muted); }
.account-who { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.manage-users { width: 100%; margin-bottom: 6px; }
.pw-title { margin: 14px 0 10px; }

.users-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 14px; align-items: start; }
#userList { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.user-row:disabled { cursor: default; opacity: .75; }
.perm-table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.perm-table th { font-size: 13px; color: var(--muted); font-weight: 600; text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.perm-table th:not(:first-child), .perm-table td:not(:first-child) { text-align: center; width: 84px; }
.perm-table td { padding: 9px 8px; border-bottom: 1px solid var(--border); font-size: 14px; }
.perm-table tr:last-child td { border-bottom: 0; }
/* on/off switch */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; min-height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--border-strong); transition: background .15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.switch input:checked + span { background: var(--text); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 3px solid var(--hl); outline-offset: 2px; }
.user-row {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; text-align: left; cursor: pointer;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
}
.user-row:hover { background: var(--surface-2); }
.user-row.active { border-color: var(--hl); background: var(--hl-soft); }
.user-row .who { flex: 1; min-width: 0; }
.user-row .who small { display: block; color: var(--muted); font-size: 12px; }
.role-badge { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--text); }
.role-badge.r-admin { background: var(--text); color: var(--on-navy); }
.role-badge.r-manager { background: var(--hl-soft); color: var(--hl-ink); }
.user-form { border-top: 1px solid var(--border); padding-top: 14px; }
.user-form h3 { margin-bottom: 12px; }
.user-form .check { flex-direction: row; justify-content: flex-start; color: var(--text); font-weight: 500; }
.user-form .check input { width: 18px; flex: none; }
#userActiveRow[hidden] { display: none; }
#bookingAudit:empty { display: none; }

/* laptops: with seven Vietnamese tab names, the tabs get their own row under the top bar */
@media (max-width: 1360px) {
  .topbar { flex-wrap: wrap; row-gap: 8px; padding: 10px 20px 8px; }
  .brand { flex: 1; }
  .tabs { order: 3; flex-basis: 100%; }
  .tab .long { display: none; }
  .tab .short { display: inline; }
}

/* =========================================================
   Tablet (up to 1100px): tabs get their own row
   ========================================================= */
@media (max-width: 1100px) {
  .topbar { flex-wrap: wrap; row-gap: 8px; padding: 10px 20px 8px; }
  .brand { flex: 1; }
  .tabs { order: 3; flex-basis: 100%; }
  /* icon above the name, so all tabs fit one row even with long Vietnamese names */
  .tab { flex: 1 1 0; min-width: 0; flex-direction: column; justify-content: center; gap: 2px; padding: 6px 4px; font-size: 12.5px; }
  .tab > span { white-space: normal; text-align: center; line-height: 1.15; }
  .tab .tab-badge { position: absolute; top: 3px; left: calc(50% + 8px); }
  .tab .long { display: none; }
  .tab .short { display: inline; }
  .users-layout { grid-template-columns: 1fr; }
  main { padding: 20px; }
  .msg-layout { grid-template-columns: 240px 1fr; }
}

/* tables become cards on tablets and phones (two across on tablets) */
@media (max-width: 1100px) {
  .table-wrap { background: none; border: 0; box-shadow: none; overflow: visible; }
  .table thead { display: none; }
  .table, .table tbody { display: block; }
  .table tbody tr {
    display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px 10px; align-items: start;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card);
    padding: 14px; margin-bottom: 10px; box-shadow: var(--shadow);
  }
  .table td { display: block; padding: 0; border: 0; white-space: normal; text-align: left; min-width: 0; }
  .table td.num { text-align: left; }
  .table td[data-label]::before { content: attr(data-label); display: block; font-size: 12px; font-weight: 600; color: var(--muted); }
  .table td.empty { grid-column: 1 / -1; text-align: center; }
  .table tr:has(td.empty) { display: block; }
  /* bookings card: name + status, room + source, dates, money, buttons */
  #bkRows tr { grid-template-areas: "guest guest status" "room room source" "in out nights" "total balance balance" "act act act"; }
  #bkRows .c-guest { grid-area: guest; font-size: 16px; }
  #bkRows .c-status { grid-area: status; justify-self: end; }
  #bkRows .c-room { grid-area: room; color: var(--muted); }
  #bkRows .c-source { grid-area: source; justify-self: end; color: var(--muted); font-size: 13px; }
  #bkRows .c-in { grid-area: in; }
  #bkRows .c-out { grid-area: out; }
  #bkRows .c-nights { grid-area: nights; }
  #bkRows .c-total { grid-area: total; }
  #bkRows .c-balance { grid-area: balance; }
  #bkRows .c-actions { grid-area: act; }
  #guestRows tr { grid-template-areas: "guest guest stays" "phone phone stays" "last last last" "act act act"; }
  #guestRows .c-guest { grid-area: guest; font-size: 16px; }
  #guestRows .c-stays { grid-area: stays; justify-self: end; text-align: right; }
  #guestRows .c-phone { grid-area: phone; color: var(--muted); }
  #guestRows .c-last { grid-area: last; }
  #guestRows .c-actions { grid-area: act; }
  .table .c-actions { display: flex; gap: 8px; margin-top: 4px; }
  .table .c-actions .btn { flex: 1; min-height: 40px; }

  .table tr:has(td.empty) { display: block; }
}
@media (min-width: 761px) and (max-width: 1100px) {
  .table tbody { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
  .table tbody tr { margin: 0; }
}

/* =========================================================
   Phone (up to 760px): bottom tab bar, cards instead of tables, sheets for forms
   ========================================================= */
@media (max-width: 760px) {
  :root { --label-w: 92px; --cell-w: 46px; --row-h: 56px; --tabbar-h: calc(64px + env(safe-area-inset-bottom)); }
  body { font-size: 15px; padding-bottom: var(--tabbar-h); }
  body.one-tab { padding-bottom: 0; }
  /* 16px stops phones zooming into fields */
  input, select, textarea { font-size: 16px; }

  /* no blur here: it would trap the fixed tab bar inside the top bar */
  .topbar { flex-wrap: nowrap; gap: 10px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); backdrop-filter: none; }

  .property-select { font-size: 17px; max-width: none; flex: 1; }
  .btn.cta { padding: 0; width: 40px; justify-content: center; }
  .btn.cta .cta-text { display: none; }
  .user-btn { padding: 0; width: 40px; justify-content: center; }
  .user-text { display: none; }

  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; order: 0;
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 0;
    height: var(--tabbar-h); padding: 4px 4px env(safe-area-inset-bottom);
    background: var(--text);
    border-top: 1px solid var(--accent-ink); overflow: visible;
  }
  .tab {
    flex-direction: column; justify-content: center; gap: 2px; padding: 6px 2px; border-radius: 12px;
    font-size: 11px; font-weight: 600; min-width: 0;
  }
  /* Vietnamese tab names are long: let them wrap onto two short lines */
  .tab > span { max-width: 100%; white-space: normal; text-align: center; line-height: 1.12; font-size: 10.5px; overflow-wrap: anywhere; }
  .tab-ic { width: 23px; height: 23px; }
  .tab.active { background: none; color: var(--on-navy); }
  .tab.active .tab-ic { background: var(--hl); color: var(--text); border-radius: 10px; padding: 2px 8px; width: 40px; box-sizing: content-box; height: 22px; margin: 0 -8px; }
  .tab .long { display: none; }
  .tab .short { display: inline; }
  .tab .tab-badge { position: absolute; top: 2px; left: calc(50% + 6px); }

  main { padding: 14px 12px 20px; }
  h2 { font-size: 19px; }

  /* calendar */
  .cal-toolbar { gap: 10px; }
  .cal-nav { width: 100%; flex-wrap: nowrap; }
  .cal-nav h2 { min-width: 0; font-size: 18px; margin-left: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .cal-controls { width: 100%; }
  .cal-controls select { flex: 1; min-width: 0; }
  .segmented { width: 100%; }
  .segmented button { flex: 1 0 auto; padding: 8px 10px; }
  .segmented .long { display: none; }
  .segmented .short { display: inline; }
  .legend { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; gap: 14px; padding-bottom: 2px; }
  .legend::-webkit-scrollbar, .cal-stats::-webkit-scrollbar { display: none; }
  .cal-stats { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -12px 12px; padding: 0 12px; }
  .cal-body { max-height: none; border-radius: 14px; }
  .tl-label { padding: 6px 10px; }
  .tl-label .meta { display: none; }
  .tl-label .name { font-size: 14px; }
  .bar { padding: 0 9px; font-size: 12px; top: 9px; bottom: 9px; }
  .bar .sub { display: none; }
  .hint { font-size: 12px; }
  .day-view { padding: 10px; grid-template-columns: 1fr; }

  /* month grid fits the screen: dots instead of names */
  .mgrid { grid-template-columns: repeat(7, minmax(0, 1fr)); min-width: 0; }
  .mgrid .dow { padding: 8px 2px; text-align: center; font-size: 12px; }
  .mcell { min-height: 74px; padding: 4px 3px; gap: 2px; }
  .mcell .top { flex-direction: column; gap: 1px; }
  .mcell .top .muted { font-size: 9px; }
  .chip { font-size: 0; height: 6px; padding: 0; border-radius: 3px; }
  .chip::before { content: none !important; }
  .more { font-size: 10px; text-align: center; }

  /* overview: two figures per row */
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 12px 14px; }
  .kpi .value { font-size: 23px; }
  .kpi .label { font-size: 12px; }
  .card { padding: 16px; }

  /* lists */
  .list-toolbar input[type=search] { min-width: 0; flex: 1 1 100%; }
  .list-toolbar select { flex: 1 1 40%; min-width: 0; }
  .list-toolbar > .muted { font-size: 13px; flex-basis: 100%; order: 3; }

  /* bookings changes list */
  .sync-changes li { grid-template-columns: 20px minmax(0, 1fr); }
  .sync-changes li small { grid-column: 2; }

  /* messages */
  .msg-layout { grid-template-columns: 1fr; }
  #templateList { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -18px; padding: 0 18px 2px; }
  #templateList::-webkit-scrollbar { display: none; }
  .tpl-item { flex: 0 0 auto; width: auto; max-width: 220px; border-color: var(--border); }
  .booking-pick { grid-template-columns: 1fr; }
  .ph-row { grid-template-columns: 1fr auto; }
  .ph-row > :first-child { grid-column: 1 / -1; }

  /* rooms */
  .prop-card .actions .btn { flex: 1 1 auto; }
  .users-layout { grid-template-columns: 1fr; }
  .perm-table th:not(:first-child), .perm-table td:not(:first-child) { width: 64px; }
  .room-grid { grid-template-columns: 1fr; }

  /* forms slide up as sheets */
  dialog {
    width: 100vw; max-width: 100vw; max-height: 94dvh; margin: auto 0 0; border-radius: 22px 22px 0 0;
  }
  dialog[open] { animation: sheet-up .22s ease-out; }
  .form { padding: 18px 16px calc(16px + env(safe-area-inset-bottom)); }
  .form h2 { font-size: 19px; }
  .dialog-x { top: 18px; right: 14px; }
  .grid2 { grid-template-columns: 1fr 1fr; gap: 12px; }
  .grid2 > :is(.guest-field, .span2), .grid2 > label:has(textarea), .grid2 > label:has(.date-field) { grid-column: 1 / -1; }
  .suggest { width: 100%; }
  .actions { position: sticky; bottom: calc(-16px - env(safe-area-inset-bottom)); background: var(--surface); padding: 12px 0 4px; margin-top: 12px; border-top: 1px solid var(--border); }
  .actions .btn { flex: 1 1 auto; }
  .actions .spacer { display: none; }
  .confirm-dialog .actions { position: static; border: 0; }
  .cal-add { grid-template-columns: 1fr auto; }
  .cal-add > select { grid-column: 1 / -1; }
  .toast { bottom: calc(14px + var(--tabbar-h)); }
}

@keyframes sheet-up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  dialog[open] { animation: none; }
  .bar, .toast { transition: none; }
}

/* ---------- picking rooms in the booking form ---------- */
.room-field { border: 0; margin: 0; padding: 0; min-width: 0; }
.room-field legend { padding: 0; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.room-field legend .muted { font-weight: 400; }
.room-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.room-chip { position: relative; cursor: pointer; }
.room-chip input { position: absolute; opacity: 0; width: 1px; height: 1px; min-height: 0; }
.room-chip span {
  display: inline-flex; align-items: center; gap: 7px; min-height: 40px; padding: 7px 14px;
  border: 1px solid var(--border-strong); border-radius: var(--r-ctl); background: var(--surface);
  font-weight: 600; color: var(--text); font-size: 14px;
}
.room-chip span i { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.room-chip input:checked + span { background: var(--text); border-color: var(--text); color: var(--on-navy); }
.room-chip input:checked + span::after { content: "✓"; font-size: 13px; margin-left: 2px; }
.room-chip input:focus-visible + span { outline: 3px solid var(--hl); outline-offset: 2px; }
.room-chip input:disabled + span { opacity: .45; cursor: not-allowed; }
.room-chip input:checked:disabled + span { opacity: 1; }
.room-tag { display: inline-flex; align-items: center; margin-right: 8px; white-space: nowrap; }

/* ---------- locked accounts (Users tab) ---------- */
.lock-note { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: -4px 0 12px; padding: 10px 12px;
  border-radius: 12px; background: #f6dcd6; color: #7a2418; font-size: 14px; font-weight: 600; }
.lock-note[hidden] { display: none; }
.lock-note .btn { margin-left: auto; }
.user-row .locked { color: var(--danger); font-weight: 700; }

/* ---------- blocked devices (Users tab) ---------- */
.users-layout .blocked-card { grid-column: 1 / -1; }
.blocked-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.blocked-row:first-child { border-top: 0; }
.blocked-row > div { flex: 1; min-width: 0; }
.blocked-row small { display: block; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }

/* ---------- "remember me" on the sign-in card ---------- */
.auth-card label.remember { flex-direction: row; align-items: flex-start; gap: 10px; color: var(--text); font-size: 14px; cursor: pointer; }
.auth-card label.remember input { width: 20px; height: 20px; margin: 1px 0 0; flex: none; }
.auth-card label.remember small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; margin-top: 2px; }
