/* ==========================================================================
   Mossy – brand stylesheet
   Monochrome identity (brand sheet: grey #E6E7E8, black, white; Zalando Sans).
   Colour is reserved for meaning (available / booked / yours, on / off, errors).
   Loaded after Tailwind on every page. Component classes are prefixed "es-".
   ========================================================================== */

@font-face {
  font-family: "Zalando Sans";
  src: url("../fonts/ZalandoSans-var.woff") format("woff");
  font-weight: 300 800;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Brand */
  --es-ink: #0b0b0c;          /* near-black: text, primary actions        */
  --es-ink-2: #2a2b2d;        /* hover on ink                             */
  --es-grey: #e6e7e8;         /* brand grey: page canvas                  */
  --es-grey-2: #f3f3f4;       /* lighter canvas (app background)          */
  --es-surface: #ffffff;
  --es-line: #d9dadc;         /* hairlines                                */
  --es-line-strong: #0b0b0c;  /* the brand's heavy rule                   */
  --es-on-ink: #ffffff;       /* text on ink (primary buttons etc.)       */
  --es-surface-2: #f8f8f9;    /* subtle raised surface                    */
  --es-field-line: #c9cacc;   /* input borders                            */
  --es-tabbar-bg: rgba(255, 255, 255, .96);
  --es-sidebar: #0b0b0c;      /* admin sidebar (dark in both themes)      */
  --es-focus: rgba(11, 11, 12, .12);
  --es-muted: #5c5d5f;        /* secondary text (AA on white and grey)    */
  --es-faint: #8a8b8e;

  /* Meaning */
  --es-ok: #15803d;      --es-ok-bg: #e8f5ec;
  --es-warn: #b45309;    --es-warn-bg: #fdf3e2;
  --es-bad: #b42318;     --es-bad-bg: #fdecea;
  --es-info: #1d4ed8;    --es-info-bg: #e8eefc;

  /* Shape & rhythm */
  --es-radius: 12px;
  --es-radius-sm: 8px;
  --es-shadow: 0 1px 2px rgba(11, 11, 12, .06), 0 1px 1px rgba(11, 11, 12, .04);
  --es-shadow-lg: 0 12px 32px rgba(11, 11, 12, .16);
  --es-header-h: 60px;
  --es-tabbar-h: 64px;
  --es-font: "Zalando Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ---------- Base ---------------------------------------------------------- */
html { -webkit-text-size-adjust: 100%; }
body.es {
  font-family: var(--es-font);
  background: var(--es-grey-2);
  color: var(--es-ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}
body.es input, body.es select, body.es textarea, body.es button { font-family: inherit; }
body.es :focus-visible { outline: 2px solid var(--es-ink); outline-offset: 2px; border-radius: 4px; }
body.es h1, body.es h2, body.es h3 { letter-spacing: -0.01em; }

/* ---------- Wordmark (text-based, matches the tentative stacked mark) ------ */
.es-wordmark { display: inline-flex; align-items: center; line-height: 0; color: inherit; text-decoration: none; }
.es-wordmark .es-wm-img { display: block; width: auto; height: 100%; }
.es-wordmark .es-wm-ondark { display: none; }
html[data-theme="dark"] .es-wordmark .es-wm-onlight,
.es-sidebar .es-wordmark .es-wm-onlight { display: none; }
html[data-theme="dark"] .es-wordmark .es-wm-ondark,
.es-sidebar .es-wordmark .es-wm-ondark { display: block; }
.es-wordmark.es-wm-sm { height: 24px; }
.es-wordmark.es-wm-md { height: 32px; }
.es-wordmark.es-wm-lg { height: 52px; }

/* ---------- App shell: header ------------------------------------------- */
.es-header {
  position: sticky; top: 0; z-index: 40;
  background: var(--es-surface);
  border-bottom: 1px solid var(--es-line);
}
.es-header-inner {
  max-width: 1200px; margin: 0 auto; height: var(--es-header-h);
  display: flex; align-items: center; gap: 16px; padding: 0 16px;
}
.es-header .es-brand { display: flex; align-items: center; gap: 12px; color: var(--es-ink); text-decoration: none; }
.es-area-tag {
  font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--es-muted); border-left: 1px solid var(--es-line); padding-left: 12px; line-height: 1.2;
}
.es-nav { display: none; align-items: center; gap: 4px; margin-left: 8px; }
.es-nav a {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 999px;
  color: var(--es-muted); font-size: 14px; font-weight: 500; text-decoration: none; white-space: nowrap;
}
.es-nav a:hover { color: var(--es-ink); background: var(--es-grey-2); }
.es-nav a.is-active { color: var(--es-on-ink); background: var(--es-ink); }
.es-nav svg { width: 18px; height: 18px; }
.es-header-spacer { flex: 1; }

/* Account menu */
.es-account { position: relative; }
.es-account-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 6px 0 12px;
  border: 1px solid var(--es-line); border-radius: 999px; background: var(--es-surface); color: var(--es-ink);
  font-size: 14px; font-weight: 500; cursor: pointer;
}
.es-account-btn:hover { border-color: var(--es-ink); }
.es-avatar {
  width: 28px; height: 28px; border-radius: 999px; background: var(--es-ink); color: var(--es-on-ink);
  display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700;
}
.es-account-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: none; }
.es-menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px; z-index: 60;
  background: var(--es-surface); border: 1px solid var(--es-line); border-radius: var(--es-radius);
  box-shadow: var(--es-shadow-lg); padding: 6px; display: none;
}
.es-menu.is-open { display: block; }
.es-menu-label { padding: 8px 10px 4px; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--es-faint); }
.es-menu a, .es-menu button {
  display: flex; width: 100%; align-items: center; gap: 10px; padding: 10px; border-radius: var(--es-radius-sm);
  font-size: 14px; color: var(--es-ink); text-decoration: none; background: none; border: 0; cursor: pointer; text-align: left;
}
.es-menu a:hover, .es-menu button:hover { background: var(--es-grey-2); }
.es-menu svg { width: 18px; height: 18px; color: var(--es-muted); }
.es-menu hr { border: 0; border-top: 1px solid var(--es-line); margin: 6px 0; }
.es-menu .es-danger { color: var(--es-bad); }
.es-menu .es-danger svg { color: var(--es-bad); }

