/* ============================================================
   Design tokens
   ============================================================ */
:root {
  --sidebar-width: 240px;
  --topbar-height: 52px;
  --radius-card: 12px;
  --radius-input: 8px;
  --radius-btn: 8px;
  --shadow-card: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --color-primary: #4f46e5;
  --color-primary-hover: #4338ca;
  --color-sidebar-bg: #18181b;
  --color-sidebar-text: #a1a1aa;
  --color-sidebar-text-active: #ffffff;
  --color-sidebar-hover: rgba(255,255,255,.06);
  --color-sidebar-active: rgba(255,255,255,.10);
  --color-body: #f4f4f5;
  --color-surface: #ffffff;
  --color-border: #e4e4e7;
  --color-text: #18181b;
  --color-text-muted: #71717a;
}

/* ============================================================
   Reset / Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

/* ============================================================
   App shell
   ============================================================ */
.app-layout {
  display: flex;
  min-height: 100vh;
  background: var(--color-body);
}

/* ============================================================
   Sidebar — permanent on desktop, slide-in on mobile
   ============================================================ */
.app-sidebar {
  width: var(--sidebar-width);
  background: var(--color-sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  /* Desktop: always visible */
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 30;
}

/* Mobile: hidden off-screen to the left */
@media (max-width: 1023px) {
  .app-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    transform: translateX(calc(-1 * var(--sidebar-width)));
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 50;
    box-shadow: none;
  }
  .app-sidebar.sidebar-open {
    transform: translateX(0);
    box-shadow: 8px 0 32px rgba(0,0,0,.35);
  }
}

.sidebar-header {
  padding: 1.25rem 1rem 0.75rem;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.sidebar-logo {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0.625rem;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  color: var(--color-sidebar-text);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--color-sidebar-hover); color: #fff; }
.nav-item.active { background: var(--color-sidebar-active); color: var(--color-sidebar-text-active); }
.nav-item-icon { width: 1rem; text-align: center; font-size: 0.875rem; flex-shrink: 0; }

.sidebar-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid rgba(255,255,255,.06);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  margin-bottom: 0.625rem;
}

.sidebar-user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-user-name {
  font-size: 0.8125rem;
  font-weight: 500;
  color: #d4d4d8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-signout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 0.4375rem 0.75rem;
  background: transparent;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 7px;
  color: #a1a1aa;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
}
.sidebar-signout-btn:hover { background: rgba(255,255,255,.06); color: #e4e4e7; }

/* ============================================================
   Mobile topbar (hidden on desktop)
   ============================================================ */
.mobile-topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-height);
  background: var(--color-sidebar-bg);
  padding: 0 1rem;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

@media (max-width: 1023px) {
  .mobile-topbar { display: flex; }
}

.mobile-topbar-logo {
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
}

.topbar-hamburger {
  background: none;
  border: none;
  color: #a1a1aa;
  cursor: pointer;
  padding: 0.4375rem;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
}
.topbar-hamburger:hover { color: #fff; background: rgba(255,255,255,.08); }
.topbar-hamburger svg { display: block; }

/* ============================================================
   Sidebar overlay (mobile only)
   ============================================================ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 45;
  cursor: pointer;
}
.sidebar-overlay.active { display: block; }

/* ============================================================
   Main wrapper + content area
   ============================================================ */
.main-wrapper {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.main-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ============================================================
   Cards
   ============================================================ */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-body {
  padding: 1.25rem;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  background: var(--color-primary);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.5rem 0.875rem;
  border-radius: var(--radius-btn);
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s, box-shadow 0.12s;
  box-shadow: 0 1px 2px rgba(79,70,229,.2);
  line-height: 1.25;
}
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-primary:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  background: var(--color-surface);
  color: #3f3f46;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.5rem 0.875rem;
  border-radius: var(--radius-btn);
  border: 1px solid var(--color-border);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s;
  line-height: 1.25;
}
.btn-secondary:hover { background: #f4f4f5; }
.btn-secondary:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  background: #fee2e2;
  color: #dc2626;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.5rem 0.875rem;
  border-radius: var(--radius-btn);
  border: 1px solid #fecaca;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s;
  line-height: 1.25;
}
.btn-danger:hover { background: #fecaca; }

/* ============================================================
   Form elements
   ============================================================ */
.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: #3f3f46;
  margin-bottom: 0.375rem;
}

.form-input {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid #d4d4d8;
  border-radius: var(--radius-input);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.form-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}
.form-input::placeholder { color: #a1a1aa; }

/* ============================================================
   Flash messages
   ============================================================ */
.flash-notice {
  padding: 0.625rem 1.25rem;
  background: #f0fdf4;
  border-bottom: 1px solid #bbf7d0;
  color: #166534;
  font-size: 0.875rem;
}

.flash-alert {
  padding: 0.625rem 1.25rem;
  background: #fef2f2;
  border-bottom: 1px solid #fecaca;
  color: #991b1b;
  font-size: 0.875rem;
}

/* ============================================================
   Section divider + headings (used inside pages)
   ============================================================ */
.section-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}

/* ============================================================
   Accessibility
   ============================================================ */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  padding: 0.5rem 1rem;
  background: var(--color-primary);
  color: #fff;
  border-radius: 0 0 8px 0;
  font-size: 0.875rem;
}
.skip-link:focus {
  left: 0;
}

