/* ── Design tokens ─────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@400;600;700;800&family=Plus+Jakarta+Sans:wght@400;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --red-50:  #fff5f5;
  --red-100: #ffe4e4;
  --red-200: #fecaca;
  --red-500: #ef4444;
  --red-600: #dc2626;
  --red-700: #b91c1c;
  --red-800: #991b1b;

  --bg:        #fffbfa;
  --surface:   #ffffff;
  --surface-2: #faf6f5;
  --line:      #f1e7e5;
  --line-2:    #ead9d6;
  --ink:       #1a1212;
  --ink-2:     #4a3b3a;
  --ink-3:     #8a7a78;
  --ink-4:     #b8a9a7;

  --r-sm:  8px;
  --r-md:  12px;
  --r-lg:  16px;
  --r-xl:  22px;
  --r-pill:999px;

  --sh-1:   0 1px 2px rgba(80,20,20,.04);
  --sh-2:   0 4px 12px rgba(80,20,20,.06), 0 1px 2px rgba(80,20,20,.04);
  --sh-3:   0 12px 32px rgba(80,20,20,.10);
  --sh-pop: 0 24px 60px rgba(60,10,10,.18);
}

/* ── Base ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Noto Sans Thai', 'Plus Jakarta Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}

/* ── Shell ────────────────────────────────────────────────────────────────── */
#app { display: flex; height: 100vh; overflow: hidden; }

.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 16px; padding: 0 20px;
  z-index: 100;
  box-shadow: var(--sh-1);
}

.topbar-brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 16px; letter-spacing: -.02em;
  color: var(--ink); text-decoration: none;
}
.topbar-brand-icon {
  width: 32px; height: 32px; border-radius: var(--r-sm);
  background: var(--red-600); display: flex; align-items: center; justify-content: center;
}
.topbar-brand-icon svg { color: #fff; }

.topbar-spacer { flex: 1; }

.topbar-avatar {
  width: 34px; height: 34px; border-radius: var(--r-pill);
  background: var(--red-100); border: 2px solid var(--red-200);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; color: var(--red-700);
  cursor: pointer;
}

.sidenav {
  width: 220px; flex-shrink: 0;
  margin-top: 56px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 16px 0;
}

.sidenav-section { padding: 6px 0; }
.sidenav-label {
  padding: 4px 20px 8px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-4); font-family: 'Plus Jakarta Sans', sans-serif;
}
.sidenav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 20px; cursor: pointer;
  font-size: 13.5px; font-weight: 600; color: var(--ink-2);
  border-radius: 0;
  transition: background .12s, color .12s;
  text-decoration: none;
}
.sidenav-item:hover { background: var(--red-50); color: var(--red-700); }
.sidenav-item.active { background: var(--red-50); color: var(--red-700); }
.sidenav-item svg { opacity: .7; }
.sidenav-badge {
  margin-left: auto;
  background: var(--red-600); color: #fff;
  font-size: 11px; font-weight: 700;
  padding: 1px 7px; border-radius: var(--r-pill);
}

.main-content {
  flex: 1; margin-top: 56px; overflow-y: auto; padding: 28px 32px;
}

/* ── Page headers ─────────────────────────────────────────────────────────── */
.page-header {
  display: flex; align-items: center; gap: 16px; margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-title { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.page-subtitle { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); margin-top: 2px; font-family: 'Plus Jakarta Sans', sans-serif; }
.page-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 18px; border-radius: var(--r-md);
  font-size: 13.5px; font-weight: 700;
  border: 1.5px solid transparent;
  cursor: pointer; text-decoration: none;
  transition: background .12s, box-shadow .12s, transform .08s;
  font-family: inherit;
}
.btn:active { transform: scale(.98); }

.btn-primary {
  background: var(--red-600); color: #fff; border-color: var(--red-600);
  box-shadow: 0 4px 12px rgba(220,38,38,.25);
}
.btn-primary:hover { background: var(--red-700); border-color: var(--red-700); box-shadow: 0 6px 18px rgba(220,38,38,.35); }

