/* Reuses the "Garden Clinic" tokens from DESIGN.md so the admin tool reads
   as the same system as the customer site, not a bolted-on dashboard.
   Dark mode mirrors frontend/css/index.css's `.dark` class mechanism so the
   two surfaces behave identically for the shop owner. */
:root {
  --bg: #e6f3dd;
  --panel: #ffffff;
  --border: #e5e7eb;
  --text: #0f172a;
  --muted: #64748b;
  --muted-on-sage: #3d4f3d;
  --primary: #111827;
  --accent: #dbeafe;
  --accent-dark: #93c5fd;
  --accent-dot: #2563eb;
  --radius: 16px;
  --shadow-soft: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-card: 0 10px 30px rgba(15, 23, 42, 0.06);
  --shadow-modal: 0 20px 50px rgba(0, 0, 0, 0.18);

  --success-bg: #dcfce7;
  --success-text: #166534;
  --warning-bg: #fef3c7;
  --warning-text: #b45309;
  --error-bg: #fee2e2;
  --error-text: #991b1b;

  --sidebar-width: 248px;
  --topbar-height: 60px;
  --motion-fast: 150ms ease;
  --motion-base: 220ms ease;

  /* A shade deeper than --bg so the sidebar reads as its own sage-wash
     surface (per DESIGN.md's Green-Is-Brand rule) instead of a flat white
     panel dropped onto the canvas. --border (#e5e7eb) is calibrated against
     Panel White and is nearly invisible here (contrast ~1:1) — this darker
     sage-green line replaces it wherever a divider sits directly on
     --sidebar-bg. Same reasoning DESIGN.md already applies to muted text via
     --muted-on-sage. */
  --sidebar-bg: #dbebcd;
  --sidebar-border: #5f7f4a;
}

html.dark {
  --bg: #0b1220;
  --panel: #111827;
  --border: #2d3648;
  --text: #f1f5f9;
  --muted: #9ca3af;
  --muted-on-sage: #c7d8c0;
  --primary: #f8fafc;
  --accent: #1e293b;
  --accent-dark: #334155;
  --accent-dot: #60a5fa;
  --shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-card: 0 10px 30px rgba(0, 0, 0, 0.3);
  --shadow-modal: 0 20px 50px rgba(0, 0, 0, 0.55);

  --success-bg: #14301f;
  --success-text: #4ade80;
  --warning-bg: #3a2a0d;
  --warning-text: #fbbf24;
  --error-bg: #3b1414;
  --error-text: #fca5a5;

  /* Dark mode keeps the sidebar on the same near-black panel as every other
     surface — sage only leads in light mode — so its divider matches the
     regular dark --border instead of the light-mode sage line. */
  --sidebar-bg: #111827;
  --sidebar-border: #2d3648;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Prompt",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  transition:
    background var(--motion-base),
    color var(--motion-base);
}

.muted {
  color: var(--muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent-dark);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ===================== BUTTONS ===================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  min-height: 44px;
  border-radius: 12px;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-soft);
  transition:
    transform var(--motion-fast),
    background var(--motion-fast);
}
.btn:hover {
  transform: translateY(-2px);
  background: var(--accent);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
/* Icon+text buttons (e.g. "+ เพิ่มบริการ") had no sizing rule for their SVG,
   so it rendered at the browser's unstyled default (a few hundred px) —
   that's what was ballooning the button, not the button's own padding. */
.btn svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--bg, #fff);
}
html:not(.dark) .btn-primary {
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary);
  filter: brightness(1.15);
}

.btn-secondary {
  background: var(--panel);
}

.btn-danger {
  background: var(--error-bg);
  border-color: var(--error-bg);
  color: var(--error-text);
}
.btn-danger:hover {
  filter: brightness(0.96);
  background: var(--error-bg);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  flex: none;
  transition:
    background var(--motion-fast),
    transform var(--motion-fast);
}
.icon-btn:hover {
  background: var(--accent);
  transform: translateY(-1px);
}
.icon-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
.icon-btn:disabled:hover {
  background: var(--panel);
}
.icon-btn svg {
  width: 20px;
  height: 20px;
}

/* ===================== APP SHELL / SIDEBAR ===================== */

.admin-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
}

.nav-toggle-checkbox {
  display: none;
}

.topbar-mobile {
  display: none;
  align-items: center;
  gap: 12px;
  height: var(--topbar-height);
  padding: 0 14px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--sidebar-border);
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar-brand {
  font-weight: 800;
  font-size: 1rem;
  flex: 1;
}

