.layout-sidebar .app-main {
  margin-left: var(--layout-offset-left);
  width: calc(100% - var(--layout-offset-left));
}
/**
 * Kratevia Design System
 * A modern, contemplative design system for habit tracking
 * Version 2.0
 */

/* ============================================
   1. CSS CUSTOM PROPERTIES (DESIGN TOKENS)
   ============================================ */

:root {
  /* === Color Palette === */
  
  /* Primary Accent - Warm Amber/Gold */
  --accent-50: #fffbeb;
  --accent-100: #fef3c7;
  --accent-200: #fde68a;
  --accent-300: #fcd34d;
  --accent-400: #fbbf24;
  --accent-500: #f59e0b;
  --accent-600: #d97706;
  --accent-700: #b45309;
  --accent-800: #92400e;
  --accent-900: #78350f;
  --gold-text-start: var(--accent-700);
  --gold-text-mid: var(--accent-400);
  --gold-text-end: var(--accent-500);
  --mirror-accent: #d6b15a;
  
  /* Neutral Palette */
  --neutral-0: #ffffff;
  --neutral-50: #fafafa;
  --neutral-100: #f4f4f5;
  --neutral-200: #e4e4e7;
  --neutral-300: #d4d4d8;
  --neutral-400: #a1a1aa;
  --neutral-500: #71717a;
  --neutral-600: #52525b;
  --neutral-700: #3f3f46;
  --neutral-800: #27272a;
  --neutral-850: #1f1f23;
  --neutral-900: #18181b;
  --neutral-925: #121214;
  --neutral-950: #09090b;
  
  /* Semantic Colors */
  --success-light: #dcfce7;
  --success: #22c55e;
  --success-dark: #16a34a;
  
  --danger-light: #fee2e2;
  --danger: #ef4444;
  --danger-dark: #dc2626;
  
  --warning-light: #fef3c7;
  --warning: #f59e0b;
  --warning-dark: #d97706;
  
  --info-light: #dbeafe;
  --info: #3b82f6;
  --info-dark: #2563eb;
  
  /* === Typography === */
  --font-sans: 'Source Sans 3', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Source Sans 3', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  
  /* Font Sizes */
  --text-xs: 0.75rem;      /* 12px */
  --text-sm: 0.875rem;     /* 14px */
  --text-base: 1rem;       /* 16px */
  --text-lg: 1.125rem;     /* 18px */
  --text-xl: 1.25rem;      /* 20px */
  --text-2xl: 1.5rem;      /* 24px */
  --text-3xl: 1.875rem;    /* 30px */
  --text-4xl: 2.25rem;     /* 36px */
  --text-5xl: 3rem;        /* 48px */
  --text-6xl: 3.75rem;     /* 60px */
  
  /* Font Weights */
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;
  
  /* Line Heights */
  --leading-none: 1;
  --leading-tight: 1.25;
  --leading-snug: 1.375;
  --leading-normal: 1.5;
  --leading-relaxed: 1.625;
  
  /* Letter Spacing */
  --tracking-tighter: -0.05em;
  --tracking-tight: -0.025em;
  --tracking-normal: 0;
  --tracking-wide: 0.025em;
  --tracking-wider: 0.05em;
  --tracking-widest: 0.1em;
  
  /* === Spacing Scale === */
  --space-0: 0;
  --space-px: 1px;
  --space-0-5: 0.125rem;   /* 2px */
  --space-1: 0.25rem;      /* 4px */
  --space-1-5: 0.375rem;   /* 6px */
  --space-2: 0.5rem;       /* 8px */
  --space-2-5: 0.625rem;   /* 10px */
  --space-3: 0.75rem;      /* 12px */
  --space-3-5: 0.875rem;   /* 14px */
  --space-4: 1rem;         /* 16px */
  --space-5: 1.25rem;      /* 20px */
  --space-6: 1.5rem;       /* 24px */
  --space-7: 1.75rem;      /* 28px */
  --space-8: 2rem;         /* 32px */
  --space-9: 2.25rem;      /* 36px */
  --space-10: 2.5rem;      /* 40px */
  --space-12: 3rem;        /* 48px */
  --space-14: 3.5rem;      /* 56px */
  --space-16: 4rem;        /* 64px */
  --space-20: 5rem;        /* 80px */
  --space-24: 6rem;        /* 96px */
  --space-32: 8rem;        /* 128px */
  
  /* === Border Radius === */
  --radius-none: 0;
  --radius-sm: 0.25rem;    /* 4px */
  --radius-md: 0.5rem;     /* 8px */
  --radius-lg: 0.75rem;    /* 12px */
  --radius-xl: 1rem;       /* 16px */
  --radius-2xl: 1.25rem;   /* 20px */
  --radius-3xl: 1.5rem;    /* 24px */
  --radius-full: 9999px;
  
  /* === Shadows === */
  --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  --shadow-2xl: 0 25px 50px -12px rgb(0 0 0 / 0.25);
  --shadow-inner: inset 0 2px 4px 0 rgb(0 0 0 / 0.05);
  
  /* Glow Effects */
  --glow-accent: 0 0 20px rgb(251 191 36 / 0.3);
  --glow-accent-strong: 0 0 30px rgb(251 191 36 / 0.5);
  
  /* === Transitions === */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slower: 500ms cubic-bezier(0.4, 0, 0.2, 1);
  
  /* Calendar tokens - Base */
  --cal-cell: rgba(15, 23, 42, 0.06);
  --cal-cell-hover: rgba(15, 23, 42, 0.1);
  --cal-border: rgba(15, 23, 42, 0.12);
  
  /* Calendar - Status colors (current month) */
  --cal-done-bg: rgba(34, 197, 94, 0.15);
  --cal-done-br: rgba(34, 197, 94, 0.4);
  --cal-skip-bg: rgba(239, 68, 68, 0.15);
  --cal-skip-br: rgba(239, 68, 68, 0.4);
  --cal-plan-bg: rgba(251, 191, 36, 0.15);
  --cal-plan-br: rgba(251, 191, 36, 0.4);
  --cal-off-bg: rgba(15, 23, 42, 0.03);
  --cal-off-br: rgba(15, 23, 42, 0.1);
  
  /* Calendar - Status colors (out-of-month, dimmed) */
  --cal-done-bg-dim: rgba(34, 197, 94, 0.08);
  --cal-done-br-dim: rgba(34, 197, 94, 0.2);
  --cal-skip-bg-dim: rgba(239, 68, 68, 0.08);
  --cal-skip-br-dim: rgba(239, 68, 68, 0.2);
  --cal-plan-bg-dim: rgba(251, 191, 36, 0.08);
  --cal-plan-br-dim: rgba(251, 191, 36, 0.2);
  --cal-off-bg-dim: rgba(15, 23, 42, 0.02);
  --cal-off-br-dim: rgba(15, 23, 42, 0.06);
  
  /* Calendar - Today highlight */
  --cal-today-glow: rgba(251, 191, 36, 0.15);
  --cal-today-header-bg: rgba(251, 191, 36, 0.18);
  --cal-today-text: var(--accent-600);
  --cal-today-column-bg: rgba(251, 191, 36, 0.04);
  --cal-today-border: rgba(251, 191, 36, 0.5);
  
  /* Calendar - Past states (solid backgrounds, pastel) */
  --cal-past-done-bg: rgba(74, 222, 128, 0.25);
  --cal-past-done-br: rgba(74, 222, 128, 0.5);
  --cal-past-skip-bg: rgba(248, 113, 113, 0.25);
  --cal-past-skip-br: rgba(248, 113, 113, 0.5);
  
  /* Calendar - Future states (outline only, more visible dashed) */
  --cal-future-plan-bg: transparent;
  --cal-future-plan-br: rgba(251, 191, 36, 0.45);
  --cal-future-off-bg: transparent;
  --cal-future-off-br: rgba(15, 23, 42, 0.1);
  
  /* Calendar - Month boundary */
  --cal-month-border: rgba(15, 23, 42, 0.2);
  
  /* Calendar - Week separator */
  --cal-week-separator: rgba(15, 23, 42, 0.15);
  
  /* === Z-Index Scale === */
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal-backdrop: 1040;
  --z-modal: 1050;
  --z-popover: 1060;
  --z-tooltip: 1070;
  
  /* === Layout === */
  --sidebar-width: 240px;
  --header-height: 64px;
  --container-max: 1400px;
  --content-max: 1200px;
  --layout-offset-left: 0px;
  --layout-offset-right: 0px;
}

/* ============================================
   2. LIGHT THEME - Material Premium
   ============================================ */

