/* ============================================================
   vPlan Design System
   Aesthetic: Technical / utilitarian — precise, efficient, engineered
   Color strategy: Restrained — tinted neutrals + one emerald accent
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=DM+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  /* ── Neutrals (warm-tinted toward emerald, +0.008 chroma) ── */
  --bg: #fafbf9;
  --bg-subtle: #f3f5f2;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --surface-sunken: #f0f2ee;
  --border: #d4d8d0;
  --border-subtle: #e4e7e0;

  /* ── Text ── */
  --text: #1a1e18;
  --text-secondary: #4a5046;
  --text-tertiary: #6b7266;
  --text-muted: #9ca396;

  /* ── Accent — Emerald ── */
  --accent: #059669;
  --accent-hover: #047857;
  --accent-light: #d1fae5;
  --accent-subtle: #ecfdf5;
  --accent-text: #ffffff;

  /* ── Semantic ── */
  --success: #059669;
  --success-surface: #ecfdf5;
  --warning: #d97706;
  --warning-surface: #fffbeb;
  --danger: #dc2626;
  --danger-surface: #fef2f2;
  --info: #2563eb;
  --info-surface: #eff6ff;

  /* ── Shadows ── */
  --shadow-xs: 0 1px 2px rgba(26, 30, 24, 0.04);
  --shadow-sm: 0 1px 3px rgba(26, 30, 24, 0.06), 0 1px 2px rgba(26, 30, 24, 0.04);
  --shadow-md: 0 4px 12px rgba(26, 30, 24, 0.07);
  --shadow-lg: 0 8px 24px rgba(26, 30, 24, 0.09);
  --shadow-xl: 0 16px 48px rgba(26, 30, 24, 0.12);

  /* ── Radius ── */
  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* ── Spacing ── */
  --sp-1: 4px;
  --sp-1_5: 6px;
  --sp-2: 8px;
  --sp-2_5: 10px;
  --sp-3: 12px;
  --sp-3_5: 14px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;
  --sp-20: 80px;
  --sp-24: 96px;

  /* ── Type ── */
  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'DM Sans', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* ── Type scale ── */
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.875rem;
  --text-lg: 1rem;
  --text-xl: 1.125rem;
  --text-2xl: 1.375rem;
  --text-3xl: 1.75rem;
  --text-4xl: 2.25rem;
  --text-5xl: 3rem;
  --text-6xl: 3.75rem;
  --text-7xl: 4.5rem;

  /* ── Motion ── */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --duration-fast: 120ms;
  --duration-normal: 200ms;
  --duration-slow: 350ms;

  /* ── Z-index ── */
  --z-base: 0;
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-overlay: 300;
  --z-modal: 400;
  --z-toast: 500;

  /* ── Layout ── */
  --sidebar-w: 240px;
  --navbar-h: 56px;
  --content-max: 1120px;
  --page-max: 1200px;

  /* ── Backward-compat aliases (old templates) ── */
  --primary: var(--accent);
  --primary-light: #34d399;
  --primary-dark: var(--accent-hover);
  --primary-50: var(--accent-subtle);
  --primary-100: var(--accent-light);
  --surface-hover: var(--bg-subtle);
  --border-light: var(--border-subtle);
  --transition: var(--duration-fast) var(--ease-out);
  --transition-slow: var(--duration-slow) var(--ease-out);
}

/* ============================================================
   RESET
   ============================================================ */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
body > main { flex: 1; }
a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
ul, ol { list-style: none; }

/* ============================================================
   FOCUS
   ============================================================ */

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ============================================================
   TYPE
   ============================================================ */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
  letter-spacing: -0.02em;
}

h1 { font-size: var(--text-5xl); font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; }
h2 { font-size: var(--text-4xl); letter-spacing: -0.025em; }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }
h5 { font-size: var(--text-lg); }
h6 { font-size: var(--text-base); font-weight: 600; }

p { line-height: 1.6; }
small { font-size: var(--text-xs); }

/* ============================================================
   LAYOUT
   ============================================================ */

.container {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 var(--sp-6);
}

.page-container {
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0 var(--sp-6);
}

.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: var(--sp-1); }
.gap-2 { gap: var(--sp-2); }
.gap-3 { gap: var(--sp-3); }
.gap-4 { gap: var(--sp-4); }
.gap-5 { gap: var(--sp-5); }
.gap-6 { gap: var(--sp-6); }
.gap-8 { gap: var(--sp-8); }

