/* ===========================================================
   Baoji Sport Complex — Web Admin
   Design Tokens (based on CreateSpace Design System)
   =========================================================== */

:root {
  /* Colors */
  --color-primary: #E11D48;
  --color-primary-soft: #FFF1F2;
  --color-secondary: #2563EB;
  --color-secondary-soft: #DBEAFE;
  --color-tertiary: #FACC15;
  --color-success: #16A34A;
  --color-success-soft: #DCFCE7;
  --color-warning: #D97706;
  --color-warning-soft: #FEF3C7;
  --color-error: #DC2626;
  --color-error-soft: #FEF2F2;
  --color-info: #2563EB;
  --color-info-soft: #DBEAFE;

  /* Surfaces */
  --surface-base: #FFFFFF;
  --surface-muted: #F9FAFB;
  --surface-raised: #FFFFFF;
  --surface-glass: rgba(255, 255, 255, 0.65);

  /* Text */
  --text-strong: #111827;
  --text-default: #1F2937;
  --text-muted: #6B7280;
  --text-soft: #9CA3AF;
  --text-on-primary: #FFFFFF;

  /* Borders */
  --border-default: #E5E7EB;
  --border-strong: #D1D5DB;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 32px;
  --space-6: 48px;
  --space-8: 64px;
  --space-10: 80px;

  /* Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-pill: 9999px;

  /* Shadows */
  --shadow-glass: 0 8px 32px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.10);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.15);
  --shadow-color: 0 8px 24px rgba(225, 29, 72, 0.25);
  --shadow-focus: 0 0 0 3px rgba(37, 99, 235, 0.35);

  /* Sidebar */
  --sidebar-width: 260px;
  --topbar-height: 64px;
}

/* ===========================================================
   Reset & Base
   =========================================================== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: 'Prompt', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-default);
  background: var(--surface-muted);
  -webkit-font-smoothing: antialiased;
}

/* ===========================================================
   Custom Scrollbars (subtle, brand-colored)
   =========================================================== */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(225, 29, 72, 0.3) transparent;
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.15);
  border-radius: 9999px;
  border: 2px solid transparent;
  background-clip: padding-box;
  transition: background 150ms ease;
}

*::-webkit-scrollbar-thumb:hover {
  background: rgba(225, 29, 72, 0.5);
  background-clip: padding-box;
  border: 2px solid transparent;
}

*::-webkit-scrollbar-corner {
  background: transparent;
}

/* Modal: hide scrollbar by default, show on hover */
.modal {
  scrollbar-gutter: stable;
}

.modal::-webkit-scrollbar-thumb {
  background: transparent;
}

.modal:hover::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.15);
  background-clip: padding-box;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  display: block;
}

button {
  font-family: inherit;
}

/* ===========================================================
   Typography
   =========================================================== */
.text-hero {
  font-size: 72px;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.02em;
}

.text-h1 {
  font-size: 40px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.text-h2 {
  font-size: 28px;
  font-weight: 600;
  line-height: 1.2;
}

.text-h3 {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
}

.text-body-lg {
  font-size: 18px;
  font-weight: 400;
  line-height: 1.6;
}

.text-body {
  font-size: 15px;
  font-weight: 400;
  line-height: 1.6;
}

.text-caption {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
  color: var(--text-muted);
}

.text-strong { color: var(--text-strong); }
.text-muted { color: var(--text-muted); }
.text-primary { color: var(--color-primary); }
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }
.text-error { color: var(--color-error); }

/* ===========================================================
   Layout: Sidebar + Topbar
   =========================================================== */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  grid-template-rows: var(--topbar-height) 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  min-height: 100vh;
  transition: grid-template-columns 250ms ease;
}

.app.is-sidebar-collapsed {
  grid-template-columns: 0px minmax(0, 1fr);
}

.app.is-sidebar-collapsed .sidebar {
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
}

/* Mobile drawer backdrop — ซ่อนบนเดสก์ท็อป, แสดงเฉพาะมือถือเมื่อเปิด drawer */
.sidebar-backdrop { display: none; }