:root,
[data-theme="light"] {
  /* === BACKGROUNDS - Editorial ivory === */
  --bg-base: #f5efe5;
  --bg-elevated: #fcf8f1;
  --bg-sunken: #eadfce;
  --bg-overlay: rgb(252 247 239 / 0.92);
  
  /* === SURFACES - Refined warm layers === */
  --surface-primary: #fffdfa;
  --surface-secondary: #fcf7ef;
  --surface-tertiary: #f4ecdf;
  --surface-elevated: #fffaf2;
  --surface-interactive: #fdf7ee;
  --surface-interactive-hover: #f2e7d7;
  
  /* === TEXT - Warm editorial contrast === */
  --text-primary: #201811;
  --text-secondary: #4b4033;
  --text-tertiary: #6b5c4d;
  --text-muted: #8a7867;
  --text-inverse: #ffffff;
  --text-accent: #764d19;
  
  /* === BORDERS - Soft but intentional === */
  --border-default: #d5c4ad;
  --border-subtle: #efe4d6;
  --border-strong: #b89f7f;
  --border-interactive: #c8b292;
  --border-accent: #bf8a43;
  --border-week: rgba(26, 24, 21, 0.12);
  --border-month: rgba(185, 127, 47, 0.56);
  
  /* === INTERACTIVE === */
  --interactive-hover: #f4eadb;
  --interactive-active: #e9dcc7;
  --interactive-focus: #b8732f;
  
  /* === ACCENT === */
  --accent-bg: #f6ecdc;
  --accent-bg-hover: #efdfc3;
  --accent-text: #764d19;
  --accent-border: #bf8a43;
  
  /* === COMPONENTS === */
  --input-bg: #fffdfa;
  --input-border: #d3c0a8;
  --input-focus-ring: #b8732f;
  
  --button-primary-bg: #f59e0b;
  --button-primary-text: #2b1906;
  --button-primary-hover: #f7ad1f;
  --button-create-bg: linear-gradient(180deg, rgba(255, 215, 92, 0.96) 0%, rgba(255, 191, 43, 0.92) 54%, rgba(248, 153, 4, 0.9) 100%);
  --button-create-hover: linear-gradient(180deg, rgba(255, 223, 108, 0.98) 0%, rgba(255, 198, 58, 0.95) 50%, rgba(250, 161, 16, 0.92) 100%);
  --button-create-text: #fff9ee;
  --button-create-border: rgba(228, 146, 16, 0.58);
  --button-create-shadow: 0 16px 28px -20px rgba(255, 161, 21, 0.26), 0 8px 14px -10px rgba(153, 90, 13, 0.12);
  --button-create-shadow-hover: 0 20px 30px -20px rgba(255, 166, 20, 0.3), 0 10px 16px -10px rgba(153, 90, 13, 0.14);
  --button-create-ring: rgba(255, 179, 28, 0.28);
  --button-template-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.985) 0%, rgba(248, 251, 255, 0.995) 48%, rgba(236, 243, 251, 0.985) 100%);
  --button-template-text: #35506f;
  --button-template-border: rgba(151, 181, 221, 0.46);
  --button-template-shadow: 0 16px 28px -24px rgba(102, 143, 193, 0.16), 0 8px 14px -12px rgba(73, 108, 149, 0.08);
  --button-template-shadow-hover: 0 20px 32px -24px rgba(102, 143, 193, 0.2), 0 10px 16px -12px rgba(73, 108, 149, 0.1);
  --button-template-ring: rgba(108, 159, 230, 0.18);
  --button-template-sheen: linear-gradient(180deg, rgba(255, 255, 255, 0.54) 0%, rgba(255, 255, 255, 0.18) 26%, rgba(255, 255, 255, 0) 56%);
  --button-template-glow: radial-gradient(138% 148% at 16% 12%, rgba(255, 255, 255, 0.96) 0%, rgba(233, 245, 255, 0.38) 28%, rgba(233, 245, 255, 0) 58%), radial-gradient(112% 118% at 82% 100%, rgba(181, 214, 246, 0.18) 0%, rgba(181, 214, 246, 0) 46%);
  --button-template-highlight: linear-gradient(115deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.12) 16%, rgba(255, 255, 255, 0.84) 40%, rgba(226, 242, 255, 0.9) 48%, rgba(180, 218, 248, 0.42) 58%, rgba(255, 255, 255, 0.08) 74%, rgba(255, 255, 255, 0) 100%);
  --button-template-highlight-opacity: 0.96;
  
  /* === ELEVATION SYSTEM - Controlled premium depth === */
  --shadow-xs: 0 1px 2px rgb(56 39 13 / 0.05);
  --shadow-sm: 0 14px 28px -22px rgb(56 39 13 / 0.2), 0 5px 10px rgb(56 39 13 / 0.06);
  --shadow-md: 0 24px 44px -30px rgb(56 39 13 / 0.24), 0 14px 22px -16px rgb(56 39 13 / 0.09);
  --shadow-lg: 0 34px 62px -38px rgb(56 39 13 / 0.28), 0 20px 32px -24px rgb(56 39 13 / 0.11);
  --shadow-xl: 0 46px 82px -46px rgb(56 39 13 / 0.32), 0 26px 40px -28px rgb(56 39 13 / 0.13);
  
  /* Card elevation: border + shadow = object */
  --card-shadow: 0 28px 52px -38px rgb(54 38 13 / 0.18), 0 16px 24px -18px rgb(54 38 13 / 0.08);
  --card-border: #e0d1be;
  --card-hover-shadow: 0 34px 64px -38px rgb(54 38 13 / 0.22), 0 20px 30px -22px rgb(54 38 13 / 0.1);
  
  /* === SCROLLBAR === */
  --scrollbar-track: #e7dfd4;
  --scrollbar-thumb: #cabfad;
  --scrollbar-thumb-hover: #aa9f90;
  
  /* === RITUAL/PARCHMENT TOKENS === */
  --parchment-bg: linear-gradient(145deg, #fffdf9 0%, #f7efe2 52%, #eee3d3 100%);
  --parchment-border: #d4c4ad;
  --parchment-shadow: 0 18px 36px -28px rgb(57 39 11 / 0.24), 0 6px 14px -12px rgb(57 39 11 / 0.12);
  --parchment-shadow-hover: 0 28px 48px -30px rgb(57 39 11 / 0.3), 0 12px 24px -18px rgb(57 39 11 / 0.14);
  --seal-glow: 0 0 20px rgba(226, 171, 69, 0.24);
  --ritual-accent: linear-gradient(135deg, #f0c97c 0%, #d6a74b 50%, #ba8a2d 100%);
}

/* === LIGHT THEME - Component Styles === */

/* Body/Page: Solid warm background with subtle texture */
[data-theme="light"] body,
[data-theme="light"] .app-page {
  background: 
    radial-gradient(circle at 14% 0%, rgba(255, 255, 255, 0.88) 0%, transparent 34%),
    radial-gradient(circle at 88% 8%, rgba(234, 197, 138, 0.16) 0%, transparent 24%),
    radial-gradient(circle at 50% 100%, rgba(255, 254, 250, 0.56) 0%, transparent 44%),
    linear-gradient(180deg, #fbf7f0 0%, #f2eadf 55%, #e9dfd0 100%);
}

/* CARDS: White objects floating on sand */
[data-theme="light"] .card,
[data-theme="light"] .app-card {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.992) 0%, rgba(255, 252, 247, 0.99) 58%, rgba(249, 241, 231, 0.994) 100%);
  border: 1px solid color-mix(in srgb, var(--card-border) 44%, transparent);
  box-shadow:
    var(--card-shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.54);
  transition: box-shadow var(--transition-base), transform var(--transition-base);
}

[data-theme="light"] .card:hover,
[data-theme="light"] .app-card:hover {
  box-shadow: var(--card-hover-shadow);
  transform: translateY(-1px);
}

[data-theme="light"] .app-card-header,
[data-theme="light"] .card-header {
  border-bottom-color: color-mix(in srgb, var(--border-subtle) 52%, transparent);
}

[data-theme="light"] .app-card-footer,
[data-theme="light"] .card-footer {
  border-top-color: color-mix(in srgb, var(--border-subtle) 52%, transparent);
  background:
    linear-gradient(180deg,
      color-mix(in srgb, var(--surface-secondary) 74%, rgba(255, 255, 255, 0.84)) 0%,
      color-mix(in srgb, var(--surface-primary) 96%, transparent) 100%);
}

/* HEADER TOP: Elevated white bar */
[data-theme="light"] .app-header {
  background: rgb(255 252 247 / 0.9);
  backdrop-filter: blur(18px) saturate(1.05);
  border-bottom: 1px solid color-mix(in srgb, var(--border-default) 84%, transparent);
  box-shadow: 0 20px 38px -32px rgb(54 38 13 / 0.18), 0 12px 20px -18px rgb(54 38 13 / 0.08);
}

/* SIDEBAR LEFT: Elevated white panel */
[data-theme="light"] .app-sidebar {
  background:
    linear-gradient(180deg, rgba(255, 254, 250, 0.98) 0%, rgba(251, 245, 236, 0.98) 100%);
  border-right: 1px solid color-mix(in srgb, var(--border-default) 74%, transparent);
  box-shadow: 20px 0 38px -36px rgb(54 38 13 / 0.18), 8px 0 16px -18px rgb(54 38 13 / 0.05);
}

/* AUTH CARD: Prominent elevation */
[data-theme="light"] .auth-card {
  background: #ffffff;
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-xl);
}

/* INPUTS: Inset feeling */
[data-theme="light"] .form-input,
[data-theme="light"] .form-select,
[data-theme="light"] .form-textarea {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  box-shadow: inset 0 1px 2px rgb(57 39 11 / 0.03);
}

[data-theme="light"] .form-input:focus,
[data-theme="light"] .form-select:focus,
[data-theme="light"] .form-textarea:focus {
  border-color: var(--accent-500);
  box-shadow: 
    inset 0 1px 2px rgb(57 39 11 / 0.03),
    0 0 0 3px rgba(226, 171, 69, 0.16);
}