/* ---------- App shell: content ------------------------------------------- */
.es-main { max-width: 1200px; margin: 0 auto; padding: 20px 16px calc(var(--es-tabbar-h) + 28px + env(safe-area-inset-bottom)); }
.es-page-title {
  border-top: 3px solid var(--es-line-strong); padding-top: 12px; margin: 4px 0 18px;
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.es-page-title h1 { font-size: 22px; font-weight: 600; margin: 0; }
.es-page-title p { color: var(--es-muted); font-size: 14px; margin: 0; }

/* ---------- Mobile tab bar ------------------------------------------------ */
.es-tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: var(--es-tabbar-bg); backdrop-filter: saturate(1.2) blur(8px);
  border-top: 1px solid var(--es-line);
  padding-bottom: env(safe-area-inset-bottom);
}
.es-tabbar-inner { display: flex; height: var(--es-tabbar-h); max-width: 640px; margin: 0 auto; }
.es-tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  color: var(--es-muted); font-size: 11px; font-weight: 500; text-decoration: none; position: relative;
}
.es-tabbar a svg { width: 22px; height: 22px; }
.es-tabbar a.is-active { color: var(--es-ink); font-weight: 600; }
.es-tabbar a.is-active::before {
  content: ""; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; background: var(--es-ink); border-radius: 0 0 3px 3px;
}

@media (min-width: 900px) {
  .es-nav { display: flex; }
  .es-tabbar { display: none; }
  .es-main { padding: 28px 24px 48px; }
  .es-account-name { display: inline; }
  .es-header-inner { padding: 0 24px; }
}

