/* ─── Reset + base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: #f4f6fa;
  color: #1a2233;
  line-height: 1.45;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  /* iOS safe areas */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
h1, h2, h3 { margin: 0; font-weight: 700; }
button { font: inherit; cursor: pointer; }
input, select, textarea {
  font: inherit;
  font-size: 16px; /* prevents iOS zoom on focus */
}

/* ─── Buttons ───────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 15px;
  background: #e8edf5;
  color: #1a2233;
  transition: background 120ms, transform 60ms;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:hover { background: #dde4f0; }
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: #0a3d62;
  color: white;
}
.btn-primary:hover { background: #0c4d7a; }
.btn-danger {
  background: #c0392b;
  color: white;
}
.btn-danger:hover { background: #a93226; }
.btn-ghost {
  background: transparent;
  color: #1a2233;
  padding: 8px 12px;
}
.btn-ghost:hover { background: rgba(0, 0, 0, 0.06); }
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

/* ─── Login ─────────────────────────────────────────────────────────── */
[hidden] { display: none !important; }
.screen { width: 100%; }
#login-view {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-card {
  background: white;
  width: 100%;
  max-width: 380px;
  padding: 28px;
  border-radius: 18px;
  box-shadow: 0 8px 30px rgba(10, 30, 60, 0.08);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: #0a3d62;
  color: white;
  display: grid;
  place-items: center;
  font-size: 24px;
  font-weight: 800;
}
.brand-mark.sm { width: 36px; height: 36px; font-size: 18px; border-radius: 10px; }
.brand h1 { font-size: 22px; }
.brand-sub { margin: 2px 0 0; color: #6b7a90; font-size: 13px; }

#login-form { display: grid; gap: 14px; }
label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #4a5566;
}
input, select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid #d6dce6;
  border-radius: 10px;
  background: white;
  color: #1a2233;
  min-height: 44px;
}
/* PIN-style code input on the login screen */
.code-input {
  text-align: center;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 16px;
  padding-left: 20px; /* offset letter-spacing so caret looks centered */
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}
.code-input::placeholder {
  color: #c4ccd9;
  letter-spacing: 16px;
}

input:focus, select:focus {
  outline: none;
  border-color: #0a3d62;
  box-shadow: 0 0 0 3px rgba(10, 61, 98, 0.15);
}
.error-msg {
  background: #fde8e6;
  color: #a93226;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  margin: 0;
}

/* ─── Topbar ────────────────────────────────────────────────────────── */
.topbar {
  background: white;
  border-bottom: 1px solid #e3e7ee;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  min-width: 0;
}
.topbar-brand strong { display: block; }
.muted { color: #6b7a90; font-size: 12px; display: block; }
.topbar-actions { display: flex; gap: 6px; flex-shrink: 0; }

#refresh-btn {
  font-size: 18px;
  width: 44px;
  padding: 0;
}

