:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #2b2a7b;
  --primary-ink: #ffffff;
  --primary-soft: #e7e6f6;
  --gold: #f2b33d;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --gray-soft: #e2e8f0;
  --radius: 14px;
  --nav-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --card: #131c2e;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --line: #24314b;
    --primary: #a5a3f5;
    --primary-ink: #12113a;
    --primary-soft: #1e1d4a;
    --danger: #f87171;
    --danger-soft: #3b1515;
    --warn: #fbbf24;
    --warn-soft: #3a2a0a;
    --ok: #4ade80;
    --ok-soft: #0f2d1a;
    --blue: #60a5fa;
    --blue-soft: #132a4d;
    --gray-soft: #26324a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overscroll-behavior-y: none;
}
body.noscroll { overflow: hidden; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.danger-text { color: var(--danger); }
.ok-text { color: var(--ok); }
.right { text-align: right; }
.num { font-variant-numeric: tabular-nums; }

.view {
  max-width: 760px;
  margin: 0 auto;
  padding: calc(12px + var(--safe-t)) 16px calc(var(--nav-h) + var(--safe-b) + 90px);
}
.view.wide { max-width: 1200px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

/* Top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 14px; }
.topbar .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.topbar-right { display: flex; gap: 8px; align-items: center; }

/* Cards & sections */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.section { margin-top: 20px; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; margin: 0 2px 8px; }
.section-title h2 { font-size: 16px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 600px) { .stats.four { grid-template-columns: repeat(4, 1fr); } .stats.three { grid-template-columns: repeat(3, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: 12px; color: var(--muted); }
.stat.accent { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.stat.accent .label, .stat.accent .hint { color: inherit; opacity: .85; }

.banner { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 12px 14px; border-radius: var(--radius); background: var(--warn-soft); color: var(--warn); margin-bottom: 14px; font-size: 14px; }

/* Lists */
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.row:first-child { border-top: 0; }
.row:active { background: var(--bg); }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .end { text-align: right; flex-shrink: 0; }
.row .chev { color: var(--muted); }
.empty { padding: 22px 14px; text-align: center; color: var(--muted); font-size: 14px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; flex-shrink: 0; font-size: 14px; }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-reserved { background: var(--blue-soft); color: var(--blue); }
.b-checked_in { background: var(--ok-soft); color: var(--ok); }
.b-checked_out { background: var(--gray-soft); color: var(--muted); }
.b-cancelled { background: var(--danger-soft); color: var(--danger); }
.b-owing { background: var(--warn-soft); color: var(--warn); }
.b-late { background: var(--danger-soft); color: var(--danger); }

/* Room tiles */
.rooms-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 520px) { .rooms-grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 700px) { .rooms-grid { grid-template-columns: repeat(6, 1fr); } }
.tile { border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px; text-align: left; font: inherit; color: inherit; cursor: pointer; min-height: 68px; display: flex; flex-direction: column; justify-content: space-between; border-left-width: 5px; }
.tile .t-name { font-weight: 700; font-size: 14px; }
.tile .t-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.occupied { border-left-color: var(--ok); }
.tile.arriving { border-left-color: var(--blue); }
.tile.clean { border-left-color: var(--line); }
.tile.dirty { border-left-color: var(--warn); }
.tile.maintenance { border-left-color: var(--danger); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* Buttons */
.btn { appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-weight: 600; padding: 11px 14px; border-radius: 12px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; text-align: center; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; }
.btn.danger { color: var(--danger); }
.btn.danger-fill { background: var(--danger); color: #fff; border-color: transparent; }
.btn.ok { background: var(--ok); color: #fff; border-color: transparent; }
.btn.small { padding: 6px 10px; min-height: 34px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.icon-btn { appearance: none; border: 0; background: var(--bg); color: var(--text); width: 38px; height: 38px; border-radius: 50%; font-size: 18px; cursor: pointer; display: grid; place-items: center; flex-shrink: 0; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn-grid .full { grid-column: 1 / -1; }

.fab { position: fixed; right: max(16px, calc(50% - 364px)); bottom: calc(var(--nav-h) + var(--safe-b) + 16px); width: 58px; height: 58px; border-radius: 18px; border: 0; background: var(--primary); color: var(--primary-ink); font-size: 30px; line-height: 1; box-shadow: 0 8px 24px rgba(43, 42, 123, .35); cursor: pointer; z-index: 20; }

/* Chips / segmented filter */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin: 0 -16px 10px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 7px 13px; border-radius: 999px; font: inherit; font-size: 14px; white-space: nowrap; cursor: pointer; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip .count { opacity: .7; margin-left: 4px; }

/* Forms */
.search { width: 100%; margin-bottom: 10px; }
input, select, textarea {
  font: inherit; font-size: 16px; /* 16px stops iOS zooming */
  color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; width: 100%; min-height: 44px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.calc { background: var(--bg); border-radius: 12px; padding: 12px; margin: 4px 0 12px; font-size: 14px; }
.calc .tot { font-size: 20px; font-weight: 700; }
.warn { color: var(--danger); font-size: 14px; font-weight: 600; margin: -4px 0 10px; min-height: 0; }
.warn:empty { display: none; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px 0; margin: 0 0 12px; }
legend { font-size: 13px; color: var(--muted); padding: 0 4px; }

/* Month nav */
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; margin-bottom: 12px; }
.month-nav b { font-size: 16px; }

/* Horizontal bars */
.hbar { margin-bottom: 10px; }
.hbar-top { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; margin-bottom: 4px; }
.hbar-track { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.hbar-fill { height: 100%; background: var(--primary); border-radius: 99px; }
.hbar-fill.alt { background: var(--warn); }

/* Trend chart */
.trend { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; align-items: end; height: 150px; padding-top: 6px; }
.trend .col { display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.trend .pair { display: flex; gap: 3px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.trend .b { width: 40%; max-width: 18px; border-radius: 4px 4px 0 0; min-height: 2px; }
.trend .b.rev { background: var(--primary); }
.trend .b.exp { background: var(--warn); }
.trend .lbl { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* Booking chart */
.chart-tools { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.chart-tools input { width: auto; flex: 1; min-width: 140px; }
.chart-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); max-height: calc(100vh - var(--nav-h) - var(--safe-b) - 170px); -webkit-overflow-scrolling: touch; }
.chart { border-collapse: separate; border-spacing: 0; table-layout: fixed; }
.chart th, .chart td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 0; height: 46px; width: 48px; min-width: 48px; }
.chart thead th { position: sticky; top: 0; background: var(--card); z-index: 3; font-weight: 500; font-size: 11px; color: var(--muted); height: 50px; line-height: 1.2; }
.chart thead th b { display: block; font-size: 15px; color: var(--text); }
.chart thead th.today { background: var(--primary-soft); }
.chart thead th.today b { color: var(--primary); }
.chart .rcol { position: sticky; left: 0; z-index: 2; background: var(--card); width: 86px; min-width: 86px; padding: 0 8px; font-size: 13px; font-weight: 600; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chart thead .rcol { z-index: 4; }
.chart tr.free-row th { position: sticky; top: 50px; z-index: 3; height: 26px; font-size: 11px; background: var(--bg); color: var(--muted); }
.chart tr.free-row th.rcol { z-index: 4; background: var(--bg); }
.chart td.wk { background: color-mix(in srgb, var(--bg) 60%, transparent); }
.chart td.today { background: color-mix(in srgb, var(--primary-soft) 55%, transparent); }
.free { width: 100%; height: 100%; border: 0; background: transparent; cursor: pointer; padding: 0; }
.free:active { background: var(--primary-soft); }
.bar { display: block; width: calc(100% - 6px); margin: 0 3px; height: 36px; border-radius: 9px; border: 0; padding: 0 8px; font: inherit; font-size: 12px; font-weight: 600; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; border-left: 4px solid; }
.bar.st-reserved { background: var(--blue-soft); color: var(--blue); }
.bar.st-checked_in { background: var(--ok-soft); color: var(--ok); }
.bar.st-checked_out { background: var(--gray-soft); color: var(--muted); }
.bar.owing { box-shadow: inset 0 -3px 0 var(--warn); }

/* Key/value */
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin: 12px 0; }
.kv > div { background: var(--card); padding: 9px 12px; }
.kv span { display: block; font-size: 12px; color: var(--muted); }
.kv b { font-variant-numeric: tabular-nums; }

/* Bottom tab bar */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
.tabbar a { flex: 1; height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 11px; font-weight: 600; }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.on { color: var(--primary); }

/* Bottom sheet */
.sheet { position: fixed; inset: 0; z-index: 50; display: none; }
.sheet.open { display: block; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(2, 6, 23, .5); animation: fade .2s ease; }
.sheet-panel { position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; background: var(--card); border-radius: 20px 20px 0 0; padding: 8px 16px calc(20px + var(--safe-b)); animation: up .25s cubic-bezier(.2, .8, .2, 1); max-width: 640px; margin: 0 auto; }
@media (min-width: 700px) { .sheet-panel { bottom: auto; top: 50%; transform: translateY(-50%); border-radius: 20px; animation: fade .2s ease; max-height: 88vh; } }
.sheet-grip { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 10px; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 6px; }
.sheet-actions .btn { flex: 1; }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 20px); transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: .25s; z-index: 60; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Lock screen */
.lock { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: grid; place-items: center; padding: 24px; }
.lock .box { width: 100%; max-width: 320px; text-align: center; }
.lock img { width: 72px; height: 72px; border-radius: 18px; margin-bottom: 14px; }
.lock input { text-align: center; font-size: 24px; letter-spacing: .4em; margin: 16px 0 10px; }

.menu .row svg { width: 22px; height: 22px; stroke: var(--primary); fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Printable receipt */
.print-area { display: none; }
@media print {
  body > *:not(.print-area) { display: none !important; }
  .print-area { display: block !important; color: #000; font-size: 13px; }
  .print-area table { width: 100%; border-collapse: collapse; margin: 12px 0; }
  .print-area td, .print-area th { border-bottom: 1px solid #ccc; padding: 6px 4px; text-align: left; }
  .print-area .r { text-align: right; }
  .print-area h1 { font-size: 22px; }
  @page { margin: 16mm; }
}

/* Brand */
.brand-logo { height: 44px; width: auto; display: block; margin-bottom: 6px; }
@media (prefers-color-scheme: dark) { .brand-logo { background: #fff; border-radius: 8px; padding: 4px 8px; } }
.stat.accent { border-bottom: 4px solid var(--gold); }
.tabbar a.on::after { content: ""; width: 18px; height: 3px; border-radius: 3px; background: var(--gold); }

/* Sign-in screen */
.auth input { font-size: 16px; letter-spacing: normal; text-align: left; margin: 0 0 10px; }
.auth h2 { margin-bottom: 4px; }
.auth form p.muted { margin: 0 0 16px; }

/* Offline notice */
body.offline::before {
  content: "You're offline — changes can't be saved until the connection is back.";
  position: fixed; top: 0; left: 0; right: 0; z-index: 70;
  padding: calc(6px + var(--safe-t)) 12px 6px; text-align: center; font-size: 13px; font-weight: 600;
  background: var(--danger); color: #fff;
}
