/* ==========================================================================
   MonitSed 3D — folha de estilos comum a todos os locais
   --------------------------------------------------------------------------
   Não é preciso editar este ficheiro para mudar um local.
   Os textos e as malhas vivem no bloco CONFIG de cada HTML.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
    overflow: hidden;
    background: #fafafa;
    color: #1b1d21;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* --------------------------------------------------------------------------
 * Palco 3D
 * ------------------------------------------------------------------------ */
#stage {
    position: fixed;
    inset: 0;
    background: radial-gradient(120% 90% at 50% 0%, #ffffff 0%, #f2f4f6 55%, #e9ecef 100%);
    touch-action: none;
}

#stage model-viewer {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    background: transparent;
    --poster-color: transparent;
    outline: none;
    pointer-events: none;
    touch-action: none;
}

.stage-loading {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.pulsing-text {
    font-size: 12px;
    font-style: italic;
    color: #777;
    letter-spacing: 0.5px;
    animation: pulse 1.8s infinite ease-in-out;
}

@keyframes pulse {
    0% { opacity: 0.4; }
    50% { opacity: 0.9; }
    100% { opacity: 0.4; }
}

/* --------------------------------------------------------------------------
 * Painel de camadas
 * ------------------------------------------------------------------------ */
.panel {
    position: fixed;
    left: 18px;
    bottom: 18px;
    z-index: 50;
    width: 340px;
    max-height: calc(100dvh - 36px);
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.92);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.10);
    overflow: hidden;
}

.panel[hidden] { display: none; }

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.panel[data-collapsed="true"] .panel-head { border-bottom: 0; }

.panel-kicker {
    display: block;
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #8a9099;
}

.panel-title {
    margin: 2px 0 0;
    font-size: 15px;
    line-height: 1.2;
    font-weight: 600;
}

.panel-body {
    padding: 12px 14px 14px;
    overflow: auto;
    overscroll-behavior: contain;
}

.panel[data-collapsed="true"] .panel-body { display: none; }

.icon-btn {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid #e0e3e7;
    border-radius: 8px;
    background: #fff;
    color: #5b6169;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, transform 0.2s;
}

.icon-btn:hover { background: #f4f6f8; color: #1b1d21; }
.icon-btn svg { transition: transform 0.2s; }
.panel[data-collapsed="true"] .icon-btn svg { transform: rotate(180deg); }

/* --------------------------------------------------------------------------
 * Interruptor genérico (rotação automática)
 * ------------------------------------------------------------------------ */
.options {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
    padding: 7px 10px;
    border: 1px solid #e6e8eb;
    border-radius: 10px;
    background: #fff;
    cursor: pointer;
    user-select: none;
}

.options-label {
    font-size: 11.5px;
    font-weight: 600;
    color: #3c4249;
}

.switch {
    position: relative;
    flex: none;
    width: 34px;
    height: 19px;
}

.switch input {
    position: absolute;
    inset: 0;
    margin: 0;
    opacity: 0;
    cursor: pointer;
    z-index: 1;
}

.switch-track {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    background: #d5d9de;
    transition: background 0.18s;
}

.switch-track::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
    transition: transform 0.18s;
}