/* ---------- Admin shell (sidebar + drawer on mobile) --------------------- */
.es-admin { display: flex; min-height: 100vh; }
.es-sidebar {
  width: 260px; flex-shrink: 0; background: var(--es-sidebar); color: #fff;
  display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; z-index: 50;
  transform: translateX(-100%); transition: transform .2s ease;
}
.es-sidebar.is-open { transform: translateX(0); box-shadow: var(--es-shadow-lg); }
.es-sidebar-head { padding: 20px 20px 16px; border-bottom: 1px solid rgba(255, 255, 255, .12); display: flex; align-items: center; justify-content: space-between; }
.es-sidebar-head .es-area-tag { color: rgba(255, 255, 255, .6); border-color: rgba(255, 255, 255, .2); }
.es-sidebar nav { padding: 12px 10px; flex: 1; overflow-y: auto; }
.es-sidebar .es-side-label { padding: 14px 12px 6px; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: rgba(255, 255, 255, .45); }
.es-sidebar nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--es-radius-sm);
  color: rgba(255, 255, 255, .78); font-size: 14px; text-decoration: none;
}
.es-sidebar nav a svg { width: 18px; height: 18px; flex-shrink: 0; }
.es-sidebar nav a:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.es-sidebar nav a.is-active { color: #0b0b0c; background: #fff; font-weight: 600; }
.es-sidebar-foot { padding: 14px 20px 20px; border-top: 1px solid rgba(255, 255, 255, .12); font-size: 12px; color: rgba(255, 255, 255, .5); }
.es-sidebar-foot button {
  width: 100%; margin-bottom: 12px; padding: 10px; border-radius: var(--es-radius-sm); cursor: pointer;
  background: transparent; color: #fff; border: 1px solid rgba(255, 255, 255, .25); font-size: 14px;
}
.es-sidebar-foot button:hover { background: rgba(255, 255, 255, .08); }
.es-scrim { position: fixed; inset: 0; background: rgba(11, 11, 12, .45); z-index: 45; display: none; }
.es-scrim.is-open { display: block; }
.es-admin-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.es-admin-top {
  position: sticky; top: 0; z-index: 30; height: var(--es-header-h); background: var(--es-surface);
  border-bottom: 1px solid var(--es-line); display: flex; align-items: center; gap: 12px; padding: 0 16px;
}
.es-admin-top h1 { font-size: 17px; font-weight: 600; margin: 0; }
.es-icon-btn {
  width: 40px; height: 40px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 10px; border: 1px solid var(--es-line); background: var(--es-surface); color: var(--es-ink); cursor: pointer;
}
.es-icon-btn svg { width: 20px; height: 20px; }
.es-sidebar .es-icon-btn { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .25); }
.es-admin-main { padding: 20px 16px 40px; min-width: 0; }
@media (min-width: 1024px) {
  .es-sidebar { position: sticky; top: 0; height: 100vh; transform: none; }
  .es-sidebar .es-icon-btn, .es-admin-top .es-menu-toggle { display: none; }
  .es-scrim { display: none !important; }
  .es-admin-top { padding: 0 28px; }
  .es-admin-main { padding: 28px; }
}

