/* =========================================================
   Booking Optisanté — Admin
   Mobile-first design system. Single CSS file, no framework.
   Tokens → reset → layout → primitives → components → utils.
   ========================================================= */

/* ---------- 1. Tokens ---------- */
:root {
  /* Brand */
  --c-primary: #1a56db;
  --c-primary-hover: #1247b8;
  --c-primary-press: #0e3a99;
  --c-primary-soft: #e8f0fe;
  --c-primary-fg: #ffffff;

  /* Neutrals (light) */
  --c-bg: #f7f8fb;
  --c-surface: #ffffff;
  --c-surface-2: #f1f4fa;
  --c-surface-3: #e7ecf4;
  --c-border: #e2e8f0;
  --c-border-strong: #cbd5e1;
  --c-text: #0f172a;
  --c-text-muted: #5b6478;
  --c-text-subtle: #94a3b8;

  /* Semantic */
  --c-success: #15803d;
  --c-success-bg: #dcfce7;
  --c-success-fg: #166534;
  --c-warn: #b45309;
  --c-warn-bg: #fef3c7;
  --c-warn-fg: #92400e;
  --c-danger: #b91c1c;
  --c-danger-bg: #fee2e2;
  --c-danger-fg: #991b1b;
  --c-info: #1e40af;
  --c-info-bg: #dbeafe;
  --c-info-fg: #1e3a8a;

  /* Elevation */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow-md: 0 6px 18px rgba(15, 23, 42, .08);
  --shadow-lg: 0 14px 28px rgba(15, 23, 42, .12);

  /* Geometry */
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;

  /* Layout */
  --topbar-h: 56px;
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bot: env(safe-area-inset-bottom, 0);
  --container-max: 760px;

  /* Type */
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --c-primary: #5183ee;
    --c-primary-hover: #6995f4;
    --c-primary-press: #82a7f7;
    --c-primary-soft: #15203a;
    --c-primary-fg: #0b1220;
    --c-bg: #0b1220;
    --c-surface: #131c2f;
    --c-surface-2: #1a2540;
    --c-surface-3: #243154;
    --c-border: #2a3a5e;
    --c-border-strong: #3a4d76;
    --c-text: #e6ecf7;
    --c-text-muted: #94a3b8;
    --c-text-subtle: #64748b;
    --c-success: #4ade80;
    --c-success-bg: #052e16;
    --c-success-fg: #86efac;
    --c-warn: #fbbf24;
    --c-warn-bg: #422006;
    --c-warn-fg: #fcd34d;
    --c-danger: #f87171;
    --c-danger-bg: #450a0a;
    --c-danger-fg: #fca5a5;
    --c-info: #60a5fa;
    --c-info-bg: #0c1f44;
    --c-info-fg: #93c5fd;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 6px 18px rgba(0, 0, 0, .5);
    --shadow-lg: 0 14px 28px rgba(0, 0, 0, .6);
  }
}

[data-theme="dark"] {
  --c-primary: #5183ee;
  --c-primary-hover: #6995f4;
  --c-primary-press: #82a7f7;
  --c-primary-soft: #15203a;
  --c-primary-fg: #0b1220;
  --c-bg: #0b1220;
  --c-surface: #131c2f;
  --c-surface-2: #1a2540;
  --c-surface-3: #243154;
  --c-border: #2a3a5e;
  --c-border-strong: #3a4d76;
  --c-text: #e6ecf7;
  --c-text-muted: #94a3b8;
  --c-text-subtle: #64748b;
  --c-success: #4ade80;
  --c-success-bg: #052e16;
  --c-success-fg: #86efac;
  --c-warn: #fbbf24;
  --c-warn-bg: #422006;
  --c-warn-fg: #fcd34d;
  --c-danger: #f87171;
  --c-danger-bg: #450a0a;
  --c-danger-fg: #fca5a5;
  --c-info: #60a5fa;
  --c-info-bg: #0c1f44;
  --c-info-fg: #93c5fd;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, .5);
  --shadow-lg: 0 14px 28px rgba(0, 0, 0, .6);
}

