/**
 * Messor - Main Stylesheet
 * Based on COSTCHEF_STYLE_GUIDE.md
 */

/* ============================================
   CSS Variables - Theme System
   ============================================ */

:root {
    /* Light Theme (Default) */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);

    /* Accent Color (Customizable - overridden by theme from DB) */
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-light: #dbeafe;
    --accent-dark: #1e40af;

    /* Semantic Colors (Fixed - do not change with theme) */
    --success: #22c55e;
    --success-light: #dcfce7;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --info: #3b82f6;
    --info-light: #dbeafe;

    /* Spacing Scale (8px base) */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 2rem;
    --line-height: 1.5;
    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;

    /* Layout */
    --sidebar-width: 260px;
    --topbar-height: 60px;
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-primary: #1e293b;
    --bg-secondary: #0f172a;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #334155;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
    --accent-light: rgba(37, 99, 235, 0.2);
    --success-light: rgba(34, 197, 94, 0.2);
    --warning-light: rgba(245, 158, 11, 0.2);
    --danger-light: rgba(239, 68, 68, 0.2);
    --info-light: rgba(59, 130, 246, 0.2);
}

/* ============================================
   Reset & Base Styles
   ============================================ */

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: var(--line-height);
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    min-height: 100vh;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

img {
    max-width: 100%;
    height: auto;
}

/* ============================================
   Typography
   ============================================ */

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

h1 { font-size: var(--font-size-3xl); }
h2 { font-size: var(--font-size-2xl); }
h3 { font-size: var(--font-size-xl); }
h4 { font-size: var(--font-size-lg); }
h5 { font-size: var(--font-size-base); }
h6 { font-size: var(--font-size-sm); }

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

/* ============================================
   Layout - Sidebar
   ============================================ */

.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform var(--transition-normal);
}

.sidebar-header {
    padding: var(--space-xs) var(--space-md) var(--space-sm);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: flex-end;
    gap: var(--space-sm);
}

.sidebar-header .logo {
    flex: 1;
}

.logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
}

.logo-icon {
    font-size: var(--font-size-2xl);
}

.logo-img {
    height: 100px;
    width: auto;
    object-fit: contain;
}

/* Logo switching for light/dark mode */
.logo-img.logo-dark {
    display: none;
}

html[data-theme="dark"] .logo-img.logo-light {
    display: none;
}

html[data-theme="dark"] .logo-img.logo-dark {
    display: block;
}

.logo-text {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: #5D4037;
    text-align: center;
    letter-spacing: 0.5px;
    margin-top: -20px;
    position: relative;
    z-index: 1;
}

.search-btn {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0.6rem;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1;
}

.search-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent);
}

.logo-text {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
}

.sidebar-close {
    display: none;
    background: none;
    border: none;
    font-size: var(--font-size-xl);
    color: var(--text-secondary);
    cursor: pointer;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-sm);
}

/* Search trigger button in sidebar */
.search-trigger {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    width: 100%;
    padding: 0.35rem var(--space-sm);
    margin-bottom: var(--space-xs);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}
.search-trigger:hover {
    background: var(--bg-tertiary);
    border-color: var(--text-muted);
}
.search-trigger-icon {
    font-size: 1rem;
}
.search-trigger-text {
    flex: 1;
    text-align: left;
}
.search-trigger-kbd {
    background: var(--bg-primary);
    padding: 0.125rem 0.375rem;
    border-radius: var(--radius-sm);
    font-size: 0.625rem;
    font-family: inherit;
    border: 1px solid var(--border-color);
}

/* Hide search trigger text when sidebar is collapsed */
body.sidebar-collapsed .search-trigger {
    justify-content: center;
    padding: var(--space-sm);
}
body.sidebar-collapsed .search-trigger-text,
body.sidebar-collapsed .search-trigger-kbd {
    display: none;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    text-decoration: none;
    transition: all var(--transition-fast);
    margin-bottom: var(--space-xs);
}

.nav-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    text-decoration: none;
}

.nav-item.active {
    background: var(--accent-light);
    color: var(--accent);
}

.nav-icon {
    font-size: var(--font-size-lg);
}

