/**
 * Responsive Styles
 * Planejador de Estudos
 * Desenvolvido por B20 Conteúdo Digital
 */

/* ===== MOBILE BASE OVERRIDES (all phones < 768px) ===== */
@media (max-width: 767px) {

    /* --- Header Mobile --- */
    .app-header {
        padding: 0 var(--spacing-sm) 0 var(--spacing-md);
        height: 56px;
    }

    .header-logo img {
        width: 30px;
        height: 30px;
    }

    .header-logo h1 {
        font-size: var(--font-size-base);
    }

    body {
        padding-top: 56px;
    }

    /* --- Hero Mobile --- */
    .hero {
        padding: var(--spacing-md) 0;
        text-align: center;
    }

    .hero-banner {
        border-radius: var(--radius-md);
        margin-bottom: var(--spacing-md);
    }

    /* Mobile Accordions */
    .section-header.accordion-toggle {
        cursor: pointer;
        position: relative;
        padding-right: 35px;
        text-align: left; /* Better for accordions */
        margin-bottom: 0.5rem;
    }
    
    .section-header.accordion-toggle::after {
        content: '\f078'; /* fa-chevron-down */
        font-family: 'Font Awesome 6 Free';
        font-weight: 900;
        position: absolute;
        right: 15px;
        top: 50%;
        transform: translateY(-50%);
        transition: transform 0.3s ease;
        font-size: 1.2rem;
        color: var(--primary-color);
        background: var(--primary-subtle);
        width: 32px;
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
    }
    
    .section-header.accordion-toggle.active::after {
        transform: translateY(-50%) rotate(180deg);
    }
    
    .accordion-body {
        animation: fadeIn 0.3s ease-out;
    }
    
    @keyframes fadeIn {
        from { opacity: 0; transform: translateY(-10px); }
        to { opacity: 1; transform: translateY(0); }
    }

    .hero-banner img {
        aspect-ratio: 16 / 8;
    }

    .hero-icon {
        font-size: 2.5rem;
        margin-bottom: var(--spacing-sm);
    }

    .hero-title {
        font-size: var(--font-size-2xl);
        margin-bottom: var(--spacing-xs);
    }

    .hero-subtitle {
        font-size: var(--font-size-sm);
        margin-bottom: var(--spacing-md);
        line-height: 1.5;
    }

    .hero-features {
        gap: var(--spacing-sm);
        margin-bottom: var(--spacing-lg);
    }

    .feature-item {
        padding: 6px var(--spacing-md);
        font-size: var(--font-size-xs);
    }

    /* CTA Button full-width on mobile */
    .hero .btn-lg {
        width: 100%;
        max-width: 320px;
    }

    /* --- New Content Sections Mobile --- */
    .section-alt {
        padding: var(--spacing-xl) 0;
    }

    .steps-container {
        flex-direction: column;
        align-items: center;
        gap: var(--spacing-sm);
    }

    .step-card {
        max-width: 100%;
        width: 100%;
        padding: var(--spacing-lg) var(--spacing-md);
    }

    .step-connector {
        padding: 0;
        transform: rotate(90deg);
    }

    .features-grid,
    .audience-grid {
        grid-template-columns: 1fr;
        gap: var(--spacing-md);
    }

    .feature-card,
    .audience-card {
        padding: var(--spacing-md);
    }

    .audience-cta .btn-lg {
        width: 100%;
        max-width: 320px;
    }

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

    /* --- Questionnaire Mobile Optimizations --- */
    .section-header {
        margin-bottom: var(--spacing-md);
    }

    .section-header h2 {
        font-size: var(--font-size-lg);
        gap: 6px;
    }

    .section-header p {
        font-size: var(--font-size-sm);
    }

    .progress-container {
        margin-bottom: var(--spacing-md);
    }

    /* Compact step header on mobile */
    .step-header {
        margin-bottom: var(--spacing-md);
    }

    .step-icon {
        width: 48px;
        height: 48px;
        margin-bottom: var(--spacing-sm);
        font-size: 1.2rem;
    }

    .step-header h3 {
        font-size: var(--font-size-lg);
        margin-bottom: 2px;
    }

    .step-header p {
        font-size: var(--font-size-sm);
    }

    /* Form fields */
    .form-group {
        margin-bottom: var(--spacing-sm);
    }

    .form-group label {
        font-size: var(--font-size-sm);
        margin-bottom: 4px;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 10px var(--spacing-md);
        min-height: 44px;
        font-size: var(--font-size-base);
    }

    /* Step actions — sticky bottom bar on mobile */
    .step-actions {
        position: sticky;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: var(--z-sticky);
        margin: var(--spacing-md) calc(-1 * var(--spacing-md)) 0;
        padding: var(--spacing-md);
        background: var(--card-background);
        border-top: 1px solid var(--border-color);
        gap: var(--spacing-sm);
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
    }

    [data-theme="dark"] .step-actions {
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.3);
    }

    .step-actions .btn {
        flex: 1;
        max-width: none;
        min-height: 48px;
    }

    /* Subjects */
    .subjects-container {
        padding: var(--spacing-md);
    }

    .subjects-presets {
        gap: 6px;
        margin-bottom: var(--spacing-sm);
    }

    .subjects-presets .preset-label {
        font-size: var(--font-size-xs);
    }

    .subjects-presets .btn-sm {
        padding: 4px 10px;
        font-size: 11px;
        min-height: 28px;
    }

    .subjects-list {
        max-height: 220px;
        gap: 6px;
    }

    .subject-item {
        padding: 6px var(--spacing-sm);
    }

    .subject-item .subject-name {
        font-size: var(--font-size-sm);
    }

    .add-subject-form .form-row {
        flex-direction: column;
        gap: var(--spacing-sm);
    }

    .add-subject-form .form-row .form-group {
        width: 100%;
    }

    .add-subject-form .form-row .btn-secondary {
        width: 100%;
    }

    /* Days selector mobile */
    .days-selector {
        gap: 6px;
    }

    .day-label {
        width: 44px;
        height: 58px;
        border-radius: var(--radius-sm);
    }

    .day-short {
        font-size: var(--font-size-base);
    }

    .day-full {
        font-size: 9px;
    }

    /* Hours selector */
    .hours-input-group input {
        width: 64px;
        font-size: var(--font-size-xl);
    }

    /* Knowledge levels */
    .knowledge-levels {
        gap: var(--spacing-sm);
    }

    .knowledge-item {
        padding: var(--spacing-sm) var(--spacing-md);
    }

    .knowledge-item .subject-name {
        font-size: var(--font-size-sm);
    }

    /* Schedule Summary */
    .schedule-summary {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--spacing-sm);
    }

    .summary-card {
        padding: var(--spacing-md);
    }

    .summary-icon {
        width: 36px;
        height: 36px;
        font-size: 1rem;
        margin-bottom: 4px;
    }

    .summary-value {
        font-size: var(--font-size-lg);
    }

    .summary-label {
        font-size: 10px;
    }

    /* Calendar mobile */
    .calendar-day {
        min-height: 80px;
        padding: var(--spacing-xs);
    }

    .calendar-day-header {
        font-size: 11px;
        padding: 6px var(--spacing-xs);
    }

    .calendar-session {
        font-size: 10px;
        padding: 2px 4px;
    }

    /* Distribution */
    .distribution-item .subject-name {
        width: 80px;
        font-size: var(--font-size-xs);
    }

    .distribution-item .hours-value {
        width: 40px;
        font-size: var(--font-size-xs);
    }

    /* Empty state */
    .empty-state {
        padding: var(--spacing-xl) var(--spacing-md);
    }

    .empty-icon {
        width: 64px;
        height: 64px;
        font-size: 1.5rem;
    }

    /* Schedule actions */
    .schedule-actions {
        flex-direction: column;
        gap: var(--spacing-sm);
    }

    .schedule-actions .btn {
        width: 100%;
        justify-content: center;
    }

    /* FAQ mobile */
    .faq-question {
        padding: var(--spacing-md);
        font-size: var(--font-size-sm);
    }

    .faq-answer {
        padding: 0 var(--spacing-md) var(--spacing-md);
        font-size: var(--font-size-sm);
    }

    /* Footer mobile */
    .app-footer {
        padding: var(--spacing-xl) var(--spacing-md);
    }

    .footer-content {
        gap: var(--spacing-md);
    }

    .footer-links {
        flex-wrap: wrap;
        justify-content: center;
        gap: var(--spacing-sm) var(--spacing-md);
    }

    .footer-links a {
        font-size: var(--font-size-xs);
    }

    .footer-credits {
        font-size: 10px;
    }

    /* Existing plan card */
    .existing-plan-card {
        margin-top: var(--spacing-md);
        padding: var(--spacing-md);
    }

    .existing-plan-card .card-actions {
        flex-direction: column;
    }

    .existing-plan-card .card-actions .btn {
        width: 100%;
        justify-content: center;
    }

    /* Legal pages */
    .legal-content {
        padding: var(--spacing-lg) var(--spacing-md);
    }

    .legal-content h1 {
        font-size: var(--font-size-2xl);
    }

    .legal-content h2 {
        font-size: var(--font-size-lg);
        margin-top: var(--spacing-lg);
    }

    .legal-content p,
    .legal-content li {
        font-size: var(--font-size-sm);
        line-height: 1.7;
    }

    /* Toast mobile */
    .toast-container {
        left: var(--spacing-sm);
        right: var(--spacing-sm);
        max-width: none;
        width: auto;
    }

    /* Modal mobile */
    .modal-content {
        max-width: calc(100% - var(--spacing-lg));
    }
}

