/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:       #2563eb;
  --primary-dark:  #1d4ed8;
  --primary-light: #dbeafe;
  --success:       #16a34a;
  --success-light: #dcfce7;
  --warning:       #d97706;
  --warning-light: #fef3c7;
  --danger:        #dc2626;
  --danger-light:  #fee2e2;
  --gray-50:  #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;
  --white: #ffffff;
  --sidebar-w: 240px;
  --topbar-h: 56px;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);

  /* Reservation status colors */
  --res-booked-1: #2563eb;
  --res-booked-2: #0891b2;
  --res-booked-3: #4338ca;
  --res-booked-4: #0284c7;
  --res-canceled: #94a3b8;
  --res-partial:  #f97316;
  --res-refunded: #ef4444;
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-100);
  color: var(--gray-800);
  line-height: 1.5;
  min-height: 100vh;
}

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

/* ===== LAYOUT ===== */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--gray-900);
  color: var(--white);
  overflow-y: auto;
  z-index: 200;
  transition: transform .25s ease;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px;
  font-size: 1.1rem;
  font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,.1);
  flex-shrink: 0;
}

.sidebar-close {
  display: none;
  background: none;
  border: none;
  color: var(--gray-400);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
}

.nav-list {
  list-style: none;
  padding: 12px 0;
  flex: 1;
}

.nav-section {
  padding: 12px 16px 4px;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--gray-500);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: var(--gray-300);
  border-radius: var(--radius);
  margin: 1px 8px;
  font-size: .9rem;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: rgba(255,255,255,.07); color: var(--white); text-decoration: none; }
.nav-link.active { background: var(--primary); color: var(--white); }
.nav-link.nav-sub { font-size: .85rem; padding: 7px 16px; }
.nav-icon { width: 18px; text-align: center; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 190;
}

/* Main content area */
.main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  z-index: 100;
  box-shadow: var(--shadow);
}

.hamburger {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}
.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--gray-600);
  border-radius: 2px;
}

.topbar-title {
  flex: 1;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--gray-800);
}

.topbar-user {
  font-size: .8rem;
  color: var(--gray-500);
  display: none;
}

.page-content {
  flex: 1;
  padding: 24px 20px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

/* ===== ALERTS ===== */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin: 12px 20px;
  font-size: .9rem;
  font-weight: 500;
}
.alert-success { background: var(--success-light); color: var(--success); border: 1px solid #86efac; }
.alert-error   { background: var(--danger-light);  color: var(--danger);  border: 1px solid #fca5a5; }
.alert-warning { background: var(--warning-light); color: var(--warning); border: 1px solid #fcd34d; }

/* ===== CARDS ===== */
.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-800);
}

.card-body { padding: 20px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius);
  border: none;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, box-shadow .15s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }

.btn-primary   { background: var(--primary); color: var(--white); }
.btn-primary:hover   { background: var(--primary-dark); }
.btn-success   { background: var(--success); color: var(--white); }
.btn-danger    { background: var(--danger);  color: var(--white); }
.btn-secondary { background: var(--gray-200); color: var(--gray-700); }
.btn-secondary:hover { background: var(--gray-300); }
.btn-outline   { background: var(--white); color: var(--primary); border: 1px solid var(--primary); }
.btn-sm        { padding: 5px 10px; font-size: .8rem; }
.btn-block     { width: 100%; justify-content: center; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  margin-bottom: 6px;
  font-size: .875rem;
  font-weight: 500;
  color: var(--gray-700);
}
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: .9rem;
  color: var(--gray-800);
  background: var(--white);
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.form-control[readonly] { background: var(--gray-50); color: var(--gray-500); }

select.form-control { cursor: pointer; }

.form-hint { font-size: .78rem; color: var(--gray-500); margin-top: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .form-row { grid-template-columns: 1fr; } }

.form-check { display: flex; align-items: center; gap: 8px; }
.form-check input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; }
.form-check label { font-size: .875rem; cursor: pointer; }