.switch input:checked + .switch-track { background: #1b1d21; }
.switch input:checked + .switch-track::after { transform: translateX(15px); }
.switch input:focus-visible + .switch-track { outline: 2px solid #2f6fd0; outline-offset: 2px; }

/* --------------------------------------------------------------------------
 * Presets
 * ------------------------------------------------------------------------ */
.presets {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.presets:empty { display: none; }

.preset {
    font: inherit;
    font-size: 11px;
    font-weight: 600;
    padding: 5px 9px;
    border-radius: 999px;
    border: 1px solid #d8dbe0;
    background: #fff;
    color: #4a5058;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.preset:hover { background: #f4f6f8; }
.preset[aria-pressed="true"] {
    background: #1b1d21;
    border-color: #1b1d21;
    color: #fff;
}

/* --------------------------------------------------------------------------
 * Camadas
 * ------------------------------------------------------------------------ */
.layers {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.layer {
    border: 1px solid #e6e8eb;
    border-radius: 10px;
    padding: 9px 10px;
    background: #fff;
    transition: border-color 0.15s, background 0.15s;
}

.layer.is-off {
    background: #fafbfc;
    border-style: dashed;
}

.layer.is-refused { animation: refuse 0.35s ease-in-out; }

@keyframes refuse {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

.layer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.layer-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    cursor: pointer;
}

.layer-toggle input {
    flex: none;
    width: 15px;
    height: 15px;
    accent-color: #1b1d21;
    cursor: pointer;
}

.swatch {
    flex: none;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--swatch, #888);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.06);
}

.layer-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.layer-name {
    font-size: 12.5px;
    font-weight: 600;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.layer-date {
    font-size: 10.5px;
    line-height: 1.3;
    color: #7c828b;
}

.opacity-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 7px;
}

.opacity-label {
    flex: none;
    width: 58px;
    font-size: 10px;
    color: #8a9099;
}

.opacity {
    flex: 1;
    height: 14px;
    accent-color: #1b1d21;
    cursor: pointer;
}

.opacity-value {
    flex: none;
    width: 34px;
    text-align: right;
    font-size: 10px;
    color: #5b6169;
    font-variant-numeric: tabular-nums;
}

.layer-progress {
    height: 2px;
    margin-top: 7px;
    border-radius: 2px;
    background: #eef0f2;
    overflow: hidden;
}

.layer-progress span {
    display: block;
    height: 100%;
    width: 0;
    background: #2f6fd0;
    transition: width 0.2s linear;
}

.layer-status {
    margin: 4px 0 0;
    font-size: 10px;
    color: #8a9099;
}

.layer-status:empty { display: none; }
.layer-status.is-error { color: #b42318; }

.legend {
    margin: 12px 0 0;
    font-size: 10.5px;
    line-height: 1.6;
    color: #7c828b;
}

.legend-erosion {
    background-color: #c9daf8;
    color: #1a3b6b;
    padding: 1px 5px;
    border-radius: 4px;
    font-weight: 600;
    white-space: nowrap;
}

.legend-deposition {
    background-color: #f4cccc;
    color: #6b1a1a;
    padding: 1px 5px;
    border-radius: 4px;
    font-weight: 600;
    white-space: nowrap;
}

.legend:empty { display: none; }

.hint {
    margin: 8px 0 0;
    font-size: 10px;
    color: #9aa0a8;
}

.hint:empty { display: none; }

kbd {
    font: inherit;
    font-size: 9.5px;
    padding: 1px 4px;
    border: 1px solid #dcdfe3;
    border-bottom-width: 2px;
    border-radius: 4px;
    background: #fff;
}

/* --------------------------------------------------------------------------
 * Ecrã inteiro
 * ------------------------------------------------------------------------ */
.fullscreen-btn {
    position: fixed;
    right: 14px;
    bottom: 14px;
    z-index: 60;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
    border: 1px solid #dcdcdc;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.85);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    color: #444;
    font: inherit;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease-in-out;
}

.fullscreen-btn:hover {
    background: #ffffff;
    color: #111;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.12);
}

.fullscreen-btn:active { transform: translateY(0); }

/* --------------------------------------------------------------------------
 * Toast + erro fatal
 * ------------------------------------------------------------------------ */
.toast {
    position: fixed;
    top: 16px;
    left: 50%;
    z-index: 70;
    max-width: min(420px, calc(100vw - 32px));
    padding: 9px 14px;
    border-radius: 10px;
    background: rgba(27, 29, 33, 0.92);
    color: #fff;
    font-size: 12px;
    line-height: 1.35;
    text-align: center;
    opacity: 0;
    transform: translate(-50%, -8px);
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
}

.toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

.fatal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(250, 250, 250, 0.94);
}

.fatal[hidden] { display: none; }

.fatal-card {
    width: min(420px, 100%);
    padding: 22px;
    border: 1px solid #e3e5e8;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    text-align: center;
}

.fatal-card h2 {
    margin: 0 0 8px;
    font-size: 16px;
}

.fatal-card p {
    margin: 0 0 16px;
    font-size: 13px;
    line-height: 1.5;
    color: #5b6169;
}

.fatal-card button {
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    padding: 7px 14px;
    border: 0;
    border-radius: 8px;
    background: #1b1d21;
    color: #fff;
    cursor: pointer;
}

:focus-visible {
    outline: 2px solid #2f6fd0;
    outline-offset: 2px;
}

/* --------------------------------------------------------------------------
 * Mobile
 * ------------------------------------------------------------------------ */
@media (max-width: 768px) {
    .panel {
        left: 8px;
        right: 8px;
        bottom: 8px;
        width: auto;
        max-height: min(58dvh, 420px);
    }

    .panel[data-collapsed="true"] {
        right: auto;
        width: auto;
    }

    .fullscreen-btn {
        top: 10px;
        right: 10px;
        bottom: auto;
    }

    .layer-name { white-space: normal; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        transition-duration: 0.001ms !important;
    }
}
