/* ==========================================
   Calcula Max · Max Mohr
   Tecnologia em Argamassa e Concreto

   Paleta corporativa institucional:
   --navy:      #1a3054   (azul escuro corporativo)
   --navy-mid:  #1f3d6b   (navy médio)
   --navy-light:#253f63   (navy suave para bordas/painéis)
   --blue:      #2a5a8f   (azul principal de botões)
   --blue-mid:  #4a90c4   (azul médio para realce)
   --sky:       #7dc4e8   (azul claro para textos destacados)
   --ice:       #b8e2f5   (azul gelo)
   --accent:    #e8a424   (dourado/ouro para contraste)
   ========================================== */

:root {
    --navy: #1a3054;
    --navy-mid: #1f3d6b;
    --navy-light: #253f63;
    --blue: #2a5a8f;
    --blue-mid: #4a90c4;
    --sky: #7dc4e8;
    --ice: #b8e2f5;
    --accent: #e8a424;
    --accent-hover: #d4921c;
    --surface: #0a1220;
    --surface-2: #142237;
    --text-primary: #e4edf7;
    --text-secondary: #8fa7c4;
    --text-muted: #5a7a9e;
    --danger: #ef4444;
    --success: #10b981;
    --radius: 12px;
    --radius-lg: 16px;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --glow-blue: 0 0 20px rgba(74, 144, 196, 0.15);
    --glow-accent: 0 0 24px rgba(232, 164, 36, 0.25);
}

/* === FONT === (carregada via <link> no template da aplicação) */

/* === RESET === */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--surface);
    font-family: 'Inter', sans-serif;
    color: var(--text-primary);
    overflow: hidden;
}

.font-mono {
    font-family: 'JetBrains Mono', monospace;
}

/* ==========================================
   Título CalculaMax — Corporativo e Sóbrio
   ========================================== */
.titulo-calcula-max {
    display: flex;
    align-items: baseline;
    gap: 1px;
    line-height: 1;
}