/* ---------- 2. Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  color: var(--c-text);
  background: var(--c-bg);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: contain;
}
button, input, select, textarea {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  margin: 0;
}
button { cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 2px;
}
a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { display: block; max-width: 100%; }

/* ---------- 3. Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 4px;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) 6px 0;
  background: var(--c-primary);
  color: var(--c-primary-fg);
  box-shadow: var(--shadow-sm);
}
.topbar-title {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-icon-btn {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: inherit;
  border-radius: 10px;
  transition: background-color 120ms ease, transform 120ms ease;
}
.topbar-icon-btn:active { transform: scale(0.94); background: rgba(255, 255, 255, .18); }
.topbar-icon-btn[hidden] { display: none; }

/* ---------- 4. App container ---------- */
.app {
  padding: 16px 14px calc(40px + var(--safe-bot));
  max-width: var(--container-max);
  margin: 0 auto;
  min-height: calc(100dvh - var(--topbar-h));
}
@media (min-width: 720px) {
  .app { padding: 24px 24px calc(48px + var(--safe-bot)); }
}

/* ---------- 5. Type primitives ---------- */
.h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin: 0 0 4px; }
.h2 { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 4px; }
.h3 { font-size: 15px; font-weight: 600; margin: 0 0 4px; }
.t-muted { color: var(--c-text-muted); }
.t-subtle { color: var(--c-text-subtle); }
.t-mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--c-text-muted);
  margin: 20px 4px 10px;
}
.section-label:first-child { margin-top: 4px; }

/* ---------- 6. Card / list ---------- */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 10px; }

.list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }

.tap {
  display: block;
  width: 100%;
  text-align: left;
  color: inherit;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  min-height: 56px;
  transition: background-color 120ms ease, transform 120ms ease, border-color 120ms ease;
}
.tap:hover { border-color: var(--c-border-strong); }
.tap:active { transform: scale(0.99); background: var(--c-surface-2); }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.row-stack { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.row-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; font-size: 13px; color: var(--c-text-muted); }
.row-meta > span { white-space: nowrap; }

.chev {
  color: var(--c-text-subtle);
  width: 18px; height: 18px;
  flex-shrink: 0;
}

.kv {
  display: grid;
  grid-template-columns: minmax(110px, 38%) 1fr;
  gap: 4px 12px;
  font-size: 14px;
}
.kv-key { color: var(--c-text-muted); }
.kv-val { color: var(--c-text); font-weight: 500; word-break: break-word; }
.kv-val a { word-break: break-word; }

/* ---------- 7. Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 12px;
  background: var(--c-primary);
  color: var(--c-primary-fg);
  border: 1px solid transparent;
  transition: background-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
  width: 100%;
}
.btn:hover { background: var(--c-primary-hover); }
.btn:active { background: var(--c-primary-press); transform: scale(0.99); }
.btn[disabled], .btn.is-disabled { opacity: 0.55; pointer-events: none; cursor: not-allowed; }

/* Primary CTA — used when a button needs to stand out from a peer in the
 * same row or sticky bar (e.g. the multi-select export footer where
 * "Exporter ZIP" must read as the dominant action vs "Tous/Aucun"). */
.btn--primary {
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 4px 12px rgba(37, 99, 235, 0.25);
  font-weight: 700;
}
.btn--primary:hover { box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 6px 16px rgba(37, 99, 235, 0.30); }

.btn-ghost {
  background: var(--c-surface);
  color: var(--c-text);
  border: 1px solid var(--c-border);
}
.btn-ghost:hover { background: var(--c-surface-2); }
.btn-ghost:active { background: var(--c-surface-3); }

.btn-soft {
  background: var(--c-primary-soft);
  color: var(--c-primary);
  border: 1px solid transparent;
}
.btn-soft:hover { background: var(--c-surface-3); }

