/* ============================================
   EXCALIBUR UNIFIED THEME
   Consistent styling across all pages
   ============================================ */

/* Color Palette - Dark Theme (Default) */
:root,
[data-theme="dark"] {
    /* Background Colors */
    --bg-primary: #0F0F11;
    --bg-secondary: #161616;
    --bg-tertiary: #1C1C1C;
    --bg-accent: #3a3a3a;
    --bg-surface: #2a2a2a;
    
    /* Text Colors */
    --text-primary: #ECE9E1;
    --text-secondary: #BDB8AA;
    --text-muted: #666;
    
    /* Brand Colors */
    --primary: #F0E68C;
    --primary-dark: #C6A24D;
    --primary-hover: #f5d657;
    --accent-gold: #C6A24D;
    
    /* Semantic Colors */
    --success: #6ED8A3;
    --warning: #F1B24A;
    --error: #FF6B6B;
    --danger: #FF6B6B;
    --info: #3498db;
    
    /* Border & Dividers */
    --border: #444;
    --border-color: #2A2A2A;
    --border-light: #555;
    
    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 20px rgba(240, 230, 140, 0.3);
    
    /* Spacing */
    --radius: 8px;
    --radius-sm: 4px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

/* Light Theme */
[data-theme="light"] {
    /* Background Colors */
    --bg-primary: #FFFFFF;
    --bg-secondary: #F8F9FA;
    --bg-tertiary: #E9ECEF;
    --bg-accent: #E9ECEF;
    --bg-surface: #FFFFFF;
    
    /* Text Colors */
    --text-primary: #212529;
    --text-secondary: #6C757D;
    --text-muted: #ADB5BD;
    
    /* Brand Colors */
    --primary: #C6A24D;
    --primary-dark: #A88936;
    --primary-hover: #D4B25F;
    --accent-gold: #A88936;
    
    /* Semantic Colors */
    --success: #2D9F6B;
    --warning: #D89B2A;
    --error: #DC3545;
    --danger: #DC3545;
    --info: #0D6EFD;
    
    /* Border & Dividers */
    --border: #DEE2E6;
    --border-color: #DEE2E6;
    --border-light: #E9ECEF;
    
    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.12);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.16);
    --shadow-glow: 0 0 20px rgba(198, 162, 77, 0.2);
    
    /* Spacing */
    --radius: 8px;
    --radius-sm: 4px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

/* Smooth theme transitions */
* {
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* Accessibility - Reduce motion for users who prefer it */
@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;
    }
}

/* Base Styles */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.75; /* Increased from 1.6 for better readability */
    min-height: 100vh;
    font-size: 16px; /* Increased from 14px for accessibility */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    margin: 0 0 1rem 0;
    font-weight: 600;
    line-height: 1.2;
    color: var(--text-primary);
}

h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.25rem; }
h5 { font-size: 1rem; }
h6 { font-size: 0.875rem; }

p {
    margin: 0 0 1rem 0;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Layout Utilities */
.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    width: 100%;
}

.center {
    text-align: center;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 2rem; /* Increased from 1.5rem for better visual separation */
}

.cluster {
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem; /* Increased from 1rem for better spacing */
    align-items: center;
}

.grid {
    display: grid;
    gap: 2rem; /* Increased from 1.5rem for better visual breathing room */
}

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

/* Cards */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem; /* Increased from 1.5rem for more breathing room */
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s ease;
}

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

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.875rem 1.75rem; /* Increased from 0.75rem 1.5rem for larger touch targets */
    font-size: 0.9375rem; /* Slightly increased from 0.875rem */
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease;
    white-space: nowrap;
    min-height: 44px; /* Ensure minimum touch target size for accessibility */
}

.btn:hover {
    background: var(--bg-accent);
    border-color: var(--primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.btn:focus {
    outline: 3px solid var(--primary); /* Increased from 2px for better visibility */
    outline-offset: 3px; /* Increased from 2px */
}

.btn:focus:not(:focus-visible) {
    outline: none;
}

.btn:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 3px;
}

.btn:active {
    transform: translateY(0);
}

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

.btn-primary {
    background: var(--primary);
    color: #000000;
    border-color: var(--primary);
    font-weight: 600;
}

.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: #000000;
}

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

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

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

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