.nav-backdrop {
  display: none;
}

.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  /* Without this, content taller than the viewport (5 nav items + footer on
     a short phone screen) just overflows past the bottom edge with nothing
     to scroll it into view — "ออกจากระบบ"/theme toggle become untappable,
     not just visually clipped. Sidebar has its own scroll region instead of
     relying on the page (which is position:fixed on mobile and can't help). */
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 16px;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-logo {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex: none;
  box-shadow: var(--shadow-soft);
}

.sidebar-brand-name {
  font-weight: 800;
  font-size: 0.9rem;
  line-height: 1.25;
}

.sidebar-brand-sub {
  font-size: 0.8rem;
  /* --muted is calibrated against Panel White (3.8:1 here, fails AA) —
     --muted-on-sage is DESIGN.md's documented swap for sage surfaces. */
  color: var(--muted-on-sage);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.9rem;
  text-decoration: none;
  color: var(--text);
  transition:
    background var(--motion-fast),
    color var(--motion-fast);
}

.sidebar-nav-item svg {
  width: 20px;
  height: 20px;
  flex: none;
}

.sidebar-nav-item:hover {
  background: var(--accent);
}

.sidebar-nav-item.active {
  background: var(--primary);
  color: var(--bg);
}
html:not(.dark) .sidebar-nav-item.active {
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 12px;
  border-top: 1px solid var(--sidebar-border);
}

.sidebar-action {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  min-height: 44px;
  transition: background var(--motion-fast);
}
.sidebar-action:hover {
  background: var(--accent);
}
.sidebar-action svg {
  width: 20px;
  height: 20px;
  flex: none;
}

.sidebar-action-danger {
  color: var(--error-text);
}
.sidebar-action-danger:hover {
  background: var(--error-bg);
}

.admin-main {
  padding: 28px 28px 60px;
  max-width: 1300px;
  width: 100%;
  margin: 0 auto;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.page-head h1 {
  margin: 0 0 4px;
  font-size: 1.45rem;
  font-weight: 800;
  line-height: 1.2;
}

.page-head p {
  margin: 0;
}

@media (max-width: 900px) {
  .admin-shell {
    display: block;
  }
  .topbar-mobile {
    display: flex;
  }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 50;
    width: min(280px, 84vw);
    /* 100vh on mobile browsers sizes to the viewport with the address bar
       hidden — taller than what's actually on screen while it's showing, so
       the drawer's own box extends past the visible fold with nothing
       "overflowing" to trigger a scrollbar (footer/logout just sits off
       screen). 100dvh tracks the real visible viewport; vh stays first as a
       fallback for browsers that don't support dvh. */
    height: 100vh;
    height: 100dvh;
    transform: translateX(-100%);
    transition: transform var(--motion-base);
    box-shadow: var(--shadow-modal);
  }
  .nav-toggle-checkbox:checked ~ .sidebar {
    transform: translateX(0);
  }
  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 40;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--motion-base);
  }
  .nav-toggle-checkbox:checked ~ .nav-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
  .admin-main {
    padding: 20px 16px 48px;
  }
}

/* ===================== CARDS ===================== */

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-card);
  margin-top: 20px;
}
.admin-main .card:first-of-type {
  margin-top: 0;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.card h2 {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 800;
  line-height: 1.2;
}
.card-head-note {
  margin: 0;
  font-size: 0.85rem;
}

/* ===================== STAT CARDS ===================== */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 4px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg);
  border: 1px solid var(--panel);
  border-radius: 16px;
  padding: 16px 18px;
}
html.dark .stat-card {
  border-color: var(--border);
}

.stat-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  /* Sage-tinted chip instead of flat ink-on-white — reinforces the
     documented Green-Is-Brand rule (sage should read first, not recede to a
     token accent) on what was otherwise the most monochrome corner of the
     dashboard. Dark mode keeps the original ink-on-panel look, matching how
     sage already recedes in dark mode everywhere else in this system. */
  background: var(--panel);
  color: var(--sidebar-border);
  flex: none;
  box-shadow: var(--shadow-soft);
}
html.dark .stat-icon {
  background: var(--panel);
  color: var(--primary);
}
.stat-icon svg {
  width: 22px;
  height: 22px;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--muted-on-sage);
  font-weight: 600;
}

