/* ===== Reset ===== */
*, *::before, *::after { 
    margin: 0; padding: 0; box-sizing: border-box; 
    -webkit-tap-highlight-color: transparent; /* Remove blue highlight on Android */
}

:root {
    --white: #ffffff;
    --bg: #f4f4f5;
    --bg-card: #ffffff;
    --border: #dcdce0;
    --border-light: #ebebee;
    --text: #1f2937;
    --text-secondary: #4b5563;
    --text-muted: #8e8e9a;
    --primary: #2e7d32;
    --primary-light: #e8f5e9;
    --primary-dark: #1b5e20;
    --primary-bg: #f0f7f0;
    --link: #1565c0;
    --link-hover: #0d47a1;
    --danger: #c62828;
    --warning-bg: #fffbeb;
    --warning-border: #f59e0b;
    --radius: 12px;
    --shadow: 0 4px 20px rgba(0,0,0,0.03), 0 1px 5px rgba(0,0,0,0.02);
    --shadow-md: 0 8px 30px rgba(0,0,0,0.05), 0 3px 10px rgba(0,0,0,0.03);
    --shadow-hover: 0 12px 40px rgba(0,0,0,0.08), 0 4px 14px rgba(0,0,0,0.04);
}



html { font-size: 15px; scroll-behavior: smooth; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    overscroll-behavior-y: none; /* Previne o efeito "elástico" (pull-to-refresh) nativo no topo da página */
    padding-bottom: env(safe-area-inset-bottom); /* Respeita a barra inferior do iPhone */
}

a { color: var(--link); text-decoration: none; transition: color 0.2s ease; }
a:hover { color: var(--link-hover); text-decoration: underline; }

.container { max-width: 1440px; margin: 0 auto; padding: 0 20px; }

/* ===== Header ===== */
.header {
    background: rgba(46, 125, 50, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: white;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    padding-top: env(safe-area-inset-top);
}

.header-inner {
    display: flex;
    align-items: center;
    height: 54px;
    gap: 20px;
}

.logo {
    color: white;
    font-size: 1.45rem;
    font-weight: 800;
    text-decoration: none;
    display: flex;
    align-items: center;
    white-space: nowrap;
    flex-shrink: 0;
    letter-spacing: -0.03em;
}
.logo:hover { text-decoration: none; color: white; }
.logo-plus { 
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: white;
    color: var(--primary);
    width: 24px;
    height: 24px;
    border-radius: 6px;
    font-size: 1.2rem;
    font-weight: 900;
    margin-right: 6px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

/* Global Search */
.header-search {
    flex: 1;
    max-width: 380px;
    position: relative;
}

.header-search input {
    width: 100%;
    padding: 7px 14px;
    font-size: 0.85rem;
    font-family: inherit;
    border: none;
    border-radius: 4px;
    background: rgba(255,255,255,0.2);
    color: white;
    outline: none;
    transition: background 0.2s;
}
.header-search input::placeholder { color: rgba(255,255,255,0.65); }
.header-search input:focus { background: rgba(255,255,255,0.3); }

.search-results {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0; right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    max-height: 320px;
    overflow-y: auto;
    z-index: 200;
    opacity: 0;
    transform: translateY(10px) scale(0.98);
    pointer-events: none;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.search-results.open { 
    display: block; 
    opacity: 1; 
    transform: translateY(0) scale(1); 
    pointer-events: auto; 
}

.search-result-item {
    display: block;
    padding: 10px 14px;
    font-size: 0.87rem;
    color: var(--text);
    cursor: pointer;
    border-bottom: 1px solid var(--border-light);
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: var(--primary-light); text-decoration: none; color: var(--primary-dark); }
.search-result-item small { display: block; font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }

.search-no-result { padding: 12px 14px; font-size: 0.85rem; color: var(--text-muted); }

.header-nav {
    display: flex;
    gap: 2px;
    margin-left: auto;
    flex-shrink: 0;
}

.header-link {
    color: rgba(255,255,255,0.85);
    font-size: 0.82rem;
    font-weight: 500;
    padding: 7px 12px;
    border-radius: var(--radius);
    transition: background 0.2s;
    white-space: nowrap;
}
.header-link:hover {
    background: rgba(255,255,255,0.15);
    color: white;
    text-decoration: none;
}

.menu-toggle {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    flex-shrink: 0;
}
.menu-toggle span { display: block; width: 22px; height: 2px; background: white; border-radius: 2px; }

/* ===== Layout ===== */
.main-wrap { padding: 24px 20px 48px; }

.layout {
    display: grid;
    grid-template-columns: 220px 1fr 280px; /* Esquerda(Menu) | Meio(Conteúdo) | Direita(Anúncios) */
    gap: 24px;
    align-items: start;
}

/* ===== Sidebar ===== */
.sidebar {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    position: sticky;
    top: 78px;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
}
.sidebar::-webkit-scrollbar { width: 3px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.sidebar-section { border-bottom: 1px solid var(--border-light); }
.sidebar-section:last-child { border-bottom: none; }

.sidebar-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 14px 16px 4px;
    position: sticky;
    top: 0;
    background: var(--bg-card);
}

.sidebar-list { list-style: none; padding-bottom: 6px; }

.sidebar-list li a {
    display: block;
    padding: 5px 16px;
    font-size: 0.84rem;
    color: var(--text-secondary);
    transition: all 0.15s;
    border-left: 3px solid transparent;
}
.sidebar-list li a:hover {
    background: var(--primary-light);
    color: var(--primary-dark);
    text-decoration: none;
    border-left-color: var(--primary);
}

.sidebar-subcat {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--primary);
    padding: 12px 16px 2px;
    text-transform: uppercase;
    opacity: 0.8;
    background: var(--bg-card);
}

/* ===== Right Ad Sidebar (Desktop) ===== */
.sidebar-right {
    position: sticky;
    top: 78px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.sidebar-ad-unit {
    width: 100%;
    min-height: 600px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===== Content Area ===== */
.content { min-height: 60vh; }

.home-subcat-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--primary-dark);
    margin: 24px 0 12px 0;
    padding-bottom: 4px;
    border-bottom: 1px dashed var(--border-light);
}

/* Home: Popular Section */
.popular-section {
    background: var(--primary-bg);
    border: 1px solid #c8e6c9;
    border-radius: var(--radius);
    padding: 20px 24px;
    margin-bottom: 28px;
}

.popular-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 12px;
}

/* ===== Monetization (Ads) ===== */
.ad-container {
    width: 100%;
    margin: 24px 0;
    text-align: center;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    /* CLS Protection: Prevent layout shift by reserving space */
    min-height: 90px;
}
.ad-placeholder {
    display: none;
}

.popular-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
}