/* Forms */
.input,
input[type="text"],
input[type="email"],
input[type="number"],
input[type="tel"],
input[type="url"],
input[type="password"],
input[type="search"],
input[type="date"],
input[type="datetime-local"],
textarea,
select {
    width: 100%;
    padding: 0.875rem; /* Increased from 0.75rem for better usability */
    font-size: 1rem; /* Increased from 0.875rem to match body text */
    font-family: inherit;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 2px solid var(--border); /* Increased from 1px for better visibility */
    border-radius: var(--radius-sm);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    min-height: 44px; /* Ensure minimum touch target size */
}

.input:focus,
input:focus,
textarea:focus,
select:focus {
    outline: 3px solid var(--primary); /* Added visible outline */
    outline-offset: 2px;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(244, 208, 63, 0.15); /* Increased from 3px to 4px */
}

.input:disabled,
input:disabled,
textarea:disabled,
select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

label {
    display: block;
    font-size: 0.9375rem; /* Increased from 0.875rem */
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.625rem; /* Increased from 0.5rem */
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

thead {
    background: var(--bg-accent);
    border-bottom: 2px solid var(--border);
}

th {
    padding: 0.75rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
}

td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
}

tbody tr {
    transition: background-color 0.2s ease;
}

tbody tr:hover {
    background-color: var(--bg-accent);
}

/* Text Utilities */
.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.875rem; }
.text-base { font-size: 1rem; }
.text-lg { font-size: 1.125rem; }
.text-xl { font-size: 1.25rem; }
.text-2xl { font-size: 1.5rem; }
.text-3xl { font-size: 1.875rem; }
.text-4xl { font-size: 2.25rem; }

.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--primary); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-error { color: var(--error); }
.text-info { color: var(--info); }

.font-bold { font-weight: 600; }
.font-normal { font-weight: 400; }
.uppercase { text-transform: uppercase; }

/* Spacing Utilities */
.m-0 { margin: 0; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.mb-8 { margin-bottom: 2rem; }

.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }

.p-2 { padding: 0.5rem; }
.p-4 { padding: 1rem; }
.p-6 { padding: 1.5rem; }
.p-8 { padding: 2rem; }

.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.py-4 { padding-top: 1rem; padding-bottom: 1rem; }
.py-8 { padding-top: 2rem; padding-bottom: 2rem; }

.px-2 { padding-left: 0.5rem; padding-right: 0.5rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.px-6 { padding-left: 1.5rem; padding-right: 1.5rem; }

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

.flex-col { flex-direction: column; }
.flex-row { flex-direction: row; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }

.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }

.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }

.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-4 { gap: 1rem; }
.gap-6 { gap: 1.5rem; }
.gap-8 { gap: 2rem; }

/* Width Utilities */
.w-full { width: 100%; }
.w-auto { width: auto; }

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

/* Z-Index */
.z-10 { z-index: 10; }
.z-50 { z-index: 50; }
.z-1000 { z-index: 1000; }

/* Border Utilities */
.border { border: 1px solid var(--border); }
.border-b { border-bottom: 1px solid var(--border); }
.border-b-2 { border-bottom: 2px solid var(--border); }
.rounded { border-radius: var(--radius-sm); }
.rounded-lg { border-radius: var(--radius); }
.rounded-full { border-radius: 9999px; }

/* Background Utilities */
.bg-primary { background-color: var(--bg-primary); }
.bg-secondary { background-color: var(--bg-secondary); }
.bg-accent { background-color: var(--bg-accent); }
.bg-success { background-color: var(--success); }
.bg-warning { background-color: var(--warning); }
.bg-error { background-color: var(--error); }
.bg-info { background-color: var(--info); }

/* Loading States */
.spinner {
    width: 3rem;
    height: 3rem;
    border: 3px solid var(--bg-accent);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

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

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

/* Accessibility */
.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;
}

.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--primary);
    color: var(--bg-primary);
    padding: 8px;
    z-index: 100;
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-weight: bold;
}

.skip-link:focus {
    top: 6px;
}

