:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #f7f7f9;
  --border: #e8e8ec;
  --border-strong: #d8d8de;
  --text: #1c1c1e;
  --text-muted: #6e6e73;
  --text-faint: #aeaeb2;
  --primary: #007aff;
  --primary-dark: #0062cc;
  --primary-light: #e8f1ff;
  --primary-ring: rgba(0, 122, 255, 0.18);
  --danger: #ff3b30;
  --danger-light: #ffece9;
  --success: #34c759;
  --success-light: #e8f9ec;
  --warning: #ff9500;
  --warning-light: #fff3e2;
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgba(20, 20, 22, 0.04);
  --shadow: 0 2px 10px rgba(20, 20, 22, 0.06);
  --shadow-lg: 0 24px 50px -18px rgba(20, 20, 22, 0.35);
  --ease: cubic-bezier(0.25, 0.8, 0.25, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable", "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

/* ---------- Topbar ---------- */

header.topbar {
  background: rgba(242, 242, 247, 0.78);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid rgba(60, 60, 67, 0.29);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 20;
}

header.topbar .brand {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  object-fit: cover;
}

nav.mainnav { display: flex; gap: 2px; align-items: center; }
nav.mainnav a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-weight: 590;
  font-size: 13.5px;
  padding: 6px 12px;
  border-radius: 999px;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
nav.mainnav a svg { flex-shrink: 0; }
nav.mainnav a:hover { color: var(--text); background: rgba(60, 60, 67, 0.06); }
nav.mainnav a.active { color: var(--primary); background: var(--primary-light); }

.userbox { display: flex; align-items: center; gap: 10px; color: var(--text-muted); font-size: 13.5px; }
.btn.btn-icon {
  padding: 8px;
  border-radius: 50%;
  line-height: 0;
}
.btn.btn-icon.btn-sm { padding: 7px; }

/* ---------- Bottom tab bar (mobile) ---------- */

nav.tabbar { display: none; }
.userbox span::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  margin-right: 6px;
  box-shadow: 0 0 0 3px var(--success-light);
}

/* ---------- Layout ---------- */

main { max-width: 1120px; margin: 0 auto; padding: 28px 24px 60px; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}

h1 { font-size: 28px; margin: 0 0 4px; font-weight: 750; letter-spacing: -0.022em; }
h2 { font-size: 17px; margin: 0 0 14px; font-weight: 700; letter-spacing: -0.01em; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
}

/* ---------- Tables ---------- */

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px; font-size: 14px; }
thead th {
  color: var(--text-faint);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background 0.12s var(--ease); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 980px;
  border: none;
  background: rgba(60, 60, 67, 0.06);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 590;
  text-decoration: none;
  transition: background 0.15s var(--ease), box-shadow 0.15s var(--ease), transform 0.08s var(--ease);
}
.btn:hover { background: rgba(60, 60, 67, 0.1); text-decoration: none; }
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--primary); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-danger:hover { background: #ffdcd8; }

.btn-sm { padding: 6px 13px; font-size: 12.5px; }

form.inline { display: inline; }

/* ---------- Forms ---------- */

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 590; margin-bottom: 6px; font-size: 13px; color: var(--text-muted); }
.form-row { display: flex; gap: 14px; }
.form-row .form-group { flex: 1; }

input, select, textarea {
  width: 100%;
  padding: 10px 13px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  background: var(--surface-2);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border);
  transition: box-shadow 0.15s var(--ease), background 0.15s var(--ease);
}
input:hover, select:hover, textarea:hover { box-shadow: inset 0 0 0 1px var(--border-strong); }
input:focus, select:focus, textarea:focus {
  outline: none;
  background: var(--surface);
  box-shadow: 0 0 0 4px var(--primary-ring), inset 0 0 0 1.5px var(--primary);
}
textarea { resize: vertical; min-height: 70px; }