.nav-divider {
    height: 1px;
    background: var(--border-color);
    margin: var(--space-sm) 0;
}

.sidebar-footer {
    padding: var(--space-md);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.user-name {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

/* ============================================
   Layout - Main Content
   ============================================ */

.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    background: var(--bg-secondary);
}

.topbar {
    display: none;
    height: var(--topbar-height);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    padding: 0 var(--space-md);
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
}

.menu-toggle {
    background: none;
    border: none;
    font-size: var(--font-size-xl);
    color: var(--text-primary);
    cursor: pointer;
}

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

.page-content {
    padding: var(--space-lg);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
}

/* Sidebar Collapsed State */
body.sidebar-collapsed .sidebar {
    width: 64px;
    transition: width 0.2s ease;
}
body.sidebar-collapsed .sidebar .logo-text,
body.sidebar-collapsed .sidebar .nav-text,
body.sidebar-collapsed .sidebar .user-name {
    display: none;
}
body.sidebar-collapsed .sidebar .sidebar-header {
    justify-content: center;
    padding: var(--space-sm);
}
body.sidebar-collapsed .sidebar .logo {
    justify-content: center;
    cursor: pointer;
}
body.sidebar-collapsed .sidebar .logo-icon {
    font-size: 1.5rem;
}
body.sidebar-collapsed .sidebar .logo-img {
    height: 32px;
    width: auto;
}
body.sidebar-collapsed .sidebar .logo-text {
    display: none;
}
body.sidebar-collapsed .sidebar .nav-item {
    justify-content: center;
    padding: var(--space-sm);
}
body.sidebar-collapsed .sidebar .nav-icon {
    font-size: var(--font-size-xl);
}
body.sidebar-collapsed .sidebar .sidebar-footer {
    flex-direction: column;
    gap: var(--space-sm);
    padding: var(--space-sm);
}
body.sidebar-collapsed .sidebar .user-menu {
    justify-content: center;
}
body.sidebar-collapsed .sidebar .theme-toggle {
    display: none;
}
body.sidebar-collapsed .main-content {
    margin-left: 64px;
    transition: margin-left 0.2s ease;
}

/* ============================================
   Auth Layout
   ============================================ */

.auth-layout {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-primary) 50%, var(--bg-secondary) 100%);
    position: relative;
    overflow: hidden;
}

/* Decorative background elements */
.auth-layout::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 30% 30%, var(--accent-light) 0%, transparent 40%),
                radial-gradient(circle at 70% 70%, var(--accent-light) 0%, transparent 40%);
    opacity: 0.3;
    animation: authBgPulse 15s ease-in-out infinite;
}

@keyframes authBgPulse {
    0%, 100% { transform: scale(1) rotate(0deg); opacity: 0.3; }
    50% { transform: scale(1.1) rotate(5deg); opacity: 0.2; }
}

.auth-container {
    width: 100%;
    max-width: 420px;
    position: relative;
    z-index: 1;
    animation: authFadeIn 0.6s ease-out;
}

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

.auth-card {
    background: var(--bg-primary);
    border-radius: var(--radius-xl);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15), 0 0 0 1px var(--border-color);
    padding: var(--space-2xl);
    backdrop-filter: blur(10px);
}

[data-theme="dark"] .auth-card {
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.4), 0 0 0 1px var(--border-color);
}

.auth-header {
    text-align: center;
    margin-bottom: var(--space-xl);
}

.auth-logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: var(--space-md);
}

.auth-logo-img {
    height: 120px;
    width: auto;
    object-fit: contain;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.1));
    transition: transform var(--transition-normal);
}

/* Auth logo switching for light/dark mode */
.auth-logo-img.logo-dark {
    display: none;
}

html[data-theme="dark"] .auth-logo-img.logo-light {
    display: none;
}

html[data-theme="dark"] .auth-logo-img.logo-dark {
    display: block;
}

.auth-logo:hover .auth-logo-img {
    transform: scale(1.05);
}

