/* ====== CRITICAL CSS - ABOVE THE FOLD ====== */
/* Mobile-first approach with performance optimizations */

/* CSS Reset and Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #fafafa;
    color: #222;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-display: swap; /* Font display optimization for system fonts */
}

/* ====== MOBILE-FIRST LAYOUT ====== */
.main-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ====== MOBILE MENU TOGGLE ====== */
.menu-toggle {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 11000;
    background: #2c3e50;
    color: #fff;
    border: none;
    font-size: 1.4rem;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.menu-toggle:hover,
.menu-toggle:focus {
    background: #34495e;
    outline: 2px solid #3498db;
    outline-offset: 2px;
}

/* ====== SIDEBAR - MOBILE FIRST ====== */
.sidebar {
    position: fixed;
    left: -100vw;
    top: 0;
    width: 85vw;
    max-width: 320px;
    height: 100vh;
    background: #2c3e50;
    color: #ecf0f1;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 9998;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.sidebar.open {
    left: 0;
}

.sidebar::before {
    content: '';
    position: fixed;
    top: 0;
    left: 100%;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: -1;
}

.sidebar.open::before {
    opacity: 1;
    pointer-events: auto;
}

/* ====== LOGO SECTION ====== */
.logo {
    background: #fff;
    padding: 15px;
    margin: 0;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.logo img {
    max-width: 120px;
    width: 100%;
    height: auto;
    margin-bottom: 8px;
}

.logo h1 {
    color: #2c3e50;
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
}

/* ====== NAVIGATION MENU ====== */
.menu ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.menu ul li {
    border-bottom: 1px solid #34495e;
}

.menu ul li a {
    color: #ecf0f1;
    text-decoration: none;
    padding: 16px 20px;
    display: block;
    transition: background-color 0.2s ease;
    font-size: 0.95rem;
    touch-action: manipulation;
}

.menu ul li a:hover,
.menu ul li a:focus,
.menu ul li a.active {
    background-color: #34495e;
    outline: none;
}

/* ====== MAIN CONTENT - MOBILE FIRST ====== */
.content {
    flex: 1;
    padding: 60px 16px 20px;
    max-width: 100%;
    overflow-x: hidden;
}

/* ====== TYPOGRAPHY ====== */
h1 {
    font-size: 1.5rem;
    color: #2c3e50;
    margin-bottom: 1rem;
    line-height: 1.3;
}

h2 {
    font-size: 1.25rem;
    color: #2c3e50;
    margin: 1.5rem 0 1rem;
    line-height: 1.4;
}

h3 {
    font-size: 1.1rem;
    color: #2c3e50;
    margin: 1rem 0 0.5rem;
}

p {
    margin-bottom: 1rem;
    line-height: 1.6;
}

/* ====== HERO SECTION ====== */
.hero-section {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    padding: 30px 20px;
    border-radius: 12px;
    margin: 20px 0;
    text-align: center;
    border-left: 5px solid #3498db;
}

.subtitle {
    font-size: 1.1rem;
    color: #666;
    margin-bottom: 1rem;
}

.hero-description {
    font-size: 1.05rem;
    line-height: 1.7;
}

.hero-description mark {
    background: #fff3cd;
    padding: 2px 4px;
    border-radius: 3px;
}

/* ====== QUICK TOOLS GRID ====== */
.quick-tools {
    margin: 30px 0;
}

.tools-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin-top: 20px;
}

.tool-card {
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    text-align: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.tool-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
}

.tool-card h3 {
    color: #2c3e50;
    margin-bottom: 8px;
    font-size: 1.1rem;
}

.tool-card p {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 15px;
}

.btn-tool {
    display: inline-block;
    background: #2563eb; /* Improved contrast ratio 4.5:1 */
    color: #fff;
    text-decoration: none;
    padding: 10px 20px;
    border-radius: 6px;
    font-weight: 600;
    transition: background 0.2s ease;
    font-size: 0.9rem;
}

.btn-tool:hover,
.btn-tool:focus {
    background: #1d4ed8;
    outline: 2px solid #fbbf24;
    outline-offset: 2px;
}

/* ====== TOOLS LIST ====== */
.tools-list {
    margin: 40px 0;
}

.tools-description {
    margin-top: 20px;
}

.tool-item {
    background: #fff;
    padding: 20px;
    margin-bottom: 16px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border-left: 4px solid #3498db;
}

.tool-item h3 {
    margin-bottom: 8px;
}

.tool-item h3 a {
    color: #2c3e50;
    text-decoration: none;
    transition: color 0.2s ease;
}

.tool-item h3 a:hover {
    color: #3498db;
}

.tool-item p {
    color: #666;
    font-size: 0.95rem;
    margin-bottom: 10px;
}

.tool-tags {
    display: inline-block;
    font-size: 0.8rem;
    color: #888;
    background: #f8f9fa;
    padding: 4px 8px;
    border-radius: 12px;
    margin-top: 8px;
}

/* ====== OFFICIAL LINKS ====== */
.official-links {
    margin: 40px 0;
}

.links-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-top: 20px;
}

