:root {
  --navy: #17324d;
  --navy-2: #244d70;
  --ink: #17212b;
  --muted: #6b7785;
  --line: #dfe5eb;
  --soft: #f4f6f8;
  --white: #fff;
  --orange: #e99a31;
  --orange-soft: #fff2dc;
  --blue: #2877b8;
  --blue-soft: #e5f1fb;
  --gray: #7b8794;
  --gray-soft: #edf0f3;
  --green: #287a55;
  --green-soft: #e5f5ec;
  --red: #b63d3d;
  --red-soft: #fae7e7;
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: #eef2f5;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: #eef2f5; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at top right, #356d95 0, #17324d 42%, #10263a 100%); }
.auth-card { width: min(420px, 100%); padding: 36px; background: white; border-radius: 18px; box-shadow: 0 24px 80px #091c2c66; }
.auth-card h1 { margin: 18px 0 6px; font-size: 26px; }
.auth-card p { margin: 0 0 24px; color: var(--muted); }
.brand-mark { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 15px; color: white; background: var(--navy); font-weight: 800; font-size: 25px; }
.brand-mark.small { width: 40px; height: 40px; border-radius: 11px; font-size: 18px; }

.topbar { position: sticky; top: 0; z-index: 20; height: 72px; padding: 0 28px; display: flex; align-items: center; justify-content: space-between; gap: 28px; color: white; background: var(--navy); box-shadow: 0 2px 12px #10263a25; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 220px; }
.brand .brand-mark { background: white; color: var(--navy); }
.brand h1 { margin: 0; max-width: 260px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 17px; }
.brand p { margin: 2px 0 0; color: #b9cad8; font-size: 12px; }
nav { display: flex; align-self: stretch; }
nav button { padding: 0 22px; border: 0; color: #d2dfeb; background: transparent; border-bottom: 3px solid transparent; }
nav button:hover, nav button.active { color: white; background: #ffffff0c; border-bottom-color: #72b4e4; }

main { width: min(1760px, 100%); margin: 0 auto; padding: 24px; }
.view { display: none; }
.view.active { display: block; }
.panel { overflow: hidden; background: white; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 5px 22px #17324d0b; }
.panel-head { min-height: 78px; padding: 20px 22px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 19px; }
.panel-head p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }

.summary-grid { margin-bottom: 18px; display: grid; grid-template-columns: repeat(5, minmax(130px, 1fr)); gap: 12px; }
.summary-card { padding: 16px 18px; background: white; border: 1px solid var(--line); border-radius: 12px; }
.summary-card span { color: var(--muted); font-size: 13px; }
.summary-card strong { margin-top: 6px; display: block; color: var(--navy); font-size: 25px; }

.grid-toolbar { flex-wrap: wrap; }
.toolbar-actions, .filter-bar, .inline-form { display: flex; align-items: center; gap: 9px; }
.toolbar-actions button { white-space: nowrap; }
button { min-height: 38px; padding: 8px 13px; border: 1px solid transparent; border-radius: 8px; font-weight: 650; transition: .15s ease; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { color: white; background: var(--navy-2); }
button.primary:hover { background: var(--navy); }
button.secondary { color: var(--navy); background: white; border-color: #bfcbd5; }
button.secondary:hover { background: var(--soft); }
button.danger { color: white; background: var(--red); }
button.warning { color: #714300; background: #ffd998; }
button.full { width: 100%; }
.icon-button, .close-button { border: 0; background: transparent; color: inherit; font-size: 24px; }
.mobile-only { display: none; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.sync-button { min-height: 34px; padding: 6px 10px; display: inline-flex; align-items: center; gap: 7px; color: #eef7ff; background: #ffffff12; border-color: #ffffff28; font-size: 12px; }
.sync-button:hover { background: #ffffff20; }
.sync-button i { width: 8px; height: 8px; border-radius: 50%; background: #e8a546; }
.sync-button i.ok { background: #62cf93; }
.sync-button i.offline { background: #aab5bf; }
.sync-button i.pending { background: #f0ad4e; }
.text-button { min-height: 32px; color: var(--navy-2); background: transparent; border: 0; font-size: 13px; }
.text-button:hover { text-decoration: underline; }
.pairing-import { margin-top: 14px; padding-top: 16px; display: grid; gap: 12px; border-top: 1px solid var(--line); }
.security-hint { margin: 8px 0 0 !important; color: var(--red) !important; font-size: 12px; line-height: 1.55; }

input, select, textarea { width: 100%; min-height: 40px; padding: 8px 10px; color: var(--ink); background: white; border: 1px solid #bdc8d2; border-radius: 7px; outline: 0; }
input:focus, select:focus, textarea:focus { border-color: #4a89b7; box-shadow: 0 0 0 3px #4a89b726; }
label { display: grid; gap: 6px; color: #384653; font-size: 13px; font-weight: 650; }
textarea { resize: vertical; }

.legend { padding: 10px 20px; display: flex; flex-wrap: wrap; gap: 18px; color: var(--muted); background: #fafbfc; border-bottom: 1px solid var(--line); font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; }
.dot.waiting { background: var(--orange); }
.dot.occupied { background: var(--blue); }
.dot.checked-out { background: var(--gray); }
.clean-tag { padding: 2px 6px; border-radius: 5px; font-style: normal; font-size: 11px; font-weight: 700; }
.clean-tag.clean { color: var(--green); background: var(--green-soft); }
.clean-tag.dirty { color: var(--red); background: var(--red-soft); }

.room-grid-wrap { max-height: calc(100vh - 330px); min-height: 300px; overflow: auto; }
.room-grid { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; }
.room-grid th, .room-grid td { min-width: 118px; width: 118px; height: 68px; padding: 0; vertical-align: top; background: white; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.room-grid thead th { position: sticky; top: 0; z-index: 8; height: 52px; padding: 8px; text-align: center; background: #f7f9fb; font-size: 12px; }
.room-grid th:first-child, .room-grid td:first-child { position: sticky; left: 0; z-index: 7; min-width: 146px; width: 146px; }
.room-grid thead th:first-child { z-index: 10; }
.room-grid .today-column { background: #f4f9fd; }
.date-head strong { display: block; color: var(--navy); font-size: 13px; }
.date-head span { color: var(--muted); font-weight: 400; }
.room-label { height: 68px; padding: 10px 12px !important; background: #fbfcfd !important; }
.room-label strong { display: block; font-size: 15px; }
.room-label small { display: block; margin: 3px 0 5px; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.room-label button { min-height: auto; padding: 0; border: 0; background: none; }
.room-cell { position: relative; min-height: 67px; padding: 5px; cursor: pointer; }
.room-cell:hover { box-shadow: inset 0 0 0 2px #74a9ce; }
.empty-cell::after { content: "+"; position: absolute; right: 8px; bottom: 4px; color: #b9c4cc; opacity: 0; }
.empty-cell:hover::after { opacity: 1; }
.stay-chip { height: 57px; padding: 7px 8px; overflow: hidden; border-radius: 7px; border-left: 4px solid; }
.stay-chip.waiting { color: #65400d; background: var(--orange-soft); border-color: var(--orange); }
.stay-chip.checked_in { color: #123d60; background: var(--blue-soft); border-color: var(--blue); }
.stay-chip.checked_out { color: #4f5962; background: var(--gray-soft); border-color: var(--gray); }
.stay-chip strong { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 13px; }
.stay-chip span { display: block; margin-top: 4px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 11px; opacity: .78; }
.multi-stay { height: auto; min-height: 27px; margin-bottom: 3px; padding: 3px 5px; }

.filter-bar { padding: 16px 20px; background: #fafbfc; border-bottom: 1px solid var(--line); }
.filter-bar > *:first-child { flex: 2; min-width: 220px; }
.filter-bar > * { flex: 1; }
.table-wrap { overflow: auto; }
.data-table { width: 100%; min-width: 980px; border-collapse: collapse; }
.data-table th, .data-table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); font-size: 13px; }
.data-table th { color: #4f5d69; background: #f7f9fb; white-space: nowrap; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: #f7fafc; }
.status-pill { display: inline-block; padding: 4px 8px; border-radius: 999px; font-size: 11px; font-weight: 750; }
.status-pill.waiting { color: #744700; background: var(--orange-soft); }
.status-pill.checked_in { color: #154e78; background: var(--blue-soft); }
.status-pill.checked_out, .status-pill.cancelled { color: #59646e; background: var(--gray-soft); }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.setting-list { padding: 0 20px; }
.setting-row { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 14px; border-bottom: 1px solid var(--line); }
.setting-row:last-child { border-bottom: 0; }
.setting-row strong { display: block; }
.setting-row small { display: block; margin-top: 3px; color: var(--muted); }
.setting-row .row-actions { display: flex; gap: 7px; }
.system-block { margin: 18px 22px; display: grid; gap: 7px; }
.system-block code { padding: 10px; overflow-wrap: anywhere; color: var(--navy); background: var(--soft); border-radius: 7px; }
.sync-status-card { margin: 18px 22px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.sync-status-card > div { padding: 13px; background: var(--soft); border-radius: 9px; }
.sync-status-card span { display: block; color: var(--muted); font-size: 12px; }
.sync-status-card strong { display: block; margin-top: 5px; color: var(--navy); font-size: 14px; }
.pairing-output { padding: 20px 22px; display: grid; gap: 12px; }
.pairing-output textarea, .pairing-import textarea { font-family: ui-monospace, Consolas, monospace; font-size: 11px; word-break: break-all; }
.conflict-list { display: grid; gap: 7px; }
.conflict-list > div { padding: 10px 12px; background: var(--red-soft); border-radius: 7px; color: #7d2929; font-size: 13px; }
.notice { margin: 18px 22px; padding: 12px; color: #6e4c12; background: #fff6df; border-radius: 8px; font-size: 13px; }
.inline-form { padding: 22px; }
.inline-form input { flex: 1; }
.restore-box, .password-form { padding: 20px 22px; display: grid; gap: 12px; }
.restore-box { grid-template-columns: minmax(0, 1fr) auto; align-items: end; border-top: 1px solid var(--line); }
.migration-box { margin: 0 22px 22px; padding: 16px; background: var(--soft); border-radius: 10px; }
.migration-box h3 { margin: 0; font-size: 15px; }
.migration-box p { margin: 5px 0 12px; color: var(--muted); font-size: 12px; }
.migration-box > div { margin-top: 8px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 8px; }
.migration-box > div:first-of-type { grid-template-columns: minmax(0, 1fr) auto; }
.password-form button { justify-self: start; }
.danger-zone { border-color: #eccaca; }
.danger-zone > button { margin: 22px; }
.empty-state, .loading { padding: 44px 20px; text-align: center; color: var(--muted); }

dialog { border: 0; }
dialog::backdrop { background: #10263a99; backdrop-filter: blur(2px); }
.modal { width: min(520px, calc(100vw - 28px)); max-height: calc(100vh - 28px); padding: 0; overflow: auto; border-radius: 14px; box-shadow: 0 24px 90px #07162266; }
.modal.wide { width: min(940px, calc(100vw - 28px)); }
.modal form { padding: 22px; display: grid; gap: 18px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.modal-head h2 { margin: 0; }
.modal-head p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.form-grid { display: grid; gap: 13px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.section-title { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.section-title h3 { margin: 0; font-size: 16px; }
.section-title p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
#guest-list { margin-top: 10px; display: grid; gap: 8px; }
.guest-row { display: grid; grid-template-columns: 1fr 1.4fr 1fr 38px; gap: 8px; align-items: end; padding: 10px; background: var(--soft); border-radius: 8px; }
.guest-row button { padding: 5px; color: var(--red); background: white; border-color: #ebc3c3; }
.stay-ledger { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; padding-top: 4px; }
.stay-ledger h3 { margin: 0 0 7px; font-size: 14px; }
.stay-ledger .full-row { grid-column: 1 / -1; }
.ledger-list { overflow: hidden; border: 1px solid var(--line); border-radius: 8px; }
.ledger-item { padding: 8px 10px; display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--line); font-size: 12px; }
.ledger-item:last-child { border-bottom: 0; }
.ledger-item span { color: var(--muted); }
.ledger-empty { padding: 10px; color: var(--muted); font-size: 12px; }
.calculation-preview { padding: 12px; color: var(--navy); background: #eef6fb; border: 1px solid #c9dfef; border-radius: 8px; font-size: 13px; font-weight: 700; }
.locked-field { opacity: .72; }
.checkbox { display: flex; align-items: center; gap: 8px; }
.checkbox input { width: auto; min-height: auto; }
.form-error { min-height: 18px; margin: 0; color: var(--red); font-size: 13px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; padding-top: 4px; }
.modal-actions.split { justify-content: space-between; align-items: center; }
.modal-actions > div { display: flex; gap: 8px; }
#stay-status-actions { flex-wrap: wrap; }
.toast { position: fixed; z-index: 100; right: 22px; bottom: 22px; max-width: min(420px, calc(100vw - 44px)); padding: 12px 16px; transform: translateY(90px); opacity: 0; color: white; background: #19364e; border-radius: 9px; box-shadow: 0 10px 30px #10263a44; transition: .2s ease; pointer-events: none; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast.error { background: var(--red); }

@media (max-width: 900px) {
  .mobile-only { display: inline-grid; }
  .topbar { height: 58px; padding: env(safe-area-inset-top) 12px 0; }
  .brand { min-width: 0; }
  .brand-mark.small { width: 35px; height: 35px; }
  #menu-toggle { display: none; }
  nav { position: fixed; z-index: 50; left: 0; right: 0; bottom: 0; height: calc(58px + env(safe-area-inset-bottom)); padding: 0 5px env(safe-area-inset-bottom); display: flex; justify-content: space-around; color: var(--ink); background: #fffffff2; border-top: 1px solid var(--line); box-shadow: 0 -5px 22px #17324d14; backdrop-filter: blur(12px); }
  nav button { min-width: 0; flex: 1; min-height: 56px; padding: 5px 2px; color: #64717d; text-align: center; border: 0; border-top: 3px solid transparent; border-radius: 0; font-size: 12px; }
  nav button:hover, nav button.active { color: var(--navy); background: #eef5fa; border: 0; border-top: 3px solid var(--blue); }
  main { padding: 10px 10px calc(72px + env(safe-area-inset-bottom)); }
  .summary-grid { margin: 0 -10px 10px; padding: 0 10px 2px; display: flex; gap: 7px; overflow-x: auto; scroll-snap-type: x proximity; }
  .summary-card { min-width: 94px; padding: 10px 11px; flex: 1 0 94px; scroll-snap-align: start; }
  .summary-card:last-child { grid-column: auto; }
  .summary-card strong { margin-top: 3px; font-size: 20px; }
  .panel-head { padding: 16px; }
  .toolbar-actions { width: 100%; overflow-x: auto; padding-bottom: 2px; }
  .toolbar-actions > * { flex: 0 0 auto; }
  .room-grid-wrap { max-height: calc(100dvh - 300px); min-height: 320px; }
  .room-grid th, .room-grid td { min-width: 104px; width: 104px; height: 63px; }
  .room-grid th:first-child, .room-grid td:first-child { min-width: 98px; width: 98px; }
  .room-label { height: 63px; padding: 8px !important; }
  .room-label small { font-size: 10px; }
  .room-cell { min-height: 62px; padding: 4px; }
  .stay-chip { height: 54px; padding: 6px; }
  .settings-grid { grid-template-columns: 1fr; }
  .filter-bar { flex-wrap: wrap; }
  .filter-bar > * { flex: 1 1 150px; }
  .filter-bar > *:first-child { flex-basis: 100%; min-width: 0; }
  .restore-box { grid-template-columns: 1fr; }
  .migration-box > div, .migration-box > div:first-of-type { grid-template-columns: 1fr; }
  .form-grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .guest-row { grid-template-columns: 1fr 1fr 38px; }
  .stay-ledger { grid-template-columns: 1fr; }
  .stay-ledger .full-row { grid-column: auto; }
  .guest-row label:nth-child(2) { grid-column: 1 / 2; }
  .guest-row label:nth-child(3) { grid-column: 2 / 3; grid-row: 1; }
  .guest-row button { grid-column: 3; grid-row: 1; }
  .modal-actions.split { align-items: stretch; flex-direction: column; }
  .modal-actions.split > div:last-child { justify-content: flex-end; }
  .sync-status-card { margin: 14px 16px; grid-template-columns: 1fr; gap: 6px; }
  .sync-status-card > div { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; }
  .sync-status-card strong { margin-top: 0; text-align: right; }
  .sync-button span { display: none; }
  .sync-button { width: 34px; justify-content: center; padding: 5px; }
  #install-app { display: none !important; }
}

@media (max-width: 520px) {
  .brand h1 { max-width: 190px; font-size: 15px; }
  .brand p { display: none; }
  .summary-grid { gap: 7px; }
  .summary-card { padding: 12px; }
  .summary-card strong { font-size: 21px; }
  .grid-panel .panel-head p { display: none; }
  .room-grid-wrap { max-height: calc(100dvh - 285px); }
  .grid-toolbar { min-height: auto; }
  .grid-toolbar > div:first-child { width: 100%; }
  .toolbar-actions #print-grid { display: none; }
  .form-grid.three { grid-template-columns: 1fr; }
  .guest-row { grid-template-columns: 1fr 38px; }
  .guest-row label, .guest-row label:nth-child(2), .guest-row label:nth-child(3) { grid-column: 1; grid-row: auto; }
  .guest-row button { grid-column: 2; grid-row: 1; }
  .auth-card { padding: 26px 22px; }
}

@media print {
  @page { size: A4 landscape; margin: 8mm; }
  body, :root { background: white; }
  .topbar, .summary-grid, .toolbar-actions, .legend { display: none !important; }
  main { width: 100%; padding: 0; }
  .panel { border: 0; box-shadow: none; }
  .panel-head { min-height: auto; padding: 0 0 10px; }
  .panel-head p { display: block !important; }
  .room-grid-wrap { max-height: none; min-height: 0; overflow: visible; }
  .room-grid { width: 100%; table-layout: fixed; }
  .room-grid th, .room-grid td { min-width: 0; width: auto; height: 42px; }
  .room-grid th:first-child, .room-grid td:first-child { position: static; min-width: 76px; width: 76px; }
  .room-grid thead th { position: static; height: 36px; padding: 3px; font-size: 9px; }
  .room-label { height: 42px; padding: 4px !important; }
  .room-label strong { font-size: 10px; }
  .room-label small, .room-label .clean-tag { font-size: 7px; }
  .room-cell { min-height: 41px; padding: 2px; }
  .stay-chip { height: 37px; padding: 3px; border-left-width: 2px; }
  .stay-chip strong { font-size: 8px; }
  .stay-chip span { margin-top: 2px; font-size: 6px; }
}