.auth-logo-text {
    font-size: 1.75rem;
    font-weight: var(--font-weight-bold);
    color: #5D4037;
    letter-spacing: 1.5px;
    margin-top: -12px;
    position: relative;
    z-index: 1;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.auth-header h1 {
    margin-bottom: var(--space-xs);
    font-size: var(--font-size-xl);
    color: var(--text-primary);
}

.auth-header p {
    color: var(--text-secondary);
    font-size: var(--font-size-base);
}

/* Flash messages inside auth card */
.auth-flash-messages {
    margin-bottom: var(--space-lg);
}

.auth-flash-messages .alert {
    margin-bottom: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.auth-form .form-input {
    padding: var(--space-md);
    font-size: var(--font-size-base);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.auth-form .form-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.auth-form .btn-primary {
    padding: var(--space-md);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-semibold);
    border-radius: var(--radius-md);
    transition: all var(--transition-normal);
}

.auth-form .btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px -8px var(--accent);
}

.auth-footer {
    margin-top: var(--space-xl);
    padding-top: var(--space-lg);
    border-top: 1px solid var(--border-color);
    text-align: center;
}

.auth-footer .btn-ghost {
    color: var(--text-secondary);
    transition: color var(--transition-fast);
}

.auth-footer .btn-ghost:hover {
    color: var(--accent);
}

/* ============================================
   Forms
   ============================================ */

.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.form-label {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
}

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

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

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

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

.form-check {
    flex-direction: row;
    align-items: center;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    cursor: pointer;
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.checkbox {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

/* ============================================
   Buttons
   ============================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-medium);
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
}

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

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

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

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

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

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
}

.btn-sm {
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-size-sm);
}

.btn-lg {
    padding: var(--space-md) var(--space-lg);
    font-size: var(--font-size-lg);
}

.btn-block {
    width: 100%;
}

/* ============================================
   Cards
   ============================================ */

.card {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

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

.card-header h3 {
    font-size: var(--font-size-lg);
    margin: 0;
}

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

.card-footer {
    padding: var(--space-md);
    border-top: 1px solid var(--border-color);
}

/* ============================================
   Alerts & Flash Messages
   ============================================ */

.flash-messages {
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.alert {
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
}

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

.alert-error {
    background: var(--danger-light);
    color: var(--danger);
}

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

.alert-info {
    background: var(--info-light);
    color: var(--info);
}

.alert-close {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    opacity: 0.7;
}

/* ============================================
   Toast Notifications
   ============================================ */

#toast-container {
    position: fixed;
    bottom: var(--space-lg);
    right: var(--space-lg);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.toast {
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: var(--space-md);
    min-width: 300px;
    max-width: 400px;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    animation: slideIn var(--transition-normal);
}

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

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ============================================
   Dashboard
   ============================================ */

.dashboard {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.welcome-section {
    padding: var(--space-md) 0;
}

.welcome-section h2 {
    margin-bottom: var(--space-xs);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-md);
}

.stat-card {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: var(--space-md);
    display: flex;
    align-items: center;
    gap: var(--space-md);
    border: 1px solid var(--border-color);
}

.stat-icon {
    font-size: 32px;
}

.stat-value {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
}

.stat-label {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

/* Stats Row - flex version */
.stats-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.stats-row-compact {
    gap: var(--space-sm);
    margin-bottom: 0;
}

.stat-card-small {
    padding: var(--space-sm) var(--space-md);
    flex: 1;
    min-width: 100px;
}

.stat-card-small .stat-value {
    font-size: var(--font-size-lg);
}

.stat-card-small .stat-label {
    font-size: var(--font-size-xs);
}

.stat-card-primary {
    background: rgba(37, 99, 235, 0.08);
    border-color: var(--accent);
}

[data-theme="dark"] .stat-card-primary {
    background: rgba(37, 99, 235, 0.15);
}

.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.empty-state {
    text-align: center;
    padding: var(--space-xl);
    color: var(--text-secondary);
}

.empty-icon {
    font-size: 48px;
    display: block;
    margin-bottom: var(--space-sm);
    opacity: 0.5;
}

/* ============================================
   Grid System
   ============================================ */

.grid {
    display: grid;
    gap: var(--space-md);
}

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

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

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

/* ============================================
   Error Pages
   ============================================ */

.error-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--space-lg);
}

.error-content {
    max-width: 400px;
}

.error-code {
    font-size: 120px;
    font-weight: var(--font-weight-bold);
    color: var(--accent);
    line-height: 1;
    display: block;
}

.error-page h1 {
    margin: var(--space-md) 0;
}

.error-page p {
    color: var(--text-secondary);
    margin-bottom: var(--space-lg);
}

/* ============================================
   Theme Toggle Icons
   ============================================ */

[data-theme="light"] .theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: none; }

/* ============================================
   Global Search Modal (Ctrl+K)
   ============================================ */

.search-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding-top: 15vh;
    z-index: 1000;
    backdrop-filter: blur(2px);
}
.search-modal-overlay.active {
    display: flex;
}
.search-modal {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 600px;
    box-shadow: var(--shadow-lg), 0 0 0 1px var(--border-color);
    overflow: hidden;
}
.search-modal-input {
    display: flex;
    align-items: center;
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-color);
    gap: var(--space-sm);
}
.search-modal-icon {
    font-size: 1.25rem;
    opacity: 0.5;
}
.search-modal-input input {
    flex: 1;
    border: none;
    background: none;
    font-size: 1.125rem;
    color: var(--text-primary);
    outline: none;
}
.search-modal-input input::placeholder {
    color: var(--text-muted);
}
.search-modal-kbd {
    background: var(--bg-tertiary);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-family: inherit;
}
.search-modal-results {
    max-height: 400px;
    overflow-y: auto;
}
.search-modal-empty {
    padding: var(--space-lg);
    text-align: center;
    color: var(--text-muted);
}
.search-modal-group {
    padding: var(--space-sm) var(--space-md);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}
.search-modal-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    text-decoration: none;
    color: var(--text-primary);
}
.search-modal-item:hover,
.search-modal-item.selected {
    background: var(--bg-tertiary);
}
.search-modal-item-icon {
    font-size: 1.25rem;
    width: 2rem;
    text-align: center;
}
.search-modal-item-content {
    flex: 1;
    min-width: 0;
}
.search-modal-item-title {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.search-modal-item-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
}
.search-modal-loading {
    padding: var(--space-lg);
    text-align: center;
    color: var(--text-muted);
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-close {
        display: block;
    }

    .sidebar-overlay.open {
        display: block;
    }

    .main-content {
        margin-left: 0;
    }

    .topbar {
        display: flex;
    }

    .page-content {
        padding: var(--space-md);
    }

    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
    }

    #toast-container {
        left: var(--space-md);
        right: var(--space-md);
        bottom: var(--space-md);
    }

    .toast {
        min-width: auto;
        width: 100%;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .auth-card {
        padding: var(--space-lg);
    }

    .quick-actions {
        flex-direction: column;
    }

    .quick-actions .btn {
        width: 100%;
    }
}