/* ===== SMALL PHONES (< 360px) ===== */
@media (max-width: 359px) {
    :root {
        --spacing-md: 12px;
        --spacing-lg: 16px;
    }

    .hero-title {
        font-size: var(--font-size-xl);
    }

    .hero-features {
        flex-direction: column;
    }

    .feature-item {
        width: 100%;
        justify-content: center;
    }

    .day-label {
        width: 38px;
        height: 50px;
    }

    .day-full {
        display: none;
    }

    .schedule-summary {
        grid-template-columns: 1fr 1fr;
    }

    .add-subject-form .form-row {
        flex-direction: column;
    }
}

/* ===== STANDARD PHONES (360px - 479px) ===== */
@media (min-width: 360px) and (max-width: 479px) {
    .hero-features {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
    }

    .feature-item {
        width: auto;
    }
}

/* ===== LARGE PHONES (480px - 639px) ===== */
@media (min-width: 480px) and (max-width: 639px) {
    .container {
        padding: 0 var(--spacing-lg);
    }

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

    .summary-card {
        padding: var(--spacing-sm);
    }

    .step-actions .btn {
        max-width: 200px;
    }

    .schedule-actions {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .schedule-actions .btn {
        width: auto;
    }
}

/* ===== SMALL TABLETS (640px - 767px) ===== */
@media (min-width: 640px) and (max-width: 767px) {
    .container {
        padding: 0 var(--spacing-xl);
    }

    .hero {
        padding: var(--spacing-xl) var(--spacing-lg);
    }

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

    .questionnaire-form {
        max-width: 500px;
    }

    .form-row {
        flex-wrap: nowrap;
    }

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

    .calendar-day {
        min-height: 100px;
    }

    .distribution-item .subject-name {
        width: 150px;
    }

    .step-actions .btn {
        max-width: 200px;
    }

    .add-subject-form .form-row {
        flex-direction: row;
    }

    .add-subject-form .form-row .btn-secondary {
        width: auto;
    }

    .schedule-actions {
        flex-direction: row;
    }

    .schedule-actions .btn {
        width: auto;
    }
}

/* ===== TABLET (768px+) ===== */
@media (min-width: 768px) {
    /* Hide mobile menu button, show desktop nav */
    .mobile-menu-btn {
        display: none !important;
    }

    .mobile-nav {
        display: none !important;
    }

    .desktop-nav {
        display: flex;
    }

    /* Header adjustments */
    .app-header {
        padding: 0 var(--spacing-xl);
        height: var(--header-height);
    }

    body {
        padding-top: var(--header-height);
    }

    .header-logo h1 {
        font-size: var(--font-size-xl);
    }

    /* Container */
    .container {
        padding: 0 var(--spacing-xl);
    }

    /* Hero */
    .hero {
        padding: var(--spacing-2xl) var(--spacing-xl);
    }

    .hero-icon {
        font-size: 4rem;
    }

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

    .hero-subtitle {
        font-size: var(--font-size-lg);
        max-width: 600px;
    }

    .hero-features {
        gap: var(--spacing-lg);
    }

    .hero-banner {
        border-radius: var(--radius-xl);
    }

    /* Form */
    .questionnaire-form {
        max-width: 600px;
    }

    .step-header h3 {
        font-size: var(--font-size-2xl);
    }

    .step-actions .btn {
        max-width: 200px;
    }

    .add-subject-form .form-row {
        flex-direction: row;
    }

    .add-subject-form .form-row .btn-secondary {
        width: auto;
    }

    /* Days selector */
    .day-label {
        width: 80px;
        height: 90px;
    }

    .day-short {
        font-size: var(--font-size-xl);
    }

    .day-full {
        font-size: var(--font-size-sm);
    }

    /* Schedule */
    .schedule-actions {
        flex-direction: row;
        justify-content: flex-end;
    }

    .schedule-actions .btn {
        width: auto;
    }

    .schedule-summary {
        grid-template-columns: repeat(4, 1fr);
        gap: var(--spacing-lg);
    }

    .summary-card {
        padding: var(--spacing-lg);
    }

    .summary-icon {
        width: 44px;
        height: 44px;
        font-size: 1.25rem;
    }

    .summary-value {
        font-size: var(--font-size-2xl);
    }

    /* Calendar */
    .calendar-day {
        min-height: 130px;
        padding: var(--spacing-md);
    }

    .calendar-session {
        font-size: var(--font-size-xs);
        padding: var(--spacing-xs) var(--spacing-sm);
    }

    /* Distribution */
    .distribution-item .subject-name {
        width: 180px;
    }

    /* FAQ */
    .faq-question {
        padding: var(--spacing-lg);
        font-size: var(--font-size-base);
    }

    .faq-answer {
        padding: 0 var(--spacing-lg) var(--spacing-lg);
    }

    /* Footer */
    .app-footer {
        padding: var(--spacing-2xl) var(--spacing-xl);
    }

    .footer-content {
        flex-direction: row;
        justify-content: space-between;
        text-align: left;
        flex-wrap: wrap;
    }

    .footer-links {
        gap: var(--spacing-lg);
    }

    /* Toast */
    .toast-container {
        max-width: 400px;
    }

    /* Legal */
    .legal-content {
        padding: var(--spacing-2xl) var(--spacing-xl);
    }

    .legal-content h1 {
        font-size: var(--font-size-3xl);
    }
}

/* ===== DESKTOP (1024px+) ===== */
@media (min-width: 1024px) {
    .container {
        padding: 0 var(--spacing-2xl);
    }

    .app-header {
        padding: 0 var(--spacing-2xl);
    }

    .desktop-nav {
        gap: var(--spacing-sm);
    }

    .desktop-nav .nav-link {
        padding: var(--spacing-sm) var(--spacing-lg);
    }

    .hero {
        padding: var(--spacing-2xl) 0;
        max-width: 800px;
        margin: 0 auto;
    }

    .hero-icon {
        font-size: 4.5rem;
    }

    .questionnaire-form {
        max-width: 700px;
    }

    .form-row {
        gap: var(--spacing-md);
    }

    .schedule-summary {
        max-width: 900px;
        margin: 0 auto var(--spacing-xl);
    }

    .weekly-calendar {
        max-width: 1100px;
        margin: 0 auto var(--spacing-xl);
    }

    .calendar-day {
        min-height: 150px;
    }

    .hours-distribution {
        max-width: 800px;
        margin: 0 auto;
    }

    .distribution-item .subject-name {
        width: 200px;
    }
}

/* ===== LARGE DESKTOP (1440px+) ===== */
@media (min-width: 1440px) {
    :root {
        --container-max-width: 1400px;
    }

    .hero {
        max-width: 900px;
    }

    .questionnaire-form {
        max-width: 800px;
    }

    .weekly-calendar {
        max-width: 1300px;
    }

    .calendar-day {
        min-height: 170px;
    }
}

/* ===== LANDSCAPE MOBILE ===== */
@media (max-width: 767px) and (orientation: landscape) {
    .hero {
        padding: var(--spacing-sm) 0;
    }

    .hero-icon {
        font-size: 2rem;
        margin-bottom: var(--spacing-xs);
    }

    .hero-title {
        font-size: var(--font-size-lg);
    }

    .hero-subtitle {
        margin-bottom: var(--spacing-sm);
    }

    .hero-banner {
        max-height: 160px;
    }

    .hero-features {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .step-icon {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }

    .days-selector {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: var(--spacing-sm);
        -webkit-overflow-scrolling: touch;
    }

    .day-label {
        min-width: 44px;
    }
}

/* ===== HIGH DPI DISPLAYS ===== */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .spinner {
        border-width: 3px;
    }
}

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .hero-icon {
        animation: none;
    }

    .spinner {
        animation: none;
        border-top-color: var(--primary-color);
        border-right-color: var(--primary-color);
    }
}

