:root {
  --bg: #f5f5f7;
  --surface: #fff;
  --sidebar: #eeeef1;
  --sidebar-hover: #e3e3e8;
  --subtle: #fafafb;
  --text: #1d1d1f;
  --muted: #626269;
  --line: #e3e3e8;
  --control-line: #b6b6bf;
  --accent: #0066cc;
  --accent-hover: #0054a8;
  --accent-soft: #e8f1fb;
  --neutral: #ececf0;
  --neutral-hover: #dfdfe5;
  --green-bg: #e6f3ec;
  --green: #236041;
  --amber-bg: #fdf1dc;
  --amber: #78420a;
  --red: #b42318;
  --red-hover: #8f1b13;
  --red-bg: #fdecea;
  --control: 38px;
  color: var(--text);
  background: var(--bg);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  accent-color: var(--accent);
  caret-color: var(--accent);
}

@media (pointer: coarse) { :root { --control: 44px; } }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; -webkit-font-smoothing: antialiased; }
::selection { background: #cfe3f8; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }

a { color: var(--accent); text-underline-offset: 2px; }
p { line-height: 1.55; max-width: 72ch; }
h1 { font-size: 26px; font-weight: 650; letter-spacing: -.022em; line-height: 1.2; margin: 0; }
h2 { font-size: 17px; font-weight: 620; letter-spacing: -.012em; margin: 0 0 8px; }
h3 { font-size: 15px; margin: 0 0 6px; }
.sub { color: var(--muted); margin: 6px 0 0; font-size: 14px; }
.muted { color: var(--muted); }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 12px; top: -60px; background: var(--surface); padding: 12px; z-index: 10; }
.skip:focus { top: 12px; }