/* ---------- Components ---------------------------------------------------- */
.es-card { background: var(--es-surface); border: 1px solid var(--es-line); border-radius: var(--es-radius); box-shadow: var(--es-shadow); }
.es-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 18px; border-radius: 10px; font-size: 15px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s;
}
.es-btn-primary { background: var(--es-ink); color: var(--es-on-ink); }
.es-btn-primary:hover { background: var(--es-ink-2); }
.es-btn-secondary { background: var(--es-surface); color: var(--es-ink); border-color: var(--es-line); }
.es-btn-secondary:hover { border-color: var(--es-ink); }
.es-btn-danger { background: var(--es-bad); color: #fff; }
.es-btn-danger:hover { filter: brightness(.92); }
.es-btn-block { width: 100%; }

/* Modal (logout etc.) */
.es-modal { position: fixed; inset: 0; z-index: 70; background: rgba(11, 11, 12, .5); display: flex; align-items: center; justify-content: center; padding: 16px; }
.es-modal.hidden { display: none; }
.es-modal-card { background: var(--es-surface); border-radius: 16px; box-shadow: var(--es-shadow-lg); width: 100%; max-width: 380px; padding: 24px; }
.es-modal-card h2 { font-size: 18px; font-weight: 600; margin: 0 0 6px; }
.es-modal-card p { color: var(--es-muted); font-size: 14px; margin: 0 0 20px; }
.es-modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- Harmonise existing page content (Tailwind utilities) ---------
   Page views still use Tailwind classes. These rules bring their primary
   actions, cards, forms and tables in line with the brand without editing
   every view. Status colours (green/red/yellow/blue tints) are untouched.   */
body.es .shadow, body.es .shadow-md, body.es .shadow-lg { box-shadow: var(--es-shadow) !important; }
body.es .bg-white.rounded-xl, body.es .bg-white.rounded-lg, body.es .bg-white.rounded-2xl { border: 1px solid var(--es-line); }

/* Primary action buttons (were blue/green/gray-800) → brand ink */
body.es button.bg-blue-600, body.es a.bg-blue-600, body.es input[type=submit].bg-blue-600,
body.es button.bg-green-600, body.es a.bg-green-600,
body.es button.bg-gray-800, body.es a.bg-gray-800,
body.es button.bg-indigo-600, body.es a.bg-indigo-600 {
  background-color: var(--es-ink) !important; color: var(--es-on-ink) !important; border-color: var(--es-ink) !important;
}
body.es button.bg-blue-600:hover, body.es a.bg-blue-600:hover,
body.es button.bg-green-600:hover, body.es a.bg-green-600:hover,
body.es button.bg-gray-800:hover, body.es a.bg-gray-800:hover,
body.es button.bg-indigo-600:hover, body.es a.bg-indigo-600:hover { background-color: var(--es-ink-2) !important; }
body.es button.bg-green-600:disabled, body.es button.bg-blue-600:disabled { opacity: .55; }
body.es a.text-blue-600, body.es a.text-blue-700 { color: var(--es-ink); }
body.es a.text-blue-600, body.es a.text-blue-700 { text-decoration: underline; text-underline-offset: 2px; }

/* Rounded rectangles → consistent radius */
body.es button.rounded, body.es a.rounded:not(.rounded-full) { border-radius: var(--es-radius-sm); }

/* Form fields */
/* Zero-specificity defaults (:where) so a field's own colour classes
   (e.g. green "Manual ON" / red "Manual OFF" / blue "Timer" on the Control page) still win. */
:where(body.es) :where(input[type=text], input[type=email], input[type=password], input[type=search],
input[type=number], input[type=date], input[type=time], input[type=tel], select, textarea) {
  border-color: var(--es-line); border-radius: var(--es-radius-sm); background-color: var(--es-surface); color: var(--es-ink);
}
body.es input:focus, body.es select:focus, body.es textarea:focus {
  outline: none; border-color: var(--es-ink) !important; box-shadow: 0 0 0 3px var(--es-focus) !important;
}
body.es input[type=checkbox], body.es input[type=radio] { accent-color: var(--es-ink); }

/* Tables */
body.es table thead, body.es table thead tr { background: var(--es-grey-2); }
body.es table th { font-weight: 600; color: var(--es-muted); font-size: 12px; letter-spacing: .02em; }
body.es table td, body.es table th { border-color: var(--es-line) !important; }

/* Secondary surfaces */
body.es .bg-gray-100 { background-color: var(--es-grey-2); }
body.es .bg-gray-50 { background-color: var(--es-surface-2); }

/* flatpickr calendar: brand ink instead of default blue/teal */
body.es .flatpickr-day.selected, body.es .flatpickr-day.selected:hover,
body.es .flatpickr-day.today.selected { background: var(--es-ink) !important; border-color: var(--es-ink) !important; color: var(--es-on-ink) !important; }
body.es .flatpickr-day.today { border-color: var(--es-ink); }
body.es .flatpickr-calendar { font-family: var(--es-font); box-shadow: none; border: 1px solid var(--es-line); border-radius: var(--es-radius); }
body.es .flatpickr-months .flatpickr-month, body.es .flatpickr-current-month, body.es span.flatpickr-weekday,
body.es .flatpickr-weekdays { background: var(--es-surface) !important; color: var(--es-ink) !important; fill: var(--es-ink) !important; }

/* Pager (CodeIgniter) */
body.es ul.pagination { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding-left: 0; margin: 0; }
body.es ul.pagination li { list-style: none; }
body.es ul.pagination li a, body.es ul.pagination li span { display: inline-block; padding: 6px 11px; border: 1px solid var(--es-line); border-radius: var(--es-radius-sm); text-decoration: none; background: var(--es-surface); }
body.es ul.pagination li a:hover { border-color: var(--es-ink); }
body.es ul.pagination li.active span { background: var(--es-ink); color: var(--es-on-ink); border-color: var(--es-ink); }
body.es ul.pagination li.disabled span { color: var(--es-faint); }

/* Wide tables scroll inside their card on phones instead of stretching the page */
body.es .overflow-x-auto { -webkit-overflow-scrolling: touch; }

/* ---------- Auth pages (login / forgot / reset) --------------------------- */
body.es-auth {
  font-family: var(--es-font); background: var(--es-grey); color: var(--es-ink); margin: 0;
  min-height: 100vh; display: flex; flex-direction: column; -webkit-font-smoothing: antialiased;
}
.es-auth-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 32px 16px; }
.es-auth-card { width: 100%; max-width: 400px; }
.es-auth-card .es-wordmark { margin-bottom: 28px; }
.es-auth-panel { background: var(--es-surface); border-radius: 16px; padding: 28px 24px; box-shadow: var(--es-shadow); }
.es-auth-panel h1 { font-size: 20px; font-weight: 600; margin: 0 0 4px; }
.es-auth-panel .es-sub { color: var(--es-muted); font-size: 14px; margin: 0 0 22px; }
.es-rule { border: 0; border-top: 3px solid var(--es-line-strong); margin: 0 0 18px; }
.es-field { margin-bottom: 16px; }
.es-field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.es-field .es-hint { font-size: 12px; color: var(--es-muted); margin: -2px 0 8px; }
.es-input {
  width: 100%; height: 46px; padding: 0 14px; font-size: 16px; font-family: inherit; color: var(--es-ink);
  background: var(--es-surface); border: 1px solid var(--es-field-line); border-radius: 10px; box-sizing: border-box;
}
.es-input:focus { outline: none; border-color: var(--es-ink); box-shadow: 0 0 0 3px var(--es-focus); }
.es-password { position: relative; }
.es-password .es-input { padding-right: 64px; }
.es-password .es-reveal {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%); height: 34px; padding: 0 10px;
  font-size: 12px; font-weight: 600; color: var(--es-muted); background: none; border: 0; border-radius: 8px; cursor: pointer; font-family: inherit;
}
.es-password .es-reveal:hover { color: var(--es-ink); background: var(--es-grey-2); }
.es-auth-links { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; font-size: 14px; }
.es-auth-links a { color: var(--es-ink); text-underline-offset: 3px; }
.es-alert { border-radius: 10px; padding: 12px 14px; font-size: 14px; margin-bottom: 16px; line-height: 1.45; }
.es-alert-error { background: var(--es-bad-bg); color: var(--es-bad); }
.es-alert-success { background: var(--es-ok-bg); color: var(--es-ok); }
.es-auth-foot { text-align: center; font-size: 12px; color: var(--es-muted); padding: 20px 16px 28px; }
.es-auth-foot a { color: inherit; }