.texto-concreto {
    font-family: 'Inter', sans-serif;
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    /* Efeito textura de concreto/cimento queimado */
    background:
        repeating-conic-gradient(rgba(180, 175, 168, 0.06) 0% 25%,
            transparent 0% 50%) 0 0 / 4px 4px,
        linear-gradient(135deg,
            #a8a099 0%,
            #bcb5ab 15%,
            #9e9890 30%,
            #b5aea5 45%,
            #c2bbb2 55%,
            #a09a92 70%,
            #b8b1a8 85%,
            #a8a099 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
}

.texto-neon {
    font-family: 'Inter', sans-serif;
    font-size: 2.5rem;
    font-weight: 900;
    letter-spacing: -0.02em;
    color: #3b62bf;
    text-shadow:
        0 0 7px rgba(5, 57, 183, 0.8),
        0 0 15px rgba(5, 57, 183, 0.5),
        0 0 30px rgba(5, 57, 183, 0.3),
        0 0 50px rgba(5, 57, 183, 0.15);
    /* Ativa a pulsação contínua e suave do neon */
    animation: pulsar-neon 1800ms infinite ease-in-out;
}

/* Animação customizada que oscila apenas a intensidade do brilho (sem apagar a letra) */
@keyframes pulsar-neon {

    0%,
    100% {
        text-shadow:
            0 0 7px rgba(183, 5, 109, 0),
            0 0 15px rgba(183, 5, 124, 0),
            0 0 30px rgba(183, 5, 118, 0),
            0 0 50px rgba(183, 5, 115, 0);
    }

    50% {
        text-shadow:
            0 0 14px rgba(5, 57, 183, 1),
            0 0 25px rgba(5, 57, 183, 0.8),
            0 0 45px rgba(5, 57, 183, 0.6),
            0 0 75px rgba(5, 57, 183, 0.3);
    }
}

/* ==========================================
   Grid Blueprint Corporativo (Sutil)
   ========================================== */
.blueprint-grid {
    background-image:
        linear-gradient(rgba(74, 144, 196, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(74, 144, 196, 0.05) 1px, transparent 1px);
    background-size: 40px 40px;
    background-position: center center;
    opacity: 0.8;
}

/* ==========================================
   Glassmorphism Sóbrio
   ========================================== */
.glass-header {
    background: rgba(10, 18, 32, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(74, 144, 196, 0.15);
    height: 72px;
}

.glass-panel {
    background: rgba(20, 34, 55, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

/* ==========================================
   Inputs Modernos
   ========================================== */
.input-neon {
    background: rgba(5, 10, 20, 0.6);
    border: 1px solid rgba(74, 144, 196, 0.25);
    border-radius: var(--radius);
    padding: 10px 14px;
    color: #fff;
    transition: var(--transition);
    outline: none;
}

.input-neon:focus {
    border-color: var(--blue-mid);
    box-shadow: 0 0 15px rgba(74, 144, 196, 0.25);
    background: rgba(74, 144, 196, 0.05);
}

select.input-neon {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%234a90c4'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 16px;
    padding-right: 40px;
}

select.input-neon option {
    background-color: var(--surface-2);
    color: #ffffff;
}

/* ==========================================
   Sidebar Tool Buttons
   ========================================== */
.btn-tool {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(74, 144, 196, 0.15);
    color: var(--text-secondary);
    transition: var(--transition);
}

.btn-tool:hover {
    background: rgba(74, 144, 196, 0.1);
    border-color: rgba(74, 144, 196, 0.35);
    color: #fff;
    transform: translateX(2px);
}

.btn-tool.active {
    background: rgba(42, 90, 143, 0.3);
    border-color: var(--blue-mid);
    color: var(--sky);
    box-shadow: var(--glow-blue);
}

.btn-tool.auto {
    border-color: var(--success);
    color: var(--success);
}

.btn-tool.auto:hover {
    background: rgba(16, 185, 129, 0.15);
    border-color: var(--success);
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.15);
}

.btn-tool.danger {
    color: var(--danger);
    border-color: rgba(239, 68, 68, 0.2);
}

.btn-tool.danger:hover {
    background: rgba(239, 68, 68, 0.15);
    border-color: var(--danger);
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.15);
}

/* ==========================================
   Botões de Ação Superior / Primários
   ========================================== */
.btn-accent {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
    color: var(--navy);
    border: none;
    border-radius: 8px;
    font-weight: 800;
    transition: var(--transition);
}

.btn-accent:hover {
    box-shadow: var(--glow-accent);
    transform: translateY(-1px);
}

.btn-accent:active {
    transform: translateY(1px);
}

.btn-ghost {
    color: var(--text-secondary);
    transition: var(--transition);
}

.btn-ghost:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
}

/* ==========================================
   Scrollbar
   ========================================== */
.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgba(74, 144, 196, 0.2);
    border-radius: 10px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: var(--blue-mid);
}

/* ==========================================
   Modal
   ========================================== */
.modal-backdrop {
    background: rgba(5, 10, 20, 0.85);
    backdrop-filter: blur(8px);
}

.modal-content {
    background: var(--surface-2);
    border: 1px solid rgba(74, 144, 196, 0.2);
    border-radius: 20px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.5);
}

/* ==========================================
   Cards de Volume/Resultados
   ========================================== */
.result-card {
    background: linear-gradient(135deg, rgba(26, 48, 84, 0.7) 0%, rgba(31, 61, 107, 0.3) 100%);
    border: 1px solid rgba(74, 144, 196, 0.3);
}

/* ==========================================
   Animations
   ========================================== */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(15px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-in {
    animation: fadeInUp 0.35s ease-out forwards;
}

/* ==========================================
   Integração Web (WordPress / iframe)
   ========================================== */
body {
    height: 100vh;
    height: 100dvh;
}

#mainCanvas {
    /* Gestos do canvas ficam com a calculadora (desenho, pinça, mover) */
    touch-action: none;
}

