@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&display=swap');

:root {
  --app-bg: #f4f7fb;
  --panel-bg: rgba(244, 247, 251, 0.82);
  --panel-border: rgba(148, 163, 184, 0.22);
  --shadow-soft: 0 18px 60px rgba(15, 23, 42, 0.08);
  --surface: #ffffff;
  --surface-secondary: #f8fafc;
  --surface-hover: #f1f5f9;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-tertiary: #64748b;
  --border-color: rgba(226, 232, 240, 0.9);
  --border-strong: #cbd5e1;
  --glass-bg: rgba(255, 255, 255, 0.82);
  --sidebar-shadow: 0 20px 60px rgba(15, 23, 42, 0.08);
  --body-gradient: radial-gradient(circle at top left, rgba(15, 23, 42, 0.06), transparent 28%),
    radial-gradient(circle at top right, rgba(2, 132, 199, 0.08), transparent 24%),
    linear-gradient(180deg, #fbfcfe 0%, #f4f7fb 100%);
  --nav-active: #0f172a;
  --nav-inactive: #475569;
  --toast-bg: rgba(255, 255, 255, 0.96);
  --confirm-bg: #fff;
  --confirm-footer: #f8fafc;
  --chart-grid: rgba(148, 163, 184, 0.25);
}

[data-theme="dark"] {
  --app-bg: #0b1121;
  --panel-bg: rgba(15, 23, 42, 0.88);
  --panel-border: rgba(71, 85, 105, 0.3);
  --shadow-soft: 0 18px 60px rgba(0, 0, 0, 0.4);
  --surface: #1e293b;
  --surface-secondary: #172033;
  --surface-hover: #263348;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-tertiary: #64748b;
  --border-color: rgba(71, 85, 105, 0.35);
  --border-strong: #475569;
  --glass-bg: rgba(30, 41, 59, 0.88);
  --sidebar-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  --body-gradient: radial-gradient(circle at top left, rgba(56, 189, 248, 0.04), transparent 28%),
    radial-gradient(circle at top right, rgba(99, 102, 241, 0.05), transparent 24%),
    linear-gradient(180deg, #0f172a 0%, #0b1121 100%);
  --nav-active: #f1f5f9;
  --nav-inactive: #64748b;
  --toast-bg: rgba(30, 41, 59, 0.96);
  --confirm-bg: #1e293b;
  --confirm-footer: #172033;
  --chart-grid: rgba(71, 85, 105, 0.3);
}

html { font-family: 'Manrope', 'Inter', system-ui, sans-serif; }

body {
  background: var(--body-gradient);
  transition: background 0.2s ease;
}

[data-theme="dark"] body {
  color-scheme: dark;
}

.glass-card {
  border: 1px solid var(--panel-border);
  border-radius: 1.75rem;
  background: var(--glass-bg);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px);
}

.app-sidebar { box-shadow: var(--sidebar-shadow); }

[data-theme="dark"] .app-sidebar {
  border-right-color: rgba(71, 85, 105, 0.25);
}

/* Surface backgrounds */
[data-theme="dark"] .bg-white,
[data-theme="dark"] .bg-white\/80,
[data-theme="dark"] .bg-white\/90,
[data-theme="dark"] .bg-white\/95 { background-color: var(--surface) !important; }

[data-theme="dark"] .bg-slate-50,
[data-theme="dark"] .bg-slate-50\/50,
[data-theme="dark"] .bg-slate-50\/70,
[data-theme="dark"] .bg-slate-50\/80 { background-color: var(--surface-secondary) !important; }

[data-theme="dark"] .bg-slate-100 { background-color: var(--surface-hover) !important; }

[data-theme="dark"] .bg-slate-200 { background-color: rgba(71, 85, 105, 0.3) !important; }

[data-theme="dark"] .bg-slate-950 { background-color: #334155 !important; }

[data-theme="dark"] .bg-rose-50 { background-color: rgba(244, 63, 94, 0.12) !important; }
[data-theme="dark"] .bg-emerald-50 { background-color: rgba(16, 185, 129, 0.12) !important; }
[data-theme="dark"] .bg-amber-50 { background-color: rgba(245, 158, 11, 0.12) !important; }

/* Text colors */
[data-theme="dark"] .text-slate-900,
[data-theme="dark"] .text-slate-950 { color: var(--text-primary) !important; }

[data-theme="dark"] .text-slate-700 { color: #cbd5e1 !important; }

[data-theme="dark"] .text-slate-600 { color: var(--text-secondary) !important; }

[data-theme="dark"] .text-slate-500,
[data-theme="dark"] .text-slate-400 { color: var(--text-tertiary) !important; }

[data-theme="dark"] .text-slate-300,
[data-theme="dark"] .text-slate-200 { color: #94a3b8 !important; }

[data-theme="dark"] .text-white { color: var(--text-primary) !important; }

/* Border colors */
[data-theme="dark"] .border-slate-200,
[data-theme="dark"] .border-slate-200\/70,
[data-theme="dark"] .border-slate-200\/90 { border-color: var(--border-color) !important; }

[data-theme="dark"] .border-slate-300 { border-color: var(--border-strong) !important; }

[data-theme="dark"] .border-white\/60,
[data-theme="dark"] .border-white\/70 { border-color: rgba(71, 85, 105, 0.3) !important; }

[data-theme="dark"] .divide-slate-200\/70 > * + * { border-color: var(--border-color) !important; }

[data-theme="dark"] .border-rose-200 { border-color: rgba(244, 63, 94, 0.25) !important; }
[data-theme="dark"] .border-emerald-200 { border-color: rgba(16, 185, 129, 0.25) !important; }
[data-theme="dark"] .border-amber-200 { border-color: rgba(245, 158, 11, 0.25) !important; }

/* Ring / focus */
[data-theme="dark"] .focus\:border-slate-950:focus { border-color: #60a5fa !important; }
[data-theme="dark"] .focus\:ring-4:focus { --tw-ring-color: rgba(96, 165, 250, 0.2) !important; }

/* Hover states */
[data-theme="dark"] .hover\:text-slate-950:hover { color: var(--text-primary) !important; }
[data-theme="dark"] .hover\:border-slate-300:hover { border-color: var(--border-strong) !important; }

/* Buttons */
[data-theme="dark"] .hover\:bg-white:hover { background-color: var(--surface) !important; }

[data-theme="dark"] .hover\:bg-slate-800:hover { background-color: #334155 !important; }

/* Tables */
[data-theme="dark"] .bg-slate-50\/70 thead { background-color: var(--surface-secondary) !important; }
[data-theme="dark"] thead.bg-slate-50\/70 { background-color: var(--surface-secondary) !important; }

/* Shadows */
[data-theme="dark"] .shadow-2xl,
[data-theme="dark"] .shadow-xl,
[data-theme="dark"] .shadow-lg,
[data-theme="dark"] .shadow-sm,
[data-theme="dark"] .shadow { box-shadow: 0 0 0 1px rgba(71, 85, 105, 0.2), 0 4px 20px rgba(0, 0, 0, 0.3) !important; }

[data-theme="dark"] .shadow-xl { box-shadow: 0 0 0 1px rgba(71, 85, 105, 0.2), 0 20px 60px rgba(0, 0, 0, 0.4) !important; }

[data-theme="dark"] .shadow-2xl { box-shadow: 0 0 0 1px rgba(71, 85, 105, 0.2), 0 28px 80px rgba(0, 0, 0, 0.5) !important; }

/* Modal/dialog backdrop */
[data-theme="dark"] .backdrop\:bg-slate-950\/50::backdrop { background: rgba(0, 0, 0, 0.65) !important; }

[data-theme="dark"] .app-toast { background: var(--toast-bg) !important; border-color: rgba(71, 85, 105, 0.35) !important; }
[data-theme="dark"] .app-toast__title { color: var(--text-primary) !important; }
[data-theme="dark"] .app-toast__message { color: var(--text-secondary) !important; }
[data-theme="dark"] .app-toast__close { color: var(--text-tertiary) !important; }
[data-theme="dark"] .app-toast__close:hover { background: var(--surface-hover) !important; color: var(--text-primary) !important; }

[data-theme="dark"] .app-confirm__panel { background: var(--confirm-bg) !important; }
[data-theme="dark"] .app-confirm__title { color: var(--text-primary) !important; }
[data-theme="dark"] .app-confirm__message { color: var(--text-secondary) !important; }
[data-theme="dark"] .app-confirm__eyebrow { color: var(--text-tertiary) !important; }
[data-theme="dark"] .app-confirm__actions { background: var(--confirm-footer) !important; border-color: var(--border-color) !important; }
[data-theme="dark"] .app-confirm__button--secondary { background: var(--surface) !important; border-color: var(--border-strong) !important; color: var(--text-primary) !important; }
[data-theme="dark"] .app-confirm__button--danger { background: #ef4444 !important; border-color: #ef4444 !important; }

/* Charts */
[data-theme="dark"] canvas { filter: brightness(0.85); }

/* Sidebar in dark */
[data-theme="dark"] [data-sidebar] {
  background: rgba(15, 23, 42, 0.96) !important;
  border-right-color: rgba(71, 85, 105, 0.2) !important;
}

[data-theme="dark"] .sidebar-brand-bg {
  border-color: rgba(71, 85, 105, 0.25) !important;
}

/* Navigation */
[data-theme="dark"] nav a:not(.bg-slate-950) { color: var(--nav-inactive) !important; }
[data-theme="dark"] nav a.bg-slate-950 { background-color: #334155 !important; color: #fff !important; }

/* Inputs, selects */
[data-theme="dark"] input, [data-theme="dark"] select, [data-theme="dark"] textarea {
  background-color: var(--surface) !important;
  color: var(--text-primary) !important;
  border-color: var(--border-color) !important;
}

[data-theme="dark"] input:focus, [data-theme="dark"] select:focus, [data-theme="dark"] textarea:focus {
  border-color: #60a5fa !important;
  --tw-ring-color: rgba(96, 165, 250, 0.2) !important;
}

/* File input button */
[data-theme="dark"] input::file-selector-button {
  background-color: var(--surface-hover) !important;
  color: var(--text-primary) !important;
}

/* Datetime input fix */
[data-theme="dark"] input[type="date"],
[data-theme="dark"] input[type="datetime-local"],
[data-theme="dark"] input[type="month"] {
  color-scheme: dark;
}

/* Sidepanel */
[data-theme="dark"] [data-sidepanel] { background: var(--panel-bg) !important; }

/* Pagination active */
[data-theme="dark"] .bg-slate-950.text-white { background-color: #334155 !important; }

/* Modals */
[data-theme="dark"] dialog .bg-white { background-color: var(--surface) !important; }
[data-theme="dark"] dialog .border-slate-200 { border-color: var(--border-color) !important; }

/* Nav active state override */
[data-theme="dark"] nav a.text-slate-600 { color: var(--nav-inactive) !important; }

/* Badge / chip */
[data-theme="dark"] .bg-slate-100.text-slate-600 { background: rgba(71, 85, 105, 0.3) !important; color: var(--text-secondary) !important; }

/* Theme toggle button */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  border-radius: 999px;
  border: 1px solid var(--border-color);
  background: var(--surface);
  padding: 0.25rem;
  cursor: pointer;
  line-height: 1;
  transition: background 0.15s ease;
}
.theme-toggle__option {
  display: grid;
  width: 1.75rem;
  height: 1.75rem;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0;
  transition: background 0.15s ease, color 0.15s ease;
}
.theme-toggle__option.is-active {
  background: var(--nav-active);
  color: #fff;
}
[data-theme="dark"] .theme-toggle__option.is-active { background: #475569; color: #fff; }

.modal-panel {
  max-height: calc(100dvh - 2rem);
  overflow-y: auto;
}

.toast-root {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1200;
  display: grid;
  width: min(24rem, calc(100vw - 2rem));
  gap: 0.75rem;
  pointer-events: none;
}

.app-toast {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.75rem;
  align-items: start;
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-left-width: 4px;
  border-radius: 1rem;
  background: var(--toast-bg);
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.16);
  opacity: 0;
  padding: 0.9rem;
  pointer-events: auto;
  transform: translateY(-0.5rem);
  transition: opacity 180ms ease, transform 180ms ease;
}

.app-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.app-toast.is-leaving {
  opacity: 0;
  transform: translateY(-0.5rem);
}

.app-toast--success { border-left-color: #059669; }
.app-toast--error { border-left-color: #dc2626; }
.app-toast--warning { border-left-color: #d97706; }
.app-toast--info { border-left-color: #0284c7; }

.app-toast__icon {
  display: grid;
  width: 1.8rem;
  height: 1.8rem;
  place-items: center;
  border-radius: 999px;
  background: #f1f5f9;
  color: #0f172a;
  font-size: 0.8rem;
  font-weight: 800;
}

.app-toast--success .app-toast__icon { background: #d1fae5; color: #047857; }
.app-toast--error .app-toast__icon { background: #fee2e2; color: #b91c1c; }
.app-toast--warning .app-toast__icon { background: #fef3c7; color: #b45309; }
.app-toast--info .app-toast__icon { background: #e0f2fe; color: #0369a1; }

.app-toast__body { min-width: 0; }

.app-toast__title {
  margin: 0 0 0.15rem;
  color: #0f172a;
  font-size: 0.9rem;
  font-weight: 800;
}

.app-toast__message {
  margin: 0;
  color: #475569;
  font-size: 0.9rem;
  line-height: 1.45;
}

.app-toast__close {
  display: grid;
  width: 2rem;
  height: 2rem;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
}

.app-toast__close:hover { background: #f1f5f9; color: #0f172a; }

.app-confirm {
  width: min(92vw, 28rem);
  border: 0;
  border-radius: 1.5rem;
  background: transparent;
  padding: 0;
}

.app-confirm::backdrop { background: rgba(15, 23, 42, 0.55); }

.app-confirm__panel {
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 1.5rem;
  background: var(--confirm-bg);
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.28);
}

.app-confirm__content { padding: 1.35rem; }

.app-confirm__eyebrow {
  margin: 0;
  color: #64748b;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.app-confirm__title {
  margin: 0.45rem 0 0;
  color: #0f172a;
  font-size: 1.2rem;
  font-weight: 800;
}

.app-confirm__message {
  margin: 0.65rem 0 0;
  color: #475569;
  font-size: 0.95rem;
  line-height: 1.55;
}

.app-confirm__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.75rem;
  border-top: 1px solid rgba(226, 232, 240, 0.9);
  background: var(--confirm-footer);
  padding: 1rem 1.35rem;
}

.app-confirm__button {
  min-height: 2.75rem;
  border-radius: 0.9rem;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 800;
  padding: 0.65rem 1rem;
}

.app-confirm__button--secondary {
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #334155;
}

.app-confirm__button--danger {
  border: 1px solid #0f172a;
  background: #0f172a;
  color: #fff;
}

@media (max-width: 640px) {
  .toast-root {
    top: auto;
    right: 1rem;
    bottom: 1rem;
    left: 1rem;
    width: auto;
  }

  .app-confirm__actions {
    display: grid;
  }
}

[data-sidebar].is-open {
  transform: translateX(0);
}

@media (min-width: 768px) {
  html.sidebar-prefers-pinned [data-sidebar] {
    transform: translateX(0);
  }

  html.sidebar-prefers-pinned [data-app-shell] {
    padding-left: 280px;
  }

  html.sidebar-prefers-pinned .app-sidebar-backdrop {
    opacity: 0;
    pointer-events: none;
  }
}

.app-shell {
  transition: padding-left 0.3s ease;
}

.app-sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(15, 23, 42, 0.28);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.app-shell.sidebar-open:not(.sidebar-pinned) .app-sidebar-backdrop {
  opacity: 1;
  pointer-events: auto;
}

/* Clear section hierarchy for the floating sidebar, without card containers. */
[data-theme="light"] .app-shell.sidebar-open:not(.sidebar-pinned) [data-sidebar-category] {
  border-top: 1px solid rgba(148, 163, 184, 0.38);
  padding-top: 0.75rem;
}

[data-theme="light"] .app-shell.sidebar-open:not(.sidebar-pinned) [data-sidebar-category]:first-child {
  border-top: 0;
  padding-top: 0;
}

[data-theme="light"] .app-shell.sidebar-open:not(.sidebar-pinned) [data-sidebar-category-toggle] {
  position: relative;
  background: transparent;
  color: #334155;
  letter-spacing: 0.16em;
}

[data-theme="light"] .app-shell.sidebar-open:not(.sidebar-pinned) [data-sidebar-category-toggle]:hover {
  background: rgba(241, 245, 249, 0.78);
  color: #0f172a;
}

[data-theme="light"] .app-shell.sidebar-open:not(.sidebar-pinned) [data-sidebar-category].is-active [data-sidebar-category-toggle] {
  color: #1d4ed8;
}

[data-theme="light"] .app-shell.sidebar-open:not(.sidebar-pinned) [data-sidebar-category].is-active [data-sidebar-category-toggle]::before {
  position: absolute;
  top: 50%;
  left: 0;
  width: 3px;
  height: 1.1rem;
  border-radius: 999px;
  background: #2563eb;
  content: "";
  transform: translateY(-50%);
}

[data-theme="light"] .app-shell.sidebar-open:not(.sidebar-pinned) [data-sidebar-category-content] {
  margin-top: 0.2rem;
}

[data-theme="dark"] .app-shell.sidebar-open:not(.sidebar-pinned) [data-sidebar-category] {
  border-top: 1px solid rgba(100, 116, 139, 0.42);
  padding-top: 0.75rem;
}

[data-theme="dark"] .app-shell.sidebar-open:not(.sidebar-pinned) [data-sidebar-category]:first-child {
  border-top: 0;
  padding-top: 0;
}

[data-theme="dark"] .app-shell.sidebar-open:not(.sidebar-pinned) [data-sidebar-category-toggle] {
  position: relative;
  background: transparent !important;
  color: #cbd5e1 !important;
  letter-spacing: 0.16em;
}

[data-theme="dark"] .app-shell.sidebar-open:not(.sidebar-pinned) [data-sidebar-category-toggle]:hover {
  background: rgba(51, 65, 85, 0.58) !important;
  color: #f8fafc !important;
}

[data-theme="dark"] .app-shell.sidebar-open:not(.sidebar-pinned) [data-sidebar-category].is-active [data-sidebar-category-toggle] {
  color: #60a5fa !important;
}

[data-theme="dark"] .app-shell.sidebar-open:not(.sidebar-pinned) [data-sidebar-category].is-active [data-sidebar-category-toggle]::before {
  position: absolute;
  top: 50%;
  left: 0;
  width: 3px;
  height: 1.1rem;
  border-radius: 999px;
  background: #3b82f6;
  content: "";
  transform: translateY(-50%);
}

[data-theme="dark"] .app-shell.sidebar-open:not(.sidebar-pinned) [data-sidebar-category-content] {
  margin-top: 0.2rem;
}

.app-shell.sidebar-pinned {
  padding-left: 280px;
}

.app-shell.sidebar-pinned .app-sidebar-backdrop {
  opacity: 0 !important;
  pointer-events: none !important;
}

.sidebar-pin-btn.is-pinned {
  border-color: rgb(15 23 42);
  background: rgb(15 23 42);
  color: white;
}

[data-theme="dark"] .app-sidebar-backdrop {
  background: rgba(0, 0, 0, 0.45);
}

[data-theme="dark"] .sidebar-pin-btn.is-pinned {
  border-color: rgb(226 232 240);
  background: rgb(226 232 240);
  color: rgb(15 23 42);
}

@media (max-width: 767px) {
  .app-shell.sidebar-pinned {
    padding-left: 0;
  }
}