/* ===== TABLES ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--gray-200); font-size: .875rem; }
th { font-weight: 600; color: var(--gray-600); background: var(--gray-50); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--gray-50); }
.text-right { text-align: right; }
.text-center { text-align: center; }

/* ===== BADGES ===== */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: .75rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-booked   { background: var(--primary-light); color: var(--primary); }
.badge-canceled { background: var(--gray-200); color: var(--gray-600); }
.badge-partial  { background: #ffedd5; color: #c2410c; }
.badge-refunded { background: var(--danger-light); color: var(--danger); }

/* ===== MODAL ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 300;
  align-items: flex-start;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.modal-overlay.active { display: flex; }

.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 540px;
  margin: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn .2s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(-16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-weight: 600; font-size: 1rem; }
.modal-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--gray-500);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}
.modal-close:hover { background: var(--gray-100); }
.modal-body { padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--gray-200);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ===== GRID UTILITIES ===== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
@media (max-width: 768px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ===== STAT CARDS ===== */
.stat-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  text-align: center;
}
.stat-label { font-size: .8rem; color: var(--gray-500); font-weight: 500; margin-bottom: 6px; }
.stat-value { font-size: 1.6rem; font-weight: 700; color: var(--gray-800); }
.stat-sub { font-size: .8rem; color: var(--gray-500); margin-top: 4px; }

/* ===== LOCATION CARDS ===== */
.location-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 20px;
  border-left: 4px solid var(--primary);
}
.location-card h3 { font-size: 1rem; font-weight: 600; margin-bottom: 4px; }
.location-card p  { font-size: .85rem; color: var(--gray-500); margin-bottom: 12px; }
.location-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== PAGE HEADERS ===== */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-header h2 { font-size: 1.2rem; font-weight: 700; }

/* ===== CALENDAR ===== */
.cal-wrapper { background: var(--white); border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden; }

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
}
.cal-nav h2 { font-size: 1.1rem; font-weight: 600; }
.cal-nav-btns { display: flex; gap: 8px; }

.cal-dow-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
}
.cal-dow {
  padding: 8px 4px;
  text-align: center;
  font-size: .75rem;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: .05em;
}

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

.cal-day {
  min-height: 70px;
  border-right: 1px solid var(--gray-200);
  border-bottom: 1px solid var(--gray-200);
  padding: 4px;
  cursor: pointer;
  background: var(--white);
  position: relative;
  overflow: visible;
  transition: background .1s;
}
.cal-day:nth-child(7n) { border-right: none; }
.cal-day:hover { background: var(--gray-50); }
.cal-day.other-month { background: var(--gray-50); }
.cal-day.other-month .day-num { color: var(--gray-400); }
.cal-day.today .day-num {
  background: var(--primary);
  color: var(--white);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.day-num {
  font-size: .8rem;
  font-weight: 600;
  color: var(--gray-700);
  line-height: 1;
  margin-bottom: 2px;
  display: inline-flex;
  width: 24px;
  height: 24px;
  align-items: center;
  justify-content: center;
}

/* Reservation blocks on calendar */
.cal-day.has-res { cursor: pointer; }

.res-block {
  position: absolute;
  bottom: 0;
  height: calc(100% - 26px);
  min-height: 18px;
  display: flex;
  align-items: center;
  padding: 0 5px;
  font-size: .72rem;
  font-weight: 600;
  color: var(--white);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: filter .15s ease, box-shadow .15s ease;
}
.res-block:hover {
  filter: brightness(1.18);
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
  z-index: 2;
}

/* Status colors — booked uses 4 rotating shades */
.res-block.status-booked.shade-0 { background: var(--res-booked-1); }
.res-block.status-booked.shade-1 { background: var(--res-booked-2); }
.res-block.status-booked.shade-2 { background: var(--res-booked-3); }
.res-block.status-booked.shade-3 { background: var(--res-booked-4); }
.res-block.status-canceled           { background: var(--res-canceled); }
.res-block.status-partially_refunded { background: var(--res-partial); }
.res-block.status-fully_refunded     { background: var(--res-refunded); }

/*
  Layout: check-in day = right 60%, check-out day = left 30%.
  10% gap naturally appears when two stays share a turnover day.
  Middle days fill the full cell to keep the band unbroken.
*/
/* Check-in day: right 60% — text overflows into adjacent cells */
.res-block.pos-start {
  left: 40%; right: 0;
  border-radius: 4px 0 0 4px;
  overflow: visible;
  white-space: nowrap;
  z-index: 3;
}
/* Check-out day: left 20% */
.res-block.pos-end {
  left: 0; width: 20%;
  border-radius: 0 4px 4px 0;
  z-index: 2;
}
/* Middle and week-boundary continuation days: full width, sit below start text */
.res-block.pos-middle,
.res-block.pos-week-start,
.res-block.pos-week-end {
  left: 0; right: 0;
  border-radius: 0;
  z-index: 2;
}
/* Single-night: same as check-in, text can overflow */
.res-block.pos-single {
  left: 40%; right: 0;
  border-radius: 4px;
  overflow: visible;
  white-space: nowrap;
  z-index: 3;
}

@media (max-width: 600px) {
  .cal-day { min-height: 52px; }
  .res-block { font-size: .65rem; padding: 0 3px; height: calc(100% - 22px); }
}

.cal-day.pending-start {
  background: #eff6ff !important;
  outline: 2px solid var(--primary);
  outline-offset: -2px;
  cursor: crosshair;
}
.cal-day.pending-start .day-num {
  background: var(--primary);
  color: var(--white);
  border-radius: 50%;
}

.cal-legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 20px;
  border-top: 1px solid var(--gray-200);
  font-size: .78rem;
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }

/* ===== STATEMENTS ===== */
.stmt-header {
  text-align: center;
  margin-bottom: 24px;
}
.stmt-header h1 { font-size: 1.4rem; margin-bottom: 4px; }
.stmt-header p  { font-size: .9rem; color: var(--gray-600); }

.stmt-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

.stmt-party h4 { font-size: .8rem; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.stmt-party p  { font-size: .875rem; line-height: 1.6; }

.stmt-totals { background: var(--gray-50); border-radius: var(--radius); padding: 16px; margin-top: 20px; }
.stmt-total-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: .9rem;
  border-bottom: 1px solid var(--gray-200);
}
.stmt-total-row:last-child { border-bottom: none; font-weight: 700; font-size: 1rem; color: var(--success); }
.stmt-total-row.indent { padding-left: 16px; color: var(--gray-600); font-size: .85rem; }

/* Print styles */
@media print {
  .topbar, .sidebar, .sidebar-overlay, .no-print, .alert, .btn { display: none !important; }
  .main-wrap { margin-left: 0 !important; }
  .page-content { padding: 0 !important; }
  body { background: white; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}

/* ===== LOGIN PAGE ===== */
.auth-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #1e293b 0%, #1d4ed8 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
  overflow: hidden;
}

.auth-header {
  background: var(--gray-900);
  color: var(--white);
  padding: 28px 28px 20px;
  text-align: center;
}
.auth-header h1 { font-size: 1.5rem; margin-bottom: 4px; }
.auth-header p  { font-size: .85rem; color: var(--gray-400); }

.auth-body { padding: 28px; }

.auth-tabs { display: flex; margin-bottom: 24px; border: 1px solid var(--gray-200); border-radius: var(--radius); overflow: hidden; }
.auth-tab {
  flex: 1;
  padding: 9px;
  text-align: center;
  cursor: pointer;
  font-size: .875rem;
  font-weight: 500;
  background: var(--white);
  border: none;
  color: var(--gray-600);
  transition: background .15s;
}
.auth-tab.active { background: var(--primary); color: var(--white); }

.auth-form { display: none; }
.auth-form.active { display: block; }

/* ===== MISC ===== */
.mt-4  { margin-top: 16px; }
.mt-6  { margin-top: 24px; }
.mb-4  { margin-bottom: 16px; }
.mb-6  { margin-bottom: 24px; }
.gap-2 { gap: 8px; }
.flex  { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.text-muted { color: var(--gray-500); font-size: .875rem; }
.text-sm    { font-size: .875rem; }
.text-xs    { font-size: .78rem; }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.font-bold { font-weight: 700; }
.w-full { width: 100%; }
hr.divider { border: none; border-top: 1px solid var(--gray-200); margin: 16px 0; }

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--gray-500);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 12px; }
.empty-state h3 { font-size: 1rem; font-weight: 600; color: var(--gray-700); margin-bottom: 6px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-close { display: block; }
  .sidebar-overlay.active { display: block; }

  .main-wrap { margin-left: 0; }

  .hamburger { display: flex; }
  .topbar-user { display: none; }

  .grid-2 { grid-template-columns: 1fr 1fr; }
  .stmt-parties { grid-template-columns: 1fr; }

  .page-content { padding: 16px 12px; }
}

@media (max-width: 400px) {
  .grid-2 { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
}

/* ===== CHARTS ===== */
.chart-container { position: relative; height: 260px; }