.stat-value {
  font-size: 1.45rem;
  font-weight: 800;
  margin-top: 2px;
}

/* ===================== FORM FIELDS ===================== */

.form-field {
  margin-bottom: 14px;
}
.form-field label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 0.9rem;
}
.form-field input {
  width: 100%;
  max-width: 420px;
  padding: 11px 12px;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
}
.form-field input:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(147, 197, 253, 0.4);
}

.form-field select {
  width: 100%;
  max-width: 420px;
  padding: 11px 12px;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
}
.form-field select:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(147, 197, 253, 0.4);
}
.form-field .field-hint {
  margin: 6px 0 0;
  font-size: 0.85rem;
}
.bulk-save-template-row input {
  width: 100%;
  max-width: 420px;
  padding: 11px 12px;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
}
.bulk-save-template-row input:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(147, 197, 253, 0.4);
}
/* ===================== TOOLBAR (bookings page) ===================== */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.search-field {
  position: relative;
  flex: 1 1 240px;
  min-width: 200px;
  /* .toolbar wraps chip-toggle/filter-date onto their own line at
     in-between widths (e.g. ~1200px) — with nothing left to share the row,
     flex-grow:1 stretched this alone to the full row width (600px+) instead
     of staying search-box-sized. */
  max-width: 360px;
}
.search-field svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--muted);
  pointer-events: none;
}
.search-field input {
  width: 100%;
  padding: 11px 12px 11px 38px;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
}
.search-field input:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(147, 197, 253, 0.4);
}

.chip-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  flex: none;
}
.chip-toggle button {
  border: none;
  background: var(--panel);
  color: var(--text);
  padding: 10px 16px;
  min-height: 44px;
  font-weight: 700;
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background var(--motion-fast);
  white-space: nowrap;
}
.chip-toggle button:hover:not(.active) {
  background: var(--accent);
}
.chip-toggle button.active {
  background: var(--primary);
  color: var(--bg);
}
html:not(.dark) .chip-toggle button.active {
  color: #fff;
}

.filter-date {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.filter-date input[type="date"] {
  padding: 10px 12px;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
}

.result-count {
  margin: 12px 2px 0;
  font-size: 0.9rem;
}

.include-all-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.include-all-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

.list-scope-hint {
  margin: 4px 2px 0;
  font-size: 0.8rem;
}

.table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}
.table-footer .result-count {
  margin: 0;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.pagination button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 6px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background var(--motion-fast);
}
.pagination button:hover:not(:disabled):not(.active) {
  background: var(--accent);
}
.pagination button.active {
  background: var(--primary);
  color: var(--bg);
}
html:not(.dark) .pagination button.active {
  color: #fff;
}
.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.pagination button svg {
  width: 18px;
  height: 18px;
}
.pagination-ellipsis {
  padding: 0 4px;
  color: var(--muted);
}

/* ===================== SUMMARY / CHART ===================== */

.summary-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.summary-controls label {
  font-size: 0.9rem;
  font-weight: 700;
}
.summary-controls input {
  padding: 9px 10px;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
}

/* Native <input type="date"> renders its text in whatever order the
   browser/OS locale picks (often m/d/y), which we can't override directly —
   so the digits are hidden and a JS-driven span on top shows d/m/y instead.
   The real input stays interactive underneath for typing and the picker. */
.date-field {
  position: relative;
  display: inline-flex;
}
.summary-controls .date-field input[type="date"] {
  color: transparent;
}
.summary-controls .date-field input[type="date"]::-webkit-datetime-edit,
.summary-controls .date-field input[type="date"]::-webkit-datetime-edit-fields-wrapper,
.summary-controls .date-field input[type="date"]::-webkit-datetime-edit-text,
.summary-controls .date-field input[type="date"]::-webkit-datetime-edit-month-field,
.summary-controls .date-field input[type="date"]::-webkit-datetime-edit-day-field,
.summary-controls .date-field input[type="date"]::-webkit-datetime-edit-year-field {
  color: transparent;
}
.date-display {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  font: inherit;
  color: var(--text);
  white-space: nowrap;
}

.granularity-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.granularity-toggle button {
  border: none;
  background: var(--panel);
  padding: 8px 16px;
  min-height: 44px;
  font-weight: 700;
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--text);
  transition: background var(--motion-fast);
}
.granularity-toggle button:hover:not(.active) {
  background: var(--accent);
}
.granularity-toggle button.active {
  background: var(--primary);
  color: var(--bg);
}
html:not(.dark) .granularity-toggle button.active {
  color: #fff;
}

