/* ==========================================
   MOBILE & TABLET RESPONSIVENESS
   ========================================== */

@media (max-width: 1024px) {
    .app-container {
        padding: 0 1rem 1rem 1rem;
        padding-top: 64px; /* Preserve fixed top-bar clearance */
    }
}

@media (max-width: 768px) {
    .app-container {
        padding: 0 0.4rem 0.4rem 0.4rem;
        padding-top: 64px !important; /* CRITICAL: keep fixed top-bar clearance on small screens */
    }

    /* Header & Navigation */
    .top-nav {
        margin-bottom: 1.5rem;
    }

    .logo {
        font-size: 1.8rem;
        flex-wrap: wrap;
        justify-content: center;
        margin-bottom: 0.25rem;
    }

    .tagline {
        font-size: 0.85rem;
        padding: 0 0.5rem;
    }

    .app-nav {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.4rem;
        margin-top: 1rem;
        border-radius: 1rem;
        padding: 0.5rem;
    }

    .nav-btn {
        padding: 0.6rem;
        font-size: 0.85rem;
        flex: 1 1 calc(50% - 0.4rem);
        justify-content: center;
        text-align: center;
    }

    /* Backup Controls Strip */
    .backup-controls {
        flex-wrap: wrap;
        margin-top: 1rem;
        width: 100%;
        background: rgba(0, 0, 0, 0.2);
        padding: 0.5rem;
        border-radius: 1rem;
        border: 1px solid var(--glass-border);
        gap: 0.4rem !important;
    }

    .backup-controls .btn-utility {
        flex: 1 1 auto;
        justify-content: center;
        font-size: 0.8rem !important;
        padding: 0.5rem !important;
        border-radius: 1rem !important;
        margin: 0;
    }

    .backup-controls .btn-utility span {
        display: inline-block;
        /* Show text for clarity, it fits now that padding is reduced */
        margin-left: 0.25rem;
    }

    /* Main Content Layouts */
    .main-content {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .glass-panel {
        padding: 0.8rem;
        border-radius: 1rem;
    }

    .form-row {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    /* Make frictionless data entry elements smaller on mobile to fit more per row */
    .chip {
        padding: 0.2rem 0.5rem;
        font-size: 0.7rem;
    }

    .btn-duration {
        padding: 0.2rem 0.4rem;
        font-size: 0.65rem;
    }

    /* Dashboard top widgets: collapse to single column on mobile */
    .dashboard-top-widgets {
        grid-template-columns: 1fr !important;
    }

    /* Dashboard Revision Cards */
    .revision-cards {
        grid-template-columns: 1fr;
    }

    /* Table View adjustments */
    .table-header-section {
        padding: 1rem 1rem 0.5rem 1rem;
    }

    .table-header-section h2 {
        font-size: 1.1rem;
    }

    .subject-tabs {
        flex-wrap: wrap;
        /* allow multiple subjects to wrap gracefully to new row */
        justify-content: flex-start;
        padding: 0 1rem 0.5rem 1rem;
        gap: 0.5rem;
        width: 100%;
        box-sizing: border-box;
    }

    .sub-tab {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
        white-space: nowrap;
    }

    /* Transform Log Table into Cards for Mobile */
    .table-container {
        padding-bottom: 0.5rem;
        width: 100%;
        overflow-x: hidden;
    }

    .revision-table {
        width: 100%;
        min-width: 0 !important; /* Override desktop min-width so it fits phone */
        table-layout: fixed;
        margin-top: 0.5rem;
    }

    .revision-table,
    .revision-table thead,
    .revision-table tbody,
    .revision-table th,
    .revision-table td,
    .revision-table tr {
        display: block;
    }

    .revision-table thead tr {
        display: none;
    }

    .revision-table tbody tr {
        border: 1px solid var(--glass-border);
        border-radius: 1rem;
        margin-bottom: 0.75rem;
        background: linear-gradient(145deg, rgba(30, 41, 59, 0.5), rgba(255, 255, 255, 0.02));
        padding: 0.75rem;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }

    .revision-table td {
        border: none !important;
        padding: 0 !important;
        text-align: left !important;
        display: block !important;
        width: 100% !important;
        box-sizing: border-box;
    }

    /* Topic name — bold title */
    .revision-table td[data-label="Chapter / Topic"] {
        font-size: 1rem !important;
        font-weight: 600 !important;
        color: var(--text-primary);
        margin-bottom: 0.2rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Date — subtitle style */
    .revision-table td[data-label="Date Read"] {
        font-size: 0.8rem !important;
        color: var(--text-secondary);
        margin-bottom: 0.5rem;
        padding-bottom: 0.5rem !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.06) !important;
    }

    /* ── Revision status cells: CSS GRID for perfect wrapping ── */

    /* Make the <tr> a grid container so:
       - Chapter / Date span full width
       - The revision TDs form an auto-wrapping grid */
    .revision-table tbody tr {
        display: grid !important;
        grid-template-columns: repeat(auto-fit, minmax(65px, 1fr));
        gap: 0;
    }

    /* Chapter and Date take full width */
    .revision-table td[data-label="Chapter / Topic"],
    .revision-table td[data-label="Date Read"] {
        grid-column: 1 / -1;
        width: 100% !important;
        display: block !important;
    }

    /* The revision cells wrap automatically based on minmax(65px, 1fr) */
    .revision-table td.center-col {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: flex-start !important;
        padding: 0.35rem 0.15rem !important;
        box-sizing: border-box;
        text-align: center !important;
        width: 100% !important;
    }

    /* Label above each circle (2-DAY REV etc.) */
    .revision-table td::before {
        content: attr(data-label);
        display: block;
        font-size: 0.55rem;
        font-weight: 700;
        color: var(--text-secondary);
        text-transform: uppercase;
        letter-spacing: 0.3px;
        margin-bottom: 0.25rem;
        text-align: center;
        width: 100%;
    }

    .revision-table td[data-label="Chapter / Topic"]::before,
    .revision-table td[data-label="Date Read"]::before {
        display: none;
    }

    .status-cell-wrapper {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        gap: 0.2rem !important;
        width: 100%;
    }

    /* Scale the circles down to fit tiny screens */
    .status-cell {
        width: 26px !important;
        height: 26px !important;
        font-size: 0.7rem !important;
        flex-shrink: 0;
    }

    .status-date {
        font-size: 0.52rem !important;
        white-space: nowrap;
        text-align: center;
    }


    /* Time Tracker History Feed */
    .time-log-card {
        grid-template-columns: 1fr;
        gap: 0.75rem;
        padding: 1rem;
    }

    .tl-duration {
        text-align: left;
        display: flex;
        align-items: baseline;
        gap: 0.5rem;
    }

    /* AI Insights View */
    .api-config-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .api-config-actions {
        width: 100%;
        flex-direction: column;
    }

    .api-config-actions input {
        width: 100%;
    }

    .btn-save-key {
        width: 100%;
        justify-content: center;
    }

    .insights-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .period-selector {
        justify-content: center;
        margin-bottom: 0.5rem;
    }

    .btn-generate {
        justify-content: center;
        padding: 1rem;
        font-size: 1.05rem;
    }

    .insights-grid {
        grid-template-columns: 1fr;
    }

    .insights-history-bar {
        flex-direction: column;
        gap: 0.75rem;
        text-align: center;
    }

    .ai-rating-score {
        font-size: 2.5rem;
    }
}

@media (max-width: 480px) {
    .nav-btn {
        flex: 2 2 35%;
    }

    .analytics-value {
        font-size: 2.5rem;
    }
}

/* Exam Countdown Custom Styles */
.exam-countdown-container {
    animation: fadeIn 0.8s ease-out;
}

.countdown-panel {
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.countdown-panel:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 35px rgba(245, 158, 11, 0.15);
}

@media (max-width: 768px) {
    .countdown-panel {
        flex-direction: row !important;
        justify-content: space-around !important;
        align-items: center !important;
        gap: 0.5rem !important;
        padding: 1rem 0.5rem !important;
    }

    .countdown-divider {
        display: block !important;
        height: 30px !important;
        width: 1px !important;
        background: rgba(255, 255, 255, 0.1);
        margin: 0 !important;
    }

    .countdown-days {
        font-size: 1.5rem !important;
    }

    .countdown-label {
        font-size: 0.75rem !important;
        margin-bottom: 0.25rem !important;
    }

    .countdown-unit {
        font-size: 0.75rem !important;
    }


    /* Mobile specific font size reductions for professional feel */
    .glass-panel h2 {
        font-size: 1.2rem;
        margin-bottom: 1rem;
    }

    .btn-primary {
        padding: 0.8rem;
        font-size: 1rem;
    }

    .revision-card {
        padding: 1rem;
    }

    .card-topic {
        font-size: 1.1rem;
    }
}