/* BUTTONS */
[data-theme="light"] .btn-primary:not(.btn-create) {
  box-shadow: 0 16px 26px -22px rgba(245, 158, 11, 0.26), 0 8px 14px -10px rgba(120, 71, 10, 0.1);
}

[data-theme="light"] .btn-primary:not(.btn-create):hover:not(:disabled) {
  box-shadow: 0 20px 30px -22px rgba(245, 158, 11, 0.3), 0 10px 16px -10px rgba(120, 71, 10, 0.12);
  transform: translateY(-1px);
}

/* NAV LINKS */
[data-theme="light"] .nav-link:hover,
[data-theme="light"] .header-nav-link:hover,
[data-theme="light"] .sidebar-nav-link:hover {
  background: var(--interactive-hover);
}

[data-theme="light"] .nav-link.active,
[data-theme="light"] .sidebar-nav-link.active {
  background: var(--accent-bg);
  border-left: 3px solid var(--accent-500);
}

/* DROPDOWNS & MENUS */
[data-theme="light"] .dropdown-menu,
[data-theme="light"] .popover {
  background: #ffffff;
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-lg);
}

/* TABLE ROWS */
[data-theme="light"] .table-row:hover,
[data-theme="light"] tr:hover {
  background: var(--interactive-hover);
}

/* MODAL */
[data-theme="light"] .modal-content {
  background: #ffffff;
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-xl);
}

/* SCROLLBAR */
[data-theme="light"] ::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border: 2px solid var(--bg-base);
}

/* ============================================
   3. DARK THEME
   ============================================ */

[data-theme="dark"],
body.dark-theme {
  /* Backgrounds - Layered, not flat black */
  --bg-base: var(--neutral-925);
  --bg-elevated: var(--neutral-850);
  --bg-sunken: var(--neutral-950);
  --bg-overlay: rgb(0 0 0 / 0.6);
  
  /* Surfaces (Cards, Panels) */
  --surface-primary: var(--neutral-850);
  --surface-secondary: var(--neutral-800);
  --surface-tertiary: var(--neutral-700);
  --surface-elevated: #2f2f35;
  --surface-interactive: var(--neutral-800);
  --surface-interactive-hover: var(--neutral-700);
  
  /* Text Colors */
  --text-primary: var(--neutral-50);
  --text-secondary: var(--neutral-300);
  --text-tertiary: var(--neutral-400);
  --text-muted: var(--neutral-500);
  --text-inverse: var(--neutral-900);
  --text-accent: var(--accent-400);
  
  /* Border Colors */
  --border-default: var(--neutral-700);
  --border-subtle: var(--neutral-800);
  --border-strong: var(--neutral-600);
  --border-interactive: var(--neutral-600);
  --border-accent: var(--accent-500);
  --border-week: rgba(255, 255, 255, 0.12);
  --border-month: rgba(251, 191, 36, 0.45);
  
  /* Interactive States */
  --interactive-hover: var(--neutral-700);
  --interactive-active: var(--neutral-600);
  --interactive-focus: var(--accent-500);
  
  /* Accent Variants */
  --accent-bg: rgb(251 191 36 / 0.1);
  --accent-bg-hover: rgb(251 191 36 / 0.15);
  --accent-text: var(--accent-400);
  --accent-border: var(--accent-600);
  
  /* Component Specific */
  --input-bg: var(--neutral-800);
  --input-border: var(--neutral-600);
  --input-focus-ring: var(--accent-500);
  
  --button-primary-bg: var(--accent-500);
  --button-primary-text: var(--neutral-900);
  --button-primary-hover: var(--accent-400);
  --button-create-bg: linear-gradient(180deg, rgba(255, 209, 78, 0.95) 0%, rgba(255, 182, 23, 0.9) 54%, rgba(243, 138, 0, 0.88) 100%);
  --button-create-hover: linear-gradient(180deg, rgba(255, 217, 96, 0.97) 0%, rgba(255, 190, 38, 0.93) 50%, rgba(246, 148, 8, 0.9) 100%);
  --button-create-text: #fff8ea;
  --button-create-border: rgba(255, 184, 48, 0.42);
  --button-create-shadow: 0 14px 26px -18px rgba(255, 148, 0, 0.3), 0 10px 16px -12px rgba(0, 0, 0, 0.3);
  --button-create-shadow-hover: 0 18px 30px -18px rgba(255, 155, 0, 0.34), 0 12px 18px -12px rgba(0, 0, 0, 0.34);
  --button-create-ring: rgba(255, 184, 52, 0.22);
  --button-template-bg: linear-gradient(180deg, rgba(38, 49, 68, 0.96) 0%, rgba(43, 59, 86, 0.98) 48%, rgba(48, 75, 111, 1) 100%);
  --button-template-text: #eef6ff;
  --button-template-border: rgba(130, 177, 241, 0.42);
  --button-template-shadow: 0 14px 24px -18px rgba(69, 118, 189, 0.26), 0 10px 16px -12px rgba(0, 0, 0, 0.32);
  --button-template-shadow-hover: 0 18px 28px -18px rgba(88, 141, 220, 0.34), 0 12px 18px -12px rgba(0, 0, 0, 0.36);
  --button-template-ring: rgba(130, 177, 246, 0.22);
  --button-template-sheen: linear-gradient(180deg, rgba(236, 246, 255, 0.13) 0%, rgba(236, 246, 255, 0.05) 28%, rgba(236, 246, 255, 0) 58%);
  --button-template-glow: radial-gradient(140% 150% at 16% 12%, rgba(230, 242, 255, 0.2) 0%, rgba(146, 196, 250, 0.12) 30%, rgba(146, 196, 250, 0) 60%), radial-gradient(120% 126% at 84% 100%, rgba(112, 165, 236, 0.16) 0%, rgba(112, 165, 236, 0) 48%);
  --button-template-highlight: linear-gradient(115deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.02) 14%, rgba(207, 233, 255, 0.24) 34%, rgba(246, 250, 255, 0.78) 48%, rgba(177, 217, 255, 0.58) 56%, rgba(118, 176, 246, 0.22) 66%, rgba(255, 255, 255, 0) 100%);
  --button-template-highlight-opacity: 0.98;
  
  --card-shadow: 0 4px 12px rgb(0 0 0 / 0.4), 0 2px 4px rgb(0 0 0 / 0.3);
  --card-border: var(--neutral-700);
  --card-hover-shadow: 0 8px 24px rgb(0 0 0 / 0.5), 0 4px 8px rgb(0 0 0 / 0.4);
  --card-glow: 0 0 0 1px rgba(251, 191, 36, 0.1);
  
  /* Scrollbar */
  --scrollbar-track: var(--neutral-800);
  --scrollbar-thumb: var(--neutral-600);
  --scrollbar-thumb-hover: var(--neutral-500);
  
  /* Shadows adjusted for dark */
  --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.3);
  --shadow-sm: 0 1px 3px rgb(0 0 0 / 0.4), 0 1px 2px rgb(0 0 0 / 0.3);
  --shadow-md: 0 4px 8px rgb(0 0 0 / 0.5), 0 2px 4px rgb(0 0 0 / 0.4);
  --shadow-lg: 0 12px 24px rgb(0 0 0 / 0.5), 0 4px 8px rgb(0 0 0 / 0.4);
  --shadow-xl: 0 24px 48px rgb(0 0 0 / 0.6), 0 8px 16px rgb(0 0 0 / 0.5);
  
  /* Calendar tokens - Dark theme overrides */
  --cal-done-bg: rgba(34, 197, 94, 0.18);
  --cal-done-br: rgba(34, 197, 94, 0.45);
  --cal-skip-bg: rgba(239, 68, 68, 0.18);
  --cal-skip-br: rgba(239, 68, 68, 0.45);
  --cal-plan-bg: rgba(251, 191, 36, 0.18);
  --cal-plan-br: rgba(251, 191, 36, 0.45);
  --cal-off-bg: rgba(255, 255, 255, 0.03);
  --cal-off-br: rgba(255, 255, 255, 0.08);
  
  --cal-done-bg-dim: rgba(34, 197, 94, 0.08);
  --cal-done-br-dim: rgba(34, 197, 94, 0.18);
  --cal-skip-bg-dim: rgba(239, 68, 68, 0.08);
  --cal-skip-br-dim: rgba(239, 68, 68, 0.18);
  --cal-plan-bg-dim: rgba(251, 191, 36, 0.08);
  --cal-plan-br-dim: rgba(251, 191, 36, 0.18);
  --cal-off-bg-dim: rgba(255, 255, 255, 0.02);
  --cal-off-br-dim: rgba(255, 255, 255, 0.05);
  
  --cal-today-glow: rgba(251, 191, 36, 0.15);
  --cal-today-header-bg: rgba(251, 191, 36, 0.2);
  --cal-today-text: var(--accent-400);
  --cal-today-column-bg: rgba(251, 191, 36, 0.06);
  --cal-today-border: rgba(251, 191, 36, 0.6);
  
  /* Calendar - Past states (solid backgrounds, pastel) - Dark */
  --cal-past-done-bg: rgba(74, 222, 128, 0.28);
  --cal-past-done-br: rgba(74, 222, 128, 0.5);
  --cal-past-skip-bg: rgba(248, 113, 113, 0.28);
  --cal-past-skip-br: rgba(248, 113, 113, 0.5);
  
  /* Calendar - Future states (outline only, more visible) - Dark */
  --cal-future-plan-bg: transparent;
  --cal-future-plan-br: rgba(251, 191, 36, 0.4);
  --cal-future-off-bg: transparent;
  --cal-future-off-br: rgba(255, 255, 255, 0.1);
  
  --cal-month-border: rgba(255, 255, 255, 0.15);
  --cal-week-separator: rgba(255, 255, 255, 0.1);
  
  /* === RITUAL/PARCHMENT TOKENS - Dark === */
  --parchment-bg: linear-gradient(145deg, var(--neutral-800) 0%, var(--neutral-850) 50%, var(--neutral-875) 100%);
  --parchment-border: var(--neutral-600);
  --parchment-shadow: 0 4px 20px rgb(0 0 0 / 0.4), 0 2px 8px rgb(0 0 0 / 0.3);
  --parchment-shadow-hover: 0 16px 40px rgb(0 0 0 / 0.5), 0 6px 16px rgb(0 0 0 / 0.4);
  --seal-glow: 0 0 30px rgba(251, 191, 36, 0.25);
  --ritual-accent: linear-gradient(135deg, #fbbf24 0%, #d97706 50%, #b45309 100%);
}