/* Alça do painel: só aparece no celular */
.cm-sheet-handle {
    display: none;
}

/* Botão tela cheia (quando incorporado no site) */
.cm-fullscreen-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 35;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
    color: var(--sky);
    background: rgba(10, 18, 32, 0.9);
    border: 1px solid rgba(74, 144, 196, 0.3);
    border-radius: 10px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    cursor: pointer;
    transition: var(--transition);
}

.cm-fullscreen-btn:hover {
    color: #fff;
    border-color: var(--blue-mid);
    box-shadow: var(--glow-blue);
}

/* ==========================================
   Mobile (≤ 768px)
   ========================================== */
@media (max-width: 768px) {

    /* --- Cabeçalho compacto --- */
    .glass-header {
        height: 56px;
        padding: 8px 10px;
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
        gap: 8px;
    }

    .cm-brand {
        gap: 8px !important;
        min-width: 0;
    }

    .cm-logo {
        height: 36px;
        max-width: 64px;
    }

    .cm-brand-divider {
        height: 22px;
    }

    .texto-concreto,
    .texto-neon {
        font-size: 1.3rem;
    }

    .cm-header-actions {
        gap: 2px;
        flex-shrink: 0;
    }

    .cm-header-actions .cm-label {
        display: none;
    }

    .cm-header-actions button {
        width: 40px;
        height: 40px;
        padding: 0;
        justify-content: center;
    }

    .cm-header-actions button img {
        width: 22px;
        height: 22px;
    }

    /* --- Layout em coluna: canvas > ferramentas > painel --- */
    .cm-main {
        flex-direction: column;
    }

    #canvasContainer {
        order: 1;
        min-height: 0;
    }

    /* --- Barra de ferramentas horizontal --- */
    #toolbar {
        order: 2;
        width: 100%;
        height: auto;
        flex-direction: row;
        flex-shrink: 0;
        gap: 6px;
        padding: 6px 8px;
        overflow-x: auto;
        overflow-y: hidden;
        border-right: 0;
        border-top: 1px solid rgba(30, 58, 138, 0.2);
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        /* Indica que há mais ferramentas (Desfazer / Limpar) rolando para o lado */
        -webkit-mask-image: linear-gradient(to right, #000 88%, transparent);
        mask-image: linear-gradient(to right, #000 88%, transparent);
    }

    #toolbar.cm-scroll-fim {
        -webkit-mask-image: none;
        mask-image: none;
    }

    #toolbar::-webkit-scrollbar {
        display: none;
    }

    #toolbar .cm-toolbar-title {
        display: none;
    }

    #toolbar .cm-toolbar-spacer {
        flex: 1 0 4px;
    }

    #toolbar .btn-tool {
        flex: 0 0 auto;
        width: 62px;
        height: 54px;
        margin: 0;
        padding: 2px;
        gap: 2px;
    }

    #toolbar .btn-tool .text-xl {
        font-size: 1.1rem;
        line-height: 1.2;
    }

    #toolbar .btn-tool:hover {
        transform: none;
    }

    body.cm-modo-resultado #toolbar {
        display: none;
    }

    /* --- Painel direito vira painel inferior --- */
    #painelDireito {
        order: 3;
        width: 100%;
        height: auto;
        flex-shrink: 0;
        border-left: 0;
        border-top: 1px solid rgba(74, 144, 196, 0.2);
        padding-bottom: env(safe-area-inset-bottom);
    }

    .cm-sheet-handle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        padding: 10px 14px;
        font-size: 11px;
        font-weight: 800;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        color: var(--sky);
        background: rgba(10, 18, 32, 0.6);
        border-bottom: 1px solid rgba(74, 144, 196, 0.12);
    }

    .cm-sheet-badge {
        display: inline-block;
        margin-left: 4px;
        padding: 1px 6px;
        border-radius: 4px;
        font-size: 10px;
        color: #7dd3fc;
        background: rgba(59, 130, 246, 0.1);
    }

    .cm-sheet-arrow {
        transition: transform var(--transition);
    }

    #painelDireito.is-open .cm-sheet-arrow {
        transform: rotate(180deg);
    }

    body.cm-modo-resultado .cm-sheet-handle {
        display: none;
    }

    #panelEdit:not(.hidden),
    #panelResult:not(.hidden) {
        height: auto;
    }

    /* Parâmetros e vigas: escondidos até abrir o painel */
    #panelEditBody {
        display: none;
        padding: 14px 16px;
        gap: 14px;
        max-height: 34vh;
        max-height: 34dvh;
        overflow-y: auto;
    }

    #painelDireito.is-open #panelEditBody {
        display: flex;
    }

    #panelEditBody .cm-vigas-wrap {
        flex: none;
        min-height: auto;
    }

    #panelEditBody #listaVigas {
        overflow: visible;
        padding-bottom: 0;
    }

    .cm-panel-footer {
        padding: 10px 12px;
    }

    #btnCalcularVolume {
        padding-top: 12px;
        padding-bottom: 12px;
    }

    #btnSalvar {
        margin-top: 6px;
        padding-top: 4px;
    }

    /* Resultado: compacto para o 3D continuar visível */
    .cm-result-top {
        padding: 8px 12px;
    }

    #btnVoltarEditar {
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .cm-result-body {
        padding: 12px;
        gap: 10px;
        max-height: 46vh;
        max-height: 46dvh;
    }

    .cm-result-cta {
        padding: 10px 12px;
    }

    .cm-result-card {
        padding: 12px;
    }

    .cm-result-volume {
        font-size: 2.25rem;
        line-height: 1.1;
    }

    .cm-result-whatsapp {
        padding-top: 12px;
        padding-bottom: 12px;
    }

    /* --- Assistente menor e minimizável --- */
    #assistenteBox {
        top: 8px;
        left: 8px;
        max-width: calc(100% - 64px);
        padding: 8px 10px;
    }

    /* Só o título minimiza; o resto deixa o toque passar para o canvas */
    #assistenteBox > div:first-child {
        pointer-events: auto;
        cursor: pointer;
    }

    #assistenteBox p,
    #assistenteBox > div:not(:first-child) {
        font-size: 11px;
    }

    #assistenteBox > div:first-child::after {
        content: '▾';
        margin-left: 4px;
        font-size: 11px;
    }

    #assistenteBox.is-min > :not(:first-child) {
        display: none;
    }

    #assistenteBox.is-min > div:first-child {
        margin-bottom: 0;
    }

    #assistenteBox.is-min > div:first-child::after {
        content: '▸';
    }

    .cm-fullscreen-btn {
        top: 8px;
        right: 8px;
    }

    /* --- Controles 3D --- */
    #viewControls {
        bottom: 12px;
    }

    #viewControls button {
        padding: 8px 12px;
        font-size: 10px;
    }

    /* --- Modais --- */
    .modal-backdrop {
        padding: 16px;
    }

    .modal-content {
        width: 100%;
        max-width: 420px;
        max-height: calc(100dvh - 32px);
        overflow-y: auto;
    }

    #modalInfo .modal-content {
        padding: 20px;
    }

    /* iOS: fonte ≥ 16px evita zoom automático ao focar inputs */
    select.input-neon,
    #vigaLargura,
    #vigaAltura {
        font-size: 16px;
    }
}

@media (max-width: 360px) {
    .cm-brand-divider {
        display: none;
    }

    .cm-logo {
        max-width: 48px;
    }

    .texto-concreto,
    .texto-neon {
        font-size: 1.1rem;
    }

    .cm-header-actions button {
        width: 36px;
    }
}