.chart-wrap {
  overflow-x: auto;
}
.chart-svg {
  display: block;
}
.chart-bar {
  /* Brand green instead of flat ink — the revenue chart was the single
     largest all-black surface in the admin. Dark mode swaps to the
     Success-green token purely for its already-verified contrast against
     the dark panel background (--sidebar-border's dark value is a
     near-invisible blue-gray here), not to claim a "success" state. */
  fill: var(--sidebar-border);
  transition: fill var(--motion-fast);
}
html.dark .chart-bar {
  fill: var(--success-text);
}
.chart-bar:hover {
  fill: var(--accent-dot);
}
.chart-axis-label {
  font-size: 0.8rem;
  fill: var(--muted);
  font-family: "Prompt", system-ui, sans-serif;
}

.chart-empty,
.empty-state {
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 40px 16px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.empty-state svg {
  width: 36px;
  height: 36px;
  opacity: 0.6;
}
.empty-state strong {
  color: var(--text);
  font-size: 1rem;
}

/* ===================== SERVICE BREAKDOWN (DONUT) ===================== */

.breakdown-controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.service-breakdown-wrap {
  display: flex;
  align-items: center;
  gap: 32px;
  flex-wrap: wrap;
}
.donut-chart-col {
  position: relative;
  flex: none;
  width: 200px;
  height: 200px;
}
.donut-chart-col svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.donut-segment {
  transition: opacity var(--motion-fast);
}
.donut-segment.dimmed {
  opacity: 0.25;
}
.donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
}
.donut-center .donut-total {
  font-size: 1.45rem;
  font-weight: 800;
}
.donut-center .donut-total-label {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 2px;
}

.service-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.service-legend li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  cursor: default;
}
.service-legend .swatch {
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 999px;
}
.service-legend .service-name {
  flex: 1;
  font-weight: 700;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.service-legend .service-figures {
  flex: none;
  text-align: right;
  font-size: 0.8rem;
  color: var(--muted);
}
.service-legend .service-figures strong {
  color: var(--text);
  font-weight: 700;
  font-size: 0.85rem;
  display: block;
}

.chart-tooltip {
  position: absolute;
  z-index: 1000;
  background: var(--primary);
  color: var(--bg);
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 0.8rem;
  line-height: 1.5;
  pointer-events: none;
  box-shadow: var(--shadow-card);
}
html:not(.dark) .chart-tooltip {
  color: #fff;
}

/* ===================== TABLE ===================== */

.table-wrap {
  overflow-x: auto;
}

/* Bookings table specifically: bounded height + internal scroll, paired
   with pagination in bookings.js, so a long list scrolls inside its own
   box instead of stretching the whole page. */
#bookingsTableWrap {
  max-height: 60vh;
  overflow-y: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

/* Fixed column widths (set via <colgroup> in bookings.html) instead of the
   default auto layout, which recalculates every column's width from
   whatever's in the currently-rendered rows — filtering to "ว่าง" makes
   ลูกค้า/เบอร์/บริการ/หมายเหตุ/สลิป collapse to a single "-" each, so the
   auto algorithm dumped all the freed-up width:100% space into one arbitrary
   column and the table visibly lurched between filters. ลูกค้า/บริการ/
   หมายเหตุ can hold real sentences, so those three wrap instead of nowrap-ing
   past their fixed width. */
#bookingsTable {
  table-layout: fixed;
}
#bookingsTable td:nth-child(4),
#bookingsTable td:nth-child(6),
#bookingsTable td:nth-child(7) {
  white-space: normal;
  word-break: break-word;
}
th {
  color: var(--muted);
  font-weight: 700;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

#bookingsTable thead th {
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 2;
}

/* Same bounded-height + internal-scroll treatment as #bookingsTableWrap — a
   long styles list scrolls inside its own box instead of stretching the
   whole page and pushing everything else down with it. */
#stylesTableWrap {
  max-height: 70vh;
  overflow-y: auto;
}
#stylesTable thead th {
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 2;
}

tbody tr {
  transition: background var(--motion-fast);
}
tbody tr:hover {
  background: var(--accent);
}

td .btn {
  min-height: 38px;
  padding: 8px 14px;
}

/* The actions column used to require scrolling all the way right to reach
   past the other 8 columns — pinning it keeps it reachable at any scroll
   position instead of hiding it off-screen. */