/* === DARK THEME - Component Styles === */

/* Body/Page: Deep layered background */
[data-theme="dark"] body,
[data-theme="dark"] .app-page {
  background: 
    radial-gradient(ellipse 100% 60% at 50% 0%, rgba(251, 191, 36, 0.03) 0%, transparent 50%),
    var(--bg-base);
}

/* CARDS: Elevated with subtle glow */
[data-theme="dark"] .card,
[data-theme="dark"] .app-card {
  background: var(--surface-primary);
  border: 1px solid var(--card-border);
  box-shadow: var(--card-shadow), var(--card-glow);
  transition: box-shadow var(--transition-base), transform var(--transition-base);
}

[data-theme="dark"] .card:hover,
[data-theme="dark"] .app-card:hover {
  box-shadow: var(--card-hover-shadow), 0 0 0 1px rgba(251, 191, 36, 0.15);
}

/* HEADER TOP: Elevated dark panel */
[data-theme="dark"] .app-header {
  background: var(--surface-primary);
  border-bottom: 1px solid var(--border-default);
  box-shadow: 0 2px 12px rgb(0 0 0 / 0.3);
}

/* SIDEBAR LEFT: Elevated dark panel */
[data-theme="dark"] .app-sidebar {
  background: var(--surface-primary);
  border-right: 1px solid var(--border-default);
  box-shadow: 2px 0 16px rgb(0 0 0 / 0.3);
}

/* AUTH CARD */
[data-theme="dark"] .auth-card {
  background: var(--surface-primary);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-xl), 0 0 0 1px rgba(251, 191, 36, 0.08);
}

/* INPUTS */
[data-theme="dark"] .form-input:focus,
[data-theme="dark"] .form-select:focus,
[data-theme="dark"] .form-textarea:focus {
  border-color: var(--accent-500);
  box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.15);
}

/* BUTTONS */
[data-theme="dark"] .btn-primary:not(.btn-create) {
  box-shadow: 0 2px 8px rgb(245 158 11 / 0.3), 0 0 0 1px rgba(251, 191, 36, 0.2) inset;
}

[data-theme="dark"] .btn-primary:not(.btn-create):hover:not(:disabled) {
  box-shadow: 0 4px 16px rgb(245 158 11 / 0.4), 0 0 24px rgb(251 191 36 / 0.2);
  transform: translateY(-1px);
}

/* NAV LINKS */
[data-theme="dark"] .nav-link.active,
[data-theme="dark"] .sidebar-nav-link.active {
  background: var(--accent-bg);
  border-left: 3px solid var(--accent-500);
  box-shadow: inset 0 0 12px rgba(251, 191, 36, 0.1);
}

/* DROPDOWNS & MENUS */
[data-theme="dark"] .dropdown-menu,
[data-theme="dark"] .popover {
  background: var(--surface-primary);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(251, 191, 36, 0.05);
}

/* MODAL */
[data-theme="dark"] .modal-content {
  background: var(--surface-primary);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-xl), 0 0 0 1px rgba(251, 191, 36, 0.08);
}

/* ============================================
   4. BASE RESET & DEFAULTS
   ============================================ */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text-primary);
  background-color: var(--bg-base);
  min-height: 100vh;
  transition: background-color var(--transition-slow), color var(--transition-slow);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

/* Selection */
::selection {
  background-color: var(--accent-400);
  color: var(--neutral-900);
}

/* Focus Visible */
:focus-visible {
  outline: 2px solid var(--interactive-focus);
  outline-offset: 2px;
}

/* Screen Reader Only */
.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;
}

/* ============================================
   5. TYPOGRAPHY
   ============================================ */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: var(--font-semibold);
  line-height: var(--leading-tight);
  color: var(--text-primary);
}

.heading-1 { font-size: var(--text-5xl); letter-spacing: var(--tracking-tight); }
.heading-2 { font-size: var(--text-4xl); letter-spacing: var(--tracking-tight); }
.heading-3 { font-size: var(--text-3xl); }
.heading-4 { font-size: var(--text-2xl); }
.heading-5 { font-size: var(--text-xl); }
.heading-6 { font-size: var(--text-lg); }

.text-display {
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 5vw, 4rem);
  font-weight: var(--font-medium);
  line-height: var(--leading-none);
  letter-spacing: var(--tracking-tight);
}

.text-body {
  font-size: calc(var(--text-base) * 1.08);
  color: var(--text-secondary);
}

.text-body-lg {
  font-size: calc(var(--text-lg) * 1.08);
  color: var(--text-secondary);
}

.text-body-sm {
  font-size: calc(var(--text-sm) * 1.12);
  color: var(--text-secondary);
}

.text-caption {
  font-size: calc(var(--text-xs) * 1.12);
  color: var(--text-tertiary);
  letter-spacing: var(--tracking-wide);
}

.text-overline {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-widest);
  color: var(--text-tertiary);
}

.text-accent { color: var(--text-accent); }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }

/* ============================================
   6. LAYOUT SYSTEM
   ============================================ */

/* App Shell - Supports both header and sidebar layouts */
.app-shell {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}

/* Header Layout (Default) */
.app-shell[data-layout="header"],
.app-shell:not([data-layout]) {
  flex-direction: column;
}

.app-shell[data-layout="header"] .app-sidebar,
.app-shell:not([data-layout]) .app-sidebar {
  display: none;
}

/* Sidebar Layout */
.app-shell[data-layout="sidebar"] {
  flex-direction: row;
  --layout-offset-left: var(--sidebar-width);
}

.app-shell[data-layout="sidebar"] .app-header {
  display: none;
}

.app-shell[data-layout="sidebar"] .app-sidebar {
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  min-height: 100vh;
  position: fixed;
  left: 0;
  top: 0;
  z-index: var(--z-fixed);
  background: var(--surface-primary);
  border-right: 1px solid var(--border-subtle);
}

.app-shell[data-layout="sidebar"] .app-main {
  margin-left: var(--sidebar-width);
  width: calc(100% - var(--sidebar-width));
}

/* App Header */
.app-header {
  height: var(--header-height);
  background: var(--surface-primary);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  backdrop-filter: blur(12px);
}

.app-header-inner {
  max-width: var(--container-max);
  height: 100%;
  margin: 0 auto;
  padding: 0 var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

/* App Sidebar */
.app-sidebar {
  padding: var(--space-6);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding-bottom: var(--space-6);
  margin-bottom: var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  flex: 1;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: var(--space-6);
  border-top: 1px solid var(--border-subtle);
}

/* App Main Content */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Container */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: var(--space-6);
}

.container-sm { max-width: 640px; }
.container-md { max-width: 768px; }
.container-lg { max-width: 1024px; }
.container-xl { max-width: var(--content-max); }

/* Page Layout */
.page {
  padding: var(--space-8) var(--space-6);
}

.page-header {
  margin-bottom: var(--space-8);
}

.page-title {
  font-size: var(--text-3xl);
  font-weight: var(--font-semibold);
  margin-bottom: var(--space-2);
}

.page-subtitle {
  font-size: var(--text-lg);
  color: var(--text-secondary);
}

/* ============================================
   7. COMPONENTS - BUTTONS
   ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2-5) var(--space-4);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  line-height: var(--leading-normal);
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Primary Button - With Accent Glow */
.btn-primary {
  background: var(--button-primary-bg);
  color: var(--button-primary-text);
  border-color: transparent;
  box-shadow: var(--shadow-sm);
}

.btn-primary:not(.btn-create):hover:not(:disabled) {
  background: var(--button-primary-hover);
  box-shadow: var(--glow-accent);
  transform: translateY(-1px);
}

.btn-primary:not(.btn-create):active:not(:disabled) {
  transform: translateY(0);
}

/* Secondary Button */
.btn-secondary {
  background: var(--surface-interactive);
  color: var(--text-primary);
  border-color: var(--border-default);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-interactive-hover);
  border-color: var(--border-strong);
}

/* Ghost Button */
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--interactive-hover);
  color: var(--text-primary);
}