@media (prefers-reduced-motion: reduce) {
  .app-sidebar,
  .nav-item,
  .btn-primary,
  .btn-secondary,
  .form-input {
    transition: none !important;
  }
}

/* ============================================================
   Dark mode
   ============================================================
   The views use plain Tailwind light-palette utilities; rather than adding
   dark: variants to every template, this block remaps the design tokens and
   the utilities actually used in the codebase. app.css loads after the
   Tailwind build and unlayered rules beat @layer utilities, so these win. */
:root {
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-body: #101013;
    --color-surface: #1b1b1f;
    --color-border: #2c2c33;
    --color-text: #f4f4f5;
    --color-text-muted: #9d9da7;
    --shadow-card: 0 1px 3px rgba(0,0,0,.5), 0 1px 2px rgba(0,0,0,.4);
  }

  /* --- Neutral surfaces --- */
  .bg-white { background-color: var(--color-surface); }
  .bg-gray-50 { background-color: #222227; }
  .bg-gray-100 { background-color: #27272d; }
  .bg-gray-200 { background-color: #2f2f36; }
  .bg-gray-300 { background-color: #3a3a42; }
  .hover\:bg-gray-50:hover { background-color: #26262c; }
  .hover\:bg-gray-100:hover { background-color: #2c2c33; }

  /* --- Neutral text --- */
  .text-gray-900 { color: #f4f4f5; }
  .text-gray-800 { color: #e7e7ea; }
  .text-gray-700 { color: #d4d4d8; }
  .text-gray-600 { color: #b0b0b9; }
  .text-gray-500 { color: #93939e; }
  .text-gray-400 { color: #74747e; }
  .text-gray-300 { color: #55555e; }
  .hover\:text-gray-700:hover { color: #e7e7ea; }
  .hover\:text-gray-600:hover { color: #d4d4d8; }
  .hover\:text-gray-500:hover { color: #b0b0b9; }

  /* --- Neutral borders / dividers --- */
  .border-gray-100, .border-gray-200, .border-gray-300 { border-color: var(--color-border); }
  .border-white { border-color: var(--color-surface); }
  .divide-gray-50 > :not([hidden]) ~ :not([hidden]),
  .divide-gray-100 > :not([hidden]) ~ :not([hidden]),
  .divide-gray-200 > :not([hidden]) ~ :not([hidden]) { border-color: var(--color-border); }

  /* --- Indigo (primary accent) --- */
  .bg-indigo-50 { background-color: rgba(99,102,241,.14); }
  .bg-indigo-100 { background-color: rgba(99,102,241,.20); }
  .hover\:bg-indigo-50:hover { background-color: rgba(99,102,241,.18); }
  .text-indigo-900, .text-indigo-800, .text-indigo-700 { color: #a5b4fc; }
  .text-indigo-600, .text-indigo-500 { color: #818cf8; }
  .hover\:text-indigo-600:hover, .hover\:text-indigo-800:hover { color: #a5b4fc; }
  .border-indigo-100, .border-indigo-200, .border-indigo-300 { border-color: rgba(99,102,241,.4); }
  .ring-indigo-300 { --tw-ring-color: rgba(99,102,241,.45); }

  /* --- Red / danger --- */
  .bg-red-50 { background-color: rgba(239,68,68,.10); }
  .hover\:bg-red-50:hover { background-color: rgba(239,68,68,.16); }
  .text-red-800, .text-red-700 { color: #fca5a5; }
  .text-red-600, .text-red-500 { color: #f87171; }
  .hover\:text-red-700:hover, .hover\:text-red-600:hover, .hover\:text-red-500:hover { color: #fca5a5; }
  .border-red-100, .border-red-200, .border-red-400 { border-color: rgba(239,68,68,.35); }

  /* --- Amber / warning --- */
  .bg-amber-50 { background-color: rgba(245,158,11,.10); }
  .text-amber-900, .text-amber-800, .text-amber-700 { color: #fcd34d; }
  .text-amber-600, .text-amber-500 { color: #fbbf24; }
  .border-amber-100, .border-amber-200, .border-amber-300, .border-amber-400 { border-color: rgba(245,158,11,.35); }

  /* --- Yellow --- */
  .bg-yellow-50, .bg-yellow-100 { background-color: rgba(234,179,8,.12); }
  .border-yellow-200, .border-yellow-300 { border-color: rgba(234,179,8,.35); }
  .text-yellow-800, .text-yellow-700, .text-yellow-600 { color: #facc15; }

  /* --- Green / success --- */
  .bg-green-50, .bg-green-100 { background-color: rgba(34,197,94,.12); }
  .text-green-800, .text-green-700 { color: #86efac; }
  .text-green-600, .text-green-500 { color: #4ade80; }
  .border-green-300 { border-color: rgba(34,197,94,.4); }

  /* --- Blue --- */
  .bg-blue-50, .bg-blue-100 { background-color: rgba(59,130,246,.12); }
  .text-blue-800, .text-blue-700, .text-blue-600 { color: #93c5fd; }
  .text-blue-500 { color: #60a5fa; }
  .hover\:text-blue-500:hover { color: #93c5fd; }
  .border-blue-100, .border-blue-200, .border-blue-300, .border-blue-400 { border-color: rgba(59,130,246,.35); }

  /* --- Pink / rose (cycle UI) --- */
  .bg-pink-50 { background-color: rgba(236,72,153,.12); }
  .text-pink-800, .text-pink-700, .text-pink-600 { color: #f9a8d4; }
  .text-rose-600, .text-rose-500 { color: #fda4af; }

  /* --- Purple / teal / orange accents --- */
  .bg-purple-100 { background-color: rgba(168,85,247,.16); }
  .text-purple-800 { color: #d8b4fe; }
  .text-teal-800 { color: #5eead4; }
  .bg-orange-50 { background-color: rgba(249,115,22,.12); }
  .text-orange-600, .text-orange-500 { color: #fb923c; }
  .border-orange-200 { border-color: rgba(249,115,22,.35); }

  /* --- Components with light colors compiled in (Tailwind @apply or app.css) --- */
  .card-title { color: var(--color-text); }
  .card-footer { background: #222227; }
  .btn-secondary { color: #d4d4d8; }
  .btn-secondary:hover { background: #26262c; }
  .btn-danger { background: rgba(239,68,68,.14); color: #f87171; border-color: rgba(239,68,68,.35); }
  .btn-danger:hover { background: rgba(239,68,68,.22); }
  .btn-ghost { color: #b0b0b9; }
  .btn-ghost:hover { background: #27272d; }
  .form-label { color: #d4d4d8; }
  .form-input, .form-select { border-color: var(--color-border); color: var(--color-text); background: var(--color-surface); }
  .form-hint { color: var(--color-text-muted); }
  .flash-notice { background: rgba(34,197,94,.12); border-color: rgba(34,197,94,.3); color: #86efac; }
  .flash-alert { background: rgba(239,68,68,.12); border-color: rgba(239,68,68,.3); color: #fca5a5; }
  .badge-green { background: rgba(34,197,94,.15); color: #86efac; }
  .badge-yellow { background: rgba(234,179,8,.15); color: #facc15; }
  .badge-red { background: rgba(239,68,68,.15); color: #fca5a5; }
  .badge-blue { background: rgba(59,130,246,.15); color: #93c5fd; }
  .badge-gray { background: #27272d; color: #d4d4d8; }
  .badge-purple { background: rgba(168,85,247,.16); color: #d8b4fe; }
  .page-title { color: var(--color-text); }
}
