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

:root {
  --primary: #4A90D9;
  --primary-dark: #2c6fad;
  --sidebar-bg: #1e2740;
  --sidebar-text: #c8d0e7;
  --sidebar-hover: #2d3a5f;
  --sidebar-active: #4A90D9;
  --bg: #f4f6fb;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text: #2d3748;
  --text-muted: #718096;
  --danger: #e53e3e;
  --success: #38a169;
  --warning: #dd6b20;
  --pending: #805ad5;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,0.07);
}

body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); }

.screen { min-height: 100vh; }

/* AUTH */
#auth-screen {
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1e2740 0%, #2c6fad 100%);
  padding: 20px;
}
.auth-container {
  background: var(--card-bg); border-radius: 16px; padding: 40px;
  width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.auth-logo { text-align: center; margin-bottom: 28px; }
.logo-icon { font-size: 48px; margin-bottom: 10px; width: 56px; height: 56px; display: flex; align-items: center; justify-content: center; overflow: hidden; border-radius: 8px; }
.auth-logo h1 { font-size: 24px; font-weight: 700; color: var(--text); }
.auth-logo p { color: var(--text-muted); font-size: 14px; margin-top: 4px; }
.auth-tabs { display: flex; gap: 4px; background: var(--bg); border-radius: 8px; padding: 4px; margin-bottom: 24px; }
.auth-tab {
  flex: 1; padding: 8px; border: none; background: none; border-radius: 6px;
  cursor: pointer; font-size: 14px; font-weight: 500; color: var(--text-muted); transition: all 0.2s;
}
.auth-tab.active { background: white; color: var(--primary); box-shadow: 0 2px 6px rgba(0,0,0,0.1); }

/* APP LAYOUT */
#app-screen { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: 240px; background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column; flex-shrink: 0;
  box-shadow: 2px 0 12px rgba(0,0,0,0.15);
}
.sidebar-header {
  padding: 20px 16px; font-size: 16px; font-weight: 700; color: white;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.logo-icon-sm { font-size: 22px; width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; overflow: hidden; border-radius: 5px; flex-shrink: 0; }
.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 500;
  color: var(--sidebar-text); transition: all 0.2s; margin-bottom: 2px;
  text-decoration: none;
}
.nav-item:hover { background: var(--sidebar-hover); color: white; }
.nav-item.active { background: var(--primary); color: white; }
.nav-divider { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: #5a6787; padding: 16px 12px 6px; }
.nav-icon { font-size: 16px; }
.sidebar-footer { padding: 16px; border-top: 1px solid rgba(255,255,255,0.08); }
.user-info { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 13px; }
.user-avatar { font-size: 18px; }
.btn-logout {
  width: 100%; padding: 8px; border-radius: 6px; border: 1px solid rgba(255,255,255,0.2);
  background: transparent; color: var(--sidebar-text); cursor: pointer; font-size: 13px; transition: all 0.2s;
}
.btn-logout:hover { background: rgba(255,255,255,0.1); color: white; }

.main-content { flex: 1; overflow-y: auto; padding: 24px; }
.page { display: none; }
.page.active { display: block; }

.page-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px;
  flex-wrap: wrap; gap: 12px;
}
.page-header h2 { font-size: 22px; font-weight: 700; }

/* WEEK NAV */
.week-nav { display: flex; align-items: center; gap: 8px; }
#week-label { font-size: 15px; font-weight: 600; min-width: 200px; text-align: center; }
.room-filter { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.room-filter select { padding: 6px 10px; border-radius: 6px; border: 1px solid var(--border); font-size: 14px; }

/* CALENDAR */
.calendar-container { background: var(--card-bg); border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto; }
.calendar-grid { display: grid; min-width: 700px; }
.cal-header-row { display: contents; }
.cal-time-col { width: 60px; }
.cal-day-header {
  padding: 10px 4px; text-align: center; font-weight: 600; font-size: 13px;
  border-bottom: 2px solid var(--border); background: var(--bg); position: sticky; top: 0; z-index: 10;
  border-right: 1px solid var(--border);
}
.cal-day-header.today { color: var(--primary); }
.cal-day-header.today span.day-num { background: var(--primary); color: white; border-radius: 50%; width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center; }
.cal-body { display: grid; }
.cal-time-cell {
  font-size: 11px; color: var(--text-muted); text-align: right; padding: 0 6px;
  height: 30px; display: flex; align-items: center; justify-content: flex-end;
  border-right: 1px solid var(--border);
}
.cal-slot {
  height: 30px; border-bottom: 1px solid #f0f2f8; border-right: 1px solid var(--border);
  cursor: pointer; transition: background 0.1s; position: relative;
}
.cal-slot:hover { background: #EBF4FF; }
.cal-slot.selecting { background: #BFD9F7; }
.booking-block {
  position: absolute; left: 2px; right: 2px; border-radius: 5px; padding: 3px 6px;
  font-size: 11px; font-weight: 500; cursor: pointer; overflow: hidden;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15); z-index: 5; transition: filter 0.15s;
  color: white; line-height: 1.3;
}
.booking-block:hover { filter: brightness(0.9); }
.booking-block.pending { opacity: 0.7; border-left: 3px solid rgba(0,0,0,0.3); }

/* FORMS */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 9px 12px; border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 14px; background: var(--card-bg); color: var(--text); transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--primary);
}
.form-group textarea { resize: vertical; }
.booking-form-grid { display: grid; grid-template-columns: 1fr; gap: 0; }