.btn-tertiary {
  background:
    linear-gradient(180deg,
      color-mix(in srgb, var(--surface-primary) 88%, transparent) 0%,
      color-mix(in srgb, var(--surface-secondary) 78%, transparent) 100%);
  color: color-mix(in srgb, var(--text-secondary) 96%, transparent);
  border-color: color-mix(in srgb, var(--border-default) 22%, transparent);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 0.16),
    0 10px 18px -24px rgba(15, 23, 42, 0.08);
}

.btn-tertiary:hover:not(:disabled) {
  background:
    linear-gradient(180deg,
      color-mix(in srgb, var(--surface-primary) 90%, rgba(255, 255, 255, 0.78)) 0%,
      color-mix(in srgb, var(--surface-secondary) 84%, var(--surface-primary)) 100%);
  color: var(--text-primary);
  border-color: color-mix(in srgb, var(--border-strong) 32%, transparent);
  box-shadow: 0 14px 22px -24px rgba(15, 23, 42, 0.1);
}

[data-theme="light"] .btn-tertiary {
  border-color: color-mix(in srgb, var(--border-default) 16%, transparent);
  background:
    linear-gradient(180deg,
      rgba(255, 255, 255, 0.86) 0%,
      color-mix(in srgb, var(--surface-secondary) 70%, var(--surface-primary)) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.48),
    0 12px 20px -24px rgba(76, 53, 22, 0.12);
}

[data-theme="light"] .btn-tertiary:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--accent-500) 14%, var(--border-default));
  background:
    linear-gradient(180deg,
      rgba(255, 255, 255, 0.92) 0%,
      color-mix(in srgb, var(--accent-bg) 14%, var(--surface-secondary)) 100%);
}


/* ── Liquid-flow animation for premium .btn-create CTA ── */
/* Premium sweep animation for .btn-template */
@keyframes btn-template-sweep {
  0%,
  12% {
    transform: translate3d(-185%, 0, 0) rotate(12deg) scale(1.02);
    opacity: 0;
  }
  22% {
    opacity: calc(var(--button-template-highlight-opacity, 0.86) * 0.78);
  }
  58% {
    transform: translate3d(182%, 0, 0) rotate(12deg) scale(1.08);
    opacity: var(--button-template-highlight-opacity, 0.86);
  }
  72% {
    opacity: 0;
  }
  100% {
    transform: translate3d(238%, 0, 0) rotate(12deg) scale(1.04);
    opacity: 0;
  }
}

.btn-template {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: 40px;
  padding-inline: 1rem 1.2rem;
  border-radius: 999px;
  border: 1px solid var(--button-template-border);
  background:
    var(--button-template-sheen),
    var(--button-template-glow),
    var(--button-template-bg);
  background-size: 100% 100%, 100% 100%, 100% 100%;
  background-repeat: no-repeat;
  background-position: 0 0, 0 0, 0 0;
  color: var(--button-template-text);
  box-shadow:
    var(--button-template-shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.74),
    inset 0 -1px 0 rgba(119, 162, 219, 0.08);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.34);
  transition:
    transform var(--transition-fast),
    box-shadow var(--transition-fast),
    border-color var(--transition-fast),
    filter var(--transition-fast);
}

.btn-template::after {
  content: "";
  position: absolute;
  z-index: -1;
  top: -62%;
  bottom: -62%;
  left: -30%;
  width: 54%;
  border-radius: 999px;
  background: var(--button-template-highlight);
  filter: blur(11px);
  opacity: 0;
  transform: translate3d(-185%, 0, 0) rotate(12deg) scale(1.02);
  transform-origin: center;
  will-change: transform, opacity;
  pointer-events: none;
  animation: btn-template-sweep 5.4s cubic-bezier(0.42, 0, 0.2, 1) infinite;
}

.btn-template:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--button-template-border) 78%, rgba(124, 175, 240, 0.94));
  box-shadow:
    var(--button-template-shadow-hover),
    inset 0 1px 0 rgba(255, 255, 255, 0.8),
    inset 0 -1px 0 rgba(126, 170, 230, 0.1);
  transform: translateY(-1px);
  filter: saturate(1.02) brightness(1.015);
}

.btn-template:hover:not(:disabled)::after {
  filter: blur(12px);
}

.btn-template:active:not(:disabled) {
  transform: translateY(0.5px) scale(0.986);
  box-shadow:
    0 10px 18px -14px rgba(84, 126, 181, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.62),
    inset 0 2px 4px rgba(95, 135, 191, 0.12);
  filter: brightness(0.99) saturate(1.02);
}

.btn-template:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 3px var(--button-template-ring),
    var(--button-template-shadow-hover),
    inset 0 1px 0 rgba(255, 255, 255, 0.82);
}

.btn-sm.btn-template {
  min-height: 35px;
  padding-inline: 0.88rem 1.04rem;
  font-size: 12.5px;
}

[data-theme="dark"] .btn-template {
  box-shadow:
    var(--button-template-shadow),
    inset 0 1px 0 rgba(240, 247, 255, 0.16),
    inset 0 -1px 0 rgba(138, 180, 240, 0.1);
  text-shadow: 0 1px 0 rgba(7, 14, 26, 0.24);
}

[data-theme="dark"] .btn-template::after {
  filter: blur(13px);
}

[data-theme="dark"] .btn-template:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--button-template-border) 72%, rgba(174, 208, 255, 0.54));
  filter: saturate(1.03) brightness(1.03);
}

@media (prefers-reduced-motion: reduce) {
  .btn-template::after {
    animation: none;
    opacity: 0.46;
    transform: translate3d(36%, 0, 0) rotate(12deg) scale(1.03);
  }
}

/* Liquid-flow animation for premium .btn-create CTA */
@keyframes btn-create-flow {
  0% {
    transform: translate(-5%, -8%) rotate(0deg) scale(1);
  }
  14% {
    transform: translate(8%, -12%) rotate(50deg) scale(1.03);
  }
  32% {
    transform: translate(10%, 5%) rotate(115deg) scale(0.98);
  }
  48% {
    transform: translate(-4%, 10%) rotate(170deg) scale(1.01);
  }
  65% {
    transform: translate(-12%, 2%) rotate(235deg) scale(1.04);
  }
  82% {
    transform: translate(-7%, -10%) rotate(310deg) scale(0.97);
  }
  100% {
    transform: translate(-5%, -8%) rotate(360deg) scale(1);
  }
}

.btn-create {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: 40px;
  gap: 0.52rem;
  padding-inline: 1.1rem 1.24rem;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.012em;
  line-height: 1;
  text-shadow: 0 1px 0 rgba(74, 38, 9, 0.15);
  transition:
    transform var(--transition-fast),
    box-shadow var(--transition-fast),
    border-color var(--transition-fast),
    filter var(--transition-fast);
}

.btn-sm.btn-create {
  min-height: 35px;
  gap: 0.44rem;
  padding-inline: 0.9rem 1.04rem;
  border-radius: 999px;
  font-size: 12.5px;
}

.btn-create::before {
  content: "+";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  height: auto;
  font-size: 1.02em;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.04em;
  flex: 0 0 auto;
  transform: translateY(-0.03em);
  opacity: 0.96;
}

.btn-primary.btn-create {
  color: var(--button-create-text, var(--button-primary-text));
  border-width: 1.5px;
  border-color: color-mix(in srgb, var(--button-create-border, var(--button-primary-bg)) 82%, rgba(255, 243, 208, 0.42));
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.3) 0%, rgba(255, 248, 223, 0.12) 28%, rgba(255, 241, 206, 0) 52%),
    radial-gradient(130% 120% at 16% 14%, rgba(255, 242, 181, 0.26) 0%, rgba(255, 242, 181, 0) 42%),
    var(--button-create-bg, var(--button-primary-bg));
  box-shadow:
    var(--button-create-shadow, 0 18px 30px -22px rgba(155, 96, 27, 0.3)),
    inset 0 1px 0 rgba(255, 252, 236, 0.56),
    inset 0 -1px 0 rgba(215, 124, 0, 0.18);
}

/* Animated liquid blobs — two radial masses on oversized rotating layer */
.btn-primary.btn-create::after {
  content: '';
  position: absolute;
  z-index: -1;
  width: 260%;
  height: 260%;
  top: -80%;
  left: -80%;
  border-radius: 50%;
  background:
    radial-gradient(ellipse 46% 50% at 26% 74%,
      rgba(255, 219, 103, 0.96) 0%,
      rgba(255, 209, 74, 0.8) 34%,
      rgba(255, 209, 74, 0.34) 58%,
      transparent 78%),
    radial-gradient(ellipse 42% 64% at 56% 18%,
      rgba(255, 154, 2, 0.94) 0%,
      rgba(255, 137, 0, 0.8) 36%,
      rgba(255, 137, 0, 0.34) 62%,
      transparent 80%),
    radial-gradient(ellipse 30% 38% at 78% 62%,
      rgba(255, 187, 46, 0.46) 0%,
      transparent 72%);
  filter: blur(18px) saturate(1.12);
  will-change: transform;
  animation: btn-create-flow 6s cubic-bezier(0.37, 0, 0.63, 1) infinite;
  pointer-events: none;
  transition: filter var(--transition-fast);
}

.btn-primary.btn-create::before {
  color: currentColor;
}