.btn-danger { background: var(--c-danger); }
.btn-danger:hover { background: #991b1b; }

.btn-sm {
  min-height: 36px;
  padding: 0 14px;
  font-size: 14px;
  border-radius: 10px;
}

.btn-row {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr;
}
.btn-row.cols-2 { grid-template-columns: 1fr 1fr; }
@media (min-width: 540px) {
  .btn-row.sm-cols-2 { grid-template-columns: 1fr 1fr; }
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border-radius: 10px;
  color: var(--c-text-muted);
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  transition: background-color 120ms ease, color 120ms ease, transform 120ms ease;
}
.icon-btn:active { transform: scale(0.96); background: var(--c-surface-3); }

/* ---------- 8. Inputs ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}
.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text-muted);
}
.input, .select, .textarea {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  font-size: 16px;       /* ≥16 prevents iOS auto-zoom */
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text);
  border-radius: 12px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(26, 86, 219, .14);
  outline: 0;
}
.textarea { min-height: 88px; resize: vertical; line-height: 1.45; }

.search {
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 14px;
  width: 18px; height: 18px;
  color: var(--c-text-subtle);
  pointer-events: none;
}
.search .input {
  padding-left: 42px;
}

/* ---------- 9. Stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.stat {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: 14px 10px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}
.stat::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--c-text-subtle);
  border-top-left-radius: var(--radius-md);
  border-bottom-left-radius: var(--radius-md);
}
.stat--booked::before { background: var(--c-info); }
.stat--avail::before { background: var(--c-success); }
.stat--total::before { background: var(--c-primary); }
.stat--cancel::before { background: var(--c-danger); }
.stat-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--c-text);
}
.stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--c-text-muted);
  margin-top: 4px;
}

/* Day view : visible fill rate bar above the tiles */
.fillbar {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}
.fillbar-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.fillbar-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.fillbar-pct {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--c-text);
}
.fillbar-track {
  width: 100%;
  height: 10px;
  background: var(--c-surface-2);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}