.sidebar {
  grid-area: sidebar;
  background: linear-gradient(180deg, #0F172A 0%, #1E293B 100%);
  color: #E2E8F0;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: transform 250ms ease, opacity 250ms ease;
  overflow: hidden;
}

.sidebar-toggle {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  border: 1px solid var(--border-default);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-default);
  transition: all 150ms ease;
  flex-shrink: 0;
}
.sidebar-toggle:hover {
  background: var(--color-primary-soft);
  color: var(--color-primary);
  border-color: var(--color-primary);
}
.sidebar-toggle svg { width: 20px; height: 20px; }

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-2) var(--space-5);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  margin-bottom: var(--space-4);
}

.sidebar__brand img {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: #fff;
  padding: 4px;
}

.sidebar__brand-text {
  display: flex;
  flex-direction: column;
}

.sidebar__brand-title {
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  line-height: 1.2;
}

.sidebar__brand-sub {
  font-size: 11px;
  color: #94A3B8;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.sidebar__section {
  font-size: 11px;
  color: #64748B;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: var(--space-3) var(--space-2) var(--space-2);
}

.sidebar__link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px var(--space-3);
  border-radius: var(--radius-md);
  color: #CBD5E1;
  font-size: 14px;
  font-weight: 500;
  transition: all 150ms ease;
  cursor: pointer;
}

.sidebar__link:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.sidebar__link.is-active {
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-color);
}

.sidebar__link svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.sidebar__footer {
  padding-top: var(--space-3);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.topbar {
  grid-area: topbar;
  background: var(--surface-base);
  border-bottom: 1px solid var(--border-default);
  padding: 0 var(--space-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar__left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.topbar__title {
  font-weight: 600;
  font-size: 18px;
  color: var(--text-strong);
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.main {
  grid-area: main;
  padding: var(--space-5);
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}

/* ===========================================================
   Language Switch
   =========================================================== */
.lang-switch {
  display: inline-flex;
  background: var(--surface-muted);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-pill);
  padding: 3px;
}

.lang-switch button {
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 150ms ease;
}

.lang-switch button.is-active {
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-color);
}

/* ===========================================================
   Avatar
   =========================================================== */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
}

/* ===========================================================
   Buttons
   =========================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: all 150ms ease;
  white-space: nowrap;
}

.btn--sm { height: 32px; padding: 0 14px; font-size: 13px; min-width: 72px; }
.btn--md { height: 40px; padding: 0 20px; font-size: 14px; min-width: 100px; }
.btn--lg { height: 48px; padding: 0 28px; font-size: 16px; min-width: 140px; }

.btn--primary { background: var(--color-primary); color: #fff; }
.btn--primary:hover { background: #BE123C; box-shadow: var(--shadow-color); }

.btn--secondary { background: var(--color-secondary); color: #fff; }
.btn--secondary:hover { background: #1D4ED8; }

.btn--ghost { background: transparent; color: var(--color-primary); border: 1.5px solid var(--color-primary); }
.btn--ghost:hover { background: var(--color-primary-soft); }

.btn--success { background: var(--color-success); color: #fff; }
.btn--success:hover { background: #15803D; }

.btn--destructive { background: var(--color-error); color: #fff; }
.btn--destructive:hover { background: #B91C1C; }

.btn--neutral { background: #fff; color: var(--text-default); border: 1px solid var(--border-default); }
.btn--neutral:hover { background: var(--surface-muted); }

.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===========================================================
   Cards
   =========================================================== */
.card {
  background: var(--surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow-glass);
}

.card--glass {
  background: var(--surface-glass);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.card__title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-strong);
}

.card__sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===========================================================
   Stat Card
   =========================================================== */
.stat {
  background: var(--surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  position: relative;
  overflow: hidden;
}

.stat__label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

.stat__value {
  font-size: 32px;
  font-weight: 700;
  color: var(--text-strong);
  line-height: 1.1;
}

.stat__delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  width: fit-content;
}