.btn-primary.btn-create:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--button-create-border, var(--button-primary-bg)) 88%, rgba(255, 248, 222, 0.54));
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.34) 0%, rgba(255, 248, 223, 0.14) 30%, rgba(255, 241, 206, 0) 54%),
    radial-gradient(130% 120% at 16% 14%, rgba(255, 242, 181, 0.28) 0%, rgba(255, 242, 181, 0) 42%),
    var(--button-create-hover, var(--button-create-bg));
  box-shadow:
    var(--button-create-shadow-hover, 0 22px 36px -22px rgba(170, 104, 28, 0.34)),
    inset 0 1px 0 rgba(255, 252, 238, 0.6),
    inset 0 -1px 0 rgba(220, 128, 0, 0.18);
  transform: translateY(-1px);
  filter: brightness(1.02) saturate(1.08);
}

.btn-primary.btn-create:hover:not(:disabled)::after {
  filter: blur(16px) brightness(1.08) saturate(1.16);
}

.btn-primary.btn-create:active:not(:disabled) {
  transform: translateY(0.5px) scale(0.985);
  filter: saturate(1.02) brightness(0.98);
  box-shadow:
    0 8px 14px -10px rgba(208, 116, 0, 0.24),
    inset 0 1px 0 rgba(255, 249, 232, 0.22),
    inset 0 2px 4px rgba(176, 97, 0, 0.14);
}

.btn-primary.btn-create:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 3px var(--button-create-ring, rgba(212, 138, 46, 0.24)),
    var(--button-create-shadow, 0 18px 30px -22px rgba(155, 96, 27, 0.28)),
    inset 0 1px 0 rgba(255, 252, 238, 0.52),
    inset 0 -1px 0 rgba(220, 128, 0, 0.16);
}

.btn-primary.btn-create:disabled::after {
  animation-play-state: paused;
  opacity: 0.4;
}

[data-theme="light"] .btn-primary.btn-create {
  text-shadow: 0 1px 0 rgba(153, 83, 0, 0.16);
}

[data-theme="dark"] .btn-primary.btn-create,
body.dark-theme .btn-primary.btn-create {
  text-shadow: 0 1px 0 rgba(115, 61, 0, 0.26);
}

[data-theme="dark"] .btn-primary.btn-create::after,
body.dark-theme .btn-primary.btn-create::after {
  background:
    radial-gradient(ellipse 46% 50% at 26% 74%,
      rgba(255, 214, 92, 0.92) 0%,
      rgba(255, 202, 58, 0.76) 34%,
      rgba(255, 202, 58, 0.3) 58%,
      transparent 78%),
    radial-gradient(ellipse 42% 64% at 56% 18%,
      rgba(255, 148, 0, 0.92) 0%,
      rgba(255, 132, 0, 0.78) 36%,
      rgba(255, 132, 0, 0.3) 62%,
      transparent 80%),
    radial-gradient(ellipse 30% 38% at 78% 62%,
      rgba(255, 182, 42, 0.4) 0%,
      transparent 72%);
}

@media (prefers-reduced-motion: reduce) {
  .btn-primary.btn-create::after {
    animation: none;
    transform: translate(-4%, -4%);
    filter: blur(24px);
    opacity: 0.6;
  }
}


/* ── Create Spark — adopted create-action candidate ────────────── */
/* Replaces btn-create for create-oriented CTAs. Preserves production
   font-family and text color; uses create-spark gradient direction
   with a subtler idle shimmer and refined interaction states. */

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

.btn-create-spark {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: 40px;
  gap: 0.52rem;
  padding-inline: 1.1rem 1.24rem;
  border-radius: 999px;
  font-family: inherit;
  font-weight: 700;
  letter-spacing: 0.012em;
  line-height: 1;
  color: var(--button-create-text, var(--button-primary-text));
  border-width: 1.5px;
  border-style: solid;
  border-color: rgba(255, 244, 214, 0.36);
  background:
    linear-gradient(135deg, #ffd670 0%, #f59e0b 60%, #e8890a 100%);
  box-shadow:
    0 18px 30px -22px rgba(245, 158, 11, 0.52),
    inset 0 1px 0 rgba(255, 252, 236, 0.48),
    inset 0 -1px 0 rgba(215, 124, 0, 0.14);
  text-shadow: 0 1px 0 rgba(74, 38, 9, 0.12);
  transition:
    transform var(--transition-fast),
    box-shadow var(--transition-fast),
    border-color var(--transition-fast),
    filter var(--transition-fast);
}

.btn-sm.btn-create-spark {
  min-height: 35px;
  gap: 0.44rem;
  padding-inline: 0.9rem 1.04rem;
  border-radius: 999px;
  font-size: 12.5px;
}

.btn-create-spark::before {
  content: "+";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  height: auto;
  font-size: 1.02em;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.04em;
  flex: 0 0 auto;
  transform: translateY(-0.03em);
  opacity: 0.96;
  color: currentColor;
}

/* Subtle shimmer overlay — gentler than liquid blob */
.btn-create-spark::after {
  content: '';
  position: absolute;
  z-index: -1;
  inset: 0;
  border-radius: inherit;
  background:
    linear-gradient(
      105deg,
      transparent 20%,
      rgba(255, 255, 255, 0.22) 38%,
      rgba(255, 255, 255, 0.32) 50%,
      rgba(255, 255, 255, 0.22) 62%,
      transparent 80%
    );
  background-size: 400% 100%;
  animation: btn-spark-shimmer 4.5s ease-in-out infinite;
  pointer-events: none;
}

.btn-create-spark:hover:not(:disabled) {
  border-color: rgba(255, 248, 222, 0.54);
  box-shadow:
    0 22px 36px -22px rgba(245, 158, 11, 0.58),
    inset 0 1px 0 rgba(255, 252, 238, 0.56),
    inset 0 -1px 0 rgba(220, 128, 0, 0.16);
  transform: translateY(-1px);
  filter: brightness(1.04) saturate(1.06);
}

.btn-create-spark:hover:not(:disabled)::after {
  animation-duration: 2.8s;
}

.btn-create-spark:active:not(:disabled) {
  transform: translateY(0.5px) scale(0.985);
  filter: saturate(1.02) brightness(0.97);
  box-shadow:
    0 8px 14px -10px rgba(208, 116, 0, 0.24),
    inset 0 1px 0 rgba(255, 249, 232, 0.22),
    inset 0 2px 4px rgba(176, 97, 0, 0.14);
}

.btn-create-spark:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 3px var(--button-create-ring, rgba(212, 138, 46, 0.24)),
    0 18px 30px -22px rgba(245, 158, 11, 0.48),
    inset 0 1px 0 rgba(255, 252, 238, 0.52),
    inset 0 -1px 0 rgba(220, 128, 0, 0.16);
}

.btn-create-spark:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-create-spark:disabled::after {
  animation-play-state: paused;
  opacity: 0.3;
}

[data-theme="light"] .btn-create-spark {
  text-shadow: 0 1px 0 rgba(153, 83, 0, 0.14);
}

[data-theme="dark"] .btn-create-spark,
body.dark-theme .btn-create-spark {
  background: linear-gradient(135deg, #f0c44a 0%, #d98b08 60%, #c27a05 100%);
  border-color: rgba(255, 220, 140, 0.28);
  text-shadow: 0 1px 0 rgba(115, 61, 0, 0.22);
}

@media (prefers-reduced-motion: reduce) {
  .btn-create-spark::after {
    animation: none;
    opacity: 0.18;
  }
}

/* Danger Button */
.btn-danger {
  background: var(--danger);
  color: var(--neutral-0);
  border-color: transparent;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-dark);
}

/* Link Button */
.btn-link {
  background: transparent;
  color: var(--text-accent);
  border-color: transparent;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.btn-link:hover:not(:disabled) {
  color: var(--accent-500);
}

/* Button Sizes */
.btn-sm {
  padding: var(--space-1-5) var(--space-3);
  font-size: var(--text-xs);
  border-radius: var(--radius-md);
}

.btn-lg {
  padding: var(--space-3-5) var(--space-6);
  font-size: var(--text-base);
  border-radius: var(--radius-xl);
}

.btn-icon {
  padding: var(--space-2);
  aspect-ratio: 1;
}

.btn-full {
  width: 100%;
}

/* ============================================
   8. COMPONENTS - CARDS
   ============================================ */

.card {
  background: var(--surface-primary);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--card-shadow);
  overflow: hidden;
  transition: box-shadow var(--transition-base), transform var(--transition-base);
}

.card-hover:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

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

.card-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
}

.card-subtitle {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  margin-top: var(--space-1);
}

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

.card-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-secondary);
}

/* Card Variants */
.card-flat {
  box-shadow: none;
  border: 1px solid var(--border-default);
}

.card-elevated {
  box-shadow: var(--shadow-xl);
}

.card-accent {
  border-color: var(--border-accent);
  background: linear-gradient(135deg, var(--surface-primary), var(--accent-bg));
}

/* ============================================
   9. COMPONENTS - FORMS
   ============================================ */

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

.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.form-label-optional {
  font-weight: var(--font-normal);
  color: var(--text-muted);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: var(--space-2-5) var(--space-3);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--text-primary);
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-lg);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:hover,
.form-select:hover,
.form-textarea:hover {
  border-color: var(--border-strong);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--input-focus-ring);
  box-shadow: 0 0 0 3px rgb(251 191 36 / 0.15);
}

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

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

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20' fill='%2371717a'%3E%3Cpath fill-rule='evenodd' d='M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-10);
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-top: var(--space-1-5);
}