.btn-ghost {
  background: transparent; color: var(--ink-2); border-color: var(--line-2);
}
.btn-ghost:hover { background: var(--surface-2); }

.btn-sm { padding: 5px 12px; font-size: 12.5px; border-radius: var(--r-sm); }

/* ── Cards / Stats strip ─────────────────────────────────────────────────── */
.stats-strip { display: flex; gap: 14px; margin-bottom: 24px; flex-wrap: wrap; }
.stat-card {
  flex: 1; min-width: 140px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 16px 20px; box-shadow: var(--sh-1);
}
.stat-value { font-size: 28px; font-weight: 800; letter-spacing: -.03em; color: var(--ink); }
.stat-label { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); margin-top: 2px; font-family: 'Plus Jakarta Sans', sans-serif; }

/* ── Timetable grid ───────────────────────────────────────────────────────── */
.timetable-wrap { overflow-x: auto; border-radius: var(--r-lg); border: 1px solid var(--line); background: var(--surface); box-shadow: var(--sh-1); }
.timetable { min-width: 900px; border-collapse: collapse; width: 100%; }

.timetable th {
  background: var(--surface-2); padding: 8px 10px;
  font-size: 11px; font-weight: 700; text-align: center;
  color: var(--ink-3); letter-spacing: .04em; text-transform: uppercase;
  border-bottom: 1px solid var(--line); font-family: 'Plus Jakarta Sans', sans-serif;
  white-space: nowrap;
}
.timetable th.col-day { text-align: left; padding-left: 16px; min-width: 100px; }
.timetable th .period-time { display: block; font-size: 10px; font-weight: 400; color: var(--ink-4); margin-top: 1px; font-family: 'JetBrains Mono', monospace; }
.timetable th.col-break { background: #f5f0ef; color: var(--ink-4); }

.timetable td {
  border: 1px solid var(--line); padding: 4px;
  vertical-align: top; height: 72px; position: relative;
}
.timetable td.td-day {
  padding: 0 16px; font-weight: 700; font-size: 13px;
  background: var(--surface-2); color: var(--ink-2);
  white-space: nowrap; vertical-align: middle;
}
.timetable td.td-break { background: #faf0ed; }

/* Empty cell — bookable */
.cell-empty {
  height: 100%; border-radius: var(--r-sm);
  border: 1.5px dashed var(--line-2);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: border-color .12s, background .12s;
  color: var(--ink-4);
}
.cell-empty:hover { border-color: var(--red-500); background: var(--red-50); color: var(--red-600); }

/* Booking cells */
.booking-cell {
  border-radius: var(--r-sm); padding: 6px 8px;
  font-size: 12px; height: 100%;
  display: flex; flex-direction: column; gap: 2px;
  overflow: hidden; position: relative;
}
.booking-cell.mine    { background: var(--red-600); color: #fff; }
.booking-cell.locked  { background: #fff7ed; color: #92400e; border: 1.5px solid #fed7aa; }
.booking-cell.other   { background: var(--surface); color: var(--ink-2); border: 1px solid var(--line-2); }
.booking-cell .b-name  { font-weight: 700; font-size: 12.5px; }
.booking-cell .b-sub   { font-size: 11px; opacity: .8; }
.booking-cell .b-mine-pill {
  position: absolute; top: 5px; right: 6px;
  background: rgba(255,255,255,.25); font-size: 9px; font-weight: 800;
  padding: 1px 5px; border-radius: var(--r-pill); letter-spacing: .06em;
  font-family: 'Plus Jakarta Sans', sans-serif;
}
.booking-cell .b-lock { position: absolute; bottom: 5px; right: 6px; opacity: .6; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: var(--r-pill);
  font-size: 11px; font-weight: 700; font-family: 'Plus Jakarta Sans', sans-serif;
}
.b-active    { background: #ecfdf5; color: #047857; }
.b-pending   { background: #fef9c3; color: #a16207; }
.b-rejected  { background: #fee2e2; color: var(--red-800); }
.b-expired   { background: #f3f4f6; color: #6b7280; }
.b-suspended { background: #ffedd5; color: #9a3412; }
.b-admin     { background: var(--red-100); color: var(--red-800); }
.b-info      { background: #eff6ff; color: #1d4ed8; }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(24,20,16,.5); backdrop-filter: blur(4px);
  z-index: 200; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--surface); border-radius: var(--r-xl);
  width: 100%; max-width: 720px; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--sh-pop);
}
.modal-header {
  padding: 24px 28px 0;
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 18px; font-weight: 800; letter-spacing: -.02em; }
.modal-close {
  width: 32px; height: 32px; border-radius: var(--r-pill);
  background: var(--surface-2); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-3); transition: background .12s;
}
.modal-close:hover { background: var(--red-100); color: var(--red-700); }
.modal-body   { padding: 20px 28px; }
.modal-footer {
  padding: 0 28px 24px;
  display: flex; gap: 10px; justify-content: flex-end;
}

/* Room cards in modal */
.room-cards { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.room-card {
  flex: 1; min-width: 150px;
  border: 2px solid var(--line-2); border-radius: var(--r-md);
  padding: 12px 14px; cursor: pointer;
  transition: border-color .12s, background .12s, box-shadow .12s;
  font-weight: 600; font-size: 13px;
}
.room-card:hover { border-color: var(--red-300); background: var(--red-50); }
.room-card.selected { border-color: var(--red-600); background: var(--red-50); box-shadow: 0 0 0 3px rgba(220,38,38,.12); }

/* Day + period selection */
.day-cards, .period-cells { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.day-card, .period-cell {
  padding: 6px 14px; border-radius: var(--r-sm);
  border: 1.5px solid var(--line-2); cursor: pointer;
  font-size: 13px; font-weight: 600; transition: background .12s, border-color .12s;
}
.day-card.selected, .period-cell.selected { background: var(--red-600); color: #fff; border-color: var(--red-600); }
.day-card:hover:not(.selected), .period-cell:hover:not(.selected):not(.conflict) { background: var(--red-50); border-color: var(--red-500); }
.period-cell.conflict { background: #fef2f2; border-color: #fecaca; color: var(--ink-4); cursor: not-allowed; }
.period-cell.conflict::after { content: ' ติด'; font-size: 10px; font-weight: 700; color: var(--red-600); }

/* Range summary */
.range-summary {
  background: var(--red-50); border: 1px solid var(--red-200); border-radius: var(--r-md);
  padding: 10px 14px; margin-bottom: 16px;
  font-size: 13px; color: var(--red-800); font-weight: 600;
}
.range-summary.conflict { background: #fee2e2; border-color: #fecaca; color: var(--red-700); }

/* Form fields */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 700; color: var(--ink-2); margin-bottom: 6px; }
.form-control {
  width: 100%; padding: 9px 12px; border-radius: var(--r-md);
  border: 1.5px solid var(--line-2); background: var(--surface);
  font-family: inherit; font-size: 14px; color: var(--ink);
  transition: border-color .12s, box-shadow .12s; outline: none;
}
.form-control:focus { border-color: var(--red-500); box-shadow: 0 0 0 3px rgba(239,68,68,.12); }

/* ── Login page ───────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh; display: flex; align-items: stretch;
}
.login-left {
  flex: 1; background: var(--red-700);
  padding: 60px;
  display: flex; flex-direction: column; justify-content: center;
  color: #fff;
}
.login-right {
  width: 420px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 40px;
}
.login-card {
  width: 100%; max-width: 360px;
  background: var(--surface); border-radius: var(--r-xl);
  padding: 36px; box-shadow: var(--sh-3);
}
.login-title { font-size: 22px; font-weight: 800; letter-spacing: -.02em; margin-bottom: 6px; }
.login-sub   { font-size: 13px; color: var(--ink-3); margin-bottom: 28px; }

.btn-google {
  width: 100%; padding: 11px 18px;
  background: #fff; color: #3c4043;
  border: 1.5px solid #dadce0; border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center; gap: 10px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: box-shadow .12s;
  font-family: inherit; text-decoration: none;
}
.btn-google:hover { box-shadow: 0 2px 8px rgba(0,0,0,.12); }

.login-pending-note {
  margin-top: 20px; padding: 14px 16px;
  background: var(--red-50); border: 1px solid var(--red-200); border-radius: var(--r-md);
  font-size: 12.5px; color: var(--ink-2);
}

/* ── Pending page ─────────────────────────────────────────────────────────── */
.pending-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--bg);
}
.pending-card {
  width: 100%; max-width: 520px;
  background: var(--surface); border-radius: var(--r-xl);
  padding: 40px; box-shadow: var(--sh-3); text-align: center;
}

/* ── Tables ───────────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; padding: 10px 14px;
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-3); background: var(--surface-2);
  border-bottom: 1px solid var(--line); font-family: 'Plus Jakarta Sans', sans-serif;
}
.data-table td {
  padding: 12px 14px; border-bottom: 1px solid var(--line);
  font-size: 13.5px; color: var(--ink-2);
}
.data-table tr:hover td { background: var(--red-50); }

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--line); margin-bottom: 20px; }
.tab {
  padding: 8px 18px; font-size: 13.5px; font-weight: 700; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -2px; color: var(--ink-3);
  transition: color .12s, border-color .12s;
}
.tab:hover  { color: var(--red-700); }
.tab.active { color: var(--red-700); border-bottom-color: var(--red-600); }

/* ── Divider ─────────────────────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--line); margin: 20px 0; }

/* ── Week nav ─────────────────────────────────────────────────────────────── */
.week-nav {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-md);
  padding: 4px 8px;
}
.week-nav button {
  background: none; border: none; cursor: pointer; padding: 4px 6px;
  color: var(--ink-3); border-radius: var(--r-sm);
  transition: background .12s, color .12s;
}
.week-nav button:hover { background: var(--red-50); color: var(--red-700); }
.week-nav .week-label { font-size: 13px; font-weight: 700; color: var(--ink-2); min-width: 160px; text-align: center; }

/* ── Audit log action chips ──────────────────────────────────────────────── */
.action-chip {
  padding: 2px 8px; border-radius: var(--r-pill);
  font-size: 11px; font-weight: 700; font-family: 'Plus Jakarta Sans', sans-serif;
}
.ac-booking { background: #eff6ff; color: #1d4ed8; }
.ac-auth    { background: #ecfdf5; color: #047857; }
.ac-user    { background: #fef9c3; color: #a16207; }
.ac-delete, .ac-failed { background: #fee2e2; color: var(--red-800); }
.ac-lock    { background: #ffedd5; color: #9a3412; }
.ac-system  { background: #f3f4f6; color: #6b7280; }

/* ── Toast ────────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 24px; right: 24px; z-index: 999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 12px 18px; border-radius: var(--r-md);
  background: var(--ink); color: #fff;
  font-size: 13.5px; font-weight: 600;
  box-shadow: var(--sh-pop);
  animation: slideIn .2s ease;
}
.toast.success { background: #047857; }
.toast.error   { background: var(--red-700); }
@keyframes slideIn { from { transform: translateY(10px); opacity: 0; } }

/* ── Room color borders (My Bookings list) ───────────────────────────────── */
.room-color-red   { border-left: 3px solid var(--red-600); }
.room-color-green { border-left: 3px solid #059669; }
.room-color-blue  { border-left: 3px solid #2563eb; }

/* ── Utils ────────────────────────────────────────────────────────────────── */
.hidden  { display: none !important; }
.mono    { font-family: 'JetBrains Mono', monospace; }
.text-sm { font-size: 12px; color: var(--ink-3); }
.fw-700  { font-weight: 700; }
.mt-4    { margin-top: 16px; }
.mb-4    { margin-bottom: 16px; }
.gap-8   { gap: 8px; }
.flex    { display: flex; }
.ai-c    { align-items: center; }

@media (max-width: 768px) {
  .sidenav { display: none; }
  .login-left { display: none; }
  .login-right { width: 100%; }
  .main-content { padding: 16px; }
}