.stat__delta--up { background: var(--color-success-soft); color: var(--color-success); }
.stat__delta--down { background: var(--color-error-soft); color: var(--color-error); }

.stat__icon {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat--primary .stat__icon { background: var(--color-primary-soft); color: var(--color-primary); }
.stat--secondary .stat__icon { background: var(--color-secondary-soft); color: var(--color-secondary); }
.stat--success .stat__icon { background: var(--color-success-soft); color: var(--color-success); }
.stat--warning .stat__icon { background: var(--color-warning-soft); color: var(--color-warning); }

/* ===========================================================
   Inputs
   =========================================================== */
.input,
.select,
.textarea {
  width: 100%;
  height: 40px;
  padding: 0 14px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text-default);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  transition: all 150ms ease;
  outline: none;
}

.textarea {
  height: auto;
  padding: 10px 14px;
  min-height: 100px;
  resize: vertical;
}

.input:hover,
.select:hover {
  border-color: #9CA3AF;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--color-secondary);
  box-shadow: var(--shadow-focus);
}

.input--error {
  border-color: var(--color-error);
  background: var(--color-error-soft);
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.input-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-strong);
}

.input-help {
  font-size: 12px;
  color: var(--text-muted);
}

/* Search input with icon */
.search {
  position: relative;
}

.search__icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 18px;
  height: 18px;
  pointer-events: none;
}

.search input {
  padding-left: 40px;
}

/* ===========================================================
   Chips & Badges
   =========================================================== */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  background: #F3F4F6;
  color: var(--text-strong);
  border: 1px solid var(--border-default);
  cursor: pointer;
  transition: all 150ms ease;
}

.chip:hover {
  background: #E5E7EB;
}

.chip.is-active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}

.badge--success { background: var(--color-success-soft); color: #166534; }
.badge--warning { background: var(--color-warning-soft); color: #92400E; }
.badge--error { background: var(--color-error-soft); color: #991B1B; }
.badge--info { background: var(--color-secondary-soft); color: #1E40AF; }
.badge--neutral { background: #F3F4F6; color: #6B7280; }

.badge .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ===========================================================
   Tables
   =========================================================== */
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}

.table thead th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 12px 16px;
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border-default);
}

.table tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-default);
  color: var(--text-default);
}

.table tbody tr {
  transition: background 150ms ease;
}