.form-error {
  font-size: var(--text-xs);
  color: var(--danger);
  margin-top: var(--space-1-5);
}

/* Checkbox & Radio */
.form-check {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.form-check-input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-500);
  cursor: pointer;
}

.form-check-label {
  font-size: var(--text-sm);
  color: var(--text-primary);
  cursor: pointer;
}

/* ============================================
   10. COMPONENTS - NAVIGATION
   ============================================ */

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2-5) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--radius-lg);
  transition: all var(--transition-fast);
}

.nav-link:hover {
  background: var(--interactive-hover);
  color: var(--text-primary);
}

.nav-link.active {
  background: var(--accent-bg);
  color: var(--text-accent);
}

.nav-link-icon {
  width: 20px;
  height: 20px;
  opacity: 0.7;
}

.nav-link:hover .nav-link-icon,
.nav-link.active .nav-link-icon {
  opacity: 1;
}

/* ============================================
   11. COMPONENTS - BADGES & TAGS
   ============================================ */

.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-0-5) var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.badge-default {
  background: var(--surface-tertiary);
  color: var(--text-secondary);
}

.badge-accent {
  background: var(--accent-bg);
  color: var(--text-accent);
}

.badge-success {
  background: var(--success-light);
  color: var(--success-dark);
}

.badge-danger {
  background: var(--danger-light);
  color: var(--danger-dark);
}

.badge-warning {
  background: var(--warning-light);
  color: var(--warning-dark);
}

/* ============================================
   12. COMPONENTS - ALERTS
   ============================================ */

.alert {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
}

.alert-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}

.alert-content {
  flex: 1;
}

.alert-title {
  font-weight: var(--font-semibold);
  margin-bottom: var(--space-1);
}

.alert-info {
  background: var(--info-light);
  color: var(--info-dark);
  border: 1px solid var(--info);
}

.alert-success {
  background: var(--success-light);
  color: var(--success-dark);
  border: 1px solid var(--success);
}

.alert-warning {
  background: var(--warning-light);
  color: var(--warning-dark);
  border: 1px solid var(--warning);
}

.alert-error {
  background: var(--danger-light);
  color: var(--danger-dark);
  border: 1px solid var(--danger);
}

/* Dark theme alerts */
[data-theme="dark"] .alert-info,
body.dark-theme .alert-info {
  background: rgb(59 130 246 / 0.1);
  border-color: rgb(59 130 246 / 0.3);
}

[data-theme="dark"] .alert-success,
body.dark-theme .alert-success {
  background: rgb(34 197 94 / 0.1);
  border-color: rgb(34 197 94 / 0.3);
}

[data-theme="dark"] .alert-warning,
body.dark-theme .alert-warning {
  background: rgb(245 158 11 / 0.1);
  border-color: rgb(245 158 11 / 0.3);
}

[data-theme="dark"] .alert-error,
body.dark-theme .alert-error {
  background: rgb(239 68 68 / 0.1);
  border-color: rgb(239 68 68 / 0.3);
}

/* ============================================
   13. COMPONENTS - TABLES
   ============================================ */

.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-default);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.table th,
.table td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
}

.table th {
  font-weight: var(--font-semibold);
  color: var(--text-tertiary);
  background: var(--surface-secondary);
  text-transform: uppercase;
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wide);
}

.table tbody tr:hover {
  background: var(--interactive-hover);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

/* ============================================
   14. COMPONENTS - MODAL
   ============================================ */

/* ============================================
   CALENDAR HABIT CELL GRID LAYOUT
   ============================================ */

.habit-cell-grid {
  display: grid;
  grid-template-columns: 1.1em 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 16px;
  row-gap: 6px;
  align-items: center;
  width: 100%;
}

.habit-icon-wrap {
  grid-column: 1;
  grid-row: 1;
  background: transparent !important;
  padding: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.habit-icon-wrap img,
.habit-icon-wrap svg,
.habit-icon-wrap .habit-icon {
  width: 1.1em !important;
  height: 1.1em !important;
  display: block;
}

.habit-title {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1rem;
  font-weight: 600;
}

.habit-progress-wrap {
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
  align-self: start;
}

.habit-meta-row {
  grid-column: 1 / 3;
  grid-row: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.habit-frequency {
  font-size: 0.9rem;
  color: rgba(255,255,255,0.68);
  font-weight: 500;
  margin: 0 !important;
  padding: 0 !important;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.habit-streak {
  background: transparent !important;
  padding: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  font-size: 0.9rem;
  color: rgba(255,255,255,0.78);
  flex-shrink: 0;
}

/* Icon-only mode: hide meta row */
.icon-only-mode .habit-meta-row {
  display: none;
}

/* rimuove qualunque badge/cerchio dietro l'icona SOLO nella cella abitudine */
.habit-cell-grid .habit-icon-wrap,
.habit-cell-grid .habit-icon-wrap *{
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  outline: 0 !important;
}

/* se qualche elemento applica forma circolare via radius/padding */
.habit-cell-grid .habit-icon-wrap,
.habit-cell-grid .habit-icon-wrap *{
  border-radius: 0 !important;
  padding: 0 !important;
}

/* evita che eventuali pseudo-elementi disegnino il cerchio */
.habit-cell-grid .habit-icon-wrap::before,
.habit-cell-grid .habit-icon-wrap::after,
.habit-cell-grid .habit-icon-wrap *::before,
.habit-cell-grid .habit-icon-wrap *::after{
  content: none !important;
  background: transparent !important;
  box-shadow: none !important;
}

/* Se l'icona è dentro una classe specifica che forza il cerchio */
.habit-cell-grid .habit-icon,
.habit-cell-grid .icon,
.habit-cell-grid .icon-badge{
  background: transparent !important;
  border-radius: 0 !important;
  padding: 0 !important;
  box-shadow: none !important;
}

/* Light theme overrides for frequency and streak colors */
[data-theme="light"] .habit-frequency {
  color: rgba(0,0,0,0.6);
}

[data-theme="light"] .habit-streak {
  color: rgba(0,0,0,0.7);
}

/* ============================================
   ICON-ONLY MODE COLUMN SIZING
   ============================================ */

/* quando icon-only è attivo, la colonna abitudine deve essere stretta */
.calendar-board.icon-only-mode #habit-calendar th.habit-header-cell,
.calendar-board.icon-only-mode #habit-calendar td.habit-name-cell.habit-column-cell {
  width: 64px !important;
  min-width: 64px !important;
  max-width: 64px !important;
}

/* sincronizza anche il colgroup per header/body */
.calendar-board.icon-only-mode #habit-calendar colgroup col.habit-column {
  width: 64px !important;
  min-width: 64px !important;
  max-width: 64px !important;
}

/* Icon-only: riduci padding della colonna sticky */
.calendar-board.icon-only-mode #habit-calendar td.habit-name-cell.habit-column-cell {
  padding-left: 8px !important;
  padding-right: 8px !important;
}

/* in icon-only nascondi titolo/meta/pill e centra l'icona */
.calendar-board.icon-only-mode .habit-title,
.calendar-board.icon-only-mode .habit-meta-row,
.calendar-board.icon-only-mode .habit-progress-wrap {
  display: none !important;
}

.calendar-board.icon-only-mode .habit-cell-grid {
  grid-template-columns: 1fr !important;
  justify-items: center;
}

/* ============================================
   CALENDAR STRUCTURE - OVERFLOW CORRECTIONS
   ============================================ */

/* Container esterno con card e rounding */
.calendar-board {
  border-radius: 16px;
  overflow: hidden; /* clip rounding */
  position: relative;
  isolation: isolate;
}

/* Wrapper che scorre - SOLO orizzontale */
.calendar-wrapper {
  overflow-x: auto;
  overflow-y: hidden; /* VIETATO scroll verticale interno */
  scrollbar-gutter: stable;
  max-height: none; /* Rimuovi eventuali limiti di altezza */
}

/* Tabella */
#habit-calendar {
  border-collapse: separate;
  border-spacing: 0;
  overflow: visible; /* CRITICO: rimuove containing block che blocca sticky */
}

/* ============================================
   STICKY COLUMN - CROSS-BROWSER
   ============================================ */

/* Header colonna abitudini */
#habit-calendar th.habit-header-cell {
  position: sticky;
  left: 0;
  top: 0;
  z-index: 60;
  background: var(--surface-secondary);
  border-top-left-radius: 16px;
}

/* Angolo in alto a destra dell'ultima week-header */
#habit-calendar th.week-header:last-child {
  border-top-right-radius: 16px;
}

/* Body colonna abitudini */
#habit-calendar td.habit-name-cell,
#habit-calendar td.habit-column-cell {
  position: sticky;
  left: 0;
  z-index: 50;
  background: var(--surface-primary);
  contain: layout; /* Aiuta Firefox con sticky in tabelle */
  transform: translateZ(0); /* Forza compositor layer per Firefox */
  will-change: transform; /* Ottimizza Firefox */
}

/* Separatore interno (non esterno per non rompere rounding) */
#habit-calendar th.habit-header-cell,
#habit-calendar td.habit-name-cell,
#habit-calendar td.habit-column-cell {
  box-shadow: inset -1px 0 0 rgba(255,255,255,0.06);
}