.fillbar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--c-primary), var(--c-info));
  border-radius: 999px;
  transition: width 280ms ease;
}
.fillbar--high .fillbar-fill { background: linear-gradient(90deg, var(--c-success), #22c55e); }
.fillbar--mid .fillbar-fill { background: linear-gradient(90deg, var(--c-primary), var(--c-info)); }
.fillbar--low .fillbar-fill { background: linear-gradient(90deg, var(--c-warn), #f59e0b); }

/* Filter pills above the appointment list */
.pillbar {
  display: flex;
  gap: 8px;
  padding: 4px;
  background: var(--c-surface-2);
  border-radius: 999px;
  border: 1px solid var(--c-border);
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.pillbar::-webkit-scrollbar { display: none; }
.pill {
  flex: 1;
  min-height: 36px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text-muted);
  background: transparent;
  border: 0;
  border-radius: 999px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.pill[aria-pressed="true"] {
  background: var(--c-surface);
  color: var(--c-text);
  box-shadow: var(--shadow-sm);
}
.pill .pill-count {
  background: var(--c-surface-3);
  color: var(--c-text-muted);
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.pill[aria-pressed="true"] .pill-count {
  background: var(--c-primary-soft);
  color: var(--c-primary);
}

/* "Prochain RDV" highlight */
.appt--next {
  border-color: var(--c-primary) !important;
  background: linear-gradient(180deg, var(--c-primary-soft) 0%, var(--c-surface) 60%);
  box-shadow: var(--shadow-md);
  position: relative;
}
.appt--next::before {
  content: "Prochain";
  position: absolute;
  top: -10px;
  left: 16px;
  background: var(--c-primary);
  color: var(--c-primary-fg);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 8px;
  border-radius: 999px;
}

.appt--past .appt-time { opacity: 0.5; }
.appt--past { opacity: 0.85; }

/* Tap area for the whole appointment card. Purely additive — does not
 * override .appt's grid layout / padding / surface; only adds pointer
 * affordance, transitions and an active-press scale. */
.appt[role="button"] {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 120ms ease, background-color 120ms ease, border-color 120ms ease;
}
.appt[role="button"]:hover { border-color: var(--c-border-strong); }
.appt[role="button"]:active { transform: scale(0.99); background: var(--c-surface-2); }
.appt[role="button"]:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 2px;
}

/* ---------- Bottom sheet ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .42);
  z-index: 70;
  opacity: 0;
  transition: opacity 200ms ease;
}
.sheet-backdrop[data-show="true"] { opacity: 1; }
[data-theme="dark"] .sheet-backdrop, :root.dark .sheet-backdrop { background: rgba(0, 0, 0, .6); }

.sheet {
  position: fixed;
  z-index: 80;
  background: var(--c-surface);
  box-shadow: var(--shadow-lg);
  /* Mobile: bottom sheet anchored to safe area */
  left: 0;
  right: 0;
  bottom: 0;
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  padding: 12px 16px calc(20px + var(--safe-bot));
  max-height: 88dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: translateY(100%);
  transition: transform 240ms cubic-bezier(.2, .8, .2, 1);
}
.sheet[data-show="true"] { transform: translateY(0); }
.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: var(--c-border-strong);
  margin: 4px auto 14px;
}
.sheet-title {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
}
.sheet-subtitle {
  font-size: 13px;
  color: var(--c-text-muted);
  margin-bottom: 16px;
}
.sheet-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 16px;
}
@media (min-width: 480px) {
  .sheet-actions { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}
.sheet-action {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--c-border);
  border-radius: 14px;
  background: var(--c-surface);
  color: var(--c-text);
  font-size: 15px;
  font-weight: 600;
  text-decoration: none;
  min-height: 56px;
  transition: background-color 120ms ease, transform 120ms ease;
}
.sheet-action:hover { background: var(--c-surface-2); text-decoration: none; }
.sheet-action:active { transform: scale(0.99); background: var(--c-surface-3); }
.sheet-action-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: var(--c-primary-soft);
  color: var(--c-primary);
  flex-shrink: 0;
}
.sheet-action-stack { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.sheet-action-stack > strong { font-size: 15px; }
.sheet-action-stack > span { font-size: 12px; color: var(--c-text-muted); }

.sheet-meta {
  background: var(--c-surface-2);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 8px;
  font-size: 13px;
}
.sheet-meta + .sheet-meta { margin-top: 8px; }

@media (min-width: 720px) {
  .sheet {
    left: auto;
    right: 16px;
    bottom: 16px;
    max-width: 480px;
    border-radius: 22px;
  }
}

/* ---------- 10. Badge ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  background: var(--c-surface-2);
  color: var(--c-text-muted);
  border: 1px solid var(--c-border);
}
.badge--primary { background: var(--c-primary-soft); color: var(--c-primary); border-color: transparent; }
.badge--success { background: var(--c-success-bg); color: var(--c-success-fg); border-color: transparent; }
.badge--warn { background: var(--c-warn-bg); color: var(--c-warn-fg); border-color: transparent; }
.badge--danger { background: var(--c-danger-bg); color: var(--c-danger-fg); border-color: transparent; }
.badge--info { background: var(--c-info-bg); color: var(--c-info-fg); border-color: transparent; }

/* ---------- 11. Empty / loading / error ---------- */
.empty, .loading, .error {
  text-align: center;
  padding: 48px 16px;
  color: var(--c-text-muted);
}
.empty p, .loading p, .error p { margin: 0 0 8px; }
.error { color: var(--c-danger-fg); }

.spinner {
  display: inline-block;
  width: 28px;
  height: 28px;
  border: 3px solid var(--c-border);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, var(--c-surface-2) 0, var(--c-surface-3) 50%, var(--c-surface-2) 100%);
  background-size: 200% 100%;
  border-radius: 8px;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- 12. Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-bot));
  transform: translateX(-50%);
  background: var(--c-text);
  color: var(--c-bg);
  padding: 12px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  font-weight: 500;
  max-width: calc(100vw - 24px);
  z-index: 60;
  opacity: 0;
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}
.toast[data-show="true"] {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}
.toast--error { background: var(--c-danger); color: #fff; }

/* ---------- 13. Menu sheet (settings / mode) ---------- */
.menu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .35);
  z-index: 40;
  opacity: 0;
  transition: opacity 180ms ease;
}
.menu-backdrop[data-show="true"] { opacity: 1; }
[data-theme="dark"] .menu-backdrop, :root.dark .menu-backdrop { background: rgba(0, 0, 0, .55); }