select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  cursor: pointer;
  padding-right: 34px;
  background: var(--surface-2) url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236e6e73' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 11px center/16px 16px;
}
select:focus {
  background: var(--surface) url("data:image/svg+xml;charset=UTF-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23007aff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 11px center/16px 16px;
}
select::-ms-expand { display: none; }

input[type="checkbox"], input[type="radio"] {
  width: auto;
  accent-color: var(--primary);
  box-shadow: none;
}

/* ---------- Alerts ---------- */

.alert {
  padding: 12px 15px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: flex-start;
  gap: 9px;
}
.alert::before { content: "⚠"; flex-shrink: 0; }
.alert-error { background: var(--danger-light); color: #c4291f; }

/* ---------- Badges ---------- */

.badge {
  display: inline-block;
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.badge-confirmed { background: var(--primary-light); color: var(--primary); }
.badge-checked_in { background: var(--success-light); color: var(--success); }
.badge-checked_out { background: var(--bg); color: var(--text-muted); }
.badge-cancelled { background: var(--danger-light); color: var(--danger); }

/* ---------- Tabs (iOS segmented control) ---------- */

.tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 18px;
  background: rgba(118, 118, 128, 0.12);
  padding: 2px;
  border-radius: 10px;
  width: fit-content;
}
.tabs a {
  padding: 6px 16px;
  border-radius: 8px;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 590;
  transition: background 0.2s var(--ease), color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.tabs a:hover { color: var(--text); }
.tabs a.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }

/* ---------- Calendar ---------- */

.calendar-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
table.calendar { border-collapse: separate; border-spacing: 0; }
table.calendar th, table.calendar td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  padding: 0;
  text-align: center;
  min-width: 48px;
  font-size: 11.5px;
}
table.calendar thead th {
  padding: 8px 4px 10px;
  color: var(--text-faint);
  font-weight: 700;
  border-bottom: 1px solid var(--border-strong);
  background: var(--surface-2);
}
table.calendar thead th.weekend { background: #eef0f6; }
.cal-weekday {
  display: block;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  margin-bottom: 3px;
}
.cal-daynum {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
table.calendar thead th.today .cal-weekday { color: var(--primary); }
table.calendar thead th.today .cal-daynum { background: var(--primary); color: #fff; }

table.calendar th.roomcol, table.calendar td.roomcol {
  min-width: 152px;
  text-align: left;
  padding: 11px 14px;
  font-weight: 700;
  font-size: 13px;
  background: var(--surface);
  position: sticky;
  left: 0;
  box-shadow: 2px 0 4px -2px rgba(20, 20, 22, 0.08);
  border-right: 1px solid var(--border-strong);
}
table.calendar td.roomcol span { display: block; font-weight: 500; color: var(--text-faint); font-size: 11.5px; margin-top: 1px; margin-left: 15px; }
table.calendar tbody tr:last-child td { border-bottom: none; }

.room-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 8px;
  margin-bottom: 1px;
}
.room-dot-0 { background: var(--primary); }
.room-dot-1 { background: var(--success); }
.room-dot-2 { background: var(--warning); }
.room-dot-3 { background: #af52de; }
.room-dot-4 { background: #ff2d55; }

table.calendar td.weekend { background: #fafafd; }

table.calendar td.free a {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  color: var(--text-faint);
  font-size: 14px;
  font-weight: 400;
  opacity: 0.55;
  transition: background 0.12s var(--ease), color 0.12s var(--ease), opacity 0.12s var(--ease);
}
table.calendar td.free:hover { background: var(--primary-light); }
table.calendar td.free:hover a { opacity: 1; color: var(--primary); font-weight: 700; }

table.calendar td.booked a {
  display: flex;
  align-items: center;
  height: 40px;
  padding: 0 9px;
  margin: 4px 3px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
  text-decoration: none;
  box-shadow: 0 1px 3px rgba(0, 122, 255, 0.35);
  transition: filter 0.12s var(--ease), transform 0.1s var(--ease);
}
table.calendar td.booked a:hover { filter: brightness(1.08); transform: translateY(-1px); }
table.calendar td.booked.status-checked_in a { background: var(--success); box-shadow: 0 1px 3px rgba(52, 199, 89, 0.35); }
table.calendar td.today { background: var(--warning-light); }
table.calendar td.today.weekend { background: #fdecd2; }

/* ---------- Stats ---------- */

.stat-row { display: flex; gap: 14px; }
.stat {
  flex: 1;
  padding: 16px 18px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
}
.stat .value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.stat .label { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; font-weight: 500; }

.muted { color: var(--text-muted); }
.text-right { text-align: right; }

.detail-grid { display: flex; flex-wrap: wrap; gap: 20px 36px; }
.detail-item { flex: 1 1 150px; }
.detail-item .detail-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin-bottom: 5px;
}
.detail-item .detail-value { font-size: 15px; font-weight: 600; }

.table-wrap { overflow-x: auto; }

/* ---------- iOS-style grouped list ---------- */

.list-group {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s var(--ease);
}
.list-row:last-child { border-bottom: none; }
a.list-row { color: inherit; }
a.list-row:hover { background: var(--surface-2); }
.list-row-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.list-row-title { font-size: 15.5px; font-weight: 600; letter-spacing: -0.006em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row-subtitle { font-size: 13px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row-trailing { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.list-row-chevron { color: var(--text-faint); flex-shrink: 0; }
.list-empty { padding: 28px 16px; text-align: center; color: var(--text-muted); font-size: 14px; }

/* ---------- Login ---------- */

body:has(.auth-shell) {
  display: flex;
  min-height: 100vh;
}
main:has(.auth-shell) { display: flex; align-items: center; justify-content: center; width: 100%; padding: 24px; }
.auth-shell {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.auth-logo {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  margin: 0 auto 18px;
  display: block;
  object-fit: cover;
  box-shadow: 0 10px 24px -8px rgba(20, 20, 22, 0.35);
}
.auth-shell h1 { font-size: 22px; margin-bottom: 4px; }
.auth-shell .subtitle { color: var(--text-muted); font-size: 13.5px; margin-bottom: 26px; }
.auth-shell form { text-align: left; }
.auth-shell .btn-primary { width: 100%; justify-content: center; padding: 13px; margin-top: 6px; font-size: 15px; }

/* ---------- Confirm modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
  animation: modal-fade-in 0.15s var(--ease);
}
.modal-card {
  background: rgba(249, 249, 249, 0.85);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-radius: 14px;
  width: 270px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  animation: modal-pop-in 0.18s var(--ease);
  text-align: center;
}
.modal-message {
  margin: 0;
  padding: 19px 16px 17px;
  font-size: 13px;
  font-weight: 400;
  color: var(--text);
  line-height: 1.4;
}
.modal-actions {
  display: flex;
  border-top: 0.5px solid rgba(60, 60, 67, 0.29);
}
.modal-actions button {
  flex: 1;
  padding: 11px 0;
  font-size: 17px;
  font-weight: 400;
  color: var(--primary);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background 0.1s var(--ease);
}
.modal-actions button:hover { background: rgba(60, 60, 67, 0.06); }
.modal-actions button:active { background: rgba(60, 60, 67, 0.12); }
.modal-confirm { font-weight: 600; color: var(--danger); border-left: 0.5px solid rgba(60, 60, 67, 0.29); }
.modal-confirm:focus-visible, .modal-cancel:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }

@keyframes modal-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-pop-in { from { opacity: 0; transform: scale(0.92); } to { opacity: 1; transform: none; } }

/* ---------- Responsive ---------- */

@media (max-width: 700px) {
  header.topbar {
    padding: 0 16px;
  }
  nav.mainnav { display: none; }
  .userbox span { display: none; }

  nav.tabbar {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    background: rgba(249, 249, 249, 0.88);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-top: 0.5px solid rgba(60, 60, 67, 0.29);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  nav.tabbar a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 4px 2px;
    color: var(--text-faint);
    font-size: 10px;
    font-weight: 550;
  }
  nav.tabbar a.active { color: var(--primary); }
  nav.tabbar a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

  main { padding: 16px 14px 90px; }
  .card { padding: 16px; }

  h1 { font-size: 24px; }

  .page-header { flex-wrap: wrap; gap: 10px; align-items: flex-start; }
  .page-header > div { display: flex; flex-wrap: wrap; gap: 8px; }

  .form-row { flex-direction: column; gap: 0; }

  .stat-row { flex-wrap: wrap; }
  .stat { flex: 1 1 45%; }

  table.calendar th, table.calendar td { min-width: 38px; }
  table.calendar th.roomcol, table.calendar td.roomcol { min-width: 100px; }

  .btn { padding: 10px 15px; }
  input, select, textarea { font-size: 16px; }

  .auth-shell { padding: 28px 22px; }
}