.table tbody tr:hover {
  background: var(--surface-muted);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table__primary {
  font-weight: 600;
  color: var(--text-strong);
}

/* ===========================================================
   Court Schedule Grid
   =========================================================== */
.schedule-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.schedule-toolbar__left {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.schedule-grid-wrap {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  border-radius: var(--radius-lg);
  background: #fff;
  border: 1px solid var(--border-default);
}

.schedule-grid {
  display: grid;
  grid-template-columns: 160px repeat(16, minmax(78px, 1fr));
  grid-template-rows: 44px;
  grid-auto-rows: 64px;
  min-width: 1640px;
}

.schedule-grid__head,
.schedule-grid__court,
.schedule-grid__cell {
  border-bottom: 1px solid var(--border-default);
  border-right: 1px solid var(--border-default);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.schedule-grid__head {
  padding: 0 8px;
  font-weight: 600;
  color: var(--text-strong);
  background: var(--surface-muted);
  position: sticky;
  top: 0;
  z-index: 2;
  font-family: 'Fira Code', monospace;
  font-size: 12px;
}

.schedule-grid__corner {
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border-default);
  border-right: 1px solid var(--border-default);
  position: sticky;
  top: 0;
  left: 0;
  z-index: 3;
}

.schedule-grid__court {
  padding: 8px 14px;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 2px;
  background: #fff;
  position: sticky;
  left: 0;
  z-index: 1;
}

.schedule-grid__court-name {
  font-weight: 600;
  color: var(--text-strong);
  white-space: nowrap;
  font-size: 13px;
}

.schedule-grid__court-code {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'Fira Code', monospace;
}

.schedule-grid__cell {
  padding: 4px;
  cursor: pointer;
  transition: all 150ms ease;
  position: relative;
}

.schedule-grid__cell--available {
  background: #fff;
}

.schedule-grid__cell--available:hover {
  background: var(--color-success-soft);
}

.schedule-grid__cell--booked {
  background: #FFE4E6;
  color: #9F1239;
}

.schedule-grid__cell--locked {
  background: #FEF3C7;
  color: #92400E;
}

.schedule-grid__cell--maintenance {
  background: repeating-linear-gradient(
    45deg,
    #F3F4F6,
    #F3F4F6 4px,
    #E5E7EB 4px,
    #E5E7EB 8px
  );
  color: var(--text-muted);
}

.schedule-grid__cell-content {
  font-size: 11px;
  font-weight: 600;
  padding: 6px;
  border-radius: 6px;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  line-height: 1.3;
  gap: 2px;
}

/* Price tag on empty cell */
.schedule-grid__cell--available .price-tag {
  position: absolute;
  bottom: 4px;
  right: 6px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-soft);
  font-family: 'Fira Code', monospace;
  pointer-events: none;
}

.schedule-grid__cell--available .add-icon {
  font-size: 18px;
  color: #D1D5DB;
  font-weight: 400;
  transition: all 150ms ease;
}

.schedule-grid__cell--available:hover .add-icon {
  color: var(--color-primary);
  transform: scale(1.2);
}

.schedule-grid__cell--available:hover .price-tag {
  color: var(--color-primary);
}

.schedule-grid__cell--peak.schedule-grid__cell--available {
  background: linear-gradient(180deg, transparent 0%, transparent 60%, #FEF3C7 100%);
}

.schedule-grid__head--peak {
  background: linear-gradient(180deg, #FEF3C7 0%, #FDE68A 100%);
  color: #92400E;
}

.peak-band {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
}
.peak-band--off { background: #DBEAFE; color: #1E40AF; }
.peak-band--peak { background: #FEF3C7; color: #92400E; }

/* ===========================================================
   Modal / Drawer
   =========================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.modal-backdrop.is-open {
  display: flex;
  animation: fadeIn 200ms ease;
}

@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

.modal {
  background: #fff;
  border-radius: var(--radius-xl);
  max-width: 720px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 250ms ease;
}

@keyframes slideUp { from { transform: translateY(20px); opacity: 0 } to { transform: translateY(0); opacity: 1 } }

.modal__head {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-default);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 1;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

.modal__title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-strong);
}

.modal__sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.modal__close {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  border: none;
  cursor: pointer;
  font-size: 18px;
  color: var(--text-muted);
}
.modal__close:hover { background: #E5E7EB; }

.modal__body {
  padding: var(--space-4) var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.modal__foot {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border-default);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  position: sticky;
  bottom: 0;
  background: #fff;
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-strong);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title::before {
  content: '';
  width: 4px;
  height: 14px;
  background: var(--color-primary);
  border-radius: 2px;
}

/* Duration picker */
.duration-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.duration-tile {
  border: 1.5px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 12px;
  text-align: center;
  cursor: pointer;
  transition: all 150ms ease;
  background: #fff;
}

.duration-tile:hover {
  border-color: var(--color-primary);
}

.duration-tile.is-active {
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
}

.duration-tile__hour {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-strong);
}

.duration-tile__label {
  font-size: 12px;
  color: var(--text-muted);
}

.duration-tile.is-disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: var(--surface-muted);
}

/* Payment method radio */
.pay-method {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.pay-tile {
  border: 1.5px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 14px 12px;
  cursor: pointer;
  transition: all 150ms ease;
  text-align: center;
  background: #fff;
}

.pay-tile:hover {
  border-color: var(--color-secondary);
}

.pay-tile.is-active {
  border-color: var(--color-secondary);
  background: var(--color-secondary-soft);
}

.pay-tile__icon {
  font-size: 22px;
  margin-bottom: 4px;
}

.pay-tile__label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-strong);
}

/* Price breakdown */
.price-card {
  background: linear-gradient(135deg, #FFF1F2 0%, #DBEAFE 100%);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

.price-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  padding: 6px 0;
}

.price-row--total {
  border-top: 1px dashed #94A3B8;
  margin-top: 8px;
  padding-top: 12px;
  font-size: 22px;
  font-weight: 700;
}

.price-slot {
  display: flex;
  align-items: center;
  gap: 8px;
}

.price-slot__badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-pill);
  text-transform: uppercase;
}
.price-slot__badge--off { background: #DBEAFE; color: #1E40AF; }
.price-slot__badge--peak { background: #FEF3C7; color: #92400E; }

.legend {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-top: var(--space-3);
}

.legend__item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.legend__swatch {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid var(--border-default);
}

/* ===========================================================
   Login Page
   =========================================================== */
.login {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.login__brand {
  background: linear-gradient(135deg, #E11D48 0%, #2563EB 100%);
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: var(--space-8);
  color: #fff;
}

.login__brand::before,
.login__brand::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.5;
}

.login__brand::before {
  width: 400px;
  height: 400px;
  background: #FACC15;
  top: -100px;
  right: -100px;
}

.login__brand::after {
  width: 320px;
  height: 320px;
  background: #2563EB;
  bottom: -80px;
  left: -80px;
}

.login__brand-content {
  position: relative;
  z-index: 1;
}

.login__brand-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

.login__brand-logo img {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  background: #fff;
  padding: 6px;
}

.login__hero {
  font-size: 48px;
  font-weight: 800;
  line-height: 1.1;
  margin: 0 0 var(--space-3);
}

.login__sub {
  font-size: 18px;
  opacity: 0.9;
  max-width: 480px;
}

.login__features {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  margin-top: var(--space-6);
}

.login__feature {
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: var(--space-3);
  border-radius: var(--radius-lg);
}

.login__feature-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-2);
}

.login__feature-title {
  font-weight: 600;
  margin-bottom: 2px;
}

.login__feature-text {
  font-size: 13px;
  opacity: 0.9;
}

.login__form {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: var(--space-8);
  background: #fff;
  position: relative;
}

.login__form-inner {
  max-width: 400px;
  width: 100%;
  margin: 0 auto;
}

.login__form-title {
  font-size: 32px;
  font-weight: 700;
  color: var(--text-strong);
  margin: 0 0 var(--space-2);
}

.login__form-sub {
  color: var(--text-muted);
  margin: 0 0 var(--space-5);
}

.login__form-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.login__form-extra {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  margin-bottom: var(--space-4);
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
}

.checkbox input {
  appearance: none;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--border-strong);
  border-radius: 4px;
  position: relative;
  cursor: pointer;
  transition: all 150ms ease;
}

.checkbox input:checked {
  background: var(--color-primary);
  border-color: var(--color-primary);
}

.checkbox input:checked::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.login__topbar {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
}

/* ===========================================================
   Booking Detail Drawer / Panel
   =========================================================== */
.detail-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: var(--space-4);
}