.popular-link {
    display: block;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.87rem;
    font-weight: 500;
    color: var(--text);
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: var(--shadow);
}
.popular-link:hover {
    background: var(--primary);
    color: #ffffff;
    text-decoration: none;
    border-color: var(--primary);
    box-shadow: var(--shadow-hover);
    transform: translateY(-2px);
}

/* Home Sections */
.home-section { margin-bottom: 28px; }

.home-section-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
    padding-bottom: 8px;
    margin-bottom: 10px;
    border-bottom: 2px solid var(--primary);
    display: inline-block;
}

.tools-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}

.tool-link {
    display: block;
    padding: 18px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: var(--shadow);
}
.tool-link:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-hover);
    transform: translateY(-4px) scale(1.01);
    text-decoration: none;
}

.tool-link-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
}
.tool-link:hover .tool-link-name { color: var(--primary-dark); }

.tool-link-desc {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 3px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ===== Tool Page ===== */
.tool-page-header {
    margin-bottom: 20px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}

.tool-page-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.tool-page-desc {
    font-size: 0.9rem;
    color: var(--text-secondary);
    max-width: 600px;
}

.breadcrumb {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 10px;
}
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--primary); text-decoration: underline; }

.tool-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
}

.tool-card-title {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-light);
}

/* Reference info box below tool */
.tool-reference {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.7;
}
.tool-reference strong { color: var(--text); }

/* Forms */
.form-group { margin-bottom: 14px; }