.official-link {
    display: block;
    background: #fff;
    padding: 16px;
    border-radius: 8px;
    text-decoration: none;
    color: #2c3e50;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border-left: 4px solid #27ae60;
}

.official-link:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
}

.official-link strong {
    display: block;
    font-size: 1rem;
    margin-bottom: 4px;
    color: #2c3e50;
}

.official-link span {
    font-size: 0.9rem;
    color: #666;
}

/* ====== CALCULATOR FORMS - MOBILE OPTIMIZED ====== */
.calculator-form {
    background: #fff;
    padding: 20px 16px;
    margin: 20px 0;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    max-width: 100%;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #2c3e50;
    font-size: 0.95rem;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e1e8ed;
    border-radius: 6px;
    font-size: 1rem;
    background: #fff;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.form-group select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 12px center;
    background-repeat: no-repeat;
    background-size: 16px;
    padding-right: 40px;
}

/* ====== BUTTONS ====== */
.btn {
    background: #2563eb; /* Improved contrast ratio 4.5:1 */
    color: #fff;
    border: none;
    padding: 14px 24px;
    border-radius: 6px;
    cursor: pointer;
    width: 100%;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.2s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn:hover,
.btn:focus {
    background: #1d4ed8; /* Darker for better contrast */
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.btn:active {
    transform: translateY(0);
}

.btn:focus-visible {
    outline: 2px solid #fbbf24;
    outline-offset: 2px;
}

/* ====== RESULTS SECTIONS ====== */
.results-box,
.total-result-box {
    margin: 20px 0;
    padding: 20px 16px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.05);
}

.total-result-box {
    background: linear-gradient(135deg, #eafaf1 0%, #d5f4e6 100%);
    border-left: 5px solid #27ae60;
    text-align: center;
}

.total-result-box h3 {
    color: #14532d;
    margin-bottom: 8px;
    font-size: 1.1rem;
}

.total-result-box span {
    font-weight: 700;
    font-size: 1.5rem;
    color: #14532d;
}

.result-item,
.result-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 12px 0;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 6px;
    font-size: 0.95rem;
}

.result-row.highlight,
.result-item.highlight {
    background: #e3f2fd;
    border-left: 4px solid #2196f3;
}

/* ====== TABLES - MOBILE OPTIMIZED ====== */
.results-table,
.details-table {
    margin: 20px 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.05);
}

.results-table table,
.details-table table {
    width: 100%;
    min-width: 600px;
    border-collapse: collapse;
    background: #fff;
    font-size: 0.85rem;
}

.results-table th,
.details-table th,
.results-table td,
.details-table td {
    padding: 12px 8px;
    text-align: center;
    border-bottom: 1px solid #e1e8ed;
}

.results-table th,
.details-table th {
    background: #2c3e50;
    color: white;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 10;
}

.results-table tr:nth-child(even),
.details-table tr:nth-child(even) {
    background: #f8f9fa;
}

/* ====== CHARTS - PERFORMANCE OPTIMIZED ====== */
.chart-container {
    width: 100%;
    max-width: 500px;
    margin: 20px auto;
    padding: 16px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.05);
    position: relative;
    aspect-ratio: 16/10;
}

.chart-container canvas {
    width: 100% !important;
    height: auto !important;
    max-width: 100%;
    display: block;
}

/* ====== DISCLAIMERS AND WARNINGS ====== */
.disclaimer,
.disclaimer.warning {
    margin: 20px 0;
    padding: 16px;
    background: #fff3cd;
    border-left: 4px solid #ffc107;
    border-radius: 0 6px 6px 0;
    font-size: 0.9rem;
    line-height: 1.5;
}

.disclaimer.warning {
    background: #f8d7da;
    border-left-color: #dc3545;
    color: #721c24;
}

.disclaimer-content p {
    margin-bottom: 12px;
}

.disclaimer-content p:last-child {
    margin-bottom: 0;
}

/* ====== CONTACT SECTION ====== */
.contact-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    margin: 30px 0;
}

.contact-email {
    color: #3498db;
    text-decoration: none;
    font-weight: 600;
}

.contact-email:hover {
    text-decoration: underline;
}

/* ====== FOOTER ====== */
.footer {
    background: #2c3e50;
    color: #ecf0f1;
    text-align: center;
    padding: 20px 16px;
    margin-top: 40px;
}

.footer-content {
    max-width: 800px;
    margin: 0 auto;
}

.footer-content nav {
    margin-bottom: 12px;
}

.footer-content a {
    color: #bdc3c7;
    text-decoration: none;
    transition: color 0.2s ease;
}

.footer-content a:hover,
.footer-content a:focus {
    color: #3498db;
    text-decoration: underline;
}

.footer-content strong {
    color: #f39c12;
}

.copyright {
    margin-top: 10px;
    font-size: 0.9rem;
    color: #95a5a6;
}

/* ====== UTILITY CLASSES ====== */
.highlight {
    font-weight: 600;
    color: #27ae60;
}

.text-center {
    text-align: center;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Skip link for accessibility */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: #000;
    color: #fff;
    padding: 8px;
    text-decoration: none;
    border-radius: 0 0 4px 4px;
    z-index: 12000;
    font-weight: 600;
    transition: top 0.2s ease;
}