/* Focus Styles */
button:focus,
a:focus,
input:focus,
select:focus,
textarea:focus,
[tabindex]:not([tabindex="-1"]):focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* High Contrast Mode Support */
@media (forced-colors: active) {
    :root {
        --primary: Highlight;
        --border: ButtonText;
        --text-primary: ButtonText;
        --bg-primary: ButtonFace;
    }
    
    .card, .btn, input, select, textarea {
        border: 1px solid ButtonText;
    }
}

/* Responsive Design */
@media (max-width: 640px) {
    .container {
        padding: 0 0.5rem;
    }
    
    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.25rem; }
    h3 { font-size: 1.1rem; }
    
    .card {
        padding: 0.75rem;
    }
    
    .btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.7rem;
        gap: 0.25rem;
    }
    
    .btn span:not([aria-hidden]) {
        display: none; /* Hide button text on mobile, keep icons */
    }
    
    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
    }
    
    /* Mobile-specific table styles */
    table {
        font-size: 0.75rem;
    }
    
    table th,
    table td {
        padding: 0.5rem 0.25rem;
    }
    
    /* Stack form elements vertically on mobile */
    form .flex,
    form .cluster {
        flex-direction: column;
        align-items: stretch;
    }
    
    /* Make inputs full width on mobile */
    input, select, textarea {
        width: 100% !important;
    }
    
    /* Adjust header for mobile */
    header {
        padding: 0.5rem !important;
        gap: 0.25rem !important;
    }
    
    header nav {
        gap: 0.25rem !important;
    }
    
    /* Hide less important columns in tables on mobile */
    .hide-mobile {
        display: none !important;
    }
    
    /* Make charts responsive */
    canvas {
        max-width: 100%;
        height: auto !important;
    }
}

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

@media (min-width: 1024px) {
    .container {
        padding: 0 2rem;
    }
}

/* ============================================
   ACCESSIBILITY ENHANCEMENTS
   ============================================ */

/* Skip to main content link for keyboard navigation */
.skip-to-main {
    position: absolute;
    left: -9999px;
    z-index: 999;
    padding: 1em;
    background-color: var(--primary);
    color: #000;
    text-decoration: none;
    font-weight: 600;
}

.skip-to-main:focus {
    left: 50%;
    transform: translateX(-50%);
    top: 1rem;
}

/* Screen reader only content */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Focus visible styles for keyboard navigation */
*:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 3px;
    border-radius: 2px;
}

/* Remove focus outline for mouse users */
*:focus:not(:focus-visible) {
    outline: none;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border: #000;
        --text-primary: #000;
        --bg-primary: #fff;
    }
    
    [data-theme="dark"] {
        --border: #fff;
        --text-primary: #fff;
        --bg-primary: #000;
    }
    
    .btn {
        border-width: 2px;
    }
    
    input, select, textarea {
        border-width: 3px;
    }
}

/* Ensure interactive elements have sufficient size */
a, button, input, select, textarea {
    min-height: 44px;
    min-width: 44px;
}

/* Better link styling for accessibility */
a:focus,
a:hover {
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
}

/* Improved table accessibility */
table caption {
    font-weight: 600;
    text-align: left;
    padding: 0.75rem;
    color: var(--text-primary);
}

/* Form error states */
.input-error,
input:invalid:not(:placeholder-shown) {
    border-color: var(--error);
}

.input-error:focus,
input:invalid:not(:placeholder-shown):focus {
    outline-color: var(--error);
    box-shadow: 0 0 0 4px rgba(255, 107, 107, 0.15);
}

.error-message {
    color: var(--error);
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* Success states */
.input-success {
    border-color: var(--success);
}

.success-message {
    color: var(--success);
    font-size: 0.875rem;
    margin-top: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* Loading states */
.loading {
    position: relative;
    pointer-events: none;
    opacity: 0.6;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid var(--primary);
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 0.6s linear infinite;
}

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

/* Disabled state improvements */
[disabled],
[aria-disabled="true"] {
    cursor: not-allowed;
    opacity: 0.6;
}

/* Print Styles */
@media print {
    body {
        background: white;
        color: black;
    }
    
    .btn, .skip-link {
        display: none;
    }
    
    .card {
        border: 1px solid #ccc;
        box-shadow: none;
    }
}
