/**
 * Light / dark theme overrides for Tailwind utility classes used in views.
 * Preference is applied via html.dark (see public/js/theme.js).
 * Print rules force a light palette.
 */

:root {
  color-scheme: light;
}

html.dark {
  color-scheme: dark;
}

/* ── Surfaces & text (base layout) ─────────────────────────────── */
html.dark body {
  background-color: #020617; /* slate-950 */
  color: #e2e8f0; /* slate-200 */
}

/* ── Backgrounds ───────────────────────────────────────────────── */
html.dark .bg-white { background-color: #0f172a !important; } /* slate-900 */
html.dark .bg-slate-50 { background-color: #020617 !important; } /* slate-950 */
html.dark .bg-slate-100 { background-color: #1e293b !important; } /* slate-800 */
html.dark .bg-slate-200 { background-color: #334155 !important; } /* slate-700 */
html.dark .bg-slate-900 { background-color: #0f172a !important; }

/* Soft tint panels */
html.dark .bg-sky-50 { background-color: rgba(14, 165, 233, 0.12) !important; }
html.dark .bg-sky-100 { background-color: rgba(14, 165, 233, 0.18) !important; }
html.dark .bg-emerald-50 { background-color: rgba(16, 185, 129, 0.12) !important; }
html.dark .bg-emerald-100 { background-color: rgba(16, 185, 129, 0.18) !important; }
html.dark .bg-amber-50 { background-color: rgba(245, 158, 11, 0.12) !important; }
html.dark .bg-amber-100 { background-color: rgba(245, 158, 11, 0.18) !important; }
html.dark .bg-red-50 { background-color: rgba(239, 68, 68, 0.12) !important; }
html.dark .bg-violet-50 { background-color: rgba(139, 92, 246, 0.12) !important; }
html.dark .bg-violet-100 { background-color: rgba(139, 92, 246, 0.18) !important; }
html.dark .bg-rose-50 { background-color: rgba(244, 63, 94, 0.12) !important; }

/**
 * Plan section title bars (Today’s plan, Scheduled day headers).
 * Light: slate-200 header vs white activity rows for clear contrast.
 * Dark: near-black header (same idea as remapped bg-white/80) vs slate-900 rows.
 */
.plan-section-header {
  background-color: #e2e8f0; /* slate-200 */
}
html.dark .plan-section-header {
  background-color: rgba(2, 6, 23, 0.92) !important; /* slate-950 */
}

/* Opacity-modifier utilities used in a few views */
/* Day-of-week headers (planner) use bg-white/80 — map to near-black, not translucent white */
html.dark .bg-white\/80 { background-color: rgba(2, 6, 23, 0.92) !important; } /* slate-950 */
html.dark .bg-white\/90 { background-color: rgba(2, 6, 23, 0.95) !important; }
html.dark .bg-white\/50 { background-color: rgba(15, 23, 42, 0.7) !important; }
html.dark .bg-slate-50\/40 { background-color: rgba(15, 23, 42, 0.4) !important; }
html.dark .bg-slate-50\/80 { background-color: rgba(15, 23, 42, 0.8) !important; }
/* Settings sticky section nav — was near-white under remapped light text */
html.dark .bg-slate-50\/95 { background-color: rgba(15, 23, 42, 0.95) !important; } /* slate-900 */
html.dark .bg-slate-900\/40 { background-color: rgba(2, 6, 23, 0.55) !important; }
html.dark .bg-slate-900\/50 { background-color: rgba(2, 6, 23, 0.65) !important; }
html.dark .bg-sky-50\/60 { background-color: rgba(14, 165, 233, 0.12) !important; }
html.dark .bg-amber-100\/80 { background-color: rgba(245, 158, 11, 0.2) !important; }
html.dark .bg-violet-50\/40 { background-color: rgba(139, 92, 246, 0.12) !important; }
html.dark .bg-violet-50\/50 { background-color: rgba(139, 92, 246, 0.15) !important; }
html.dark .bg-violet-200\/80 { background-color: rgba(139, 92, 246, 0.28) !important; }
html.dark .text-sky-900\/80 { color: rgba(224, 242, 254, 0.85) !important; }
html.dark .text-emerald-800\/80 { color: rgba(167, 243, 208, 0.85) !important; }

/* Keep solid action colors readable; slight bump for contrast on dark */
html.dark .bg-sky-600 { background-color: #0284c7 !important; }
html.dark .bg-sky-700 { background-color: #0369a1 !important; }
html.dark .bg-violet-600 { background-color: #7c3aed !important; }
html.dark .bg-violet-700 { background-color: #6d28d9 !important; }
html.dark .bg-emerald-600 { background-color: #059669 !important; }
html.dark .bg-emerald-700 { background-color: #047857 !important; }

/* ── Text ──────────────────────────────────────────────────────── */
html.dark .text-slate-800 { color: #f1f5f9 !important; } /* slate-100 */
html.dark .text-slate-700 { color: #e2e8f0 !important; } /* slate-200 */
html.dark .text-slate-600 { color: #cbd5e1 !important; } /* slate-300 */
html.dark .text-slate-500 { color: #94a3b8 !important; } /* slate-400 */
html.dark .text-slate-400 { color: #64748b !important; } /* slate-500 */
html.dark .text-slate-300 { color: #94a3b8 !important; }

html.dark .text-brand-700 { color: #38bdf8 !important; } /* sky-400 */

html.dark .text-sky-600 { color: #38bdf8 !important; }
html.dark .text-sky-700 { color: #7dd3fc !important; }
html.dark .text-sky-800 { color: #bae6fd !important; }
html.dark .text-sky-900 { color: #e0f2fe !important; }
html.dark .text-sky-950 { color: #f0f9ff !important; }

html.dark .text-emerald-600 { color: #34d399 !important; }
html.dark .text-emerald-700 { color: #6ee7b7 !important; }
html.dark .text-emerald-800 { color: #a7f3d0 !important; }
html.dark .text-emerald-900 { color: #d1fae5 !important; }
html.dark .text-emerald-950 { color: #ecfdf5 !important; }

html.dark .text-amber-700 { color: #fbbf24 !important; }
html.dark .text-amber-800 { color: #fcd34d !important; }
html.dark .text-amber-900 { color: #fde68a !important; }
html.dark .text-amber-950 { color: #fef3c7 !important; }

html.dark .text-red-700 { color: #fca5a5 !important; }
html.dark .text-red-800 { color: #fecaca !important; }

html.dark .text-violet-600 { color: #a78bfa !important; }
html.dark .text-violet-700 { color: #c4b5fd !important; }
html.dark .text-violet-800 { color: #ddd6fe !important; }
html.dark .text-violet-900 { color: #ede9fe !important; }

html.dark .text-rose-600 { color: #fb7185 !important; }
html.dark .text-rose-700 { color: #fda4af !important; }
html.dark .text-rose-800 { color: #fecdd3 !important; }

/* ── Borders & dividers ────────────────────────────────────────── */
html.dark .border-slate-400 { border-color: #64748b !important; }
html.dark .border-slate-300 { border-color: #475569 !important; }
html.dark .border-slate-200 { border-color: #334155 !important; }
html.dark .border-slate-100 { border-color: #1e293b !important; }

html.dark .border-sky-100 { border-color: rgba(14, 165, 233, 0.25) !important; }
html.dark .border-sky-200 { border-color: rgba(14, 165, 233, 0.35) !important; }
html.dark .border-sky-500 { border-color: #0ea5e9 !important; }
html.dark .border-sky-600 { border-color: #0284c7 !important; }

html.dark .border-emerald-100 { border-color: rgba(16, 185, 129, 0.25) !important; }
html.dark .border-emerald-200 { border-color: rgba(16, 185, 129, 0.35) !important; }
html.dark .border-emerald-300 { border-color: rgba(16, 185, 129, 0.45) !important; }

html.dark .border-amber-100 { border-color: rgba(245, 158, 11, 0.25) !important; }
html.dark .border-amber-200 { border-color: rgba(245, 158, 11, 0.35) !important; }
html.dark .border-amber-300 { border-color: rgba(245, 158, 11, 0.45) !important; }

html.dark .border-red-100 { border-color: rgba(239, 68, 68, 0.25) !important; }
html.dark .border-red-200 { border-color: rgba(239, 68, 68, 0.35) !important; }
html.dark .border-red-300 { border-color: rgba(239, 68, 68, 0.45) !important; }

html.dark .border-violet-100 { border-color: rgba(139, 92, 246, 0.25) !important; }
html.dark .border-violet-200 { border-color: rgba(139, 92, 246, 0.35) !important; }
html.dark .border-violet-300 { border-color: rgba(139, 92, 246, 0.45) !important; }
html.dark .border-violet-400 { border-color: #a78bfa !important; }
html.dark .border-violet-500 { border-color: #8b5cf6 !important; }

html.dark .border-rose-100 { border-color: rgba(244, 63, 94, 0.25) !important; }

html.dark .divide-slate-100 > :not([hidden]) ~ :not([hidden]) {
  border-color: #1e293b !important;
}

/* ── Hover / active / focus ────────────────────────────────────── */
html.dark .hover\:bg-white:hover { background-color: #1e293b !important; }
html.dark .hover\:bg-slate-50:hover { background-color: #1e293b !important; }
html.dark .hover\:bg-slate-100:hover { background-color: #334155 !important; }
html.dark .hover\:bg-slate-200:hover { background-color: #475569 !important; }
html.dark .hover\:bg-sky-50:hover { background-color: rgba(14, 165, 233, 0.15) !important; }
html.dark .hover\:bg-sky-100:hover { background-color: rgba(14, 165, 233, 0.22) !important; }
html.dark .hover\:bg-emerald-50:hover { background-color: rgba(16, 185, 129, 0.15) !important; }
html.dark .hover\:bg-emerald-100:hover { background-color: rgba(16, 185, 129, 0.22) !important; }
html.dark .hover\:bg-amber-100:hover { background-color: rgba(245, 158, 11, 0.22) !important; }
html.dark .hover\:bg-red-50:hover { background-color: rgba(239, 68, 68, 0.15) !important; }
html.dark .hover\:bg-violet-50:hover { background-color: rgba(139, 92, 246, 0.15) !important; }
html.dark .hover\:bg-violet-100:hover { background-color: rgba(139, 92, 246, 0.22) !important; }
html.dark .hover\:bg-rose-50:hover { background-color: rgba(244, 63, 94, 0.15) !important; }

html.dark .hover\:text-slate-600:hover { color: #cbd5e1 !important; }
html.dark .hover\:text-slate-700:hover { color: #e2e8f0 !important; }
html.dark .hover\:text-slate-800:hover { color: #f1f5f9 !important; }
html.dark .hover\:text-sky-600:hover { color: #38bdf8 !important; }
html.dark .hover\:text-sky-700:hover { color: #7dd3fc !important; }
html.dark .hover\:text-sky-950:hover { color: #f0f9ff !important; }
html.dark .hover\:text-rose-600:hover { color: #fb7185 !important; }
html.dark .hover\:text-amber-900:hover { color: #fde68a !important; }

/* Planning swipe / menus (FR-022) */
html.dark .js-item-menu,
html.dark #plan-context-menu {
  background-color: #0f172a !important;
  border-color: #334155 !important;
}

/*
 * Planning card swipe (FR-022)
 * Solid opaque face slides over always-present actions — no opacity fade-through.
 */
.js-plan-item-front {
  touch-action: pan-y;
  /* Solid fills so swipe buttons never show through the face */
  background-color: #ffffff;
}
.js-plan-item-front.is-suggested {
  background-color: #f5f3ff; /* violet-50 solid */
}
.js-plan-item-front:hover {
  background-color: #f8fafc; /* slate-50 */
}
.js-plan-item-front.is-suggested:hover {
  background-color: #ede9fe; /* violet-100 solid */
}
html.dark .js-plan-item-front {
  background-color: #0f172a; /* slate-900 solid */
}
html.dark .js-plan-item-front.is-suggested {
  background-color: #1e1b4b; /* indigo-950 solid */
}
html.dark .js-plan-item-front:hover {
  background-color: #1e293b; /* slate-800 */
}
html.dark .js-plan-item-front.is-suggested:hover {
  background-color: #312e81; /* indigo-900 */
}

/* Actions only receive taps once the face has moved (set in JS) */
.js-plan-item:not(.is-swipe-reveal) .js-swipe-actions {
  pointer-events: none;
}
.js-plan-item.is-swipe-reveal .js-swipe-actions {
  pointer-events: auto;
}

.js-plan-item.is-swipe-dragging .js-plan-item-front,
.js-plan-item.is-swipe-reveal .js-plan-item-front {
  touch-action: none;
}
/* While a horizontal swipe is locked, stop the page from scrolling underneath */
html.is-plan-swiping,
html.is-plan-swiping body {
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

html.dark .hover\:border-slate-200:hover { border-color: #334155 !important; }
html.dark .hover\:border-slate-400:hover { border-color: #64748b !important; }
html.dark .hover\:border-emerald-300:hover { border-color: rgba(16, 185, 129, 0.45) !important; }
html.dark .hover\:border-rose-100:hover { border-color: rgba(244, 63, 94, 0.25) !important; }

html.dark .active\:bg-slate-100:active { background-color: #334155 !important; }

/* ── Form controls ─────────────────────────────────────────────── */
html.dark input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
html.dark select,
html.dark textarea {
  background-color: #0f172a;
  color: #e2e8f0;
  border-color: #475569;
}

html.dark input::placeholder,
html.dark textarea::placeholder {
  color: #64748b;
}

html.dark option {
  background-color: #0f172a;
  color: #e2e8f0;
}

/* ── Shadows (softer on dark surfaces) ─────────────────────────── */
html.dark .shadow-sm {
  --tw-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.4);
  --tw-shadow-colored: 0 1px 2px 0 var(--tw-shadow-color);
  box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
}

html.dark .shadow-lg {
  --tw-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.45), 0 4px 6px -4px rgb(0 0 0 / 0.4);
  --tw-shadow-colored: 0 10px 15px -3px var(--tw-shadow-color), 0 4px 6px -4px var(--tw-shadow-color);
  box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
}

/* ── Theme toggle control ──────────────────────────────────────── */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.15rem;
  border-radius: 0.5rem;
  border: 1px solid #e2e8f0; /* slate-200 */
  background: #f8fafc; /* slate-50 */
}

html.dark .theme-toggle {
  border-color: #334155;
  background: #1e293b;
}

/* Compact icon-only (guest/login) */
.theme-toggle:not(.theme-toggle--labeled) .theme-toggle-text {
  display: none;
}

.theme-toggle button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  min-width: 1.75rem;
  height: 1.75rem;
  border-radius: 0.375rem;
  border: none;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  line-height: 1;
  font-size: 0.85rem;
  padding: 0 0.35rem;
}

/* Labeled variant inside user menu */
.theme-toggle.theme-toggle--labeled {
  width: 100%;
  gap: 0.25rem;
  padding: 0.2rem;
}

.theme-toggle.theme-toggle--labeled button {
  flex: 1;
  height: 2rem;
  font-size: 0.75rem;
  font-weight: 500;
}

.theme-toggle.theme-toggle--labeled .theme-toggle-text {
  display: inline;
}

.theme-toggle button:hover {
  color: #0f172a;
  background: #e2e8f0;
}

html.dark .theme-toggle button:hover {
  color: #f1f5f9;
  background: #334155;
}

.theme-toggle button[aria-pressed="true"] {
  background: #fff;
  color: #0284c7;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.08);
}

html.dark .theme-toggle button[aria-pressed="true"] {
  background: #0f172a;
  color: #38bdf8;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.4);
}

.theme-toggle button:focus-visible {
  outline: 2px solid #0ea5e9;
  outline-offset: 1px;
}

/* ── User profile menu ─────────────────────────────────────────── */
.user-menu-trigger {
  cursor: pointer;
}

html.dark .user-menu-trigger {
  border-color: #334155;
  background: #0f172a;
  color: #e2e8f0;
}

html.dark .user-menu-trigger:hover {
  background: #1e293b;
}

.user-menu-panel {
  /* shown via .is-open; JS toggles .hidden */
}

.user-menu.is-open .user-menu-panel {
  display: block;
}

html.dark .user-menu-panel {
  background: #0f172a;
  border-color: #334155;
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.45);
}

.user-menu-trigger:focus-visible {
  outline: 2px solid #0ea5e9;
  outline-offset: 1px;
}

/* ── Print: always light ───────────────────────────────────────── */
@media print {
  html.dark,
  html.dark body {
    background: #fff !important;
    color: #000 !important;
    color-scheme: light !important;
  }
}
