/* ==========================================
   RESET E VARIÁVEIS (TEMA ESCURO PADRÃO)
========================================== */
* { box-sizing: border-box; }

:root {
    --bg-dark: #0f172a; 
    --panel-bg: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent-color: #00ffcc; 
    --akiz-green: #00ffcc;
    --danger: #ef4444;
    --border-color: #334155;
}

body {
    font-family: 'Inter', 'Segoe UI', sans-serif;
    margin: 0;
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* ==========================================
   TEMA CLARO (ESTRUTURA BASE)
========================================== */
body.light-theme .stage { background-color: #ffffff; }

/* ==========================================
   BARRA SUPERIOR (HEADER PADRONIZADO)
========================================== */
.top-bar {
    height: 65px;
    background-color: var(--panel-bg);
    border-bottom: 1px solid var(--border-color);
    display: grid;
    grid-template-columns: 1fr auto 1fr; 
    align-items: center;
    padding: 0 20px;
    z-index: 100;
}

.logo-area { display: flex; align-items: center; justify-content: flex-start; }
.logo-akiz { color: var(--akiz-green); font-weight: 800; font-size: 1.2rem; }
.logo-calc { color: var(--accent-color); font-weight: 800; font-size: 1.2rem; transition: color 0.3s; }
.hub-link { display: flex; align-items: center; margin-right: 12px; text-decoration: none; }
.logo-hub { width: 32px; height: 32px; border-radius: 50%; box-shadow: 0 0 8px rgba(0, 255, 204, 0.4); transition: transform 0.2s, box-shadow 0.2s; cursor: pointer; }
.logo-hub:hover { transform: scale(1.1); box-shadow: 0 0 15px rgba(0, 255, 204, 0.8); }

.module-selector {
    display: flex; gap: 8px; background: var(--bg-dark); padding: 5px;
    border-radius: 8px; border: 1px solid var(--border-color);
}
.module-tab {
    text-decoration: none; color: var(--text-muted); padding: 6px 18px;
    border-radius: 6px; font-size: 13px; font-weight: 600; transition: all 0.2s ease;
}
.module-tab:hover { color: var(--text-main); background: rgba(255, 255, 255, 0.05); }
.module-tab.active { color: var(--bg-dark); background: var(--accent-color); box-shadow: 0 2px 8px rgba(0, 255, 204, 0.3); }

.actions-area { display: flex; gap: 15px; justify-content: flex-end; }
.btn-icon { background: transparent; color: var(--text-main); border: 1px solid var(--border-color); padding: 8px 12px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.btn-icon.primary { background: var(--accent-color); color: #000; border: none; font-weight: bold; }

/* ==========================================
   LAYOUT GRID E PAINÉIS
========================================== */
.app-layout {
    display: grid;
    grid-template-columns: 320px 1fr 280px;
    flex: 1; overflow: hidden;
}

.panel { background-color: var(--panel-bg); padding: 20px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; overflow-x: hidden; }
.tools-panel { border-right: 1px solid var(--border-color); }
.theory-panel { border-left: 1px solid var(--border-color); }

h2 { font-size: 0.75rem; text-transform: uppercase; color: var(--text-muted); letter-spacing: 1px; margin: 10px 0 5px; }
.list-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border-color); padding-bottom: 10px; margin-bottom: 10px; }
.btn-icon-small { background: transparent; border: 1px solid var(--akiz-green); color: var(--akiz-green); padding: 4px 10px; border-radius: 4px; font-weight: bold; font-size: 11px; cursor: pointer; }

/* Resizer de colunas */
.resizer {
    width: 5px; background-color: var(--panel-bg); cursor: col-resize;
    transition: background 0.2s; z-index: 50;
    border-left: 1px solid var(--border-color); border-right: 1px solid var(--border-color);
}
.resizer:hover, .resizer.active { background-color: var(--accent-color); }

/* ==========================================
   INPUTS E COMPONENTES BÁSICOS
========================================== */
.input-group { display: flex; flex-direction: column; gap: 10px; }
input[type="text"], input[type="number"], textarea, select {
    background: var(--bg-dark); border: 1px solid var(--border-color); color: var(--text-main); 
    padding: 12px; border-radius: 6px; width: 100%; font-family: monospace;
}
textarea { flex-grow: 1; resize: none; font-family: 'Inter', sans-serif; }
textarea:disabled { opacity: 0.5; cursor: not-allowed; border-color: transparent;}
.btn-primary { background: var(--accent-color); color: #000; border: none; padding: 12px; border-radius: 6px; font-weight: 600; cursor: pointer; }
.btn-danger { background: transparent; border: 1px solid var(--danger); color: var(--danger); padding: 10px; border-radius: 6px; cursor: pointer; margin-top: auto; }

/* ==========================================
   FERRAMENTAS PRO (GRID DE BOTÕES)
========================================== */
.tools-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 20px; }
.tool-btn-pro { 
    background: var(--bg-dark); border: 1px solid var(--border-color); color: var(--text-main); 
    padding: 10px; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 600; 
    text-align: center; transition: all 0.2s ease; 
}
.tool-btn-pro:hover { border-color: var(--accent-color); }

.controls-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 20px; }
.btn-icon-file {
    background: transparent; color: var(--text-main); border: 1px solid var(--border-color); 
    padding: 10px; border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: 600;
    display: flex; align-items: center; justify-content: center; gap: 6px; transition: 0.2s;
}
.btn-icon-file:hover { background: rgba(255,255,255,0.05); }

/* ==========================================
   SISTEMA DE CAMADAS (LAYERS) E TOGGLES
========================================== */
.layer-item {
    background: var(--bg-dark); padding: 12px; border-radius: 8px; display: flex; flex-direction: column; gap: 10px;
    border-left: 4px solid var(--accent-color); transition: 0.2s; margin-bottom: 8px;
}
.layer-item.ativo { background: var(--panel-bg); border-right: 2px solid var(--accent-color); box-shadow: 0 4px 15px rgba(0,0,0,0.3); }
.layer-header { display: flex; justify-content: space-between; align-items: center; }
.layer-info { flex-grow: 1; cursor: pointer; font-family: monospace; font-size: 14px; font-weight: bold; color: var(--text-main); }
.layer-controls { display: flex; align-items: center; gap: 10px; }

input[type="color"].color-circle { -webkit-appearance: none; width: 24px; height: 24px; border: none; background: transparent; cursor: pointer; padding: 0; }
input[type="color"].color-circle::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"].color-circle::-webkit-color-swatch { border: 2px solid var(--border-color); border-radius: 50%; }

/* Toggle estilo iOS */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--border-color); transition: .4s; border-radius: 22px; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--layer-color, var(--accent-color)); }
input:checked + .slider:before { transform: translateX(18px); }

