/* ===== CSS VARIABLES ===== */
:root {
    --primary: #b91c1c;
    --primary-hover: #991b1b;
    --primary-light: #fef2f2;
    --bg-color: #f9fafb;
    --card-bg: #ffffff;
    --text-color: #111827;
    --muted-text: #6b7280;
    --border-color: #e5e7eb;
    --hover-bg: rgba(0, 0, 0, 0.04);
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --font-heading: 'Playfair Display', Georgia, serif;
    --font-body: 'Source Sans 3', system-ui, sans-serif;

    /* ===== EXTENDED TOKENS =====
       Many page stylesheets reference these names; previously they were
       undefined and survived only on inline var() fallbacks (or silently
       dropped). Defining them here gives every page one consistent source. */

    /* Aliases for the canonical theme tokens (auto-follow dark mode) */
    --text: var(--text-color);
    --text-muted: var(--muted-text);
    --border: var(--border-color);
    --bg: var(--bg-color);
    --bg-primary: var(--card-bg);
    --surface: var(--card-bg);
    --accent: var(--primary);
    --red: var(--primary);

    /* Secondary surfaces / borders / text */
    --text-secondary: #4b5563;
    --border-strong: #9ca3af;
    --border-hover: #d1d5db;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --col-bg: #f7f6f3;

    /* Neutral scale (Tailwind gray) */
    --neutral-0: #ffffff;
    --neutral-50: #f9fafb;
    --neutral-100: #f3f4f6;
    --neutral-200: #e5e7eb;
    --neutral-300: #d1d5db;
    --neutral-400: #9ca3af;
    --neutral-500: #6b7280;
    --neutral-600: #4b5563;
    --neutral-700: #374151;
    --neutral-900: #111827;

    /* Status / accent colors */
    --red-50: #fef2f2;
    --red-200: #fecaca;
    --green: #16a34a;
    --green-50: #f0fdf4;
    --green-700: #15803d;
    --blue-50: #eff6ff;
    --blue-700: #1d4ed8;
    --amber-50: #fffbeb;
    --amber-700: #b45309;

    /* Sidebar icon text */
    --sidebar-text: var(--muted-text);
    --sidebar-active-text: var(--primary);

    /* Spacing / radius / shadow / motion / extra fonts */
    --space-1: 0.25rem;
    --radius-sm: 0.5rem;
    --radius: 0.75rem;
    --radius-lg: 1rem;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --transition: 0.2s ease;
    --font-sans: var(--font-body);
    --font-mono: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, Consolas, monospace;
}

body[data-theme="dark"] {
    --bg-color: #111827;
    --card-bg: #1f2937;
    --text-color: #f9fafb;
    --muted-text: #9ca3af;
    --border-color: #374151;
    --hover-bg: rgba(255, 255, 255, 0.06);

    /* Dark variants for the static extended tokens (aliases that reference
       --*-color above already adapt automatically). */
    --text-secondary: #9ca3af;
    --border-strong: #4b5563;
    --border-hover: #4b5563;
    --bg-secondary: #1f2937;
    --bg-tertiary: #374151;
    --col-bg: #1f2937;
}

/* ===== RESET ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-body);
    background: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.3s, color 0.3s;
}

/* ===== GLOBAL UI ===== */
.skip-to-content {
    position: absolute;
    top: -100px;
    left: 0;
    background: var(--primary);
    color: white;
    padding: 0.75rem 1rem;
    text-decoration: none;
    border-radius: 0.5rem;
    z-index: 1070;
}

.skip-to-content:focus {
    top: 1rem;
    left: 1rem;
}

/* Mobile menu button hidden by default */
.mobile-menu-toggle {
    position: fixed;
    top: 1rem;
    left: 1rem;
    width: 48px;
    height: 48px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    cursor: pointer;
    z-index: 1001;
}

.mobile-menu-toggle span {
    width: 20px;
    height: 2px;
    background: var(--text-color);
    border-radius: 2px;
    transition: all 0.3s ease;
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.sidebar-backdrop.show {
    opacity: 1;
    pointer-events: auto;
}

/* ===== MOBILE SIDEBAR DRAWER =====
   The desktop sidebar (width/colors) is styled by the page's own CSS
   (e.g. dashboard.css). Here we only add the off-canvas drawer behaviour
   that the hamburger toggle + backdrop in app.js drive. Without these rules
   the toggle did nothing. */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: 0 0 24px rgba(0, 0, 0, 0.18);
    }

    .sidebar.open {
        transform: translateX(0);
    }
}

/* ===== FLASH MESSAGES ===== */
.app-messages {
    max-width: 960px;
    margin: 1rem auto 0;
    padding: 0 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.app-msg {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.9rem;
    border: 1px solid transparent;
    overflow-wrap: break-word;
    word-break: break-word;
}

.app-msg-success { background: #e8f5e9; color: #1b5e20; border-color: #c8e6c9; }
.app-msg-error,
.app-msg-danger  { background: #fdecea; color: #b71c1c; border-color: #f5c6cb; }
.app-msg-warning { background: #fff8e1; color: #8a6d00; border-color: #ffe8a3; }
.app-msg-info,
.app-msg-debug   { background: #eef2ff; color: #3949ab; border-color: #d6dcff; }

body[data-theme="dark"] .app-msg-success { background: rgba(22, 163, 74, 0.15);  color: #4ade80; border-color: rgba(22, 163, 74, 0.3); }
body[data-theme="dark"] .app-msg-error,
body[data-theme="dark"] .app-msg-danger  { background: rgba(220, 38, 38, 0.15);  color: #f87171; border-color: rgba(220, 38, 38, 0.3); }
body[data-theme="dark"] .app-msg-warning { background: rgba(245, 158, 11, 0.15);  color: #fbbf24; border-color: rgba(245, 158, 11, 0.3); }
body[data-theme="dark"] .app-msg-info,
body[data-theme="dark"] .app-msg-debug   { background: rgba(37, 99, 235, 0.15);   color: #93c5fd; border-color: rgba(37, 99, 235, 0.3); }

/* ===== ACCESSIBILITY ===== */

/* Visible keyboard-focus indicator (only shown for keyboard navigation). */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Respect the user's reduced-motion preference. */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ===== CONFIRM DIALOG ===== */
.app-confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 1080;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.app-confirm-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.app-confirm-box {
    background: var(--card-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
    max-width: 400px;
    width: 100%;
    padding: 1.5rem;
}

.app-confirm-msg {
    font-size: 1rem;
    line-height: 1.5;
    margin-bottom: 1.25rem;
}

.app-confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.app-confirm-actions button {
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--border-color);
    min-height: 40px;
}

.app-confirm-cancel {
    background: var(--card-bg);
    color: var(--text-color);
}

.app-confirm-cancel:hover {
    background: var(--hover-bg);
}

.app-confirm-ok {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.app-confirm-ok:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}