/* ============================================
   Modal System
   ============================================ */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: var(--space-md);
}

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

.modal {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-lg {
    max-width: 700px;
}

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

.modal-header h3 {
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    line-height: 1;
}

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

.modal-body {
    padding: var(--space-lg);
    overflow-y: auto;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border-color);
}

@media (max-width: 768px) {
    .modal {
        max-height: 80vh;
        margin: var(--space-md);
    }
}

/* ============================================
   Page Header
   ============================================ */

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-lg);
    flex-wrap: wrap;
    gap: var(--space-md);
}

.page-header-content h1 {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-bold);
    margin-bottom: var(--space-xs);
}

.page-header-actions {
    display: flex;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

@media (max-width: 768px) {
    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .page-header-actions {
        width: 100%;
    }

    .page-header-actions .btn {
        flex: 1;
    }
}

/* ============================================
   Tabs Navigation
   ============================================ */

.tabs {
    display: flex;
    gap: 0;
    margin-bottom: var(--space-lg);
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tab {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: transparent;
    border: none;
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: var(--font-weight-medium);
    font-size: var(--font-size-sm);
    white-space: nowrap;
    cursor: pointer;
    position: relative;
    transition: color var(--transition-fast);
}

.tab:hover {
    color: var(--accent);
    text-decoration: none;
}

.tab.active {
    color: var(--accent);
    font-weight: var(--font-weight-semibold);
}

.tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--accent);
}