/* ---------- Booking page -------------------------------------------------- */
.es-legend { display: flex; justify-content: center; gap: 18px; flex-wrap: wrap; font-size: 13px; color: var(--es-muted); margin: 6px 0 4px; }
.es-legend span { display: inline-flex; align-items: center; gap: 6px; }
.es-legend .es-slot { width: 16px; height: 16px; border-radius: 4px; display: inline-block; }

.es-slot { border: 1px solid var(--es-line); border-radius: 8px; background: var(--es-surface); color: var(--es-ink); font-weight: 500; user-select: none; }
.es-slot-free { border-color: var(--es-ink); cursor: pointer; transition: background .12s, color .12s; }
.es-slot-free:hover, .es-slot-free:focus-visible { background: var(--es-ink); color: var(--es-on-ink); }
.es-slot-mine { background: var(--es-ink); border-color: var(--es-ink); color: var(--es-on-ink); cursor: default; }
.es-slot-booked { background: var(--es-grey); border-color: var(--es-grey); color: var(--es-faint); text-decoration: line-through; cursor: not-allowed; }
.es-slot-none { font-size: 13px; color: var(--es-muted); padding: 10px 12px; border: 1px dashed var(--es-line); border-radius: 8px; white-space: nowrap; }
.hour-block.es-slot { width: 4.25rem; height: 2.75rem; }