#bookingsTable th:last-child,
#bookingsTable td:last-child {
  position: sticky;
  right: 0;
  /* Booked rows now render 3 icon buttons (edit/cancel/close). At the old
     width the row-actions flex-wrap stacked them vertically instead of in
     a row, inflating that row's height to ~4x its neighbors and making the
     buttons hard to hit precisely. 3x44px buttons + 2x8px gaps = 148px of
     content, plus the cell's own 2x10px horizontal padding = 168px; a bit
     of buffer on top of that. */
  min-width: 180px;
  background: var(--panel);
  box-shadow: -6px 0 8px -6px rgba(15, 23, 42, 0.12);
}
#bookingsTable tbody tr:hover td:last-child {
  background: var(--accent);
}

/* Styles table: name + category collapse into one wrapping column (see
   style-name-cell below) instead of nowrap-ing 3 wide text columns, so the
   whole table stays narrow enough that the action buttons don't require a
   long horizontal scroll to reach — same sticky-actions-column treatment as
   the bookings table for whatever overflow remains on narrow screens. */
.style-name-cell {
  white-space: normal;
  max-width: 320px;
}
.style-name-th {
  font-weight: 700;
}
.style-name-en {
  font-size: 0.85rem;
  margin-top: 2px;
}
.style-category-tag {
  margin-top: 6px;
}

#stylesTable th:last-child,
#stylesTable td:last-child {
  position: sticky;
  right: 0;
  min-width: 150px;
  background: var(--panel);
  box-shadow: -6px 0 8px -6px rgba(15, 23, 42, 0.12);
}
#stylesTable tbody tr:hover td:last-child {
  background: var(--accent);
}

/* ===================== BADGES ===================== */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge-booked {
  background: var(--warning-bg);
  color: var(--warning-text);
}
.badge-available {
  background: var(--success-bg);
  color: var(--success-text);
}
.badge-inactive {
  background: var(--border);
  color: var(--muted);
}
.badge-error {
  background: var(--error-bg);
  color: var(--error-text);
}

/* ===================== ROW ACTIONS (bookings table) ===================== */

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.icon-btn-sm {
  /* Kept at the 44x44 touch-target minimum even though it reads more
     compact than the old full-width text buttons — the size drop that
     shrinks the actions column comes from icon+tooltip replacing a wide
     text label, not from shrinking the tappable area itself. */
  width: 44px;
  height: 44px;
}
.icon-btn-sm svg {
  width: 18px;
  height: 18px;
}

.icon-btn-danger {
  color: var(--error-text);
}
.icon-btn-danger:hover {
  background: var(--error-bg);
}

@media (max-width: 640px) {
  table,
  thead,
  tbody,
  th,
  td,
  tr {
    display: block;
  }
  thead {
    display: none;
  }
  #bookingsTable th:last-child,
  #bookingsTable td:last-child {
    position: static;
    box-shadow: none;
  }
  tr {
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
  }
  tbody tr:hover {
    background: var(--panel);
  }
  td {
    border: none;
    white-space: normal;
    padding: 6px 4px;
  }
  td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.8rem;
    color: var(--muted);
    font-weight: 700;
    text-transform: uppercase;
    margin-bottom: 2px;
  }
}

/* ===================== MODAL (Add Slot) ===================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal {
  width: min(520px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--panel);
  border-radius: 22px;
  padding: 22px;
  box-shadow: var(--shadow-modal);
  animation: modalFadeUp 0.25s ease;
}

.modal.modal-lg {
  width: min(680px, 100%);
}

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

/* ===================== AVAILABILITY CALENDAR ===================== */

.avail-cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}
.avail-cal-label {
  font-weight: 800;
  font-size: 1rem;
}

.avail-cal-legend {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  font-size: 0.8rem;
  color: var(--muted);
}
.avail-cal-legend .badge {
  margin-right: 4px;
}

.avail-cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 6px;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

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

.avail-day {
  min-height: 84px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  transition:
    background var(--motion-fast),
    transform var(--motion-fast);
}
.avail-day:hover {
  background: var(--accent);
  transform: translateY(-1px);
}

.avail-day-num {
  font-weight: 700;
  font-size: 0.9rem;
}
.avail-day.today .avail-day-num {
  color: var(--accent-dot);
}