.form-label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 5px;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 9px 12px;
    font-size: 0.9rem;
    font-family: inherit;
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 4px); /* Slightly sharper than main cards */
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    background: var(--bg-card);
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-light);
}
.form-textarea { resize: vertical; min-height: 90px; }
.form-select { cursor: pointer; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 3px; }
.form-error { border-color: var(--danger) !important; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 22px;
    font-size: 0.87rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: calc(var(--radius) - 4px);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.btn:active { transform: scale(0.96); }

.btn-primary { 
    background: var(--primary); 
    color: white; 
    box-shadow: 0 4px 10px rgba(46,125,50,0.25);
}
.btn-primary:hover { 
    background: var(--primary-dark); 
    transform: translateY(-2px);
    box-shadow: 0 6px 14px rgba(46,125,50,0.35);
}

.btn-secondary { background: var(--white); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); transform: translateY(-2px); }

.btn-sm { padding: 6px 14px; font-size: 0.8rem; }

.btn-group { display: flex; gap: 8px; margin-top: 18px; }

/* Results */
.result-box {
    background: var(--primary-light);
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    padding: 20px;
    margin-top: 20px;
}

.result-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.result-value {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--primary-dark);
    margin-bottom: 4px;
    letter-spacing: -0.02em;
    animation: fadeInSlide 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes fadeInSlide {
    0% { opacity: 0; transform: translateY(8px); }
    100% { opacity: 1; transform: translateY(0); }
}

.result-interp {
    font-size: 0.93rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}

.result-details {
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* Document Output */
.doc-output {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    font-size: 0.87rem;
    line-height: 1.8;
    white-space: pre-wrap;
    margin-top: 16px;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.04);
    font-family: 'Courier New', monospace;
}

/* CID Search */
.cid-results { margin-top: 12px; }

.cid-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 14px;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.87rem;
}
.cid-item:last-child { border-bottom: none; }
.cid-item:hover { background: var(--primary-light); }

.cid-code {
    font-weight: 700;
    color: var(--primary-dark);
    min-width: 55px;
    font-size: 0.85rem;
}

.cid-desc { flex: 1; color: var(--text); }

.cid-copy-btn {
    background: var(--primary-light);
    border: 1px solid #c8e6c9;
    color: var(--primary-dark);
    cursor: pointer;
    padding: 3px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 4px;
    font-family: inherit;
    transition: all 0.15s;
}
.cid-copy-btn:hover { background: var(--primary); color: white; border-color: var(--primary); }

/* CPR Timer */
.cpr-display {
    font-size: 4.5rem;
    font-weight: 700;
    text-align: center;
    color: var(--primary-dark);
    padding: 24px 0;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.05em;
}

.cpr-alert {
    text-align: center;
    font-weight: 700;
    color: var(--danger);
    min-height: 24px;
    margin-top: 10px;
    font-size: 0.93rem;
}

.cpr-controls { display: flex; justify-content: center; gap: 10px; }

/* ===== Footer ===== */
.footer {
    background: var(--primary);
    color: white;
    padding: 36px 0 24px;
    margin-top: 32px;
}

.footer-cols {
    display: grid;
    grid-template-columns: 1.5fr 1fr 1fr;
    gap: 32px;
    margin-bottom: 24px;
}

.footer-about h2 {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: white;
}

.footer-about p {
    font-size: 0.82rem;
    color: rgba(255,255,255,0.8);
    line-height: 1.7;
}

.footer-links-col h3 {
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: rgba(255,255,255,0.6);
    margin-bottom: 10px;
}

.footer-links-col ul { list-style: none; }
.footer-links-col ul li { margin-bottom: 6px; }
.footer-links-col ul li a {
    font-size: 0.84rem;
    color: rgba(255,255,255,0.8);
}
.footer-links-col ul li a:hover { color: white; }

