/* ==========================================
   MOBILE RESPONSIVE STYLES
   Growing Strong - TimeGrapher
   ========================================== */

/* Tablet and below */
@media (max-width: 1024px) {
    .main-container.sidebar-hidden {
        margin-left: 40px;
        margin-right: 40px;
        max-width: calc(100vw - 80px);
        padding: 20px;
    }
    
    .main-content {
        grid-template-columns: 1fr 1fr;
        gap: 20px;
    }
    
    .input-sections-wrapper {
        flex-direction: column;
    }
}

/* Mobile devices */
@media (max-width: 768px) {
    /* Performance: previously disabled expensive full-screen blur/animation layers on mobile, now enabled per user request */

    /* App Layout */
    .app-layout {
        flex-direction: column;
    }
    
    /* Sidebar - hidden by default on mobile, slide from left */
    .sidebar {
        width: 280px;
        z-index: 1000;
        transform: translateX(-100%);
    }
    
    .sidebar.hidden {
        transform: translateX(-100%);
    }
    
    .sidebar:not(.hidden) {
        transform: translateX(0);
    }
    
    /* Sidebar toggle button */
    .sidebar-toggle-btn {
        left: 10px;
        top: 10px;
        width: 40px;
        height: 40px;
    }
    
    /* Theme toggle button */
    .theme-toggle-btn {
        right: 10px;
        top: 10px;
        width: 40px;
        height: 40px;
    }
    
    /* Main container - full width on mobile */
    .main-container {
        margin-left: 0 !important;
        max-width: 100vw !important;
        padding: 15px;
    }
    
    .main-container.sidebar-hidden {
        margin-left: 0 !important;
        margin-right: 0 !important;
        max-width: 100vw !important;
        padding: 60px 15px 15px 15px;
    }
    
    /* Header */
    .main-container header h1,
    .old-english-title {
        font-size: 2rem !important;
    }
    
    .time-number {
        font-size: 2rem;
    }
    
    .average-time {
        font-size: 1rem;
    }
    
    /* Main content grid - single column */
    .main-content {
        grid-template-columns: 1fr !important;
        gap: 15px;
    }
    
    /* Chart section */
    .chart-section {
        padding: 15px;
    }
    
    .chart-header {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }
    
    .chart-header h2 {
        font-size: 1.2rem;
    }
    
    .chart-container {
        height: 200px;
    }
    
    /* Period selector */
    .period-selector {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .period-btn {
        flex: 1;
        min-width: 80px;
        padding: 8px 12px;
        font-size: 0.85rem;
    }
    
    /* Subject distribution section */
    .subjects-section {
        padding: 20px;
    }
    
    .pie-chart-container {
        height: 180px;
    }
    
    /* Input sections wrapper - single column */
    .input-sections-wrapper {
        flex-direction: column !important;
        gap: 15px;
    }
    
    .input-section {
        padding: 15px;
    }
    
    .input-section.add-session-section,
    .input-section.manage-subjects-section {
        width: 100% !important;
    }
    
    .input-section.recent-sessions-section {
        width: 100% !important;
    }
    
    /* Form elements */
    .form-group {
        gap: 10px;
    }
    
    .form-group h3 {
        font-size: 1.1rem;
    }
    
    .form-row {
        flex-direction: column;
        gap: 10px;
    }
    
    .form-row .form-control {
        width: 100%;
    }
    
    /* Input mode toggle */
    .input-mode-toggle {
        flex-direction: column;
        gap: 8px;
    }
    
    .mode-btn {
        width: 100%;
        padding: 12px;
    }
    
    /* Time inputs */
    .time-inputs-container {
        flex-direction: column;
        gap: 10px;
    }
    
    .time-input-group {
        width: 100%;
    }
    
    /* Buttons */
    .submit-btn,
    .add-subject-btn,
    .save-config-btn {
        width: 100%;
        padding: 14px;
        font-size: 1rem;
    }
    
    /* Subject list */
    .subject-list {
        max-height: 200px;
    }
    
    .subject-item {
        padding: 10px;
    }
    
    /* Recent sessions */
    .session-item {
        padding: 12px;
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .session-item .session-info {
        width: 100%;
    }
    
    .session-item .session-actions {
        width: 100%;
        justify-content: flex-end;
    }
    
    /* Modal */
    .modal-content {
        width: 95% !important;
        margin: 10px;
        max-height: 90vh;
        overflow-y: auto;
    }
    
    /* Nav buttons */
    .nav-btn {
        width: 36px;
        height: 36px;
        min-width: 36px;
        min-height: 36px;
        font-size: 1.2rem;
    }
    
    /* Analysis pages */
    .analysis-page {
        padding: 60px 15px 15px 15px !important;
    }
    
    .analysis-page h1 {
        font-size: 1.5rem !important;
    }
    
    .analysis-page .chart-section {
        padding: 15px;
    }
    
    /* Stats grid */
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 10px;
    }
    
    .stat-card {
        padding: 15px;
    }
    
    /* Subject cards */
    .subject-cards-grid {
        grid-template-columns: 1fr !important;
    }
    
    .subject-card {
        padding: 15px;
    }
    
    /* Calendar */
    .calendar-grid {
        font-size: 0.75rem;
    }
    
    .calendar-day {
        min-height: 30px;
        padding: 2px;
    }
    
    /* Tables */
    .data-table {
        font-size: 0.8rem;
    }
    
    .data-table th,
    .data-table td {
        padding: 8px 6px;
    }
    
    /* Heatmap */
    .heatmap-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Work flow / Work load specific */
    .workflow-container,
    .workload-container {
        padding: 15px;
    }
    
    .task-card,
    .workflow-item {
        padding: 12px;
    }
    
    /* Day configurations */
    .days-grid-config {
        grid-template-columns: 1fr !important;
    }
    
    .day-config-item {
        padding: 12px;
    }
    
    /* Filters */
    .filter-section,
    .controls-row {
        flex-direction: column;
        gap: 10px;
    }
    
    .filter-section input,
    .filter-section select,
    .controls-row input,
    .controls-row select {
        width: 100%;
    }
    
    /* Period cards (study momentum) */
    .periods-grid {
        grid-template-columns: 1fr !important;
    }
    
    .period-card {
        padding: 15px;
    }
    
    /* Streak analysis */
    .streak-grid {
        grid-template-columns: 1fr !important;
    }
    
    /* Back button */
    .back-btn {
        top: 10px;
        left: 60px;
        padding: 8px 12px;
        font-size: 0.9rem;
    }
    
    /* Charts in analysis pages */
    .comparison-chart,
    .trends-chart {
        height: 250px !important;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    .main-container.sidebar-hidden {
        padding: 55px 10px 10px 10px;
    }
    
    .old-english-title {
        font-size: 1.6rem !important;
    }
    
    .time-number {
        font-size: 1.6rem;
    }
    
    .chart-container {
        height: 180px;
    }
    
    .pie-chart-container {
        height: 160px;
    }
    
    .period-btn {
        padding: 6px 10px;
        font-size: 0.8rem;
    }
    
    .subjects-section {
        padding: 15px;
    }
    
    .subject-stat {
        font-size: 0.9rem;
    }
    
    .input-section {
        padding: 12px;
    }
    
    /* Touch-friendly buttons */
    button, 
    .btn,
    input[type="submit"] {
        min-height: 44px;
    }
    
    /* Analysis pages extra small */
    .analysis-page {
        padding: 55px 10px 10px 10px !important;
    }
    
    .stat-value {
        font-size: 1.5rem !important;
    }
    
    .stat-label {
        font-size: 0.8rem;
    }
    
    /* Smaller nav buttons */
    .nav-btn {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
    }
    
    /* Form controls */
    select, input, textarea {
        font-size: 16px; /* Prevents iOS zoom on focus */
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .period-btn,
    .mode-btn,
    .analysis-btn {
        min-height: 44px;
    }
    
    /* Nav buttons need equal width/height to stay circular */
    .nav-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }
    
    /* Remove blue tap/focus outlines on touch devices */
    button,
    a,
    input,
    select,
    textarea,
    .nav-btn,
    .period-btn,
    .mode-btn,
    .analysis-btn {
        outline: none !important;
        -webkit-tap-highlight-color: transparent !important;
    }
    
    /* Disable hover effects on touch */
    .analysis-btn:hover {
        transform: none;
    }
    
    /* Active states for touch */
    .analysis-btn:active {
        background-color: var(--bg-card);
        transform: scale(0.98);
    }
}

/* Global small-screen hardening (prevents horizontal overflow and improves recall page usability) */
@media (max-width: 768px) {
    html,
    body,
    .app-layout {
        max-width: 100%;
        overflow-x: hidden;
    }

    .main-container,
    .analysis-page,
    .recall-page {
        width: 100% !important;
        max-width: 100% !important;
    }

    .chart-container canvas,
    .pie-chart-container canvas,
    .recall-chart-container canvas {
        max-width: 100% !important;
    }

    .filter-tabs {
        flex-wrap: nowrap !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
    }

    .filter-tab {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .recall-stats {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 10px !important;
    }

    .schedule-nav {
        flex-wrap: wrap;
        justify-content: center;
        gap: 8px;
        text-align: center;
    }

    .schedule-day {
        gap: 10px;
    }

    .schedule-date-col {
        width: 64px !important;
    }

    .schedule-items-col {
        min-width: 0;
    }

    .schedule-item-chip,
    .overdue-chip {
        max-width: 100%;
    }

    .schedule-week-sep {
        padding-left: 80px !important;
    }
}

@media (max-width: 480px) {
    .recall-stats {
        grid-template-columns: 1fr !important;
    }

    .schedule-date-col {
        width: 56px !important;
    }

    .schedule-week-sep {
        padding-left: 70px !important;
    }
}

/* ==========================================
   SECTION PAGES MOBILE LAYOUT FIXES
   ========================================== */
@media (max-width: 768px) {
    .page-header {
        padding: 18px 0 !important;
    }

    .header-content {
        padding: 0 12px !important;
    }

    .analysis-page .analysis-content,
    .recall-page,
    .momentum-page,
    .workflow-container {
        padding: 14px 12px !important;
    }

    .page-description {
        font-size: 0.95rem !important;
        line-height: 1.4 !important;
    }

    .selection-panel,
    .trends-selection-panel,
    .mode-selection,
    .semester-management,
    .analysis-page .chart-section,
    .detailed-breakdown,
    .insights-panel,
    .heatmap-section,
    .sessions-section,
    .coming-soon-card,
    .workflow-list,
    .add-plan-form,
    .plan-card {
        padding: 14px !important;
        margin-bottom: 16px !important;
    }

    .results-header,
    .selection-actions,
    .period-controls,
    .mode-buttons,
    .filter-controls,
    .add-item-row,
    .plan-header,
    .semester-header,
    .item-actions,
    .quality-buttons {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
    }

    .selection-actions .action-btn,
    .period-controls .create-period-btn,
    .period-controls .compare-btn,
    .mode-buttons .mode-btn,
    .add-item-row .add-btn,
    .schedule-nav-btn,
    .item-actions button,
    .quality-buttons button {
        width: 100% !important;
    }

    .add-item-row input {
        margin-right: 0 !important;
        width: 100% !important;
    }

    .visualization-section,
    .subjects-assignment,
    .trend-summary,
    .streak-cards,
    .period-comparison,
    .form-grid,
    .plans-container,
    .stats-overview {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    .subjects-grid,
    .months-grid,
    .seasons-grid {
        grid-template-columns: 1fr !important;
    }

    .period-options {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }

    .breakdown-table,
    .trends-table,
    .subjects-table,
    .sessions-list,
    .heatmap-container,
    .schedule-timeline {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .subject-row {
        grid-template-columns: 36px 1fr 72px 64px !important;
        gap: 8px !important;
        padding: 10px !important;
    }

    .pie-chart-wrapper {
        height: 220px !important;
    }

    .chart-container {
        height: 260px !important;
    }

    .line-chart-container {
        height: 240px !important;
        padding: 10px !important;
    }

    .heatmap-grid {
        min-width: 660px;
    }

    .workflow-item {
        display: grid !important;
        grid-template-columns: auto auto 1fr auto !important;
        align-items: center !important;
        gap: 8px !important;
    }

    .item-text,
    .plan-type,
    .subject-name {
        min-width: 0;
        overflow-wrap: anywhere;
    }

    .semester-stats,
    .recall-meta {
        flex-wrap: wrap !important;
        gap: 8px !important;
    }
}

@media (max-width: 480px) {
    .analysis-page .page-header h1,
    .recall-header h1 {
        font-size: 1.35rem !important;
    }

    .stats-overview .stat-card,
    .streak-card,
    .trend-card,
    .period-card,
    .recall-item,
    .schedule-day {
        padding: 12px !important;
    }

    .chart-container {
        height: 220px !important;
    }

    .line-chart-container {
        height: 210px !important;
    }
}

/* ==========================================
   MOBILE PERFORMANCE OPTIMIZATIONS
   ========================================== */

/* Disable heavy background aura animations on mobile */
@media (max-width: 768px) {
    body::before,
    body::after {
        animation: none !important;
        filter: none !important;
    }
    
    /* Disable expensive backdrop-filter on mobile */
    .subjects-section {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        background: var(--bg-card, rgba(30, 30, 30, 0.95)) !important;
    }
}