/* ─── Status / list ─────────────────────────────────────────────────── */
.status-bar {
  padding: 10px 20px;
  font-size: 13px;
  color: #6b7a90;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}
.reservations {
  padding: 8px 20px 28px;
  display: grid;
  gap: 12px;
  max-width: 1100px;
  margin: 0 auto;
}
.empty {
  text-align: center;
  padding: 40px 16px;
  color: #6b7a90;
}

/* Reservation card */
.res {
  background: white;
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(10, 30, 60, 0.05);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px 16px;
  align-items: start;
}
.res-info { min-width: 0; }
.res-name {
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.res-meta {
  margin-top: 4px;
  color: #6b7a90;
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
}
.res-meta span { white-space: nowrap; }

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.badge-airbnb { background: #ffeaee; color: #c61b4e; }
.badge-booking { background: #e6efff; color: #0e3a8a; }
.badge-expedia { background: #fff3e0; color: #b95300; }
.badge-direct { background: #e8f5e9; color: #1f7a35; }
.badge-default { background: #ecf0f5; color: #3a4a64; }

.badge-checkout {
  background: #fff7d6;
  color: #8a6300;
  border: 1px solid #f0e0a0;
}

.card-status {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.card-form { background: #e0f4ea; color: #1f7a35; }
.card-hostaway { background: #fff3e0; color: #b95300; }
.card-none { background: #fde8e6; color: #a93226; }
.card-unknown { background: #ecf0f5; color: #6b7a90; }

.res-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
  min-width: 130px;
}
.res-actions .btn {
  width: 100%;
  font-size: 14px;
  padding: 10px 12px;
}

/* ─── Modals ────────────────────────────────────────────────────────── */
.modal {
  border: none;
  border-radius: 18px;
  padding: 0;
  background: white;
  max-width: 480px;
  width: calc(100% - 32px);
  box-shadow: 0 16px 60px rgba(10, 30, 60, 0.25);
  /* Position naturally; backdrop handled below */
}
.modal::backdrop {
  background: rgba(10, 30, 60, 0.5);
  backdrop-filter: blur(4px);
}
.modal-card { display: contents; }
.modal-card.narrow { /* no extra constraint, parent already narrow */ }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 12px;
  border-bottom: 1px solid #ecf0f5;
}
.modal-head h2 { font-size: 18px; }
.modal-body {
  padding: 16px 20px;
  display: grid;
  gap: 12px;
  max-height: 60vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal-foot {
  padding: 14px 20px 18px;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  border-top: 1px solid #ecf0f5;
  flex-wrap: wrap;
}
.modal-foot .btn { flex: 1 1 auto; min-width: 120px; }

.res-summary {
  background: #f4f6fa;
  border-radius: 10px;
  padding: 12px;
  font-size: 14px;
  line-height: 1.5;
}
.res-summary strong { display: block; margin-bottom: 2px; }

.small { font-size: 12px; }

/* ─── Toast ─────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #1a2233;
  color: white;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  z-index: 100;
  max-width: calc(100% - 32px);
  text-align: center;
}
.toast.success { background: #1f7a35; }
.toast.error { background: #c0392b; }

/* ─── Mobile (iPhone) tweaks ───────────────────────────────────────── */
@media (max-width: 640px) {
  .topbar { padding: 10px 14px; }
  .topbar-brand { font-size: 14px; }
  .status-bar { padding: 8px 14px; }
  .reservations { padding: 6px 14px 24px; gap: 10px; }

  .res {
    grid-template-columns: 1fr;
    padding: 14px;
  }
  .res-actions {
    flex-direction: row;
    min-width: 0;
  }
  .res-actions .btn { flex: 1; }

  /* Modals: bottom-sheet style on phones */
  .modal {
    width: 100%;
    max-width: 100%;
    margin: auto 0 0;
    border-radius: 18px 18px 0 0;
    /* Account for safe-area at the bottom */
    padding-bottom: env(safe-area-inset-bottom);
  }
  .modal-body {
    max-height: 55vh;
  }
  .modal-foot {
    flex-direction: column-reverse;
  }
  .modal-foot .btn { width: 100%; }

  .login-card { padding: 22px; }
}

/* Very small phones (iPhone SE etc.) */
@media (max-width: 374px) {
  .res-name { font-size: 15px; }
  .topbar-actions .btn { padding: 8px 10px; font-size: 14px; }
}

/* ─── Charges modal ─── */
.modal-card-wide { max-width: 640px; }
.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #888;
  margin: 18px 0 6px;
  font-weight: 600;
}
.section-title:first-child { margin-top: 4px; }
.charges-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.charges-table th {
  text-align: left;
  font-weight: 600;
  color: #888;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border, #e5e7eb);
}
.charges-table td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--border, #f0f0f0);
  vertical-align: middle;
}
.charges-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.charges-table .row-total td {
  border-top: 2px solid var(--border, #e5e7eb);
  border-bottom: none;
  padding-top: 12px;
}
.charges-totals {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border, #e5e7eb);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
}
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
}
.badge-ok { background: #d1fae5; color: #065f46; }
.badge-warn { background: #fed7aa; color: #9a3412; }
.badge-muted { background: #e5e7eb; color: #4b5563; }
.badge-edited { background: #dbeafe; color: #1e40af; text-transform: none; }
