:root {
  --primary: #c0392b;
  --primary-dark: #96281b;
  --accent: #e67e22;
  --accent-light: #f39c12;
  --bg: #faf8f5;
  --surface: #ffffff;
  --surface-2: #f5f2ed;
  --border: #e8e0d5;
  --text: #2c2417;
  --text-muted: #8c7b6b;
  --success: #27ae60;
  --danger: #e74c3c;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --bottom-nav-h: 68px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

/* ── Auth ── */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  background: linear-gradient(135deg, #c0392b 0%, #e67e22 50%, #f39c12 100%);
}

.auth-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 40px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.auth-card .logo { font-size: 3rem; margin-bottom: 8px; }
.auth-card h1 { font-size: 1.6rem; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.auth-card .subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 32px; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; text-align: left; }

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s;
  outline: none;
  /* Prevent iOS zoom on focus */
  font-size: max(16px, 1rem);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--primary); }

.form-group textarea { resize: vertical; min-height: 80px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  min-height: 44px; /* iOS tap target */
}

.btn-primary {
  background: var(--primary);
  color: white;
  padding: 13px 22px;
  font-size: 1rem;
}
.btn-primary:active { background: var(--primary-dark); }

/* Full-width only when explicitly needed */
.btn-block { width: 100%; justify-content: center; }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1.5px solid var(--border);
}
.btn-secondary:active { background: var(--border); }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:active { background: #c0392b; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 10px;
}
.btn-ghost:active { background: var(--surface-2); color: var(--text); }

.btn-sm { padding: 9px 14px; font-size: 0.85rem; min-height: 38px; }

.error-msg { color: var(--danger); font-size: 0.85rem; margin-top: 10px; min-height: 20px; }

/* ── App Layout (desktop: sidebar) ── */
.app-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

/* ── Top Bar ── */
.topbar {
  grid-column: 1 / -1;
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  padding: 0 20px;
  height: 56px;
  gap: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar .logo { font-size: 1.3rem; }
.topbar h1 { font-size: 1.05rem; font-weight: 700; flex: 1; }
.topbar .btn-logout {
  background: rgba(255,255,255,0.15);
  color: white;
  border: 1px solid rgba(255,255,255,0.3);
  padding: 8px 14px;
  font-size: 0.85rem;
  min-height: 36px;
}

/* ── Sidebar (desktop only) ── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 20px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}

.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  color: var(--primary);
  background: #fdf0ee;
  border-left-color: var(--primary);
  font-weight: 600;
}

.nav-icon { font-size: 1.2rem; }

/* Bottom nav — hidden on desktop */
.bottom-nav { display: none; }

/* ── Main Content ── */
.main {
  padding: 24px;
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0; /* prevent grid blowout */
}

/* ── Page header ── */
.page-header { margin-bottom: 20px; }
.page-header h2 { font-size: 1.4rem; font-weight: 700; }
.page-header p { color: var(--text-muted); font-size: 0.875rem; margin-top: 3px; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 14px;
}

/* ── Dashboard ── */
.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-card .icon { font-size: 1.4rem; }
.stat-card .value { font-size: 1.6rem; font-weight: 700; }
.stat-card .label { font-size: 0.75rem; color: var(--text-muted); font-weight: 500; }

.section-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

/* ── Notes ── */
.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.note-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  position: relative;
}