/* ==========================================
   PALCO CENTRAL E CARDS GERAIS
========================================== */
.stage { background-color: var(--bg-dark); padding: 0; display: flex; }

.tool-card { background: var(--bg-dark); border: 1px solid var(--border-color); padding: 15px; border-radius: 8px; }
.tool-option { display: flex; justify-content: space-between; align-items: center; font-weight: 600; font-size: 13px; }
.tool-card.disabled { opacity: 0.3; pointer-events: none; }

/* Tooltips */
.header-with-icon { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.info-tooltip { position: relative; cursor: help; }
.info-icon { width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--text-muted); color: var(--text-muted); display: flex; justify-content: center; align-items: center; font-size: 11px; font-weight: bold; }
.tooltip-text {
    visibility: hidden; opacity: 0; width: 250px; background-color: var(--panel-bg); color: var(--text-main); 
    padding: 12px; border-radius: 6px; position: absolute; z-index: 100; bottom: 150%; left: 50%; margin-left: -125px;
    font-size: 12px; border: 1px solid var(--border-color); transition: 0.3s; box-shadow: 0 5px 15px rgba(0,0,0,0.5); line-height: 1.4;
}
.info-tooltip:hover .tooltip-text { visibility: visible; opacity: 1; }

/* ==========================================
   MODAL DE BOAS-VINDAS
========================================== */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.85); backdrop-filter: blur(5px);
    display: flex; justify-content: center; align-items: center; z-index: 9999;
}
.modal-content {
    background: var(--panel-bg); border: 1px solid var(--accent-color);
    padding: 30px; border-radius: 12px; max-width: 550px; width: 90%;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); color: var(--text-main);
}
.modal-content h2 { margin-top: 0; color: var(--accent-color); font-size: 1.5rem; text-transform: none; letter-spacing: normal; border-bottom: 1px solid var(--border-color); padding-bottom: 15px;}
.modal-content p { font-size: 14px; line-height: 1.6; color: var(--text-main); margin-bottom: 10px; }
.modal-content ul { font-size: 14px; color: var(--text-muted); line-height: 1.6; padding-left: 20px; margin-bottom: 20px;}
.modal-footer { margin-top: 25px; display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--border-color); padding-top: 15px; }

/* ==========================================
   ESTILO DA SCROLLBAR (TEMA AKIZ)
========================================== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #1e293b; border-radius: 4px; }
::-webkit-scrollbar-thumb { background: #00ffcc; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #00cca3; }
body.light-theme ::-webkit-scrollbar-track { background: #e2e8f0; }
body.light-theme ::-webkit-scrollbar-thumb { background: #0ea5e9; }

/* ==========================================================================
   OTIMIZAÇÃO RESPONSIVA - MOBILE & TABLET (BLINDAGEM DO TEMA)
========================================================================== */
@media (max-width: 1024px) {
    .app-layout { grid-template-columns: 240px 1fr 240px; } 
}