/* Bottom-left rounding per ultima riga */
#habit-calendar tbody tr:last-child td.habit-name-cell,
#habit-calendar tbody tr:last-child td.habit-column-cell {
  border-bottom-left-radius: 16px;
}

/* ============================================
   FIREFOX - DISABILITA COMPLETAMENTE STICKY
   ============================================ */

/* Firefox: rimuovi sticky da header e body */
.is-firefox #habit-calendar th.habit-header-cell,
.is-firefox #habit-calendar td.habit-name-cell,
.is-firefox #habit-calendar td.habit-column-cell {
  position: static;
  z-index: auto;
}

/* ============================================
   14. COMPONENTS - MODAL
   ============================================ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(4px);
  z-index: var(--z-modal-backdrop);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-base), visibility var(--transition-base);
}

.modal-backdrop.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  z-index: var(--z-modal);
  width: min(90vw, 500px);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-2xl);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
}

.modal.active {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%) scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
}

.modal-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-tertiary);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background: var(--interactive-hover);
  color: var(--text-primary);
}

.modal-body {
  padding: var(--space-6);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-subtle);
  background: var(--surface-secondary);
}

/* ============================================
   15. COMPONENTS - TOGGLE & SWITCH
   ============================================ */

.toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.toggle-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  width: 44px;
  height: 24px;
  background: var(--surface-tertiary);
  border-radius: var(--radius-full);
  transition: background var(--transition-fast);
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: var(--neutral-0);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast);
}

.toggle-input:checked + .toggle-track {
  background: var(--accent-500);
}

.toggle-input:checked + .toggle-track + .toggle-thumb {
  transform: translateX(20px);
}

.toggle-input:focus-visible + .toggle-track {
  outline: 2px solid var(--interactive-focus);
  outline-offset: 2px;
}

/* ============================================
   16. COMPONENTS - PROGRESS
   ============================================ */

.progress {
  height: 8px;
  background: var(--surface-tertiary);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--accent-500);
  border-radius: var(--radius-full);
  transition: width var(--transition-slow);
}

.progress-sm { height: 4px; }
.progress-lg { height: 12px; }

/* ============================================
   17. UTILITY CLASSES
   ============================================ */

/* Display */
.hidden { display: none !important; }
.block { display: block; }
.inline { display: inline; }
.inline-block { display: inline-block; }
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.grid { display: grid; }

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

/* Spacing */
.m-0 { margin: 0; }
.m-auto { margin: auto; }
.mt-0 { margin-top: 0; }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }
.mx-auto { margin-left: auto; margin-right: auto; }

.p-0 { padding: 0; }
.p-2 { padding: var(--space-2); }
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }
.p-8 { padding: var(--space-8); }
.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }
.px-6 { padding-left: var(--space-6); padding-right: var(--space-6); }
.py-4 { padding-top: var(--space-4); padding-bottom: var(--space-4); }
.py-6 { padding-top: var(--space-6); padding-bottom: var(--space-6); }

/* Text Alignment */
.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }

/* Border Radius */
.rounded-none { border-radius: var(--radius-none); }
.rounded-sm { border-radius: var(--radius-sm); }
.rounded-md { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-xl { border-radius: var(--radius-xl); }
.rounded-2xl { border-radius: var(--radius-2xl); }
.rounded-full { border-radius: var(--radius-full); }

/* Width/Height */
.w-full { width: 100%; }
.h-full { height: 100%; }
.min-h-screen { min-height: 100vh; }

/* Overflow */
.overflow-hidden { overflow: hidden; }
.overflow-auto { overflow: auto; }
.overflow-x-auto { overflow-x: auto; }

/* Position */
.relative { position: relative; }
.absolute { position: absolute; }
.fixed { position: fixed; }
.sticky { position: sticky; }

/* Cursor */
.cursor-pointer { cursor: pointer; }
.cursor-not-allowed { cursor: not-allowed; }

/* Opacity */
.opacity-0 { opacity: 0; }
.opacity-50 { opacity: 0.5; }
.opacity-75 { opacity: 0.75; }
.opacity-100 { opacity: 1; }

/* Transitions */
.transition { transition: all var(--transition-base); }
.transition-fast { transition: all var(--transition-fast); }
.transition-slow { transition: all var(--transition-slow); }

/* Divider */
.divider {
  height: 1px;
  background: var(--border-subtle);
  margin: var(--space-4) 0;
}

/* ============================================
   18. RESPONSIVE BREAKPOINTS
   ============================================ */

/* Mobile First Approach */
/* sm: 640px, md: 768px, lg: 1024px, xl: 1280px, 2xl: 1536px */

@media (max-width: 768px) {
  .app-shell[data-layout="sidebar"] .app-sidebar {
    transform: translateX(-100%);
    transition: transform var(--transition-base);
  }
  
  .app-shell[data-layout="sidebar"] .app-sidebar.open {
    transform: translateX(0);
  }
  
  .app-shell[data-layout="sidebar"] .app-main {
    margin-left: 0;
    width: 100%;
  }
  
  .container {
    padding: var(--space-4);
  }
  
  .page {
    padding: var(--space-4);
  }
  
  .hide-mobile { display: none !important; }
}

@media (min-width: 769px) {
  .hide-desktop { display: none !important; }
}

/* ============================================
   19. ANIMATIONS
   ============================================ */

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

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

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

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

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

.animate-fade-in { animation: fadeIn var(--transition-base) forwards; }
.animate-slide-up { animation: slideUp var(--transition-base) forwards; }
.animate-slide-down { animation: slideDown var(--transition-base) forwards; }
.animate-scale-in { animation: scaleIn var(--transition-base) forwards; }
.animate-pulse { animation: pulse 2s infinite; }
.animate-spin { animation: spin 1s linear infinite; }

/* ============================================
   20. PRINT STYLES
   ============================================ */

@media print {
  .app-header,
  .app-sidebar,
  .btn,
  .no-print {
    display: none !important;
  }
  
  body {
    background: white;
    color: black;
  }
  
  .card {
    box-shadow: none;
    border: 1px solid #ddd;
  }
}

/* ============================================
   21. SHARED LANGUAGE PILL
   ============================================ */

.ks-locale-pill {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 40px;
  padding: 2px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  background: var(--surface-primary);
}

.ks-locale-pill__item {
  min-height: 40px;
  min-width: 68px;
  padding: 0 var(--space-2-5);
  border-radius: var(--radius-full);
  border: 1px solid transparent;
  text-decoration: none;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1-5);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  letter-spacing: 0.02em;
  transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.ks-locale-pill__item:hover {
  color: var(--text-primary);
  background: var(--surface-interactive-hover);
}

.ks-locale-pill__item:focus-visible {
  outline: none;
  border-color: var(--accent-400);
  box-shadow: inset 0 0 0 1px rgba(251, 191, 36, 0.35), 0 0 0 2px rgba(251, 191, 36, 0.18);
}

.ks-locale-pill__item.is-active {
  color: var(--text-primary);
  background: color-mix(in srgb, var(--accent-400) 18%, var(--surface-primary));
  border-color: color-mix(in srgb, var(--accent-500) 45%, var(--border-default));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

.ks-locale-pill__item.is-busy,
.ks-locale-pill__item[aria-disabled="true"] {
  opacity: 0.65;
  pointer-events: none;
}

.ks-locale-pill__flag {
  display: inline-block;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1);
}

.ks-locale-pill__label {
  line-height: 1;
}

.ks-locale-pill--compact .ks-locale-pill__item {
  min-width: 56px;
  padding: 0 var(--space-2);
}

.ks-locale-pill--settings {
  width: 100%;
  justify-content: center;
}

.ks-locale-pill--on-dark {
  background: rgba(10, 10, 12, 0.35);
  border-color: rgba(255, 255, 255, 0.2);
}

.ks-locale-pill--on-dark .ks-locale-pill__item {
  color: rgba(255, 255, 255, 0.82);
}

.ks-locale-pill--on-dark .ks-locale-pill__item:hover {
  color: var(--neutral-50);
  background: rgba(255, 255, 255, 0.08);
}

.ks-locale-pill--on-dark .ks-locale-pill__item.is-active {
  color: var(--neutral-50);
  background: rgba(251, 191, 36, 0.22);
  border-color: rgba(251, 191, 36, 0.45);
}

html[data-theme="dark"] .ks-locale-pill,
:root[data-theme="dark"] .ks-locale-pill,
.dark-theme .ks-locale-pill {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.12);
}

html[data-theme="dark"] .ks-locale-pill__item,
:root[data-theme="dark"] .ks-locale-pill__item,
.dark-theme .ks-locale-pill__item {
  color: rgba(245, 245, 245, 0.88);
}

html[data-theme="dark"] .ks-locale-pill__item:hover,
:root[data-theme="dark"] .ks-locale-pill__item:hover,
.dark-theme .ks-locale-pill__item:hover {
  color: var(--neutral-50);
  background: rgba(255, 255, 255, 0.08);
}

html[data-theme="dark"] .ks-locale-pill__item.is-active,
:root[data-theme="dark"] .ks-locale-pill__item.is-active,
.dark-theme .ks-locale-pill__item.is-active {
  background: rgba(251, 191, 36, 0.2);
  border-color: rgba(251, 191, 36, 0.42);
}