.note-card.pinned { border-color: var(--accent); background: #fffbf5; }
.note-card .pin-badge { position: absolute; top: 12px; right: 12px; font-size: 0.72rem; color: var(--accent); font-weight: 700; }
.note-card h3 { font-size: 1rem; font-weight: 600; margin-bottom: 8px; padding-right: 50px; }
.note-card p { font-size: 0.875rem; color: var(--text-muted); line-height: 1.5; }
.note-card .note-date { font-size: 0.72rem; color: var(--text-muted); margin-top: 10px; }

.note-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

/* ── Calendar ── */
.calendar-wrap {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.cal-nav h3 { font-size: 1.05rem; font-weight: 700; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.cal-day-label {
  text-align: center;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 6px 0;
}

.cal-day {
  min-height: 64px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px;
  background: var(--surface);
  font-size: 0.75rem;
}

.cal-day.empty { background: transparent; border-color: transparent; }
.cal-day.today { border-color: var(--primary); background: #fdf0ee; }
.cal-day.past { background: var(--surface-2); opacity: 0.7; }
.cal-day .day-num { font-weight: 600; font-size: 0.82rem; color: var(--text-muted); margin-bottom: 3px; }
.cal-day.today .day-num { color: var(--primary); }

.booking-chip {
  font-size: 0.62rem;
  font-weight: 600;
  padding: 2px 4px;
  border-radius: 3px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}
.booking-chip.arrival { background: #d5f5e3; color: #1e8449; }
.booking-chip.stay { background: #d6eaf8; color: #1a5276; }
.booking-chip.departure { background: #fde8e8; color: #922b21; }

.bookings-list { display: flex; flex-direction: column; gap: 10px; }

.booking-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.booking-item .name { font-weight: 600; font-size: 0.9rem; }
.booking-item .dates { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

/* ── Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end; /* sheet from bottom on mobile */
  justify-content: center;
  z-index: 100;
  padding: 0;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px 32px;
  width: 100%;
  max-width: 500px;
  box-shadow: var(--shadow-lg);
  max-height: 92vh;
  overflow-y: auto;
}

.modal h3 { font-size: 1.15rem; font-weight: 700; margin-bottom: 18px; }

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.modal-actions .btn-secondary { flex: 1; }
.modal-actions .btn-primary { flex: 2; width: auto; }

/* ── Spinner ── */
.spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
}
.spinner::after {
  content: '';
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Utilities ── */
.hidden { display: none !important; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.empty-state { text-align: center; padding: 40px 16px; color: var(--text-muted); font-size: 0.9rem; }
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 10px; }

/* ════════════════════════════════════════════════
   MOBILE  (≤ 640px)
   ════════════════════════════════════════════════ */
@media (max-width: 640px) {

  /* Prevent any horizontal overflow */
  html, body { overflow-x: hidden; }

  /* Layout: hide sidebar, single column */
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar { display: none; }

  .main {
    padding: 16px 14px;
    padding-bottom: calc(var(--bottom-nav-h) + 20px);
    width: 100%;
    overflow-x: hidden;
  }

  /* Bottom nav */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-h);
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 50;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.68rem;
    font-weight: 600;
    padding: 8px 4px;
    transition: color 0.15s;
  }

  .bottom-nav a .nav-icon { font-size: 1.5rem; }
  .bottom-nav a.active { color: var(--primary); }

  /* Cards — no overflow */
  .card { overflow: hidden; }

  /* Stat row — 3 columns but compact */
  .stat-row { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .stat-card { padding: 12px 10px; }
  .stat-card .icon { font-size: 1.2rem; }
  .stat-card .value { font-size: 1.4rem; }
  .stat-card .label { font-size: 0.65rem; line-height: 1.3; }

  .section-row { grid-template-columns: 1fr; }
  .notes-grid { grid-template-columns: 1fr; }

  /* Full-width action buttons on mobile */
  .page-header.flex-between { flex-direction: column; align-items: flex-start; gap: 12px; }
  .page-header.flex-between .btn { width: 100%; justify-content: center; }
  .note-actions .btn-sm { flex: 1; }
  .btn-primary { width: 100%; justify-content: center; }

  /* ── Calendar mobile ── */
  .calendar-wrap {
    grid-template-columns: 1fr;
    /* bookings list comes first on mobile */
    display: flex;
    flex-direction: column-reverse;
    gap: 14px;
  }

  /* Compact day cells — just a colored dot, no text */
  .cal-day {
    min-height: 40px;
    padding: 4px 3px;
    overflow: hidden;
  }

  .cal-day-label { font-size: 0.58rem; padding: 4px 0; letter-spacing: 0; }
  .cal-day .day-num { font-size: 0.72rem; margin-bottom: 2px; }

  /* Replace chips with small color bars */
  .booking-chip {
    font-size: 0;        /* hide name text */
    padding: 3px 0;
    border-radius: 2px;
    margin-bottom: 1px;
    height: 5px;
  }

  /* Modal as bottom sheet */
  .modal-backdrop { align-items: flex-end; }
  .modal { border-radius: 20px 20px 0 0; padding: 20px 16px 36px; max-height: 85vh; }

  /* Auth */
  .auth-card { padding: 32px 20px; }

  /* Booking items full width */
  .booking-item { flex-wrap: wrap; }
}