.grid { display: grid; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* ============================================================
   CARD
   ============================================================ */

.card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--duration-normal) var(--ease-out),
              border-color var(--duration-normal) var(--ease-out);
}

.card-hover:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border);
}

.card-header {
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--border-subtle);
}

.card-body { padding: var(--sp-6); }

.card-footer {
  padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-subtle);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-5);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  border: 1px solid transparent;
  transition: all var(--duration-fast) var(--ease-out);
}

.btn:active { transform: scale(0.98); }
.btn:disabled, .btn.disabled { opacity: 0.5; pointer-events: none; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}
.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover {
  background: var(--bg-subtle);
  border-color: var(--text-muted);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background: var(--bg-subtle);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover {
  background: #b91c1c;
  border-color: #b91c1c;
}

.btn-xs { padding: var(--sp-1) var(--sp-2); font-size: var(--text-xs); border-radius: var(--radius-sm); }
.btn-sm { padding: var(--sp-1_5) var(--sp-4); font-size: var(--text-sm); }
.btn-lg { padding: var(--sp-3) var(--sp-8); font-size: var(--text-base); }
.btn-xl { padding: var(--sp-4) var(--sp-10); font-size: var(--text-lg); }

.btn-icon {
  width: 36px; height: 36px; padding: 0;
  border-radius: var(--radius);
}

/* ============================================================
   FORMS
   ============================================================ */

.form-group { margin-bottom: var(--sp-5); }

.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--sp-1_5);
}

.form-label .required { color: var(--danger); margin-left: 2px; }
.form-hint { font-size: var(--text-xs); color: var(--text-muted); margin-top: var(--sp-1); }

.form-control {
  width: 100%;
  padding: var(--sp-2_5) var(--sp-3_5);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--text-base);
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
  outline: none;
}

.form-control:hover { border-color: var(--text-muted); }

.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.form-control::placeholder { color: var(--text-muted); }

.form-control.error {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-surface);
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7266' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--sp-3) center;
  padding-right: var(--sp-10);
}

textarea.form-control { resize: vertical; min-height: 100px; }

.errorlist { list-style: none; padding: 0; margin: var(--sp-1_5) 0 0 0; }
.errorlist li { font-size: var(--text-xs); color: var(--danger); font-weight: 500; }

.django-form .form-group { margin-bottom: var(--sp-5); }
.django-form label {
  display: block; font-size: var(--text-sm); font-weight: 600;
  color: var(--text); margin-bottom: var(--sp-1_5);
}
.django-form input[type="text"],
.django-form input[type="password"],
.django-form input[type="email"],
.django-form textarea,
.django-form select {
  width: 100%; padding: var(--sp-2_5) var(--sp-3_5);
  border: 1.5px solid var(--border); border-radius: var(--radius);
  font-size: var(--text-base); color: var(--text); background: var(--surface);
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast); outline: none;
}
.django-form input:focus,
.django-form textarea:focus,
.django-form select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-subtle);
}
.django-form .errorlist { list-style: none; padding: 0; margin: var(--sp-1_5) 0 0 0; }
.django-form .errorlist li { font-size: var(--text-xs); color: var(--danger); font-weight: 500; }
.django-form .helptext { font-size: var(--text-xs); color: var(--text-muted); margin-top: var(--sp-1); }

/* ============================================================
   TABLES
   ============================================================ */

.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.data-table { width: 100%; border-collapse: collapse; }

.data-table th {
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 1;
}

.data-table td {
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--border-subtle);
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-subtle); }
.data-table td.actions { white-space: nowrap; }

/* ============================================================
   BADGES
   ============================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 2px var(--sp-2_5);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.4;
}

.badge-primary { background: var(--accent-subtle); color: var(--accent); }
.badge-success { background: var(--success-surface); color: var(--success); }
.badge-warning { background: var(--warning-surface); color: var(--warning); }
.badge-danger { background: var(--danger-surface); color: var(--danger); }
.badge-info { background: var(--info-surface); color: var(--info); }
.badge-neutral { background: var(--bg-subtle); color: var(--text-secondary); }

/* ============================================================
   TOAST
   ============================================================ */

.toast-container {
  position: fixed;
  top: var(--sp-6);
  right: var(--sp-6);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  font-weight: 500;
  pointer-events: auto;
  animation: toastIn var(--duration-slow) var(--ease-out);
  max-width: 380px;
}

.toast.removing {
  animation: toastOut var(--duration-normal) var(--ease-out) forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(100%) scale(0.96); }
  to { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateX(0) scale(1); }
  to { opacity: 0; transform: translateX(100%) scale(0.96); }
}