.menu-sheet {
  position: fixed;
  z-index: 50;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 240px;
  max-width: calc(100vw - 24px);
  padding: 6px;
  /* Mobile: anchored to top-right just under topbar */
  top: calc(var(--topbar-h) + var(--safe-top) + 6px);
  right: 8px;
  transform-origin: top right;
  transform: scale(0.96);
  opacity: 0;
  transition: opacity 140ms ease, transform 140ms ease;
}
.menu-sheet[data-show="true"] { opacity: 1; transform: scale(1); }
.menu-sheet[hidden] { display: none; }

.menu-section {
  padding: 8px 12px 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--c-text-muted);
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 500;
  color: var(--c-text);
  text-align: left;
  background: transparent;
  border: 0;
  min-height: 44px;
}
.menu-item:hover { background: var(--c-surface-2); }
.menu-item:active { background: var(--c-surface-3); }
.menu-item[aria-checked="true"] { color: var(--c-primary); }
.menu-item-check {
  margin-left: auto;
  width: 18px; height: 18px;
  color: var(--c-primary);
  opacity: 0;
}
.menu-item[aria-checked="true"] .menu-item-check { opacity: 1; }

/* ---------- 14. Day picker (event detail / day) ---------- */
.daynav {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: 8px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.daynav-current {
  flex: 1;
  text-align: center;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.daynav-input {
  flex: 1;
  font-size: 16px;
  padding: 12px 10px;
  border: 1px solid var(--c-border);
  border-radius: 10px;
  background: var(--c-surface-2);
  color: var(--c-text);
  min-height: 44px;
  font-family: inherit;
}

/* ---------- 15. Appointments ---------- */
.appt {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}
.appt-time {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--c-surface-2);
  border-radius: 10px;
  padding: 8px 4px;
  font-variant-numeric: tabular-nums;
}
.appt-time-h { font-size: 18px; font-weight: 700; color: var(--c-text); letter-spacing: -0.02em; }
.appt-time-end { font-size: 11px; color: var(--c-text-muted); margin-top: 1px; }
.appt-name { font-size: 16px; font-weight: 600; }
.appt-meta { font-size: 13px; color: var(--c-text-muted); display: flex; flex-direction: column; gap: 2px; margin-top: 2px; }
.appt-meta a { color: var(--c-text-muted); }
.appt-meta a:active { color: var(--c-primary); }
.appt--cancelled .appt-name { text-decoration: line-through; opacity: 0.65; }
.appt--cancelled .appt-time { opacity: 0.6; }

.staff-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
}
.staff-row .staff-name { font-weight: 600; }
.staff-row .staff-counts { color: var(--c-text-muted); font-variant-numeric: tabular-nums; }

/* ---------- 16. Login screen ---------- */
.login {
  min-height: calc(100dvh - var(--topbar-h) - var(--safe-top) - var(--safe-bot));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  gap: 8px;
}
.login-logo {
  width: 88px;
  height: 88px;
  margin-bottom: 12px;
}
.login h2 { margin: 0; font-size: 22px; letter-spacing: -0.01em; }
.login p { color: var(--c-text-muted); margin: 0 0 20px; max-width: 320px; }
.login .btn { max-width: 320px; }

/* ---------- 17. Disabled-pending tooltip (advanced mode write actions) ---------- */
.is-pending-azure { position: relative; }
.is-pending-azure::after {
  content: attr(data-pending);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--c-text);
  color: var(--c-bg);
  font-size: 12px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  padding: 6px 10px;
  border-radius: 8px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease;
  box-shadow: var(--shadow-md);
  z-index: 5;
}
.is-pending-azure:hover::after,
.is-pending-azure:focus::after { opacity: 1; }

