/* Calculadora flutuante — acima dos modais (10000), abaixo do menu mobile aberto */
:root {
    --calc-z-fab: 10050;
    --calc-z-panel: 10051;
}

.calc-fab {
    position: fixed;
    bottom: 24px;
    right: 20px;
    left: auto;
    top: auto;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--gradient-primary);
    color: #fff;
    border: none;
    box-shadow: 0 8px 24px rgba(13, 110, 110, 0.45);
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    z-index: var(--calc-z-fab);
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    pointer-events: auto;
    margin: 0;
    padding: 0;
    transition: box-shadow 0.2s ease, opacity 0.2s ease;
}

.calc-fab:hover {
    box-shadow: 0 10px 28px rgba(13, 110, 110, 0.55);
}

.calc-fab.dragging {
    cursor: grabbing;
    box-shadow: 0 12px 32px rgba(13, 110, 110, 0.6);
    transition: none;
}

.calc-fab.hidden {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

.calc-flutuante-panel {
    position: fixed;
    width: min(280px, calc(100vw - 32px));
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: 0 16px 48px rgba(15, 23, 42, 0.22);
    border: 1px solid var(--border-soft);
    z-index: var(--calc-z-panel);
    display: none;
    flex-direction: column;
    overflow: hidden;
    touch-action: manipulation;
    margin: 0;
    animation: calcPanelIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.calc-flutuante-panel.active {
    display: flex;
}

@keyframes calcPanelIn {
    from {
        opacity: 0;
        transform: scale(0.92) translateY(8px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.calc-flutuante-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: var(--gradient-primary);
    color: #fff;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    font-size: 13px;
    font-weight: 600;
    gap: 8px;
    touch-action: none;
}

.calc-flutuante-header.dragging {
    cursor: grabbing;
}

.calc-flutuante-header span {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.calc-flutuante-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.calc-flutuante-actions button {
    width: 28px;
    height: 28px;
    border: none;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: background var(--transition);
    touch-action: manipulation;
}

.calc-flutuante-actions button:hover {
    background: rgba(255, 255, 255, 0.32);
}

.calc-display-wrap {
    padding: 12px 14px 8px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-soft);
}

.calc-display {
    font-size: 28px;
    font-weight: 700;
    text-align: right;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    word-break: break-all;
    min-height: 36px;
    line-height: 1.2;
}

.calc-expression {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: right;
    min-height: 18px;
    margin-bottom: 4px;
    font-variant-numeric: tabular-nums;
}

.calc-keys {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 10px;
}

.calc-key {
    height: 44px;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--transition), transform 0.1s ease;
    touch-action: manipulation;
}

.calc-key:hover {
    background: var(--bg-tertiary);
}

.calc-key:active {
    transform: scale(0.96);
}

.calc-key.op {
    background: var(--primary-soft);
    color: var(--primary);
    border-color: rgba(13, 110, 110, 0.2);
}

.calc-key.op:hover {
    background: rgba(13, 110, 110, 0.14);
}

.calc-key.fn {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 14px;
}

.calc-key.equals {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.calc-key.equals:hover {
    background: var(--primary-dark);
}

.calc-key.span-2 {
    grid-column: span 2;
}

@media (max-width: 768px) {
    .calc-fab {
        width: 50px;
        height: 50px;
        font-size: 20px;
        bottom: 20px;
        right: 16px;
    }

    /* Menu mobile aberto fica por cima da calculadora */
    body.mobile-nav-open .calc-fab,
    body.mobile-nav-open .calc-flutuante-panel {
        z-index: 900;
        pointer-events: none;
    }
}

@media (max-width: 480px) {
    .calc-key {
        height: 40px;
        font-size: 15px;
    }

    .calc-display {
        font-size: 24px;
    }
}

/* Ocultar no ecrã de login */
body.login-mode .calc-fab,
body.login-mode .calc-flutuante-panel {
    display: none !important;
}