.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--danger); }
.toast-info { border-left: 3px solid var(--info); }
.toast-warning { border-left: 3px solid var(--warning); }

.toast-icon { flex-shrink: 0; font-size: var(--text-base); }
.toast-success .toast-icon { color: var(--success); }
.toast-error .toast-icon { color: var(--danger); }
.toast-info .toast-icon { color: var(--info); }

.toast-close {
  margin-left: auto;
  background: none; border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: var(--sp-1);
  border-radius: var(--radius-sm);
}
.toast-close:hover { color: var(--text); }

/* ============================================================
   MODAL
   ============================================================ */

.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(26, 30, 24, 0.4);
  backdrop-filter: blur(4px);
  z-index: var(--z-modal);
  align-items: center;
  justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  padding: var(--sp-8);
  max-width: 420px;
  width: 90%;
  animation: modalIn var(--duration-normal) var(--ease-out);
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.97) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-icon {
  width: 48px; height: 48px;
  border-radius: var(--radius-lg);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-xl);
  margin-bottom: var(--sp-5);
}

.modal-icon-danger { background: var(--danger-surface); color: var(--danger); }

.modal-box h3 { font-size: var(--text-xl); font-weight: 700; margin-bottom: var(--sp-2); }
.modal-box p { color: var(--text-secondary); font-size: var(--text-sm); line-height: 1.6; margin-bottom: var(--sp-6); }
.modal-actions { display: flex; gap: var(--sp-3); justify-content: flex-end; }

/* ============================================================
   EMPTY STATE
   ============================================================ */

.empty-state { text-align: center; padding: var(--sp-16) var(--sp-8); }

.empty-state-icon {
  width: 64px; height: 64px;
  border-radius: var(--radius-xl);
  background: var(--accent-subtle);
  color: var(--accent);
  display: inline-flex;
  align-items: center; justify-content: center;
  font-size: var(--text-2xl);
  margin-bottom: var(--sp-5);
}

.empty-state h3 { font-size: var(--text-lg); font-weight: 700; margin-bottom: var(--sp-2); }
.empty-state p { color: var(--text-secondary); font-size: var(--text-sm); max-width: 340px; margin: 0 auto var(--sp-6); line-height: 1.6; }

/* ============================================================
   SPINNER / SKELETON
   ============================================================ */

.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.spinner-lg { width: 32px; height: 32px; border-width: 3px; }

@keyframes spin { to { transform: rotate(360deg); } }

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.skeleton {
  background: linear-gradient(90deg, var(--bg-subtle) 25%, var(--surface) 50%, var(--bg-subtle) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius);
}

/* ============================================================
   PAGE HEADER
   ============================================================ */

.page-header { padding: var(--sp-8) 0 var(--sp-6); }

.page-header h1 {
  font-size: var(--text-3xl);
  font-weight: 700;
  letter-spacing: -0.025em;
}

.page-header p { color: var(--text-secondary); margin-top: var(--sp-2); font-size: var(--text-base); }

.page-header-actions { display: flex; gap: var(--sp-3); margin-top: var(--sp-5); }

/* ============================================================
   DROPDOWN
   ============================================================ */

.dropdown { position: relative; }

.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + var(--sp-1));
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  padding: var(--sp-1_5);
  z-index: var(--z-dropdown);
}

.dropdown:hover .dropdown-menu,
.dropdown-menu.show { display: block; }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2_5);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  transition: background var(--duration-fast), color var(--duration-fast);
}

.dropdown-item:hover { background: var(--bg-subtle); color: var(--text); }

.dropdown-divider { height: 1px; background: var(--border-subtle); margin: var(--sp-1_5) 0; }

/* ============================================================
   TOOLTIP
   ============================================================ */

[data-tooltip] { position: relative; }

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--text);
  color: var(--surface);
  font-size: var(--text-xs);
  font-weight: 500;
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: all var(--duration-fast);
  z-index: var(--z-toast);
}

[data-tooltip]:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============================================================
   ANIMATIONS
   ============================================================ */

@keyframes pageEnter {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes staggerIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.stagger-item {
  animation: staggerIn var(--duration-slow) var(--ease-out) both;
}
.stagger-item:nth-child(1) { animation-delay: 0ms; }
.stagger-item:nth-child(2) { animation-delay: 60ms; }
.stagger-item:nth-child(3) { animation-delay: 120ms; }
.stagger-item:nth-child(4) { animation-delay: 180ms; }
.stagger-item:nth-child(5) { animation-delay: 240ms; }
.stagger-item:nth-child(6) { animation-delay: 300ms; }

.reveal {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity var(--duration-slow) var(--ease-out), transform var(--duration-slow) var(--ease-out);
}
.reveal.visible { opacity: 1; transform: translateY(0); }

/* ============================================================
   UTILITIES
   ============================================================ */

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }
.text-primary { color: var(--text); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }

.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

.m-0 { margin: 0; }
.mt-1 { margin-top: var(--sp-1); }
.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }
.mt-5 { margin-top: var(--sp-5); }
.mt-6 { margin-top: var(--sp-6); }
.mt-8 { margin-top: var(--sp-8); }
.mb-1 { margin-bottom: var(--sp-1); }
.mb-2 { margin-bottom: var(--sp-2); }
.mb-3 { margin-bottom: var(--sp-3); }
.mb-4 { margin-bottom: var(--sp-4); }
.mb-5 { margin-bottom: var(--sp-5); }
.mb-6 { margin-bottom: var(--sp-6); }
.mb-8 { margin-bottom: var(--sp-8); }

.p-0 { padding: 0; }
.p-2 { padding: var(--sp-2); }
.p-3 { padding: var(--sp-3); }
.p-4 { padding: var(--sp-4); }
.p-5 { padding: var(--sp-5); }
.p-6 { padding: var(--sp-6); }

.w-full { width: 100%; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .container, .page-container { padding: 0 var(--sp-4); }
  h1 { font-size: var(--text-3xl); }
  h2 { font-size: var(--text-2xl); }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .toast-container { right: var(--sp-4); left: var(--sp-4); }
  .toast { max-width: none; }
  .modal-box { margin: var(--sp-4); padding: var(--sp-6); }
  .page-header h1 { font-size: var(--text-2xl); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media print {
  .no-print { display: none !important; }
  body { background: white; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}

/* ============================================================
   Dashboard / Sidebar Layout
   ============================================================ */
.dashboard-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: var(--z-sticky);
  overflow: hidden;
}

.sidebar-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: var(--sp-4) var(--sp-3);
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-section { margin-bottom: var(--sp-6); }

.sidebar-section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--sp-2) var(--sp-3);
  margin-bottom: var(--sp-1);
}

.sidebar-nav { list-style: none; display: flex; flex-direction: column; gap: 2px; }

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 7px var(--sp-3);
  border-radius: var(--radius);
  color: var(--text-tertiary);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: color var(--duration-fast), background var(--duration-fast);
  cursor: pointer;
  text-decoration: none;
  position: relative;
}
.sidebar-nav-item:hover { color: var(--text); background: var(--bg-subtle); }
.sidebar-nav-item.active { color: var(--accent); background: var(--accent-subtle); }
.sidebar-nav-item i { width: 16px; text-align: center; font-size: var(--text-sm); flex-shrink: 0; }

.sidebar-nav-item .shortcut {
  margin-left: auto;
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity var(--duration-fast);
}
.sidebar-nav-item:hover .shortcut { opacity: 1; }

.sidebar-divider { height: 1px; background: var(--border-subtle); margin: var(--sp-3); }

.sidebar-user {
  padding: var(--sp-3);
  border-top: 1px solid var(--border-subtle);
  margin-top: auto;
}

.sidebar-user-pill {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--duration-fast);
}
.sidebar-user-pill:hover { background: var(--bg-subtle); }

.sidebar-user-avatar {
  width: 28px; height: 28px;
  border-radius: var(--radius-full);
  object-fit: cover;
  flex-shrink: 0;
}

.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: var(--text-sm); font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: var(--text-xs); color: var(--text-muted); }
.sidebar-user-chevron { font-size: 9px; color: var(--text-muted); }

.dashboard-main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
}

.dashboard-page {
  padding: var(--sp-6);
}

.sidebar-mobile-toggle {
  display: none;
  position: fixed;
  bottom: var(--sp-5);
  left: var(--sp-5);
  width: 44px; height: 44px;
  border-radius: var(--radius-lg);
  background: var(--accent);
  color: #fff;
  font-size: var(--text-base);
  align-items: center; justify-content: center;
  box-shadow: var(--shadow-md);
  z-index: var(--z-overlay);
  border: none; cursor: pointer;
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); width: 260px; box-shadow: var(--shadow-xl); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-mobile-toggle { display: flex; }
  .dashboard-main { margin-left: 0; }
  .dashboard-topbar { padding: var(--sp-3) var(--sp-4); }
  .dashboard-page { padding: var(--sp-4); }
}