.es-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--es-line); margin-top: 16px; overflow-x: auto; }
.es-tab { padding: 12px 14px; font-size: 15px; font-weight: 500; color: var(--es-muted); background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; white-space: nowrap; }
.es-tab:hover { color: var(--es-ink); }
.es-tab.is-active { color: var(--es-ink); font-weight: 600; border-bottom-color: var(--es-ink); }

body.es .field-item { background: var(--es-surface); border: 1px solid var(--es-line) !important; border-radius: var(--es-radius); padding: 14px 14px 10px !important; margin-top: 10px; }
body.es .field-item .font-semibold { font-weight: 600; }
body.es .favorites-list, body.es .location-fields { list-style: none; padding: 0; }
body.es .calendar-wrapper { padding: 0 !important; }
body.es .flatpickr-calendar.inline { margin: 0 auto; }

/* ---------- Responsive tables: rows become cards on phones -------------- */
.es-time { font-weight: 600; }
@media (max-width: 700px) {
  body.es table.es-rtable, body.es table.es-rtable tbody, body.es table.es-rtable tr, body.es table.es-rtable td { display: block; width: 100%; }
  body.es table.es-rtable thead { display: none; }
  body.es table.es-rtable tr { padding: 12px 16px; border-top: 1px solid var(--es-line); position: relative; }
  body.es table.es-rtable tr:first-child { border-top: 0; }
  body.es table.es-rtable td { padding: 2px 0 !important; border: 0 !important; white-space: normal; text-align: left; }
  body.es table.es-rtable td[data-label]:not(.es-time)::before { content: attr(data-label) " · "; color: var(--es-faint); font-size: 12px; }
  body.es table.es-rtable td.es-time { font-size: 16px; padding-bottom: 4px !important; padding-right: 90px !important; }
  body.es table.es-rtable td.es-actions { position: absolute; top: 10px; right: 16px; width: auto; }
}

/* ==========================================================================
   Theme switch (System / Light / Dark) + dark theme
   <html data-theme="light|dark"> is set by the inline script in es_head
   before first paint (follows the device setting unless the user picks one).
   ========================================================================== */
:root { color-scheme: light; }