.detail-grid__col {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.kv {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: var(--space-2);
  padding: 10px 0;
  border-bottom: 1px dashed var(--border-default);
  font-size: 14px;
}

.kv:last-child { border-bottom: none; }

.kv__label { color: var(--text-muted); font-weight: 500; }
.kv__value { color: var(--text-strong); font-weight: 500; }

/* ===========================================================
   Slip OCR specific
   =========================================================== */
.slip-layout {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: var(--space-4);
}

.slip-image-frame {
  background: var(--surface-muted);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-default);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.slip-image {
  background: #fff;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  padding: 16px;
  font-family: 'Fira Code', monospace;
  font-size: 13px;
  line-height: 1.8;
  min-height: 360px;
  color: var(--text-default);
  position: relative;
}

.slip-image__bank {
  color: var(--color-secondary);
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 8px;
}

.slip-image__row {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dashed var(--border-default);
  padding: 4px 0;
}

.slip-image__amount {
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  margin: 12px 0;
  color: var(--color-success);
}

.ocr-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: var(--space-3);
  border: 1.5px solid var(--border-default);
  border-radius: var(--radius-md);
  background: #fff;
}

.ocr-field--match {
  border-color: var(--color-success);
  background: var(--color-success-soft);
}

.ocr-field--mismatch {
  border-color: var(--color-error);
  background: var(--color-error-soft);
}

