/* ========================================
   RESPONSIVE DESIGN - GLOBAL STYLES
   Mobile-First Approach for All Pages
   ======================================== */

/* ========================================
   TABLET & LARGE MOBILE (max-width: 1024px)
   ======================================== */
@media (max-width: 1024px) {
    /* Dashboard Grid Adjustments */
    .stats-grid,
    .usage-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }
    
    /* Table Adjustments */
    table {
        font-size: 0.9rem;
    }
    
    th, td {
        padding: 0.75rem;
    }
}

/* ========================================
   MOBILE & SMALL TABLETS (max-width: 768px)
   ======================================== */
@media (max-width: 768px) {
    /* ========== DASHBOARD ========== */
    .stats-grid,
    .usage-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    .stat-card,
    .usage-card {
        padding: 1rem;
    }
    
    /* ========== TABLES ========== */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }
    
    thead {
        display: none; /* Hide headers on mobile, use cards instead */
    }
    
    tbody,
    tr {
        display: block;
    }
    
    tr {
        margin-bottom: 1rem;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        padding: 1rem;
        background: var(--card-bg);
    }
    
    td {
        display: flex;
        justify-content: space-between;
        padding: 0.5rem 0;
        border: none;
    }
    
    td:before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        margin-right: 1rem;
    }
    
    /* ========== FORMS ========== */
    form .form-group {
        margin-bottom: 1.5rem;
    }
    
    label {
        font-size: 0.95rem;
        margin-bottom: 0.5rem;
        display: block;
    }
    
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px !important; /* Prevents iOS zoom */
        padding: 0.875rem;
        width: 100%;
        border-radius: 8px;
        min-height: 48px;
    }
    
    /* ========== BUTTONS ========== */
    .btn,
    button[type="submit"],
    a.btn {
        width: 100%;
        padding: 1rem;
        font-size: 1rem;
        min-height: 48px;
        text-align: center;
        justify-content: center;
    }
    
    .btn-group {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .btn-group .btn {
        width: 100%;
    }
    
    /* ========== MODALS ========== */
    .modal-content {
        width: 95%;
        max-width: 100%;
        margin: 1rem;
        padding: 1.5rem;
        border-radius: 16px;
    }
    
    .modal-header h2 {
        font-size: 1.25rem;
    }
    
    /* ========== CARDS ========== */
    .card-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    /* ========== SETTINGS PAGE ========== */
    .settings-section {
        padding: 1rem;
        margin-bottom: 1rem;
    }
    
    .settings-section h3 {
        font-size: 1.1rem;
    }
    
    /* ========== HISTORY PAGE ========== */
    .history-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
    
    .history-actions {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .history-actions .btn {
        width: 100%;
    }
    
    /* ========== BATCH PROCESSING ========== */
    .batch-status-grid {
        grid-template-columns: 1fr;
    }
    
    .batch-file-list {
        max-height: 400px;
    }
    
    /* ========== USAGE DASHBOARD ========== */
    .usage-meter {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .usage-bar {
        width: 100%;
    }
    
    /* ========== RULES DASHBOARD ========== */
    .rule-card {
        padding: 1rem;
    }
    
    .rule-actions {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .rule-actions .btn {
        width: 100%;
    }
    
    /* ========== NAVIGATION ========== */
    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }
    
    .tab {
        font-size: 0.9rem;
        padding: 0.75rem 1rem;
    }
    
    /* ========== ALERTS & NOTIFICATIONS ========== */
    .alert {
        padding: 1rem;
        font-size: 0.9rem;
    }
    
    .notification {
        padding: 0.875rem;
        font-size: 0.9rem;
    }
    
    /* ========== FOOTER ========== */
    footer {
        padding: 2rem 1rem;
    }
    
    .footer-content {
        flex-direction: column;
        text-align: center;
        gap: 1.5rem;
    }
}

/* ========================================
   SMALL MOBILE (max-width: 480px)
   ======================================== */
@media (max-width: 480px) {
    /* Further reduce font sizes */
    body {
        font-size: 14px;
    }
    
    h1 {
        font-size: 1.5rem;
    }
    
    h2 {
        font-size: 1.25rem;
    }
    
    h3 {
        font-size: 1.1rem;
    }
    
    /* Smaller cards */
    .card,
    .stat-card,
    .usage-card {
        padding: 0.875rem;
    }
    
    /* Compact buttons */
    .btn {
        padding: 0.875rem;
        font-size: 0.95rem;
    }
    
    /* Smaller inputs */
    input,
    select,
    textarea {
        padding: 0.75rem;
    }
    
    /* Modal adjustments */
    .modal-content {
        padding: 1rem;
        margin: 0.5rem;
    }
}

/* ========================================
   LANDSCAPE ORIENTATION (Mobile)
   ======================================== */
@media (max-height: 500px) and (orientation: landscape) {
    .modal-content {
        max-height: 90vh;
        overflow-y: auto;
    }
    
    .sidebar {
        max-height: 100vh;
        overflow-y: auto;
    }
}

/* ========================================
   TOUCH DEVICE OPTIMIZATIONS
   ======================================== */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    a,
    button,
    input[type="button"],
    input[type="submit"],
    .btn {
        min-height: 44px; /* Apple's minimum touch target */
        min-width: 44px;
    }
    
    /* Remove hover effects on touch devices */
    .btn:hover,
    a:hover {
        transform: none;
    }
    
    /* Active state for touch feedback */
    .btn:active,
    button:active {
        opacity: 0.8;
        transform: scale(0.98);
    }
}

/* ========================================
   HOME PAGE SPECIFIC - RESPONSIVE
   ======================================== */

/* Extract Button - CRITICAL: Always Visible and Accessible */
.btn-extract {
    margin-top: 1.5rem !important;
    width: 100%;
    display: flex !important;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative !important;
    z-index: 10 !important;
}

/* Processing Indicator */
.processing-indicator {
    display: none;
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
    border-left: 3px solid var(--accent-blue);
}

.indicator-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.indicator-content .icon {
    color: var(--accent-green);
}

/* OCR Toggle */
.ocr-toggle-container {
    display: none;
    margin-top: 1rem;
    padding: 1rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.ocr-toggle-flex {
    flex: 1;
}

.ocr-label-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.ocr-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-primary);
}

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

.ocr-label .icon {
    color: var(--accent-blue);
}

.ocr-description {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-left: 2rem;
}

.ocr-description p {
    margin: 0 0 0.5rem 0;
}

.ocr-description p:last-child {
    margin: 0;
}

.ocr-recommendation {
    display: none;
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: rgba(255, 204, 0, 0.1);
    border: 1px solid rgba(255, 204, 0, 0.3);
    border-radius: 6px;
}

.recommendation-content {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.recommendation-content .icon {
    color: #ffcc00;
}

@media (max-width: 768px) {
    .ocr-description {
        margin-left: 0;
        margin-top: 0.5rem;
        font-size: 0.8rem;
    }
}

/* ========================================
   PRINT STYLES
   ======================================== */
@media print {
    .sidebar,
    .mobile-menu-toggle,
    header,
    footer,
    .btn,
    .no-print {
        display: none !important;
    }
    
    .main-content {
        margin: 0;
        width: 100%;
    }
    
    .card {
        page-break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc;
    }
}
