/* =============================================================================
   Band Leader App - IBA Design System Styles
   Matches admin-v2, iba-invoice-portal, and availability-form styling
   Supports automatic light/dark mode based on device settings
   ============================================================================= */

/* ============================================================================
   DESIGN TOKENS - Light Mode (Default)
   ============================================================================ */

:root {
    /* Primary colors - IBA brand */
    --color-primary: #c82333;
    --color-primary-hover: #a71d2a;
    --primary-light: rgba(200, 35, 51, 0.12);
    --primary-glow: rgba(200, 35, 51, 0.25);

    /* Semantic colors */
    --color-success: #16a34a;
    --color-success-light: rgba(22, 163, 74, 0.12);
    --color-warning: #d97706;
    --color-warning-light: rgba(217, 119, 6, 0.12);
    --color-danger: #dc2626;
    --color-danger-light: rgba(220, 38, 38, 0.12);
    --color-info: #2563eb;
    --color-info-light: rgba(37, 99, 235, 0.12);

    /* Light theme surfaces */
    --bg-base: #f8f9fa;
    --bg-surface: #ffffff;
    --bg-surface-2: #f3f4f6;
    --bg-surface-3: #e5e7eb;
    --bg-surface-hover: #d1d5db;

    /* Text colors - Light mode */
    --text-primary: #111827;
    --text-secondary: #374151;
    --text-muted: #6b7280;

    /* Border colors - Light mode */
    --border-subtle: #d1d5db;
    --border-color: rgba(200, 35, 51, 0.2);

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

    /* Spacing Scale (4px base) */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;

    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-full: 9999px;

    /* Shadows - Light mode */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    --shadow-glow: 0 0 20px var(--primary-glow);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 200ms ease;
    --transition-slow: 300ms ease;

    /* Modal overlay */
    --modal-overlay: rgba(0, 0, 0, 0.5);
}

/* ============================================================================
   DESIGN TOKENS - Dark Mode (Matches admin-v2)
   Applied via class (.dark) or media query as fallback
   ============================================================================ */

/* Dark mode via class (manual toggle) */
html.dark {
    --color-success: #22c55e;
    --color-success-light: rgba(34, 197, 94, 0.15);
    --color-warning: #f59e0b;
    --color-warning-light: rgba(245, 158, 11, 0.15);
    --color-danger: #ef4444;
    --color-danger-light: rgba(239, 68, 68, 0.15);
    --color-info: #3b82f6;
    --color-info-light: rgba(59, 130, 246, 0.15);

    --bg-base: #0d0d0d;
    --bg-surface: #1a1a1a;
    --bg-surface-2: #2d2d2d;
    --bg-surface-3: #3d3d3d;
    --bg-surface-hover: #4d4d4d;

    --text-primary: #ffffff;
    --text-secondary: #e0e0e0;
    --text-muted: #888888;

    --border-subtle: #3d3d3d;

    --primary-light: rgba(200, 35, 51, 0.15);
    --primary-glow: rgba(200, 35, 51, 0.3);

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.3);

    --modal-overlay: rgba(0, 0, 0, 0.7);
}

html.dark body {
    background: linear-gradient(135deg, #0d0d0d 0%, #1a0a0c 100%);
}

/* Dark mode via media query (system preference fallback when no class set) */
@media (prefers-color-scheme: dark) {
    html:not(.light):not(.dark) {
        --color-success: #22c55e;
        --color-success-light: rgba(34, 197, 94, 0.15);
        --color-warning: #f59e0b;
        --color-warning-light: rgba(245, 158, 11, 0.15);
        --color-danger: #ef4444;
        --color-danger-light: rgba(239, 68, 68, 0.15);
        --color-info: #3b82f6;
        --color-info-light: rgba(59, 130, 246, 0.15);

        --bg-base: #0d0d0d;
        --bg-surface: #1a1a1a;
        --bg-surface-2: #2d2d2d;
        --bg-surface-3: #3d3d3d;
        --bg-surface-hover: #4d4d4d;

        --text-primary: #ffffff;
        --text-secondary: #e0e0e0;
        --text-muted: #888888;

        --border-subtle: #3d3d3d;

        --primary-light: rgba(200, 35, 51, 0.15);
        --primary-glow: rgba(200, 35, 51, 0.3);

        --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
        --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
        --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
        --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.3);

        --modal-overlay: rgba(0, 0, 0, 0.7);
    }

    html:not(.light):not(.dark) body {
        background: linear-gradient(135deg, #0d0d0d 0%, #1a0a0c 100%);
    }
}

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

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

html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: var(--bg-base);
    color: var(--text-secondary);
}

/* Touch-friendly inputs */
input, button, select, textarea {
    font-size: 16px; /* Prevents iOS zoom on focus */
    font-family: inherit;
}

button {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* =============================================================================
   Custom Scrollbar
   ============================================================================= */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-surface-2);
}

::-webkit-scrollbar-thumb {
    background: var(--border-subtle);
    border-radius: 4px;
}

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

/* =============================================================================
   Alpine.js Utilities
   ============================================================================= */

[x-cloak] {
    display: none !important;
}

/* =============================================================================
   Focus Styles
   ============================================================================= */

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

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