.avail-day.selected {
  background: var(--primary);
  border-color: var(--primary);
}
.avail-day.selected .avail-day-num {
  color: var(--bg);
}
html:not(.dark) .avail-day.selected .avail-day-num {
  color: #fff;
}

.avail-day.past {
  opacity: 0.55;
}

.avail-day-badges {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}
.avail-day-badges .badge {
  font-size: 0.8rem;
  padding: 2px 8px;
}

@media (max-width: 640px) {
  .avail-day {
    min-height: 64px;
    padding: 6px 4px;
    gap: 2px;
  }
  .avail-day-num {
    font-size: 0.8rem;
  }
  .avail-day-badges .badge {
    font-size: 0.8rem;
    padding: 1px 6px;
  }
}

/* Multi-select checklist calendar (bulk-add popup): click or drag across
   days to check them off, distinct from the single-select "selected" look
   used by the main calendar's popup trigger. */
.avail-cal-grid-multi {
  user-select: none;
}
.avail-cal-grid-multi .avail-day {
  position: relative;
  padding-left: 30px;
}
.avail-cal-grid-multi .avail-day:disabled {
  cursor: not-allowed;
}

.avail-day-check {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--bg);
}
.avail-day.checked {
  background: var(--accent);
  border-color: var(--primary);
}
.avail-day.checked .avail-day-check {
  background: var(--primary);
  border-color: var(--primary);
}
.avail-day.checked .avail-day-check::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.bulk-template-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.bulk-template-row select {
  flex: 1 1 auto;
}

.bulk-save-template-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.bulk-save-template-row input {
  flex: 1 1 260px;
}

.bulk-selection-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 14px 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.btn-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-weight: 700;
  color: var(--accent-dot);
  cursor: pointer;
}
.btn-link:hover {
  text-decoration: underline;
}

.avail-slot-list {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.avail-slot-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  flex-wrap: wrap;
}
.avail-slot-time {
  font-weight: 700;
  min-width: 52px;
}
.avail-slot-customer {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.avail-slot-link {
  margin-left: auto;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent-dot);
  text-decoration: none;
}
.avail-slot-link:hover {
  text-decoration: underline;
}

.avail-add-form {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}
.avail-add-field {
  flex: 1 1 260px;
  margin-bottom: 0;
}
.avail-past-note {
  margin: 0;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}
.modal-head h2 {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 800;
  line-height: 1.2;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

/* ===================== TOAST ===================== */

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  display: flex;
  align-items: center;
  gap: 10px;
  /* Fixed, mode-invariant colors rather than the theme's --success/--error
     tokens: those are calibrated as text-on-tinted-bg pairs (badges), and
     --error-text in particular flips to a pale red in dark mode — fine for
     text, but washed-out as a solid toast fill. A transient alert reads
     better as a deliberately deep, high-contrast color in either theme. */
  background: #166534;
  color: #fff;
  font-weight: 600;
  padding: 12px 20px;
  border-radius: 14px;
  box-shadow: var(--shadow-modal);
  z-index: 999;
  max-width: min(420px, 90vw);
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, 10px);
  transition:
    opacity 0.22s ease,
    transform 0.22s ease,
    visibility 0s linear 0.22s;
}
.toast svg {
  width: 20px;
  height: 20px;
  flex: none;
}
.toast.show {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
  transition:
    opacity 0.22s ease,
    transform 0.22s ease;
}
.toast.error {
  background: #991b1b;
}

.hidden {
  display: none !important;
}

/* ===================== LOGIN PAGE ===================== */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-wrap {
  width: 100%;
  max-width: 380px;
  padding: 20px;
}

.login-card {
  margin-top: 0;
  text-align: center;
  animation: loginFadeUp 0.3s ease;
}

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

.login-logo-link {
  display: block;
  transition: opacity var(--motion-fast);
}
.login-logo-link:hover {
  opacity: 0.85;
}

.login-logo {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  margin: 0 auto 14px;
  display: block;
  box-shadow: var(--shadow-soft);
}

.login-title {
  margin: 0 0 4px;
  font-size: 1.45rem;
  font-weight: 800;
  line-height: 1.2;
}
.login-subtitle {
  margin: 0 0 20px;
}
.login-form {
  text-align: left;
}
.login-submit {
  width: 100%;
  justify-content: center;
  margin-top: 6px;
}

.login-theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
}

.login-error {
  background: var(--error-bg);
  color: var(--error-text);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.9rem;
  margin-bottom: 12px;
}
