/* ============================================
   DESIGN SYSTEM - Mobile First Approach
   ============================================ */

:root {
    /* === MOBILE TOKENS (Default) === */
    /* Colors */
    --color-primary: #FF6B2C;
    --color-background: #F8F9FD;
    --color-surface: #FFFFFF;
    --color-text-main: #1A1D1F;
    --color-text-muted: #9A9FA5;

    /* Spacing */
    --spacing-screen-padding: 24px;
    --spacing-card-gap: 16px;
    --spacing-section-gap: 24px;

    /* Border Radius */
    --radius-card: 24px;
    --radius-button: 100px;
    --radius-small: 12px;

    /* Layout */
    --header-height: 60px;
    --touch-target-min: 44px;

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-size-base: 15px;
    --line-height-base: 1.6;
}

/* === DESKTOP TOKENS (min-width: 1024px) === */
@media (min-width: 1024px) {
    :root {
        --color-primary: #FF6B00;
        --spacing-screen-padding: 48px;
        --spacing-card-gap: 30px;
        --spacing-section-gap: 40px;
        --radius-card: 20px;
        --font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
        --font-size-base: 16px;
    }
}

/* ============================================
   RESET & BASE
   ============================================ */

* {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

html {
    scroll-behavior: smooth;
}

@media (max-width: 640px) {
    html {
        scroll-padding-top: 70px;
    }
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: var(--line-height-base);
    color: var(--color-text-main);
    background-color: var(--color-background);
}

/* ============================================
   LAYOUT UTILITIES
   ============================================ */

.container-mobile {
    padding-left: var(--spacing-screen-padding);
    padding-right: var(--spacing-screen-padding);
}

.card-gap {
    gap: var(--spacing-card-gap);
}

.section-gap {
    gap: var(--spacing-section-gap);
}

/* ============================================
   SCROLL HORIZONTAL - Mobile Pattern
   ============================================ */

.scroll-container {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    scroll-snap-type: x mandatory;

    /* Truque para scroll até a borda */
    margin-left: calc(-1 * var(--spacing-screen-padding));
    margin-right: calc(-1 * var(--spacing-screen-padding));
    padding-left: var(--spacing-screen-padding);
    padding-right: var(--spacing-screen-padding);
}

.scroll-container-inner {
    display: flex;
    flex-wrap: nowrap;
    gap: var(--spacing-card-gap);
}

.scroll-item {
    flex-shrink: 0;
    scroll-snap-align: start;
    min-width: 85vw;
}

@media (min-width: 768px) {
    .scroll-item {
        min-width: 45vw;
    }
}

@media (min-width: 1024px) {
    .scroll-container {
        margin-left: 0;
        margin-right: 0;
        padding-left: 0;
        padding-right: 0;
    }

    .scroll-container-inner {
        flex-wrap: wrap;
    }

    .scroll-item {
        min-width: auto;
        flex: 1 1 calc(50% - var(--spacing-card-gap));
    }
}

/* Scrollbar customizada para scroll horizontal */
.scroll-container::-webkit-scrollbar {
    height: 6px;
}

.scroll-container::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 10px;
}

.scroll-container::-webkit-scrollbar-thumb {
    background: var(--color-text-muted);
    border-radius: 10px;
    opacity: 0.5;
}

.scroll-container::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-main);
    opacity: 0.7;
}