.tab .badge {
    margin-left: var(--space-xs);
}

.tab.active .badge {
    background: var(--accent-light);
    color: var(--accent);
}

@media (max-width: 768px) {
    .tab {
        padding: var(--space-sm) var(--space-sm);
        font-size: var(--font-size-xs);
    }
}

/* ============================================
   Tables
   ============================================ */

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

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

.table th,
.table td {
    padding: var(--space-md);
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.table th {
    background: var(--bg-secondary);
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.table tbody tr {
    transition: background var(--transition-fast);
}

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

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

.table .text-right {
    text-align: right;
}

.table td a {
    color: var(--accent);
    text-decoration: none;
    font-weight: var(--font-weight-medium);
}

.table td a:hover {
    text-decoration: underline;
}

@media (max-width: 768px) {
    .table th,
    .table td {
        padding: var(--space-sm);
        font-size: var(--font-size-sm);
    }
}

/* ============================================
   Badges
   ============================================ */

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

.badge-neutral {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

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

.badge-warning {
    background: var(--warning-light);
    color: #92400e;
}

.badge-danger {
    background: var(--danger-light);
    color: #991b1b;
}

.badge-info {
    background: var(--info-light);
    color: #1e40af;
}

[data-theme="dark"] .badge-success {
    color: #4ade80;
}

[data-theme="dark"] .badge-warning {
    color: #fbbf24;
}

[data-theme="dark"] .badge-danger {
    color: #f87171;
}

[data-theme="dark"] .badge-info {
    color: #60a5fa;
}

/* ============================================
   Button Variants
   ============================================ */

.btn-warning {
    background: var(--warning);
    color: white;
}

.btn-warning:hover:not(:disabled) {
    background: #d97706;
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover:not(:disabled) {
    background: #16a34a;
}

.btn-info {
    background: var(--info);
    color: white;
}

.btn-info:hover:not(:disabled) {
    background: #2563eb;
}

/* ============================================
   Upload Zone
   ============================================ */

.upload-zone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--space-2xl);
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    background: var(--bg-primary);
}

.upload-zone:hover,
.upload-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-light);
}

.upload-icon {
    font-size: 48px;
    display: block;
    margin-bottom: var(--space-md);
    opacity: 0.7;
}

.upload-text {
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

.upload-text strong {
    color: var(--accent);
}

.upload-hint {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

/* ============================================
   File List
   ============================================ */

.file-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    margin-top: var(--space-md);
}

.file-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
}

.file-icon {
    font-size: var(--font-size-xl);
}

.file-info {
    flex: 1;
    min-width: 0;
}

.file-name {
    font-weight: var(--font-weight-medium);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-size {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.file-remove {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    padding: var(--space-xs);
    font-size: var(--font-size-lg);
}

/* ============================================
   Calendar View
   ============================================ */

.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-md);
}

.calendar-nav {
    display: flex;
    gap: var(--space-sm);
}

.calendar-title {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.calendar-weekday {
    background: var(--bg-secondary);
    padding: var(--space-sm);
    text-align: center;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    color: var(--text-secondary);
}

.calendar-day {
    background: var(--bg-primary);
    min-height: 100px;
    padding: var(--space-sm);
    position: relative;
}

.calendar-day.other-month {
    background: var(--bg-secondary);
    opacity: 0.5;
}

.calendar-day.today {
    background: var(--accent-light);
}

.calendar-date {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    margin-bottom: var(--space-xs);
}

.calendar-events {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.calendar-event {
    font-size: var(--font-size-xs);
    padding: 2px var(--space-xs);
    border-radius: var(--radius-sm);
    background: var(--accent-light);
    color: var(--accent);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 768px) {
    .calendar-day {
        min-height: 60px;
    }

    .calendar-event {
        display: none;
    }

    .calendar-day.has-events::after {
        content: '';
        position: absolute;
        bottom: var(--space-xs);
        left: 50%;
        transform: translateX(-50%);
        width: 6px;
        height: 6px;
        border-radius: 50%;
        background: var(--accent);
    }
}

/* ============================================
   Invoice Detail View
   ============================================ */

.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--space-lg);
    margin-bottom: var(--space-lg);
    flex-wrap: wrap;
}