.es-theme-switch { display: inline-flex; padding: 3px; gap: 2px; border: 1px solid var(--es-line); border-radius: 999px; background: var(--es-surface); }
.es-theme-switch button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 30px; padding: 0 10px;
  border: 0; border-radius: 999px; background: transparent; color: var(--es-muted); font-size: 12px; font-weight: 500; cursor: pointer; font-family: inherit;
}
.es-theme-switch button svg { width: 16px; height: 16px; }
.es-theme-switch button:hover { color: var(--es-ink); }
.es-theme-switch button.is-active { background: var(--es-ink); color: var(--es-on-ink); }
.es-menu .es-theme-row { padding: 8px 10px 6px; }
.es-menu .es-theme-switch { display: flex; width: 100%; }
.es-menu .es-theme-switch button { flex: 1; padding: 0 6px; width: auto; }
.es-menu .es-theme-switch button:hover { background: transparent; }
.es-sidebar .es-theme-switch { background: transparent; border-color: rgba(255, 255, 255, .22); display: flex; margin-bottom: 12px; }
.es-sidebar .es-theme-switch button { flex: 1; color: rgba(255, 255, 255, .7); }
.es-sidebar .es-theme-switch button.is-active { background: #fff; color: #0b0b0c; }

/* ---------- Dark tokens --------------------------------------------------- */
html[data-theme="dark"] {
  color-scheme: dark;
  --es-ink: #f2f2f3;
  --es-ink-2: #d4d5d8;
  --es-on-ink: #0b0b0c;
  --es-grey: #141517;
  --es-grey-2: #0f1011;
  --es-surface: #1a1b1d;
  --es-surface-2: #212225;
  --es-line: #2f3134;
  --es-line-strong: #f2f2f3;
  --es-field-line: #3b3d41;
  --es-muted: #a7a9ae;
  --es-faint: #7c7f85;
  --es-tabbar-bg: rgba(26, 27, 29, .96);
  --es-sidebar: #060607;
  --es-focus: rgba(242, 242, 243, .2);
  --es-ok: #4ade80;   --es-ok-bg: rgba(34, 197, 94, .14);
  --es-warn: #fbbf24; --es-warn-bg: rgba(245, 158, 11, .14);
  --es-bad: #f87171;  --es-bad-bg: rgba(239, 68, 68, .15);
  --es-info: #93c5fd; --es-info-bg: rgba(59, 130, 246, .16);
  --es-shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --es-shadow-lg: 0 16px 40px rgba(0, 0, 0, .55);
}
html[data-theme="dark"] .es-btn-danger { background: #b42318; color: #fff; }
html[data-theme="dark"] .es-sidebar { border-right: 1px solid var(--es-line); }
html[data-theme="dark"] ::placeholder { color: var(--es-faint); opacity: 1; }

/* ---------- Dark: Tailwind utilities used in page content ----------------- */
/* Default borders (Tailwind preflight is light grey). Specificity (0,0,1): beats
   preflight, loses to any colour class, so status borders keep their colour. */
:where(html[data-theme="dark"] body.es) :is(div, section, article, header, footer, nav, aside, main, form, fieldset, table, thead, tbody, tr, td, th, ul, ol, li, dl, dt, dd, details, summary, span, p, a, label, button, input, select, textarea, hr, h1, h2, h3, h4, img, canvas) { border-color: var(--es-line); }

html[data-theme="dark"] body.es .bg-white { background-color: var(--es-surface); }
html[data-theme="dark"] body.es .bg-gray-50 { background-color: var(--es-surface-2); }
html[data-theme="dark"] body.es .bg-gray-100 { background-color: #232427; }
html[data-theme="dark"] body.es .bg-gray-200 { background-color: #2b2c30; }
html[data-theme="dark"] body.es .bg-gray-300 { background-color: #36383c; }
html[data-theme="dark"] body.es .bg-gray-400 { background-color: #4b4d52; }
html[data-theme="dark"] body.es .hover\:bg-gray-50:hover,
html[data-theme="dark"] body.es .hover\:bg-gray-100:hover { background-color: #26272a; }
html[data-theme="dark"] body.es .hover\:bg-gray-200:hover,
html[data-theme="dark"] body.es .hover\:bg-gray-300:hover { background-color: #34363a; }
html[data-theme="dark"] body.es .text-black,
html[data-theme="dark"] body.es .text-gray-900,
html[data-theme="dark"] body.es .text-gray-800 { color: var(--es-ink); }
html[data-theme="dark"] body.es .text-gray-700 { color: #d4d5d8; }
html[data-theme="dark"] body.es .text-gray-600,
html[data-theme="dark"] body.es .text-gray-500 { color: var(--es-muted); }
html[data-theme="dark"] body.es .text-gray-400 { color: var(--es-faint); }
html[data-theme="dark"] body.es .border-gray-100,
html[data-theme="dark"] body.es .border-gray-200,
html[data-theme="dark"] body.es .border-gray-300 { border-color: var(--es-line); }
html[data-theme="dark"] body.es .divide-gray-200 > * + * { border-color: var(--es-line); }

/* Status tints: same meaning, darker surfaces, lighter text */
html[data-theme="dark"] body.es .bg-green-50, html[data-theme="dark"] body.es .bg-green-100,
html[data-theme="dark"] body.es .bg-emerald-50, html[data-theme="dark"] body.es .bg-emerald-100 { background-color: var(--es-ok-bg); }
html[data-theme="dark"] body.es .bg-green-200, html[data-theme="dark"] body.es .hover\:bg-green-200:hover { background-color: rgba(34, 197, 94, .26); }
html[data-theme="dark"] body.es .text-green-600, html[data-theme="dark"] body.es .text-green-700, html[data-theme="dark"] body.es .text-green-800,
html[data-theme="dark"] body.es .text-emerald-700, html[data-theme="dark"] body.es .text-emerald-800 { color: var(--es-ok); }
html[data-theme="dark"] body.es .border-green-200, html[data-theme="dark"] body.es .border-green-300,
html[data-theme="dark"] body.es .border-emerald-200, html[data-theme="dark"] body.es .border-emerald-300 { border-color: rgba(74, 222, 128, .4); }

html[data-theme="dark"] body.es .bg-red-50, html[data-theme="dark"] body.es .bg-red-100 { background-color: var(--es-bad-bg); }
html[data-theme="dark"] body.es .bg-red-200, html[data-theme="dark"] body.es .hover\:bg-red-200:hover { background-color: rgba(239, 68, 68, .26); }
html[data-theme="dark"] body.es .text-red-600, html[data-theme="dark"] body.es .text-red-700, html[data-theme="dark"] body.es .text-red-800 { color: var(--es-bad); }
html[data-theme="dark"] body.es .border-red-200, html[data-theme="dark"] body.es .border-red-300 { border-color: rgba(248, 113, 113, .45); }

html[data-theme="dark"] body.es .bg-yellow-50, html[data-theme="dark"] body.es .bg-yellow-100,
html[data-theme="dark"] body.es .bg-amber-50, html[data-theme="dark"] body.es .bg-amber-100 { background-color: var(--es-warn-bg); }
html[data-theme="dark"] body.es .text-yellow-700, html[data-theme="dark"] body.es .text-yellow-800,
html[data-theme="dark"] body.es .text-amber-700, html[data-theme="dark"] body.es .text-amber-800 { color: var(--es-warn); }
html[data-theme="dark"] body.es .border-yellow-200, html[data-theme="dark"] body.es .border-yellow-300 { border-color: rgba(251, 191, 36, .4); }

html[data-theme="dark"] body.es .bg-blue-50, html[data-theme="dark"] body.es .bg-blue-100 { background-color: var(--es-info-bg); }
html[data-theme="dark"] body.es .text-blue-800 { color: var(--es-info); }
html[data-theme="dark"] body.es .border-blue-200, html[data-theme="dark"] body.es .border-blue-300 { border-color: rgba(147, 197, 253, .4); }
html[data-theme="dark"] body.es .text-orange-600 { color: #fb923c; }

/* flatpickr calendar */
html[data-theme="dark"] body.es .flatpickr-calendar { background: var(--es-surface); color: var(--es-ink); }
html[data-theme="dark"] body.es .flatpickr-day { color: var(--es-ink); }
html[data-theme="dark"] body.es .flatpickr-day:hover { background: var(--es-surface-2); border-color: var(--es-surface-2); }
html[data-theme="dark"] body.es .flatpickr-day.flatpickr-disabled, html[data-theme="dark"] body.es .flatpickr-day.prevMonthDay,
html[data-theme="dark"] body.es .flatpickr-day.nextMonthDay { color: var(--es-faint) !important; }
html[data-theme="dark"] body.es span.flatpickr-weekday { color: var(--es-muted) !important; }
html[data-theme="dark"] body.es .flatpickr-months .flatpickr-prev-month svg,
html[data-theme="dark"] body.es .flatpickr-months .flatpickr-next-month svg { fill: var(--es-ink); }
html[data-theme="dark"] .es-slot-booked { background: #2c2d31; border-color: #2c2d31; color: #8d9096; }

/* ---------- Phone overflow guards ---------------------------------------- */
/* Dropdowns size themselves to their longest option; never let them exceed their box. */
body.es select, body.es input, body.es textarea { max-width: 100%; min-width: 0; }
body.es img, body.es canvas, body.es svg { max-width: 100%; }
@media (max-width: 700px) {
  /* Several pages wrap their content in their own padded container inside .es-main,
     which doubled the side margins on phones. */
  body.es .es-main > :is(main, div).mx-auto { padding-left: 0 !important; padding-right: 0 !important; }
  /* Filter rows: each control takes the full width */
  body.es .es-main form[method="get"] select { flex: 1 1 100%; }
}
@media (max-width: 1023px) {
  /* Admin data tables scroll inside their box instead of widening the page */
  body.es .es-admin-main table:not(.es-rtable) { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  body.es .es-admin-main pre, body.es .es-admin-main code { white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }
  body.es .es-admin-main td { overflow-wrap: anywhere; }
}
/* Long unbroken strings (emails, tokens, JSON) wrap instead of stretching cards */
body.es .es-main td, body.es .es-main .break-words { overflow-wrap: anywhere; }
html[data-theme="dark"] body.es .text-blue-600:not(a), html[data-theme="dark"] body.es .text-blue-700:not(a) { color: #60a5fa; }
/* Action / status cells: never wrap their buttons or badges; take only the width they need */
body.es td.es-actions { white-space: nowrap; overflow-wrap: normal; width: 1%; }