/* Controls */
button, .button { min-height: var(--control); display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 0; border-radius: 8px; padding: 7px 14px; background: var(--accent); color: #fff; font-weight: 590; font-size: 14px; text-decoration: none; white-space: nowrap; cursor: pointer; }
button .icon, .button .icon { width: 16px; height: 16px; stroke-width: 2; }
button:hover, .button:hover { background: var(--accent-hover); }
button:active, .button:active { transform: translateY(.5px); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.secondary, .button.secondary { background: var(--neutral); color: #25252b; }
button.secondary:hover, .button.secondary:hover { background: var(--neutral-hover); }
button.danger { background: var(--red); }
button.danger:hover { background: var(--red-hover); }
button.danger-quiet { background: var(--neutral); color: var(--red); }
button.danger-quiet:hover { background: var(--red-bg); }
.link-button { padding: 0; min-height: 0; background: transparent; color: var(--accent); font-weight: 500; font-size: inherit; }
.link-button:hover { background: transparent; text-decoration: underline; }
input, select, textarea { width: 100%; min-height: var(--control); padding: 7px 11px; border: 1px solid var(--control-line); border-radius: 8px; background: var(--surface); color: var(--text); font-size: 14px; }
input:hover, select:hover, textarea:hover { border-color: #8e8e98; }
input::placeholder { color: #707079; }
textarea { line-height: 1.5; }
.password-control { position: relative; display: block; }
.password-control input { padding-right: 68px; }
.password-control .password-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); min-height: 30px; padding: 3px 9px; background: transparent; color: var(--accent); }
.password-control .password-toggle:hover { background: var(--accent-soft); }

/* Shell */
.shell { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 100vh; }
aside { position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; padding: 18px 12px 14px; background: var(--sidebar); border-right: 1px solid var(--line); }
.brand { display: flex; gap: 10px; align-items: center; padding: 2px 8px; color: inherit; font-size: 14px; font-weight: 640; line-height: 1.2; text-decoration: none; }
.brand small, .who small { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; font-weight: 400; }
.mark { flex: none; width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px; background: var(--text); color: #fff; font-size: 17px; font-weight: 600; overflow: hidden; }
.mark img { width: 100%; height: 100%; display: block; }
nav { display: grid; gap: 2px; margin-top: 22px; }
nav a { display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 6px 10px; border-radius: 8px; color: #45454c; font-size: 14px; font-weight: 500; text-decoration: none; }
nav a .icon { color: #6c6c74; }
nav a:hover { background: var(--sidebar-hover); }
nav a[aria-current=page] { background: var(--surface); color: var(--accent); font-weight: 590; }
nav a[aria-current=page] .icon { color: var(--accent); }
.nav-divider { height: 1px; margin: 10px; background: #d9d9df; }
.sidebar-note { margin-top: auto; padding: 14px 8px 0; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: center; font-size: 13px; font-weight: 590; line-height: 1.25; }
.avatar { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; background: #dcdce2; color: #3c3c43; font-weight: 620; }
.who { overflow-wrap: anywhere; }
.who-links { grid-column: 1 / -1; display: flex; gap: 14px; align-items: center; font-weight: 500; }
.who-links a { text-decoration: none; }
.who-links a:hover { text-decoration: underline; }
main { width: 100%; max-width: 1360px; margin: 0 auto; padding: 28px 36px 64px; min-width: 0; }

/* Page header */
header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 0 0 20px; }
.header-actions, .actions, .empty-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.header-actions { justify-content: flex-end; }
.back-link { display: inline-flex; align-items: center; gap: 2px; margin: 0 0 8px -5px; color: var(--muted); font-size: 13px; text-decoration: none; }
.back-link:hover { color: var(--accent); }
.back-link .icon { width: 16px; height: 16px; }

/* Month switcher */
.month-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 6px; min-height: var(--control); margin: 0 0 14px; }
.month-name { margin: 0 6px; font-size: 19px; font-weight: 640; letter-spacing: -.016em; font-variant-numeric: tabular-nums; }
.icon-button { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px; color: #45454c; }
.icon-button:hover { background: var(--neutral); }
.month-link { margin-left: 10px; font-size: 13px; text-decoration: none; }
.month-link:hover { text-decoration: underline; }
.month-basis { margin-left: auto; color: var(--muted); font-size: 12px; }

/* Summary */
.summary { display: flex; flex-wrap: wrap; gap: 1px; margin: 0 0 16px; background: var(--line); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.summary > div { flex: 1 1 170px; min-width: 0; padding: 14px 18px; background: var(--surface); }
.summary small { display: block; margin-bottom: 5px; color: var(--muted); font-size: 12.5px; }
.summary strong { display: block; font-size: 21px; font-weight: 610; letter-spacing: -.018em; line-height: 1.2; font-variant-numeric: tabular-nums; }
.summary-note { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.summary-note span { white-space: nowrap; }
.carry-over { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; max-width: none; margin: 0 0 16px; padding: 10px 14px; border-radius: 10px; background: var(--amber-bg); color: var(--amber); font-size: 13.5px; }
.carry-over strong { font-weight: 640; font-variant-numeric: tabular-nums; }
.carry-over .link-button { color: var(--amber); font-weight: 600; text-decoration: underline; }

/* Panels */
.panel { margin-bottom: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.panel-pad { padding: 22px; }
.panel-pad h2 + .sub { margin-top: -2px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.toolbar h2 { margin: 0; }
.report-heading { padding: 16px 18px 10px; }
.report-heading h2 { margin: 0; }
#booking-form, #payment-form, #settings-form, #reset-password { max-width: 860px; }
#payout-form .form-grid, #account-form .form-grid { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.setting-section { max-width: 860px; margin-top: 28px; }

/* Ledger toolbar and filters */
.ledger-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.search-field { position: relative; flex: 1 1 260px; max-width: 440px; }
.search-field .icon { position: absolute; left: 10px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-field input { padding-left: 33px; }
.count { min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 650; line-height: 18px; text-align: center; }
#filter-toggle[aria-expanded=true] { background: var(--neutral-hover); }
.ledger-count { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: flex-end; gap: 2px 10px; margin-left: auto; font-size: 13px; }
.ledger-count strong { font-weight: 590; font-variant-numeric: tabular-nums; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 14px; align-items: end; padding: 14px 18px 16px; border-bottom: 1px solid var(--line); background: var(--subtle); }
.filter-clear { justify-self: start; }
.filter-result { display: flex; justify-content: space-between; gap: 12px; padding: 11px 18px; color: var(--muted); font-size: 13px; }

/* Tables */
.table-wrap { overflow: auto; scrollbar-width: thin; scrollbar-color: #c9c9d0 transparent; }
table { width: 100%; border-collapse: collapse; text-align: left; white-space: nowrap; font-size: 14px; }
th { padding: 9px 18px; background: var(--subtle); border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; font-weight: 520; }
td { padding: 11px 18px; border-bottom: 1px solid #efeff2; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fbfbfc; }
td small { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.money { text-align: right; font-variant-numeric: tabular-nums; }
.guest-link { color: var(--text); font-weight: 590; text-decoration: none; }
.guest-link:hover { color: var(--accent); text-decoration: underline; }
.cash-amount { color: #8a4b08; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--neutral); color: #4f4f57; font-size: 11.5px; font-weight: 550; line-height: 18px; }
.badge.paid { background: var(--green-bg); color: var(--green); }
.badge.part, .cash-badge { background: var(--amber-bg); color: var(--amber); }
.payout-notes { white-space: normal; min-width: 220px; max-width: 360px; overflow-wrap: anywhere; }
.empty { padding: 52px 24px; text-align: center; }
.empty h2 { font-size: 18px; }
.empty p { margin: 6px auto 18px; color: var(--muted); }
.empty-actions { justify-content: center; }

/* Forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 18px; }
.field { display: grid; gap: 6px; align-content: start; }
.field label { font-size: 13px; font-weight: 570; }
.field small { color: var(--muted); }
.full { grid-column: 1 / -1; }
.section-title { margin: 14px 0 0; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.section-title:first-child { margin-top: 0; }
.actions { margin-top: 22px; }
.form-foot { margin: 12px 0 0; color: var(--muted); font-size: 12.5px; }
.error { margin-bottom: 14px; padding: 11px 13px; border-radius: 8px; background: var(--red-bg); color: #8f1b13; font-size: 14px; }
.error:empty { display: none; }
.payment-callout { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 20px; padding: 11px 14px; border-radius: 9px; background: var(--accent-soft); color: #164f85; font-size: 13.5px; }
.stay-hint { margin: -6px 0 0; color: var(--muted); font-size: 13px; }
.details { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 22px; }
.detail-item small { display: block; margin-bottom: 4px; color: var(--muted); font-size: 12.5px; }
.property { padding: 18px 20px; border-bottom: 1px solid var(--line); }
.property:last-child { border-bottom: 0; }
.property h2 { margin: 0; }
.units { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.unit { padding: 3px 9px; border-radius: 6px; background: var(--bg); font-size: 13px; font-variant-numeric: tabular-nums; }
.settings-list { display: grid; gap: 10px; margin-top: 16px; }
.settings-row { display: grid; grid-template-columns: 1fr 130px auto; gap: 10px; align-items: end; }
.settings-row.simple { grid-template-columns: 1fr auto; }
.settings-row:has([name=units]) { grid-template-columns: 1fr 1fr auto; }
.settings-row label { display: grid; gap: 5px; color: var(--muted); font-size: 12px; }
.settings-row button { background: var(--neutral); color: #404047; }
.settings-row button:hover { background: var(--neutral-hover); }

/* Sign in */
.signed-out .shell { display: block; }
.signed-out aside { display: none; }
.signed-out main { max-width: 460px; padding: max(48px, 12vh) 20px 48px; }
.signed-out header { margin-bottom: 18px; }
.auth-mark { margin-bottom: 18px; }
.auth-form .form-grid { grid-template-columns: 1fr; }
.auth-form .actions button { width: 100%; }

/* Toast */
#notice:not(:empty) { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 5; max-width: 90vw; padding: 10px 18px; border-radius: 10px; background: var(--text); color: #fff; font-size: 14px; }

@media (prefers-reduced-motion: no-preference) {
  button, a, input, select, textarea { transition: background-color .15s ease-out, border-color .15s ease-out, color .15s ease-out; }
}

@media (max-width: 1000px) {
  .shell { grid-template-columns: 196px minmax(0, 1fr); }
  main { padding: 22px 20px 56px; }
}

/* Phones: a top bar for identity and a thumb-reach tab bar for navigation */
@media (max-width: 650px) {
  .shell { display: block; }
  aside { position: static; height: auto; overflow: visible; display: grid; grid-template-columns: 1fr; gap: 10px; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0; }
  .brand small { display: none; }
  .sidebar-note { margin: 0; padding: 0; grid-template-columns: minmax(0, 1fr) auto; }
  .avatar { display: none; }
  .who { font-size: 13px; }
  .who small { display: inline; margin-left: 6px; }
  .who-links { grid-column: auto; }
  nav { position: fixed; z-index: 4; left: 0; right: 0; bottom: 0; display: flex; gap: 0; margin: 0; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); overflow-x: auto; background: var(--surface); border-top: 1px solid var(--line); scrollbar-width: none; }
  nav::-webkit-scrollbar { display: none; }
  nav a { flex: 0 0 72px; flex-direction: column; justify-content: center; gap: 3px; min-height: 50px; padding: 5px 2px; font-size: 11px; line-height: 1.1; text-align: center; }
  nav a:hover { background: transparent; }
  nav a[aria-current=page] { background: transparent; }
  .nav-divider { display: none; }
  main { padding: 18px 16px 104px; }
  #notice:not(:empty) { bottom: 76px; width: max-content; }
  .signed-out main { padding-bottom: 48px; }
  h1 { font-size: 24px; }
  header { align-items: center; }
  .month-basis { width: 100%; margin: 2px 0 0 6px; }
  .summary strong { font-size: 18px; }
  .summary > div { flex-basis: 150px; padding: 12px 14px; }
  .summary-note { font-size: 11.5px; }
  .panel-pad { padding: 18px 16px; }
  .form-grid, .details { grid-template-columns: 1fr; }
  .full { grid-column: auto; }
  .toolbar { padding: 12px 14px; }
  .ledger-count { width: 100%; justify-content: space-between; margin: 0; }
  .search-field { max-width: none; }
  .filters { grid-template-columns: 1fr; padding: 14px; }
  #commission-filters { grid-template-columns: 1fr 1fr; }
  #commission-filters .field { grid-column: 1 / -1; }
  td, th { padding: 10px 14px; }
  .filter-result { flex-direction: column; gap: 4px; padding: 11px 14px; }
  .settings-row { grid-template-columns: 1fr 95px; }
  .settings-row button { grid-column: 1 / -1; justify-self: start; }
  .settings-row.simple { grid-template-columns: 1fr auto; }
  .settings-row.simple button { grid-column: auto; }
  .settings-row:has([name=units]) { grid-template-columns: 1fr; }
  .settings-row:has([name=units]) button { grid-column: auto; }

  /* The bookings ledger reads as stacked rows instead of a sideways scroll */
  .ledger { white-space: normal; }
  .ledger thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .ledger, .ledger tbody, .ledger tr, .ledger td { display: block; }
  .ledger tr { padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .ledger tbody tr:last-child { border-bottom: 0; }
  .ledger td { display: flex; justify-content: space-between; gap: 16px; padding: 4px 0; border: 0; text-align: right; }
  .ledger td::before { content: attr(data-label); flex: none; color: var(--muted); font-size: 13px; text-align: left; }
  .ledger td > div { min-width: 0; overflow-wrap: anywhere; }
  .ledger .guest-cell { padding: 0 0 6px; text-align: left; }
  .ledger .guest-cell::before { content: none; }
}