.ocr-field__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ocr-field__value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-strong);
  font-family: 'Fira Code', 'Prompt', monospace;
}

.ocr-field__expected {
  font-size: 12px;
  color: var(--text-muted);
}

.match-summary {
  padding: var(--space-3);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.match-summary--full {
  background: var(--color-success-soft);
  color: #166534;
}

.match-summary--partial {
  background: var(--color-warning-soft);
  color: #92400E;
}

.match-summary--fail {
  background: var(--color-error-soft);
  color: #991B1B;
}

.match-summary__icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
}

.match-summary__title {
  font-weight: 700;
  font-size: 15px;
}

.match-summary__text {
  font-size: 13px;
  opacity: 0.9;
}

/* ===========================================================
   Utilities
   =========================================================== */
.grid {
  display: grid;
  gap: var(--space-4);
}

.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-5 { margin-bottom: var(--space-5); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }

.w-full { width: 100%; }
.text-right { text-align: right; }
.text-center { text-align: center; }

/* ===========================================================
   Responsive
   =========================================================== */

/* Topbar title — always truncate, never wrap */
.topbar__left {
  min-width: 0;
  overflow: hidden;
  flex: 1;
}
.topbar__title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Table horizontal scroll — card เป็น scroll container */
.card { overflow-x: auto; }

@media (max-width: 1024px) {
  .grid-cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-cols-3 { grid-template-columns: repeat(2, 1fr); }
  .detail-grid { grid-template-columns: 1fr; }
  .slip-layout { grid-template-columns: 1fr; }
  .topbar .search { width: 180px; }
}

@media (max-width: 900px) {
  .topbar .search { width: 140px; }
}

@media (max-width: 768px) {
  :root { --sidebar-width: 0px; }

  /* App = คอลัมน์เดียวเสมอ — กัน grid พังเมื่อมี is-sidebar-collapsed ค้างอยู่ */
  .app,
  .app.is-sidebar-collapsed {
    grid-template-columns: 1fr;
    grid-template-areas: "topbar" "main";
  }

  /* Sidebar = drawer เลื่อนทับหน้าจอ (ปิดอยู่โดยปริยาย) */
  .sidebar {
    display: flex;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 264px;
    max-width: 82vw;
    height: 100vh;
    z-index: 60;
    transform: translateX(-100%);
    opacity: 1;
    pointer-events: auto;
  }
  /* คลาส collapse ของเดสก์ท็อปไม่มีผลบนมือถือ — drawer ปิดอยู่แล้ว */
  .app.is-sidebar-collapsed .sidebar {
    transform: translateX(-100%);
    opacity: 1;
    pointer-events: auto;
  }
  /* เปิด drawer */
  .app.is-sidebar-open .sidebar {
    transform: translateX(0);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.45);
  }
  /* Backdrop */
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 55;
    opacity: 0;
    visibility: hidden;
    transition: opacity 200ms ease;
  }
  .app.is-sidebar-open .sidebar-backdrop {
    opacity: 1;
    visibility: visible;
  }

  .login { grid-template-columns: 1fr; }
  .login__brand { display: none; }
  .grid-cols-4, .grid-cols-3, .grid-cols-2 { grid-template-columns: 1fr; }

  /* Topbar on mobile */
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar__title { font-size: 15px; max-width: 120px; }
  .topbar__actions { gap: 8px; }
  .topbar .search { display: none; }   /* ซ่อน search — ใช้ icon แทน */

  /* Table cells don't wrap on mobile */
  .table th, .table td { white-space: nowrap; }

  /* Main content padding ลดลง */
  .main { padding: 16px 12px; }

  /* Headings ย่อลง */
  .text-h2 { font-size: 20px; }
  .text-h1 { font-size: 22px; }

  /* Card header wrap */
  .card__header { flex-wrap: wrap; gap: 8px; }

  /* Buttons stack on mobile */
  .flex.gap-1 { flex-wrap: nowrap; }
}