/* ---------- 18. Utils ---------- */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.gap-2 { gap: 4px; }
.gap-3 { gap: 8px; }
.gap-4 { gap: 12px; }
.gap-5 { gap: 16px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-5 { margin-top: 24px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.text-center { text-align: center; }
.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;
}
.sr-only:focus, .sr-only:active {
  position: fixed;
  top: 8px; left: 8px;
  width: auto; height: auto;
  padding: 10px 14px;
  background: var(--c-primary);
  color: var(--c-primary-fg);
  border-radius: 10px;
  z-index: 100;
  font-weight: 600;
  clip: auto;
}

/* Hide focus outline for the main container itself when programmatically
 * focused after a route change — keep it for true keyboard users. */
#app:focus, #app:focus-visible { outline: none; }

/* ---------- View transitions ---------- */
.fadein {
  animation: fadein 220ms ease-out both;
}
@keyframes fadein {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- Offline banner ---------- */
.offline-banner {
  position: fixed;
  left: 50%;
  top: calc(var(--topbar-h) + var(--safe-top) + 8px);
  transform: translateX(-50%);
  background: var(--c-warn);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  z-index: 25;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.offline-banner svg { stroke: #fff; }
[data-theme="dark"] .offline-banner, :root.dark .offline-banner { color: #1a1206; }

/* ---------- Section heading "h2" with action chip ---------- */
.section-with-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.section-with-action .section-label { margin: 0; }

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

/* Undo bar — fixed near the bottom during the 5 s cancel grace window */
.undo-bar {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 18px;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--c-text);
  color: var(--c-bg);
  padding: 10px 14px;
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  font-weight: 600;
}
.undo-bar .btn {
  color: inherit;
  border-color: currentColor;
  background: transparent;
}

/* Timeline day view (hour grid) */
.tl {
  position: relative;
  margin-top: 4px;
}
.tl-hourline {
  position: absolute;
  left: 44px;
  right: 0;
  border-top: 1px solid var(--c-border, rgba(120, 130, 150, .18));
}
.tl-hourlabel {
  position: absolute;
  left: 0;
  width: 40px;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--c-text-muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.tl-now {
  position: absolute;
  left: 44px;
  right: 0;
  border-top: 2px solid var(--c-danger, #dc2626);
  z-index: 3;
}
.tl-now::before {
  content: '';
  position: absolute;
  left: -5px;
  top: -5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c-danger, #dc2626);
}
.tl-block {
  position: absolute;
  z-index: 2;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 4px 8px;
  border-radius: 10px;
  background: var(--c-primary-soft, rgba(59, 130, 246, .14));
  border: 1px solid var(--c-primary, #3b82f6);
  border-left-width: 4px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tl-block:active { filter: brightness(.94); }
.tl-block-time {
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--c-primary, #3b82f6);
}
.tl-block-name {
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tl-block--past { opacity: .55; }
.tl-block--next {
  border-color: var(--c-success, #16a34a);
  background: rgba(22, 163, 74, .12);
}
.tl-block--next .tl-block-time { color: var(--c-success, #16a34a); }


/* ============================================================
   Desktop hybrid layout — added 2026-06-17 (audit visuel Nabil)
   Mobile (<1024px) is unchanged. On wide screens: Home events and
   Analytics sites become responsive grids; forms stay a centered column.
   ============================================================ */
@media (min-width: 1024px) {
  #app[data-view="home"],
  #app[data-view="analytics"] { max-width: 1160px; }

  /* Top action + search cards stay a readable centered column on Home */
  #app[data-view="home"] > .card {
    max-width: 760px;
    margin-left: auto;
    margin-right: auto;
  }

  /* Event cards: 2-up grid inside each section */
  #app[data-view="home"] ul.events-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    align-items: start;
  }
  #app[data-view="home"] ul.events-list > li { min-width: 0; }

  /* Analytics: KPI bar spans full width, site cards as a 2-up grid */
  #app[data-view="analytics"] .sites-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    align-items: start;
  }
  #app[data-view="analytics"] .sites-list > .card { min-width: 0; }
}

@media (min-width: 1440px) {
  #app[data-view="home"] ul.events-list,
  #app[data-view="analytics"] .sites-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