/* =============================================================================
   Animations
   ============================================================================= */

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

.animate-spin {
    animation: spin 1s linear infinite;
}

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

/* =============================================================================
   Safe Area Padding
   ============================================================================= */

@supports (padding-top: env(safe-area-inset-top)) {
    header {
        padding-top: env(safe-area-inset-top);
    }

    .fixed.bottom-20 {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* =============================================================================
   Modal & Backdrop
   ============================================================================= */

@supports (backdrop-filter: blur(8px)) {
    .bg-black\/70 {
        backdrop-filter: blur(8px);
    }
}

/* =============================================================================
   Prevent Pull-to-Refresh
   ============================================================================= */

body {
    overscroll-behavior-y: contain;
}

/* =============================================================================
   Interactive States
   ============================================================================= */

/* Card press effect */
.bg-surface-2:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
}

/* Button press effect */
button:active:not(:disabled) {
    transform: scale(0.96);
    transition: transform 0.1s ease;
}

/* =============================================================================
   Form Elements
   ============================================================================= */

/* Checkbox styling */
input[type="checkbox"] {
    cursor: pointer;
    accent-color: var(--color-primary);
}

input[type="checkbox"]:checked {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
}

/* Select dropdown styling */
select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 20px;
    padding-right: 44px;
}

/* Dark mode select arrow - class-based */
html.dark select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23888888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

/* Dark mode select arrow - media query fallback */
@media (prefers-color-scheme: dark) {
    html:not(.light):not(.dark) select {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23888888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    }
}

select option {
    background-color: var(--bg-surface-2);
    color: var(--text-primary);
}

/* Autofill handling */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
select:-webkit-autofill,
select:-webkit-autofill:hover,
select:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--text-primary);
    -webkit-box-shadow: 0 0 0px 1000px var(--bg-surface) inset;
    transition: background-color 5000s ease-in-out 0s;
}

/* =============================================================================
   Transition Utilities
   ============================================================================= */

.transition {
    transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter;
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    transition-duration: 150ms;
}

.transition-all {
    transition-property: all;
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    transition-duration: 200ms;
}

/* =============================================================================
   Text Utilities
   ============================================================================= */

.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* =============================================================================
   Loading Skeleton
   ============================================================================= */

.skeleton {
    background: linear-gradient(
        90deg,
        rgba(0, 0, 0, 0.06) 25%,
        rgba(0, 0, 0, 0.1) 50%,
        rgba(0, 0, 0, 0.06) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
}

/* Dark mode skeleton - class-based */
html.dark .skeleton {
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.05) 25%,
        rgba(255, 255, 255, 0.1) 50%,
        rgba(255, 255, 255, 0.05) 75%
    );
    background-size: 200% 100%;
}

/* Dark mode skeleton - media query fallback */
@media (prefers-color-scheme: dark) {
    html:not(.light):not(.dark) .skeleton {
        background: linear-gradient(
            90deg,
            rgba(255, 255, 255, 0.05) 25%,
            rgba(255, 255, 255, 0.1) 50%,
            rgba(255, 255, 255, 0.05) 75%
        );
        background-size: 200% 100%;
    }
}

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

/* =============================================================================
   Bottom Sheet Modal (Mobile)
   ============================================================================= */

@media (max-width: 639px) {
    .max-h-\[90vh\] {
        max-height: 90vh;
        max-height: 90dvh;
    }

    .max-h-\[80vh\] {
        max-height: 80vh;
        max-height: 80dvh;
    }
}

/* =============================================================================
   Touch Targets
   ============================================================================= */

button, a, [role="button"] {
    min-height: 44px;
    min-width: 44px;
}

button.inline, a.inline {
    min-height: auto;
    min-width: auto;
}

/* =============================================================================
   Header Shadow on Scroll
   ============================================================================= */

header.scrolled {
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

/* =============================================================================
   Availability Status Badges
   ============================================================================= */

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

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

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

/* =============================================================================
   Primary Button Gradient
   ============================================================================= */

.btn-primary-gradient {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-hover) 100%);
    color: white;
    font-weight: 600;
    transition: all var(--transition-normal);
}

.btn-primary-gradient:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px var(--primary-glow);
}

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

/* =============================================================================
   Card Hover Effects
   ============================================================================= */

.card-hover {
    transition: all var(--transition-normal);
}

.card-hover:hover {
    border-color: rgba(200, 35, 51, 0.5);
    box-shadow: 0 4px 20px rgba(200, 35, 51, 0.1);
    transform: translateY(-2px);
}

/* =============================================================================
   Mobile Modal Swipe Gestures
   ============================================================================= */

/* Smooth transition when releasing swipe */
.modal-swipeable {
    transition: transform 0.2s ease-out;
}

.modal-swipeable.dragging {
    transition: none;
}

/* Swipe handle animation */
.swipe-handle {
    transition: opacity 0.2s ease;
}

.swipe-handle:active {
    opacity: 0.7;
}

/* =============================================================================
   Print Styles
   ============================================================================= */

@media print {
    header,
    footer,
    .fixed {
        display: none !important;
    }

    body {
        background: white;
        color: black;
    }
}
