/**
 * ZAKLE - Mobile-First CSS Framework
 * Designed for mobile devices first, scales up to desktop
 * Minimalist, Modern, Touch-Optimized
 */

/* ============================================
   1. MOBILE-FIRST BASE STYLES (320px+)
   ============================================ */

:root {
    /* Colors - Modern, Vibrant Palette */
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --primary-light: #60a5fa;
    --secondary: #8b5cf6;
    --accent: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #06b6d4;

    /* Grays */
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;

    /* Semantic Colors - Light Mode */
    --bg-primary: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-tertiary: #f3f4f6;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-tertiary: #9ca3af;
    --border: #e5e7eb;
    --border-light: #f3f4f6;

    /* Spacing Scale (Mobile-First) */
    --space-1: 0.25rem;  /* 4px */
    --space-2: 0.5rem;   /* 8px */
    --space-3: 0.75rem;  /* 12px */
    --space-4: 1rem;     /* 16px */
    --space-5: 1.25rem;  /* 20px */
    --space-6: 1.5rem;   /* 24px */
    --space-8: 2rem;     /* 32px */
    --space-10: 2.5rem;  /* 40px */
    --space-12: 3rem;    /* 48px */

    /* Typography Scale (Mobile-First) */
    --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 */

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
    --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);

    /* Border Radius */
    --radius-sm: 0.375rem;  /* 6px */
    --radius: 0.5rem;       /* 8px */
    --radius-md: 0.75rem;   /* 12px */
    --radius-lg: 1rem;      /* 16px */
    --radius-full: 9999px;

    /* Transitions */
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: all 0.15s ease;

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

/* Dark Mode Variables */
.dark-mode {
    --bg-primary: #111827;
    --bg-secondary: #1f2937;
    --bg-tertiary: #374151;
    --text-primary: #f9fafb;
    --text-secondary: #d1d5db;
    --text-tertiary: #9ca3af;
    --border: #374151;
    --border-light: #4b5563;
    --primary: #60a5fa;
    --primary-dark: #3b82f6;
    --primary-light: #93c5fd;
}

/* ============================================
   2. RESET & BASE STYLES
   ============================================ */

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

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: var(--text-base);
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    transition: background-color 0.2s, color 0.2s;
}

/* ============================================
   3. MOBILE-FIRST LAYOUT
   ============================================ */

/* Main Content Wrapper */
.main-content-wrapper {
    flex: 1 0 auto;
    width: 100%;
    padding: var(--space-4);
    padding-bottom: 80px; /* Space for mobile bottom nav */
}

.container {
    width: 100%;
    margin: 0 auto;
    padding: 0;
}

/* Mobile-First Grid System */
.grid {
    display: grid;
    gap: var(--space-4);
    grid-template-columns: 1fr;
}

.flex {
    display: flex;
    gap: var(--space-3);
}

.flex-col {
    flex-direction: column;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

/* ============================================
   4. MOBILE NAVIGATION (Bottom Tab Bar)
   ============================================ */

.mobile-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-primary);
    border-top: 1px solid var(--border);
    padding: var(--space-2) 0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: var(--z-fixed);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    height: 70px; /* Fixed height for consistent spacing */
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-2);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: var(--text-xs);
    min-width: 60px;
    transition: var(--transition-fast);
    border-radius: var(--radius);
}

.mobile-nav-item:active {
    background: var(--bg-tertiary);
    transform: scale(0.95);
}

.mobile-nav-item.active {
    color: var(--primary);
}

.mobile-nav-icon {
    font-size: var(--text-xl);
}

/* Add bottom padding on mobile to prevent content/footer overlap */
@media (max-width: 767px) {
    body {
        padding-bottom: 85px; /* Mobile nav height + extra spacing */
    }
}

/* Hide mobile nav on desktop */
.desktop-nav {
    display: none;
}

/* ============================================
   5. CARDS - Primary Mobile UI Pattern
   ============================================ */

.card {
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: var(--transition);
}

.card-interactive {
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(59, 130, 246, 0.1);
}

.card-interactive:active {
    transform: scale(0.98);
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--space-3);
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--border-light);
}

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

.card-body {
    font-size: var(--text-sm);
}

.card-footer {
    margin-top: var(--space-4);
    padding-top: var(--space-3);
    border-top: 1px solid var(--border-light);
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
}

/* ============================================
   6. MOBILE-FIRST BUTTONS
   ============================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    font-size: var(--text-base);
    font-weight: 500;
    line-height: 1.5;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
    min-height: 44px; /* Touch-friendly minimum */
    min-width: 44px;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.btn:active {
    transform: scale(0.97);
}

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

.btn-primary:active {
    background: var(--primary-dark);
}

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

.btn-secondary:active {
    background: var(--gray-300);
}

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

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

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
}

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

.btn-block {
    width: 100%;
    display: flex;
}

.btn-sm {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
    min-height: 36px;
}

.btn-lg {
    padding: var(--space-4) var(--space-6);
    font-size: var(--text-lg);
    min-height: 52px;
}

.btn-icon {
    padding: var(--space-2);
    min-width: 44px;
    min-height: 44px;
}

/* Button Loading State */
.btn-loading {
    position: relative;
    color: transparent;
    pointer-events: none;
}

.btn-loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ============================================
   7. FORM ELEMENTS - Touch-Optimized
   ============================================ */

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

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

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: var(--space-3);
    font-size: var(--text-base);
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-height: 44px; /* Touch-friendly */
    transition: var(--transition);
    -webkit-appearance: none;
    appearance: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

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

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

/* Checkbox & Radio - Touch-Optimized */
.form-checkbox,
.form-radio {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

/* ============================================
   8. MOBILE TABLE PATTERNS
   ============================================ */

/* Hide traditional tables on mobile */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: var(--space-4);
}