@media (max-width: 480px) {
  .topbar__title { max-width: 80px; }
  .topbar { padding: 0 8px; }
  .main { padding: 12px 8px; }
  .btn--md { padding: 8px 14px; font-size: 13px; }
}

/* ===========================================================
   Phase 1B additions
   =========================================================== */

/* Modal aliases & size variants */
.modal__header {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-default);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-strong);
  position: sticky; top: 0; background: #fff; z-index: 1;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}
.modal__footer {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-default);
  display: flex; justify-content: flex-end; gap: var(--space-2);
  position: sticky; bottom: 0; background: #fff;
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}
.modal--sm { max-width: 420px; }
.modal--md { max-width: 600px; }
.modal--lg { max-width: 800px; }

/* Page header */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; margin-bottom: 20px;
}
.page-title { font-size: 22px; font-weight: 700; color: var(--text-strong); margin: 0; }
.page-sub { font-size: 13px; color: var(--text-muted); margin: 2px 0 0; }

/* Form layout */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-row { margin-bottom: 0; }
.form-row--2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 0; }
.form-row--3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; margin-bottom: 0; }
.label { font-size: 13px; font-weight: 600; color: var(--text-strong); }

/* Table wrap */
.table-wrap { overflow-x: auto; }

/* Tabs */
.tab-bar { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 2px solid var(--border-default); }
.tab {
  padding: 8px 18px; border-radius: var(--radius-md) var(--radius-md) 0 0;
  font-size: 14px; font-weight: 600; color: var(--text-muted); text-decoration: none;
  transition: all 150ms;
}
.tab:hover { color: var(--color-primary); background: var(--color-primary-soft); }
.tab.is-active { color: var(--color-primary); border-bottom: 2px solid var(--color-primary); background: var(--color-primary-soft); }
.tab .badge { margin-left: 6px; }

/* Switch toggle */
.switch-label {
  display: inline-flex; align-items: center; gap: 10px; cursor: pointer;
  font-size: 14px; font-weight: 500; color: var(--text-default);
}
.switch-label input[type=checkbox] { display: none; }
.switch-track {
  width: 44px; height: 24px; border-radius: 99px; background: #D1D5DB;
  position: relative; transition: background 200ms; flex-shrink: 0;
}
.switch-track::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2); transition: transform 200ms;
}
.switch-label input:checked ~ .switch-track { background: var(--color-primary); }
.switch-label input:checked ~ .switch-track::after { transform: translateX(20px); }

/* Badge extras */
.badge--secondary { background: var(--color-secondary-soft); color: var(--color-secondary); }
.badge--muted { background: #F3F4F6; color: #6B7280; }
.badge--danger { background: var(--color-error-soft); color: var(--color-error); }

/* Button extras */
.btn--danger { background: var(--color-error); color: #fff; border: none; }
.btn--danger:hover { background: #B91C1C; }
.btn--outline { background: transparent; border: 1.5px solid currentColor; }
.btn--ghost.btn--danger { background: transparent; color: var(--color-error); border: 1.5px solid var(--color-error); }
.btn--ghost.btn--danger:hover { background: var(--color-error-soft); }

/* Utility extras */
.text-muted { color: var(--text-muted); }
.fw-600 { font-weight: 600; }
.text-danger { color: var(--color-error); }
small.text-muted { font-size: 12px; }