/* Esconde scrollbar mas mantém funcionalidade */
.scrollbar-hide {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.scrollbar-hide::-webkit-scrollbar {
    display: none;
}

/* Scrollbar thin para elementos internos */
.scrollbar-thin {
    scrollbar-width: thin;
}

.scrollbar-thin::-webkit-scrollbar {
    height: 6px;
    width: 6px;
}

.scrollbar-thumb-primary::-webkit-scrollbar-thumb {
    background-color: var(--color-primary);
}

.scrollbar-thumb-muted::-webkit-scrollbar-thumb {
    background-color: var(--color-text-muted);
}

/* ============================================
   TOUCH TARGETS - Acessibilidade Mobile
   ============================================ */

button,
.btn,
a.btn,
input[type="submit"],
input[type="button"] {
    min-height: var(--touch-target-min);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* Feedback tátil no mobile */
button:active,
.btn:active {
    transform: scale(0.98);
}

/* ============================================
   INPUTS - Mobile Friendly
   ============================================ */

input[type="number"],
input[type="text"],
input[type="email"],
select,
textarea {
    font-size: 16px; /* Previne zoom no iOS */
    min-height: var(--touch-target-min);
    -webkit-appearance: none;
    appearance: none;
    border-radius: var(--radius-small);
}

/* Focus States para Acessibilidade */
input:focus,
select:focus,
button:focus,
textarea:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* ============================================
   LOADING STATES - HTMX
   ============================================ */

.htmx-indicator {
    opacity: 0;
    transition: opacity 200ms ease-in;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    opacity: 1;
}

.htmx-swapping {
    opacity: 0;
    transition: opacity 150ms ease-out;
}

/* ============================================
   ANIMATIONS
   ============================================ */

.fade-in {
    animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(15px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.transition-smooth {
    transition-property: all;
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
    transition-duration: 200ms;
}

/* ============================================
   CARDS & SURFACES
   ============================================ */

.card {
    background: var(--color-surface);
    border-radius: var(--radius-card);
    padding: var(--spacing-card-gap);
}

.card-shadow {
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}

.card-shadow-lg {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

.hover\:card-shadow-md:hover {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    transition: box-shadow 0.2s ease;
}

@media (min-width: 1024px) {
    .hover\:scale-105:hover {
        transform: scale(1.05);
    }
}

/* ============================================
   CHARTS & GRAPHS - Responsivo
   ============================================ */

canvas {
    max-width: 100%;
    height: auto !important;
}

.chart-container {
    position: relative;
    width: 100%;
    min-height: 250px;
}

@media (min-width: 768px) {
    .chart-container {
        min-height: 300px;
    }
}

/* Container de gráficos com aspect ratio preservado */
.chart-wrapper {
    position: relative;
    width: 100%;
    padding-bottom: 60%; /* Aspect ratio 16:9.6 */
}

.chart-wrapper canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* ============================================
   SPACING ADJUSTMENTS - Mobile
   ============================================ */

@media (max-width: 640px) {
    .space-y-8 > * + * {
        margin-top: 1.5rem;
    }

    .space-y-6 > * + * {
        margin-top: 1rem;
    }
}

/* ============================================
   STICKY TABLE COLUMN - Mobile
   ============================================ */

@media (max-width: 767px) {
    table th.sticky,
    table td.sticky {
        position: sticky;
        left: 0;
        z-index: 10;
        background: var(--color-surface);
        box-shadow: 2px 0 4px rgba(0, 0, 0, 0.05);
    }
}

/* Math Formula Scroll */
.math-formula {
    overflow-x: auto;
    padding: 0.5rem 0;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.math-formula::-webkit-scrollbar {
    height: 4px;
}

.math-formula::-webkit-scrollbar-track {
    background: transparent;
}

.math-formula::-webkit-scrollbar-thumb {
    background-color: var(--color-text-muted);
    border-radius: 2px;
}

/* ============================================
   GRID RESPONSIVO - Mobile First
   ============================================ */

@media (max-width: 768px) {
    .grid-responsive {
        grid-template-columns: repeat(1, minmax(0, 1fr));
    }
}

/* ============================================
   EDUCATIONAL COMPONENTS - Rich Content
   ============================================ */

.formula-box {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 1.5rem;
    border-radius: var(--radius-small);
    margin: 1.5rem 0;
    box-shadow: 0 10px 30px rgba(102, 126, 234, 0.3);
}

.formula-box code {
    display: block;
    background: var(--color-surface);
    color: var(--color-text-main);
    padding: 1rem;
    border-radius: var(--radius-small);
    font-family: 'Courier New', monospace;
    font-size: 1.1rem;
    font-weight: 600;
}

.example-box {
    background: #f0f9ff;
    border-left: 4px solid #3b82f6;
    padding: 1.5rem;
    border-radius: var(--radius-small);
    margin: 1.5rem 0;
}

.warning-box {
    background: #fef3c7;
    border-left: 4px solid #f59e0b;
    padding: 1.5rem;
    border-radius: var(--radius-small);
    margin: 1.5rem 0;
}

.highlight-box {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1.5rem;
    border-radius: var(--radius-small);
    margin: 1.5rem 0;
    font-size: 1.1rem;
}

.result-box {
    background: #dcfce7;
    border-left: 4px solid #22c55e;
    padding: 1.5rem;
    border-radius: var(--radius-small);
    margin: 1.5rem 0;
}

.cta-box {
    background: linear-gradient(135deg, var(--color-primary) 0%, #8b5cf6 100%);
    color: white;
    padding: 2rem;
    border-radius: var(--radius-card);
    text-align: center;
    margin: 2rem 0;
    box-shadow: 0 10px 30px rgba(255, 107, 44, 0.3);
}

.cta-box a {
    display: inline-block;
    background: white;
    color: var(--color-primary);
    padding: 1rem 2rem;
    border-radius: var(--radius-button);
    font-weight: 700;
    text-decoration: none;
    margin-top: 1rem;
    transition: all 0.3s ease;
    min-height: var(--touch-target-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.cta-box a:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

/* Content Area Typography */
.content-area h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text-main);
    margin-top: 2.5rem;
    margin-bottom: 1.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 3px solid #e2e8f0;
}

@media (min-width: 768px) {
    .content-area h2 {
        font-size: 1.875rem;
        margin-top: 3rem;
    }
}

.content-area h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: #334155;
    margin-top: 2rem;
    margin-bottom: 1rem;
}

@media (min-width: 768px) {
    .content-area h3 {
        font-size: 1.5rem;
    }
}

.content-area p {
    font-size: 1rem;
    line-height: 1.8;
    color: var(--color-text-muted);
    margin-bottom: 1.25rem;
}

@media (min-width: 768px) {
    .content-area p {
        font-size: 1.125rem;
    }
}

.content-area ul,
.content-area ol {
    font-size: 1rem;
    line-height: 1.8;
    color: var(--color-text-muted);
    margin-bottom: 1.5rem;
    padding-left: 1.5rem;
}

@media (min-width: 768px) {
    .content-area ul,
    .content-area ol {
        font-size: 1.125rem;
    }
}

.content-area li {
    margin-bottom: 0.75rem;
}

.content-area strong {
    color: var(--color-text-main);
    font-weight: 600;
}

.content-area a {
    color: var(--color-primary);
    text-decoration: underline;
    font-weight: 500;
}

.content-area a:hover {
    opacity: 0.8;
}

.breadcrumb {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-bottom: 1.5rem;
}

.breadcrumb a {
    color: var(--color-primary);
    text-decoration: none;
}

.breadcrumb a:hover {
    text-decoration: underline;
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .no-print {
        display: none !important;
    }

    body {
        background: white !important;
    }

    .card-shadow,
    .card-shadow-lg,
    .hover\:card-shadow-md {
        box-shadow: none !important;
    }

    canvas {
        max-width: 100% !important;
        height: auto !important;
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .bg-gradient-to-r,
    .bg-gradient-to-br {
        background-image: none !important;
    }

    button,
    input,
    select {
        border-width: 2px !important;
    }
}

/* Landscape Mobile Support */
@media (max-width: 767px) and (orientation: landscape) {
    .min-h-screen {
        min-height: auto;
    }

    body {
        padding-top: 1rem;
        padding-bottom: 1rem;
    }
}
