/* TerraNava Algoritmo — interfaz institucional sobria */

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

:root {
    --tn-carbon:      #101010;
    --tn-carbon-soft: #1d1d1d;
    --tn-marfil:      #f6f1e8;
    --tn-marfil-fuerte:#fffdf9;
    --tn-dorado:      #a7864d;
    --tn-dorado-suave:#d8c29a;
    --tn-verde:       #27ae60;
    --tn-naranja:     #e67e22;
    --tn-rojo:        #e74c3c;
    --tn-gris-claro:  #f3efe8;
    --tn-gris:        #ddd4c6;
    --sombra:         0 18px 42px rgba(0, 0, 0, 0.16);
    --radio:          12px;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(180deg, #171717 0%, #090909 100%);
    color: #222;
}

/* ── LOGIN OVERLAY ────────────────────────────────────────────────── */
.login-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at 20% 20%, rgba(167, 134, 77, 0.12), transparent 32%),
        linear-gradient(180deg, #171717 0%, #090909 100%);
    z-index: 1000;
    animation: fadeIn 0.4s ease;
}

/* Fondo sutil */
.login-overlay::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(circle at 20% 80%, rgba(167, 134, 77, 0.14) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255, 255, 255, 0.05) 0%, transparent 50%);
    pointer-events: none;
}

.login-card {
    background: var(--tn-marfil-fuerte);
    border-radius: var(--radio);
    padding: 40px 44px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--sombra), 0 0 0 1px rgba(16,16,16,0.06);
    position: relative;
    z-index: 1;
    animation: slideUp 0.4s ease;
}

.login-logo {
    display: grid;
    gap: 6px;
    margin-bottom: 20px;
}

.logo-icon {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 11px;
    line-height: 1;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--tn-dorado);
    font-weight: 800;
}

.login-logo h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--tn-carbon);
    line-height: 1.1;
}

.login-logo p {
    font-size: 12px;
    color: #7a7166;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.login-divider {
    height: 2px;
    background: linear-gradient(90deg, var(--tn-dorado) 0%, rgba(167, 134, 77, 0.18) 100%);
    border-radius: 2px;
    margin-bottom: 24px;
}

.login-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--tn-carbon);
    margin-bottom: 4px;
}

.login-subtitle {
    font-size: 13px;
    color: #746c62;
    margin-bottom: 24px;
    line-height: 1.4;
}

.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #555;
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--tn-gris);
    border-radius: 8px;
    font-size: 14px;
    color: #333;
    background: #fbf8f2;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}

.form-group input:focus {
    border-color: var(--tn-dorado);
    box-shadow: 0 0 0 3px rgba(167, 134, 77, 0.14);
    background: white;
}

.login-error {
    background: #fef2f2;
    border: 1px solid #fca5a5;
    color: var(--tn-rojo);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 13px;
    margin-bottom: 16px;
}

.btn-login {
    width: 100%;
    padding: 13px;
    background: linear-gradient(180deg, #23201c 0%, #111111 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.18);
    margin-top: 4px;
}

.btn-login:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 16px 28px rgba(0, 0, 0, 0.24);
}

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

.btn-login:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.login-footer {
    margin-top: 24px;
    text-align: center;
    font-size: 12px;
    color: #8b847a;
}

.login-footer a {
    color: var(--tn-carbon);
    text-decoration: none;
}

.login-footer a:hover {
    text-decoration: underline;
}

/* ── DASHBOARD CONTAINER ──────────────────────────────────────────── */
.dashboard-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--tn-gris-claro);
}

/* ── TOP BAR ──────────────────────────────────────────────────────── */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: 52px;
    background: rgba(10,10,10,0.96);
    box-shadow: 0 2px 12px rgba(0,0,0,0.18);
    flex-shrink: 0;
    z-index: 100;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-logo {
    font-size: 22px;
}

.topbar-title {
    font-size: 16px;
    color: white;
    font-weight: 400;
    letter-spacing: 0.02em;
}

.topbar-title strong {
    font-weight: 700;
}

.topbar-badge {
    background: rgba(167, 134, 77, 0.16);
    color: var(--tn-dorado-suave);
    font-size: 11px;
    padding: 2px 10px;
    border-radius: 12px;
    font-weight: 500;
    border: 1px solid rgba(167, 134, 77, 0.3);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.topbar-user {
    font-size: 13px;
    color: var(--tn-celeste-claro);
}

.btn-logout {
    padding: 6px 16px;
    background: transparent;
    border: 1.5px solid rgba(255,255,255,0.3);
    color: white;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.btn-logout:hover {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.6);
}

/* ── IFRAME WRAPPER ───────────────────────────────────────────────── */
.iframe-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
}

#streamlit-frame {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

/* ── LOADING SCREEN ───────────────────────────────────────────────── */
.loading-screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--tn-gris-claro);
    gap: 16px;
    color: #666;
    font-size: 15px;
}

.loading-sub {
    font-size: 12px;
    color: #aaa;
    margin-top: -8px;
}

.loading-spinner {
    width: 44px;
    height: 44px;
    border: 4px solid var(--tn-gris);
    border-top-color: var(--tn-celeste);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

/* ── STATUS BAR ───────────────────────────────────────────────────── */
.statusbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    height: 28px;
    background: var(--tn-azul-oscuro);
    font-size: 11px;
    color: rgba(255,255,255,0.55);
    flex-shrink: 0;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-connected  { background: #2ecc71; box-shadow: 0 0 6px #2ecc71; }
.status-connecting { background: #f39c12; animation: pulse 1.2s ease-in-out infinite; }
.status-error      { background: var(--tn-rojo); }

.status-sep {
    opacity: 0.3;
    font-size: 14px;
}

/* ── ANIMACIONES ──────────────────────────────────────────────────── */
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(24px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

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

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%       { transform: translateX(-8px); }
    40%       { transform: translateX(8px); }
    60%       { transform: translateX(-5px); }
    80%       { transform: translateX(5px); }
}

.shake { animation: shake 0.5s ease; }

/* ── RESPONSIVE ───────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .login-card {
        margin: 16px;
        padding: 28px 24px;
    }
    .topbar-badge { display: none; }
}