.skip-link:focus {
    top: 0;
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* ====== FEATURE LIST STYLING ====== */
.feature-list {
    background: #e8f5e8;
    padding: 16px;
    border-radius: 8px;
    margin: 20px 0;
    border-left: 4px solid #27ae60;
}

.feature-list ul {
    margin: 8px 0 0 0;
    padding-left: 0;
    list-style: none;
}

.feature-list li {
    margin: 8px 0;
    font-size: 0.95rem;
}

/* ====== SELIC FIELDS GRID ====== */
.selic-fields {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

/* ====== INPUT ENHANCEMENTS ====== */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* ====== PERFORMANCE OPTIMIZATIONS ====== */
img {
    max-width: 100%;
    height: auto;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ====== AD-FRIENDLY STYLES ====== */
.ad-container {
    margin: 20px 0;
    text-align: center;
    min-height: 250px;
    background: transparent;
    border-radius: 8px;
    border: 1px dashed #ddd;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
}

.ad-container ins {
    display: block !important;
    background: transparent !important;
}

.ad-sidebar {
    background: #f8f9fa;
    padding: 20px;
    border-left: 1px solid #dee2e6;
    display: none;
}

.ad-placeholder {
    padding: 20px;
    background: #e9ecef;
    border: 2px dashed #adb5bd;
    text-align: center;
    color: #6c757d;
    margin-bottom: 15px;
    border-radius: 8px;
}

/* ====== TABLET BREAKPOINT (768px+) ====== */
@media (min-width: 768px) {
    .content {
        padding: 30px 40px;
    }
    
    .calculator-form {
        padding: 30px;
        max-width: 600px;
        margin: 30px auto;
    }
    
    .selic-fields {
        grid-template-columns: 1fr 1fr;
        gap: 20px;
    }
    
    .tools-grid {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
        gap: 20px;
    }
    
    .links-grid {
        grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
        gap: 16px;
    }
    
    h1 {
        font-size: 2rem;
    }
    
    h2 {
        font-size: 1.5rem;
    }
    
    .results-table table,
    .details-table table {
        font-size: 0.9rem;
    }
    
    .chart-container {
        max-width: 600px;
        padding: 24px;
    }
}

/* ====== DESKTOP BREAKPOINT (1024px+) ====== */
@media (min-width: 1024px) {
    .menu-toggle {
        display: none;
    }
    
    .main-container {
        display: grid;
        grid-template-columns: 280px 1fr;
        gap: 0;
    }
    
    .sidebar {
        position: static;
        left: 0;
        width: 280px;
        height: 100vh;
        max-width: none;
        transition: none;
    }
    
    .sidebar::before {
        display: none;
    }
    
    .content {
        padding: 40px 50px;
        max-width: 1000px;
    }
    
    .logo img {
        max-width: 200px;
    }
    
    .calculator-form {
        max-width: 700px;
    }
    
    .chart-container {
        max-width: 700px;
    }
    
    .tools-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ====== LARGE DESKTOP (1200px+) ====== */
@media (min-width: 1200px) {
    .main-container {
        grid-template-columns: 280px 1fr 300px;
    }
    
    .content {
        max-width: none;
    }
    
    .ad-sidebar {
        display: block;
        height: 100vh;
        overflow-y: auto;
    }
}

/* ====== PRINT STYLES ====== */
@media print {
    .sidebar,
    .menu-toggle,
    .footer,
    .ad-sidebar,
    .ad-container {
        display: none !important;
    }
    
    .main-container {
        display: block !important;
    }
    
    .content {
        padding: 0 !important;
        max-width: none !important;
    }
    
    body {
        background: white !important;
        color: black !important;
    }
    
    .calculator-form,
    .results-box,
    .total-result-box {
        box-shadow: none !important;
        border: 1px solid #ccc !important;
    }
}

/* ====== ACCESSIBILITY IMPROVEMENTS ====== */
@media (prefers-contrast: high) {
    .btn {
        border: 2px solid #000;
    }
    
    .form-group input:focus,
    .form-group select:focus {
        border-color: #000;
        box-shadow: 0 0 0 3px #000;
    }
}

/* Focus visible for keyboard navigation */
.btn:focus-visible,
.menu ul li a:focus-visible,
.form-group input:focus-visible,
.form-group select:focus-visible {
    outline: 2px solid #3498db;
    outline-offset: 2px;
}

/* ====== LOADING STATES ====== */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #3498db;
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ====== CRITICAL PERFORMANCE HINTS ====== */
.preload-hint {
    font-display: swap;
}

.sidebar,
.menu-toggle,
.btn {
    will-change: transform;
}

.sidebar.open {
    transform: translateZ(0);
}

/* ====== MOBILE AD SPACING ====== */
@media (max-width: 767px) {
    .ad-container {
        margin: 15px 0;
        min-height: 200px;
    }
    
    .hero-section {
        padding: 20px 16px;
    }
    
    .tool-card {
        padding: 16px;
    }
    
    .official-link {
        padding: 12px;
    }
}