/* BUTTONS */
.btn-primary {
  background: var(--primary); color: white; border: none; padding: 9px 18px;
  border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; transition: all 0.2s;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline {
  background: transparent; color: var(--text); border: 1.5px solid var(--border); padding: 9px 18px;
  border-radius: 8px; font-size: 14px; font-weight: 500; cursor: pointer; transition: all 0.2s;
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-danger { background: var(--danger); color: white; border: none; padding: 7px 14px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.btn-success { background: var(--success); color: white; border: none; padding: 7px 14px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 5px; border: none; cursor: pointer; font-weight: 500; }
.btn-icon { background: none; border: 1px solid var(--border); padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 16px; line-height: 1; }
.btn-icon:hover { background: var(--bg); }
.full-width { width: 100%; }

.error-msg { color: var(--danger); font-size: 13px; padding: 8px 12px; background: #fff5f5; border-radius: 6px; margin-bottom: 10px; }
.success-msg { color: var(--success); font-size: 13px; padding: 8px 12px; background: #f0fff4; border-radius: 6px; margin-bottom: 10px; }

/* MODAL */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); }
.modal-content { background: white; border-radius: 14px; width: 100%; max-width: 500px; max-height: 90vh; overflow-y: auto; position: relative; z-index: 1; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.modal-content.large { max-width: 700px; }
.modal-header { padding: 20px 24px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { font-size: 18px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-muted); line-height: 1; }
.modal-body { padding: 20px 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }

/* BOOKINGS LIST */
.bookings-list { display: flex; flex-direction: column; gap: 12px; }
.booking-card {
  background: var(--card-bg); border-radius: var(--radius); padding: 16px 20px;
  box-shadow: var(--shadow); display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
}
.booking-card-info h4 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.booking-card-info p { font-size: 13px; color: var(--text-muted); }
.booking-card-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.status-badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; text-transform: capitalize;
}
.status-pending { background: #F3E8FF; color: var(--pending); }
.status-approved { background: #F0FFF4; color: var(--success); }
.status-rejected { background: #FFF5F5; color: var(--danger); }
.status-cancelled { background: #EDF2F7; color: var(--text-muted); }

/* ADMIN LIST */
.admin-list { display: flex; flex-direction: column; gap: 10px; }
.admin-card {
  background: var(--card-bg); border-radius: var(--radius); padding: 16px 20px;
  box-shadow: var(--shadow); display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.admin-card-info h4 { font-size: 14px; font-weight: 600; }
.admin-card-info p { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.admin-card-actions { display: flex; gap: 6px; }

/* QUESTION FORM IN MODAL */
.question-field { padding: 14px; background: var(--bg); border-radius: 8px; margin-bottom: 14px; border: 1px solid var(--border); }
.question-field label { font-size: 14px; font-weight: 600; display: block; margin-bottom: 10px; }
.question-field .required-mark { color: var(--danger); }
.yn-buttons { display: flex; gap: 8px; }
.yn-btn { padding: 8px 20px; border: 2px solid var(--border); border-radius: 8px; cursor: pointer; font-size: 14px; background: white; font-weight: 500; transition: all 0.2s; }
.yn-btn.selected { border-color: var(--primary); background: var(--primary); color: white; }
.checkbox-option { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 14px; cursor: pointer; }
.checkbox-option input { width: 16px; height: 16px; cursor: pointer; }

/* Mobile-only elements (hidden on desktop, shown via media query) */
.mobile-only { display: none; }

/* ROOM DOT */
.room-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; }

/* Detail modal */
.detail-section { margin-bottom: 16px; }
.detail-section h4 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 8px; }
.detail-row { display: flex; gap: 12px; margin-bottom: 8px; }
.detail-label { font-size: 13px; color: var(--text-muted); min-width: 120px; }
.detail-value { font-size: 14px; font-weight: 500; }

/* CLEARABLE INPUT */
.clearable-wrap { position: relative; display: inline-flex; align-items: center; }
.clearable-wrap input { padding-right: 26px !important; }
.clearable-wrap .clear-btn {
  position: absolute; right: 6px;
  width: 16px; height: 16px;
  display: none; align-items: center; justify-content: center;
  background: transparent; color: #e53e3e;
  border: 1.5px solid #e53e3e; border-radius: 50%; cursor: pointer;
  font-size: 11px; line-height: 1; padding: 0;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.clearable-wrap .clear-btn:hover { background: #e53e3e; color: #fff; }
.clearable-wrap input:not(:placeholder-shown) ~ .clear-btn { display: flex; }

/* ═══════════════════════════════════════════════════
   MOBILE-FIRST RESPONSIVE OVERRIDES
   Breakpoints: ≤ 768px (mobile), ≤ 480px (small)
═══════════════════════════════════════════════════ */

/* ── Bottom tab bar (replaces sidebar on mobile) ─── */
@media (max-width: 768px) {
  /* App layout: vertical stack */
  #app-screen { flex-direction: column; height: 100dvh; }

  /* Sidebar becomes a bottom tab bar */
  .sidebar {
    width: 100%; height: 56px; min-height: 56px;
    flex-direction: row; order: 2;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.15);
    overflow: hidden;
  }
  .sidebar-header  { display: none; }
  .sidebar-footer  { display: none; }
  .mobile-only { display: flex; }
  .sidebar-nav {
    display: flex; flex-direction: row;
    align-items: stretch;
    padding: 0; overflow-x: auto; overflow-y: hidden;
    scrollbar-width: none; flex: 1;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar-nav::-webkit-scrollbar { display: none; }
  .nav-divider { display: none; }
  .nav-item {
    flex-direction: column; flex: 0 0 auto;
    min-width: 60px; padding: 6px 4px; gap: 3px;
    font-size: 10px; border-radius: 0;
    justify-content: center; align-items: center;
    margin-bottom: 0;
  }
  .nav-item span:last-child { font-size: 10px; line-height: 1.2; text-align: center; }
  .nav-icon { font-size: 18px; }
  .nav-item.active { background: var(--primary); }

  /* Main content fills remaining height above tab bar */
  .main-content { flex: 1; overflow-y: auto; padding: 14px; order: 1; min-height: 0; }

  /* Page header: stack vertically */
  .page-header {
    flex-direction: column; align-items: flex-start; gap: 10px; margin-bottom: 16px;
  }
  .page-header h2 { font-size: 19px; }
  .page-header > div { width: 100%; }

  /* Filter rows: wrap and stretch inputs */
  .page-header > div[style*="display:flex"],
  .page-header > div { flex-wrap: wrap !important; }
  .clearable-wrap { flex: 1 1 140px; }
  .clearable-wrap input { width: 100% !important; min-width: 0; }

  /* Cards: stack on mobile */
  .admin-card {
    flex-direction: column; align-items: flex-start; gap: 10px;
  }
  .admin-card-actions { flex-wrap: wrap; width: 100%; }
  .booking-card { flex-direction: column; align-items: flex-start; }
  .booking-card-actions { flex-wrap: wrap; }

  /* Booking form: single column (already default, kept for clarity) */

  /* Modals: full-height bottom sheet */
  .modal { align-items: flex-end; padding: 0; }
  .modal-content {
    border-radius: 18px 18px 0 0;
    max-width: 100%; width: 100%;
    max-height: 92dvh;
  }
  .modal-header { padding: 16px 20px 12px; }
  .modal-body   { padding: 16px 20px; }
  .modal-footer { padding: 12px 20px; }

  /* Bigger touch targets */
  .btn-primary, .btn-outline { padding: 11px 16px; }
  .btn-sm { padding: 8px 12px; font-size: 13px; }
  input, select, textarea { font-size: 16px !important; } /* prevents iOS zoom */

  /* Calendar: allow horizontal scroll */
  .calendar-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Week nav: compact */
  .week-nav { gap: 4px; }
  #week-label { min-width: 0; font-size: 13px; }
  .room-filter { flex-wrap: wrap; width: 100%; }
  .room-filter select { flex: 1; }

  /* Auth: tighter padding */
  .auth-container { padding: 28px 20px; }

  /* Config form rows: stack */
  .form-group > div[style*="display:flex"] { flex-direction: column; }
}

/* ── Extra-small phones ─────────────────────────── */
@media (max-width: 480px) {
  .main-content { padding: 10px; }
  .page-header h2 { font-size: 17px; }
  .modal-content { max-height: 95dvh; }
  .nav-item { min-width: 52px; }
  .nav-item span:last-child { display: none; } /* icons-only on very small screens */
  .nav-icon { font-size: 20px; }
  .nav-item { min-width: 44px; padding: 8px 4px; }
  .booking-card-info h4 { font-size: 14px; }
}