@media (max-width: 768px), (max-height: 550px) {
    ::-webkit-scrollbar { display: none !important; width: 0 !important; height: 0 !important; }
    * { -ms-overflow-style: none !important; scrollbar-width: none !important; }

    .top-bar {
        display: flex; height: auto; min-height: 55px; padding: 10px;
        justify-content: space-between; gap: 15px; border-bottom: 1px solid var(--border-color);
    }
    .logo-area, .actions-area { flex-shrink: 0; }
    .logo-akiz { display: none; }
    
    .module-selector {
        position: fixed; bottom: 0; left: 0; right: 0; width: 100%; border-radius: 0;
        border-left: none; border-right: none; border-bottom: none;
        border-top: 1px solid var(--border-color); background: var(--bg-dark);
        z-index: 5000; display: flex; overflow-x: auto; -webkit-overflow-scrolling: touch;
        padding: 12px 10px; justify-content: flex-start; 
    }
    
    .module-tab { padding: 8px 12px; font-size: 12px; white-space: nowrap; flex-shrink: 0; }

    body { height: 100vh; height: 100dvh; overflow: hidden; }
    .app-layout { 
        display: flex; flex-direction: column; overflow-y: auto; overflow-x: hidden; 
        padding-bottom: 100px !important; 
    }

    .panel {
        width: 100%; height: auto; border-left: none !important; border-right: none !important;
        border-bottom: 4px solid var(--bg-dark) !important; padding: 15px; overflow: visible; 
    }

    .tools-panel { padding: 15px 15px 5px 15px !important; } 
    .list-header { margin-bottom: 5px !important; padding-bottom: 5px !important; }
    
    #painelCriacaoFuncao { padding: 10px !important; margin-bottom: 10px !important; }
    #painelCriacaoFuncao .input-group { flex-direction: row; align-items: stretch; gap: 8px; }
    #funcaoInput, #matNome { padding: 8px 12px; font-size: 14px; flex: 1; }
    #painelCriacaoFuncao .btn-primary, #btnSalvarMatriz { margin-top: 0 !important; width: auto !important; padding: 0 15px; font-size: 12px; white-space: nowrap; }
    
    .tools-panel > div[style*="padding: 15px"] { padding: 10px !important; margin-bottom: 10px !important; }
    #matNome { height: 38px !important; font-size: 13px !important; padding: 8px 12px !important; }
    #matValores { height: 60px !important; min-height: 60px !important; font-size: 13px !important; padding: 8px 12px !important; }
    #btnSalvarMatriz { height: 38px !important; font-size: 13px !important; margin-top: 0 !important; }
    
    .layer-item { padding: 8px 12px; margin-bottom: 5px; } 
    
    .stage {
        width: 100%; height: 50vh; min-height: 250px !important; flex-shrink: 0;
        border-bottom: 25px solid var(--bg-dark) !important; position: relative;
    }

    .theory-panel { display: flex; flex-direction: column; }
    .theory-panel > h2:nth-of-type(1) { order: 1; margin-top: 0 !important; }
    .theory-panel > #painelAnalise, .theory-panel > .tool-card { order: 2; }
    .theory-panel > .spacer-small { order: 3; }
    .theory-panel > h2:nth-of-type(2) { order: 4; }
    .theory-panel > #notasUsuario, .theory-panel > #notasAlgebra, .theory-panel > #notasGeometria, .theory-panel > textarea { order: 5; }
    .theory-panel > .list-header:first-child { order: 6; margin-top: 25px !important; }
    .theory-panel > .controls-grid, .theory-panel > .list-header:first-child + div { order: 7; margin-bottom: 0 !important; }

    select { height: 38px; font-size: 13px; padding: 0 10px; }
    .resizer { display: none !important; }
    .modal-content { padding: 20px; max-height: 85vh; overflow-y: auto; }
}

/* =========================================
   CORREÇÃO DO AUTOFILL DO NAVEGADOR
   ========================================= */
input:-webkit-autofill,
input:-webkit-autofill:hover, 
input:-webkit-autofill:focus, 
input:-webkit-autofill:active{
    /* Força o fundo a ficar com a cor escura do painel */
    -webkit-box-shadow: 0 0 0 30px var(--bg-dark) inset !important;
    /* Força o texto a ficar branco/cinza claro */
    -webkit-text-fill-color: var(--text-main) !important;
    /* Tira a bordinha azul feia do Chrome */
    outline: none !important;
    /* Um pequeno truque para a cor não piscar */
    transition: background-color 5000s ease-in-out 0s;
}

/* Garante que os inputs normais (quando não estão em autofill) também fiquem dark */
input, select {
    background-color: var(--bg-dark);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}