/* ===== DARK MODE SYSTEM PREFERENCE ===== */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --background-color: #0B1120;
        --card-background: #151E30;
        --border-color: #1E2D45;
        --text-color: #F1F5F9;
        --text-secondary: #94A3B8;
        --text-muted: #64748B;
        --surface-color: #1A2438;
        --primary-subtle: #1E1B4B;
    }
}

/* ===== HOVER CAPABLE DEVICES ===== */
@media (hover: hover) and (pointer: fine) {
    .btn:hover:not(:disabled) {
        transform: translateY(-2px);
    }

    .subject-item:hover {
        border-color: var(--border-color);
    }

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

    .calendar-session:hover {
        transform: scale(1.02);
        box-shadow: var(--shadow-sm);
    }
}

/* ===== TOUCH DEVICES ===== */
@media (hover: none) and (pointer: coarse) {
    .btn {
        min-height: 48px;
    }

    .faq-question {
        min-height: 56px;
    }

    .btn:hover {
        transform: none;
    }

    .btn:active {
        transform: scale(0.98);
        opacity: 0.9;
    }

    /* Better scrollable areas on touch */
    .subjects-list {
        -webkit-overflow-scrolling: touch;
    }
}

/* ===== SAFE AREAS (iPhone X+) ===== */
@supports (padding: env(safe-area-inset-top)) {
    .app-header {
        padding-top: env(safe-area-inset-top);
    }

    @media (max-width: 767px) {
        .app-header {
            height: calc(56px + env(safe-area-inset-top));
        }

        body {
            padding-top: calc(56px + env(safe-area-inset-top));
        }
    }

    @media (min-width: 768px) {
        .app-header {
            height: calc(var(--header-height) + env(safe-area-inset-top));
        }

        body {
            padding-top: calc(var(--header-height) + env(safe-area-inset-top));
        }
    }

    .container {
        padding-left: max(var(--spacing-md), env(safe-area-inset-left));
        padding-right: max(var(--spacing-md), env(safe-area-inset-right));
    }
}

/* ===== PRINT RESPONSIVE ===== */
@media print {
    body {
        padding: 0 !important;
        font-size: 12pt;
    }

    .container {
        max-width: 100%;
        padding: 0;
    }

    .section-header {
        margin-bottom: 20pt;
    }

    .schedule-summary {
        display: flex;
        justify-content: space-around;
        margin-bottom: 20pt;
    }

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

    .weekly-calendar {
        page-break-inside: avoid;
    }

    .calendar-day {
        min-height: 60pt;
    }

    .hours-distribution {
        page-break-before: always;
    }

    .app-header,
    .mobile-nav,
    .app-footer {
        display: none !important;
    }
}