.footer-bottom {
    padding-top: 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

.footer-copyright {
    font-size: 0.85rem;
    color: rgba(255,255,255,0.7);
}

.footer-legal-links {
    display: flex;
    gap: 20px;
}

.footer-legal-links a {
    font-size: 0.85rem;
    color: rgba(255,255,255,0.7);
    transition: color 0.2s;
}

.footer-legal-links a:hover {
    color: white;
    text-decoration: underline;
}

/* ===== Utility ===== */
.hidden { display: none !important; }

/* ===== Responsive ===== */
@media (max-width: 1024px) {
    .layout { grid-template-columns: 220px 1fr; }
    .sidebar-right { display: none; } /* Esconde o pilar direito em telas médias */
}

@media (max-width: 900px) {
    .header-search { max-width: 240px; }
}

@media (max-width: 768px) {
    .header-inner { flex-wrap: wrap; height: auto; padding: 8px 20px; gap: 10px; }
    .logo { flex: 1; }
    .header-nav { display: none; }
    .header-nav.open {
        display: flex;
        flex-direction: column;
        position: absolute;
        top: 100%; left: 0; right: 0;
        background: var(--primary);
        padding: 8px 16px 16px;
        box-shadow: 0 4px 8px rgba(0,0,0,0.2);
        z-index: 101;
    }
    .header-search { flex: 0 0 100%; max-width: 100%; order: 3; }
    .menu-toggle { display: flex; order: 2; }
    .layout { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .tools-list { grid-template-columns: 1fr; }
    .popular-grid { grid-template-columns: 1fr 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .cpr-display { font-size: 3rem; }
    .footer-cols { grid-template-columns: 1fr; gap: 20px; }
    
    /* Ads Mobile */
    .ad-container { min-height: 100px; } /* Formato banner (320x100) ou menor */
    
    /* Touch Target Optimization for Mobile */
    .form-input, .form-select, .btn { 
        min-height: 48px; /* Target de toque perfeito da Apple */
        font-size: 16px !important; /* Previne auto-zoom no iOS Safari */
    }
    .tool-link { 
        padding: 18px 16px; 
        transition: transform 0.1s, background-color 0.2s;
    }
    .tool-link:active {
        transform: scale(0.97); /* Animação nativa de clique de botão */
        background-color: var(--primary-light);
    }
    .tool-card {
        padding: 20px;
    }
}

@media (max-width: 480px) {
    .popular-grid { grid-template-columns: 1fr; }
}

/* ===== Print Styles ===== */
/* Math Formulas */
.formula-box {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--bg);
    padding: 8px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
    font-family: 'Times New Roman', Times, serif;
    font-size: 1.1em;
    margin: 8px 0;
    color: var(--text);
}
.math-fraction {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    vertical-align: middle;
    margin: 0 4px;
}
.math-num {
    padding: 0 4px;
    border-bottom: 1px solid var(--text);
    line-height: 1.2;
}
.math-den {
    padding: 0 4px;
    line-height: 1.2;
}
.math-var { font-style: italic; }

@media print {
    /* Remove browser default header/footer (date, url) */
    @page {
        margin: 0;
    }

    /* Hide all UI elements */
    .header, .sidebar, .footer, .btn-group, .breadcrumb, .tool-page-header, .tool-card-title, .form-group, .form-hint, .search-overlay, #cid11Count, #cid11Results, #cid11Input {
        display: none !important;
    }

    /* Reset background and layout */
    body, html {
        background: white !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .layout {
        display: block !important;
        grid-template-columns: none !important;
        min-height: auto !important;
    }

    .content {
        padding: 0 !important;
        margin: 0 !important;
    }

    .tool-card {
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        background: transparent !important;
    }

    /* Format Document Output for A4 Print */
    .doc-output {
        border: none !important;
        background: white !important;
        color: black !important;
        padding: 2cm !important; /* Margem interna para compensar o @page margin 0 */
        margin: 0 !important;
        white-space: pre-wrap !important;
        font-family: 'Times New Roman', Times, serif, monospace !important;
        font-size: 12pt !important;
        line-height: 1.5 !important;
    page-break-inside: avoid;
    }
}

/* Legal Modal */
.legal-modal-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}
.legal-modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}
.legal-modal {
    background: var(--bg-card);
    border-radius: var(--radius);
    width: 90%; max-width: 650px;
    max-height: 90vh;
    padding: 30px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
    display: flex; flex-direction: column;
    overflow: hidden;
    color: var(--text);
    border: 1px solid var(--border);
}
.legal-title {
    font-size: 1.35rem; font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 20px;
    text-align: center;
}
.legal-content {
    flex-grow: 1; overflow-y: auto;
    font-size: 0.95rem; line-height: 1.6;
    margin-bottom: 20px; padding-right: 15px;
}
.legal-content p { margin-bottom: 12px; }
.legal-content ul { margin-bottom: 12px; padding-left: 20px; }
.legal-content li { margin-bottom: 8px; }
.legal-actions { margin-top: auto; }