.table-traditional {
    display: none; /* Hide on mobile */
}

/* Card-based table for mobile */
.table-cards {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.table-card {
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.table-card-row {
    display: flex;
    justify-content: space-between;
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--border-light);
}

.table-card-row:last-child {
    border-bottom: none;
}

.table-card-label {
    font-weight: 500;
    font-size: var(--text-sm);
    color: var(--text-secondary);
    min-width: 100px;
}

.table-card-value {
    font-size: var(--text-sm);
    color: var(--text-primary);
    text-align: right;
    word-break: break-word;
}

/* ============================================
   9. BADGES & STATUS INDICATORS
   ============================================ */

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

.badge-primary {
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary);
}

.badge-success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--accent);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

.badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* ============================================
   10. PAGE HEADERS - Mobile-First
   ============================================ */

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

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

.page-subtitle {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin-bottom: var(--space-4);
}

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

/* ============================================
   11. ALERTS & NOTIFICATIONS
   ============================================ */

.alert {
    padding: var(--space-4);
    border-radius: var(--radius);
    margin-bottom: var(--space-4);
    border-left: 4px solid;
    font-size: var(--text-sm);
}

.alert-success {
    background: rgba(16, 185, 129, 0.1);
    border-color: var(--accent);
    color: #065f46;
}

.alert-error {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--danger);
    color: #991b1b;
}

.alert-warning {
    background: rgba(245, 158, 11, 0.1);
    border-color: var(--warning);
    color: #92400e;
}

.alert-info {
    background: rgba(6, 182, 212, 0.1);
    border-color: var(--info);
    color: #0e7490;
}

/* ============================================
   12. MODALS - Mobile-Optimized
   ============================================ */

/* Modal backdrop - contains the entire modal */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1040;
    display: none;
    align-items: flex-end;
    justify-content: center;
    overflow-y: auto;
    padding: 1rem;
}

/* Show modal when display:flex is set inline */
.modal-backdrop[style*="flex"] {
    display: flex !important;
}

.modal-backdrop.show {
    display: flex !important;
}

/* Modal container inside backdrop */
.modal {
    display: block !important;
    position: relative;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    visibility: visible;
    opacity: 1;
}

/* Modal content box */
.modal-content {
    background: var(--bg-primary);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    display: flex !important;
    flex-direction: column;
    animation: slideUp 0.3s ease-out forwards !important;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    position: relative;
    z-index: 1050;
    visibility: visible !important;
    opacity: 1;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

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

.modal-title {
    font-size: var(--text-xl);
    font-weight: 600;
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: var(--text-2xl);
    color: var(--text-secondary);
    cursor: pointer;
    padding: var(--space-2);
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.modal-footer {
    padding: var(--space-4);
    border-top: 1px solid var(--border);
    display: flex;
    gap: var(--space-2);
}

/* ============================================
   13. LOADING & SKELETON STATES
   ============================================ */

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.skeleton {
    background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--border-light) 50%, var(--bg-tertiary) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius);
}

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

.skeleton-text {
    height: 1rem;
    margin-bottom: var(--space-2);
}

.skeleton-card {
    height: 120px;
}

/* ============================================
   14. EMPTY STATES
   ============================================ */

.empty-state {
    text-align: center;
    padding: var(--space-8) var(--space-4);
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: var(--space-3);
    opacity: 0.5;
}

.empty-title {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.empty-text {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin-bottom: var(--space-4);
}

/* ============================================
   15. UTILITY CLASSES
   ============================================ */

/* Spacing */
.p-0 { padding: 0; }
.p-2 { padding: var(--space-2); }
.p-3 { padding: var(--space-3); }
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }

.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }

.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

/* Text */
.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }

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

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

.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

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

/* ============================================
   16. TABLET BREAKPOINT (768px+)
   ============================================ */

@media (min-width: 768px) {
    .main-content-wrapper {
        padding: var(--space-6);
    }

    .container {
        max-width: 720px;
    }

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

    .page-title {
        font-size: var(--text-3xl);
    }

    /* Show traditional tables on tablet */
    .table-traditional {
        display: table;
        width: 100%;
        border-collapse: collapse;
    }

    .table-cards {
        display: none; /* Hide card layout on tablet+ */
    }

    /* Desktop navigation appears */
    .mobile-nav {
        display: none;
    }

    .desktop-nav {
        display: flex;
    }

    /* Modals become centered */
    .modal-backdrop {
        align-items: center;
        justify-content: center;
    }

    .modal {
        max-width: 600px;
    }

    .modal-content {
        border-radius: var(--radius-lg);
        animation: scaleIn 0.2s ease-out;
    }

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

/* ============================================
   17. DESKTOP BREAKPOINT (1024px+)
   ============================================ */

@media (min-width: 1024px) {
    .main-content-wrapper {
        padding: var(--space-8);
    }

    .container {
        max-width: 960px;
    }

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

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

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

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

    .btn:hover {
        transform: translateY(-1px);
        box-shadow: var(--shadow);
    }

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

/* ============================================
   18. LARGE DESKTOP BREAKPOINT (1280px+)
   ============================================ */

@media (min-width: 1280px) {
    .container {
        max-width: 1200px;
    }

    .page-title {
        font-size: var(--text-4xl);
    }
}

/* ============================================
   19. PRINT STYLES
   ============================================ */

@media print {
    .mobile-nav,
    .desktop-nav,
    .btn,
    .modal-backdrop,
    .modal {
        display: none !important;
    }

    body {
        background: white;
        color: black;
    }

    .card {
        box-shadow: none;
        border: 1px solid #ccc;
    }
}