.invoice-info h1 {
    font-size: var(--font-size-2xl);
    margin-bottom: var(--space-xs);
}

.invoice-meta {
    display: flex;
    gap: var(--space-md);
    flex-wrap: wrap;
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}

.invoice-meta-item {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.invoice-total {
    text-align: right;
}

.invoice-total-value {
    font-size: var(--font-size-3xl);
    font-weight: var(--font-weight-bold);
    color: var(--accent);
}

.invoice-total-label {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.invoice-grid {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: var(--space-lg);
}

.invoice-image {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: var(--space-md);
    text-align: center;
}

.invoice-image img {
    max-width: 100%;
    border-radius: var(--radius-md);
}

@media (max-width: 1024px) {
    .invoice-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .invoice-header {
        flex-direction: column;
    }

    .invoice-total {
        text-align: left;
    }
}

/* ============================================
   Notifications System
   ============================================ */

.notifications-wrapper {
    position: relative;
}

.notifications-trigger {
    position: relative;
    font-size: 1.25rem;
}

.notifications-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    font-size: 0.625rem;
    font-weight: var(--font-weight-bold);
    line-height: 18px;
    text-align: center;
    color: #fff;
    background: var(--danger);
    border-radius: 9999px;
}

.notifications-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 320px;
    max-height: 400px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    display: none;
    overflow: hidden;
}

.notifications-dropdown.active {
    display: block;
}

.notifications-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--border-color);
    font-weight: var(--font-weight-semibold);
    font-size: var(--font-size-sm);
}

.notifications-list {
    max-height: 350px;
    overflow-y: auto;
}

.notifications-empty {
    padding: var(--space-lg);
    text-align: center;
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}

.notification-item {
    display: flex;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.15s ease;
}

.notification-item:hover {
    background: var(--bg-secondary);
}

.notification-item.unread {
    background: var(--accent-light);
}

.notification-item.unread:hover {
    background: color-mix(in srgb, var(--accent-light) 70%, var(--bg-secondary));
}

.notification-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

.notification-content {
    flex: 1;
    min-width: 0;
}

.notification-title {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
    margin-bottom: 2px;
}

.notification-message {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notification-time {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    margin-top: 4px;
}

.notification-item.success .notification-icon { color: var(--success); }
.notification-item.warning .notification-icon { color: var(--warning); }
.notification-item.error .notification-icon { color: var(--danger); }
.notification-item.info .notification-icon { color: var(--info); }

@media (max-width: 480px) {
    .notifications-dropdown {
        position: fixed;
        top: 60px;
        left: var(--space-sm);
        right: var(--space-sm);
        width: auto;
    }
}

/* ============================================
   Emoji Picker
   ============================================ */

.emoji-picker-modal {
    max-width: 500px;
    width: 90vw;
}

.emoji-search-wrapper {
    margin-bottom: var(--space-md);
}

.emoji-categories {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid var(--border-color);
}

.emoji-category-btn {
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.emoji-category-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.emoji-category-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: var(--space-xs);
    max-height: 300px;
    overflow-y: auto;
    padding: var(--space-xs);
}

.emoji-item {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    background: transparent;
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.emoji-item:hover {
    background: var(--bg-secondary);
    transform: scale(1.15);
}

.emoji-item.selected {
    border-color: var(--accent);
    background: var(--accent-light);
}

.emoji-no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: var(--space-xl);
    color: var(--text-muted);
    font-size: var(--font-size-sm);
}

/* Emoji button trigger (for use in forms) */
.emoji-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    font-size: 24px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.emoji-trigger:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent);
}

@media (max-width: 480px) {
    .emoji-picker-modal {
        width: 95vw;
        max-height: 80vh;
    }

    .emoji-grid {
        grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
        max-height: 200px;
    }

    .emoji-item {
        width: 36px;
        height: 36px;
        font-size: 20px;
    }

    .emoji-category-btn {
        font-size: 10px;
        padding: 4px 8px;
    }
}
