*{
    margin:0;
    padding:0;
    box-sizing:border-box;
}

:root{
    --bg:#f4f7fb;
    --card:#ffffff;
    --border:#dbe3ee;
    --text:#1f2937;
    --muted:#6b7280;

    --primary:#2563eb;
    --primary-hover:#1d4ed8;

    --danger:#dc2626;
    --danger-hover:#b91c1c;

    --success:#16a34a;
    --warning:#d97706;

    --shadow:0 10px 30px rgba(0,0,0,0.06);
    --radius:18px;
}

body{
    font-family:"Segoe UI",Roboto,Arial,sans-serif;
    background:var(--bg);
    color:var(--text);
    min-height:100vh;
}

/* LOGIN */

.login-body{
    display:flex;
    justify-content:center;
    align-items:center;
    padding:30px;
    position:relative;
    overflow:hidden;
}

.login-body::before{
    content:"";
    position:absolute;
    width:500px;
    height:500px;
    background:rgba(37,99,235,0.08);
    border-radius:50%;
    top:-150px;
    right:-150px;
}

.login-body::after{
    content:"";
    position:absolute;
    width:400px;
    height:400px;
    background:rgba(37,99,235,0.05);
    border-radius:50%;
    bottom:-150px;
    left:-150px;
}

.login-container{
    width:100%;
    max-width:450px;
    position:relative;
    z-index:2;
}

.login-card{
    background:var(--card);
    border:1px solid var(--border);
    border-radius:var(--radius);
    padding:40px;
    box-shadow:var(--shadow);
    -webkit-backdrop-filter:blur(10px);
    backdrop-filter:blur(10px);
}

.login-header{
    text-align:center;
    margin-bottom:30px;
}

.login-header h1{
    font-size:2rem;
    margin-bottom:8px;
}

.login-header p{
    color:var(--muted);
    font-size:0.95rem;
}

.login-form{
    display:flex;
    flex-direction:column;
    gap:16px;
}

.login-form label{
    font-weight:600;
    font-size:0.95rem;
}

.login-form input,
.login-form select{
    width:100%;
    padding:14px 16px;
    border:1px solid var(--border);
    border-radius:12px;
    outline:none;
    font-size:1rem;
    transition:0.2s;
    background:#fff;
}

.login-form input:focus,
.login-form select:focus{
    border-color:var(--primary);
    box-shadow:0 0 0 4px rgba(37,99,235,0.12);
}

.login-form button{
    border:none;
    background:var(--primary);
    color:#fff;
    padding:15px;
    border-radius:12px;
    font-size:1rem;
    font-weight:600;
    cursor:pointer;
    transition:0.2s;
}

.login-form button:hover{
    background:var(--primary-hover);
    transform:translateY(-1px);
}

.admin-access{
    position:absolute;
    top:20px;
    right:20px;
    text-decoration:none;
    color:#fff;
    background:#111827;
    padding:10px 16px;
    border-radius:12px;
    font-size:0.9rem;
    font-weight:600;
    z-index:3;
    transition:0.2s;
}

.admin-access:hover{
    background:#000;
}

/* ALERTAS */

.alert{
    padding:14px 16px;
    border-radius:12px;
    margin-bottom:20px;
    font-size:0.95rem;
    font-weight:500;
}

.alert-error{
    background:#fee2e2;
    color:#991b1b;
    border:1px solid #fecaca;
}

.alert-success{
    background:#dcfce7;
    color:#166534;
    border:1px solid #bbf7d0;
}

/* APP */

.app-body{
    padding:24px;
}

/* TOPBAR */

.topbar{
    display:flex;
    justify-content:space-between;
    align-items:center;
    gap:20px;
    margin-bottom:24px;
    background:var(--card);
    border:1px solid var(--border);
    border-radius:var(--radius);
    padding:22px 24px;
    box-shadow:var(--shadow);
}

.topbar h1{
    font-size:1.7rem;
    margin-bottom:5px;
}

.topbar p{
    color:var(--muted);
}

.topbar-actions{
    display:flex;
    gap:12px;
    flex-wrap:wrap;
}

.btn-secondary,
.btn-danger{
    text-decoration:none;
    padding:12px 18px;
    border-radius:12px;
    font-weight:600;
    transition:0.2s;
    border:none;
    cursor:pointer;
    font-family:inherit;
}

.btn-secondary{
    background:#111827;
    color:#fff;
}

.btn-secondary:hover{
    background:#000;
}

.btn-danger{
    background:var(--danger);
    color:#fff;
}

.btn-danger:hover{
    background:var(--danger-hover);
}

/* LAYOUT */

.app-layout{
    display:grid;
    grid-template-columns:2fr 1fr;
    gap:24px;
}

.admin-layout{
    display:flex;
    flex-direction:column;
    gap:24px;
}

.panel{
    background:var(--card);
    border:1px solid var(--border);
    border-radius:var(--radius);
    padding:24px;
    box-shadow:var(--shadow);
}

.full-panel{
    grid-column:1 / -1;
}

.section-title{
    display:flex;
    justify-content:space-between;
    align-items:center;
    margin-bottom:24px;
    gap:10px;
}

.section-title h2{
    font-size:1.25rem;
}

.section-title span{
    background:#eff6ff;
    color:var(--primary);
    padding:8px 12px;
    border-radius:999px;
    font-size:0.85rem;
    font-weight:600;
}

/* FORM CALCULADORA */

.calc-form{
    display:flex;
    flex-direction:column;
    gap:16px;
}

.calc-form label{
    font-weight:600;
}

.calc-form input{
    width:100%;
    padding:14px 16px;
    border:1px solid var(--border);
    border-radius:12px;
    background:#f9fafb;
    font-size:1rem;
    outline:none;
    transition:0.2s;
}

.calc-form input:focus{
    border-color:var(--primary);
    box-shadow:0 0 0 4px rgba(37,99,235,0.12);
}

.calc-form button{
    font-family:inherit;
}

/* AVISOS */

.notice{
    margin-top:24px;
    background:#eff6ff;
    border:1px solid #bfdbfe;
    color:#1d4ed8;
    padding:16px;
    border-radius:12px;
    font-weight:500;
}

.empty-state{
    color:var(--muted);
    line-height:1.7;
}

/* PLACEHOLDER */

.placeholder-grid{
    display:grid;
    grid-template-columns:repeat(auto-fit,minmax(220px,1fr));
    gap:18px;
}

.placeholder-grid div{
    border:2px dashed var(--border);
    border-radius:16px;
    padding:35px 20px;
    text-align:center;
    color:var(--muted);
    background:#f9fafb;
    font-weight:600;
}

/* TABLA USUARIOS */

.table-wrap{
    overflow:auto;
}

.users-table{
    width:100%;
    border-collapse:collapse;
    min-width:900px;
}

.users-table th{
    background:#f8fafc;
    color:#374151;
    font-weight:700;
    padding:16px;
    border-bottom:1px solid var(--border);
    text-align:left;
}

.users-table td{
    padding:16px;
    border-bottom:1px solid var(--border);
    vertical-align:middle;
}

.users-table tr:hover{
    background:#f9fafb;
}

/* BADGES */

.badge{
    display:inline-flex;
    align-items:center;
    justify-content:center;
    padding:8px 12px;
    border-radius:999px;
    font-size:0.82rem;
    font-weight:700;
}

.badge-role{
    background:#eff6ff;
    color:var(--primary);
}

.badge-active{
    background:#dcfce7;
    color:#166534;
}

.badge-blocked{
    background:#fee2e2;
    color:#991b1b;
}

/* BOTONES TABLA */

.inline-form{
    display:inline;
}

.btn-small{
    border:none;
    padding:10px 14px;
    border-radius:10px;
    color:#fff;
    font-weight:700;
    cursor:pointer;
    transition:0.2s;
}

.btn-warning{
    background:var(--warning);
}

.btn-warning:hover{
    filter:brightness(0.95);
}

.btn-success{
    background:var(--success);
}

.btn-success:hover{
    filter:brightness(0.95);
}

/* OTROS */

.muted{
    color:var(--muted);
    font-size:0.9rem;
}

.empty-table{
    text-align:center;
    color:var(--muted);
    padding:30px;
}

/* ================================
   FASE 2 - CALCULADORA NEWTON
================================ */

.user-mini-info{
    margin-bottom:20px;
    background:#f8fafc;
    border:1px solid var(--border);
    padding:12px 14px;
    border-radius:12px;
    color:var(--muted);
    font-size:0.95rem;
}

.input-help{
    margin-top:-8px;
    color:var(--muted);
    line-height:1.5;
}

.quick-tools,
.examples-box{
    background:#f8fafc;
    border:1px solid var(--border);
    border-radius:14px;
    padding:16px;
    display:flex;
    flex-direction:column;
    gap:14px;
}

.quick-tools h3,
.examples-box h3,
.procedure-box h3,
.table-section h3,
.graph-section h3,
.iterations-procedure-section h3{
    font-size:1rem;
    margin-bottom:4px;
}

.quick-group{
    display:flex;
    flex-wrap:wrap;
    align-items:center;
    gap:8px;
}

.quick-group span{
    width:100%;
    font-size:0.85rem;
    color:var(--muted);
    font-weight:700;
}

.quick-group button,
.example-buttons button{
    border:1px solid var(--border);
    background:#fff;
    color:var(--text);
    padding:9px 12px;
    border-radius:10px;
    cursor:pointer;
    font-weight:600;
    transition:0.2s;
}

.quick-group button:hover,
.example-buttons button:hover{
    border-color:var(--primary);
    color:var(--primary);
    background:#eff6ff;
}

.example-buttons{
    display:flex;
    flex-wrap:wrap;
    gap:10px;
}

.suggestion-box{
    background:#fff7ed;
    border:1px solid #fed7aa;
    color:#9a3412;
    padding:14px;
    border-radius:12px;
    display:flex;
    flex-direction:column;
    gap:12px;
}

.suggestion-box button{
    align-self:flex-start;
    border:none;
    background:#ea580c;
    color:#fff;
    padding:10px 14px;
    border-radius:10px;
    font-weight:700;
    cursor:pointer;
}

.suggestion-box button:hover{
    background:#c2410c;
}

.hidden{
    display:none !important;
}

.calc-actions{
    display:flex;
    gap:12px;
    flex-wrap:wrap;
}

.btn-primary-action,
.btn-clean{
    border:none;
    padding:14px 18px;
    border-radius:12px;
    font-weight:700;
    cursor:pointer;
    transition:0.2s;
    font-family:inherit;
}

.btn-primary-action{
    background:var(--primary);
    color:#fff;
    flex:1;
}

.btn-primary-action:hover{
    background:var(--primary-hover);
}

.btn-clean{
    background:#e5e7eb;
    color:#374151;
}

.btn-clean:hover{
    background:#d1d5db;
}

/* MENSAJES DEL SISTEMA */

.system-message{
    padding:14px 16px;
    border-radius:12px;
    margin-bottom:20px;
    font-weight:600;
}

.system-success{
    background:#dcfce7;
    color:#166534;
    border:1px solid #bbf7d0;
}

.system-error{
    background:#fee2e2;
    color:#991b1b;
    border:1px solid #fecaca;
}

.system-warning{
    background:#fef3c7;
    color:#92400e;
    border:1px solid #fde68a;
}

.system-info{
    background:#eff6ff;
    color:#1d4ed8;
    border:1px solid #bfdbfe;
}

/* RESUMEN RESULTADOS */

.result-summary{
    display:grid;
    grid-template-columns:repeat(auto-fit,minmax(180px,1fr));
    gap:16px;
    margin-bottom:24px;
}

.result-summary div{
    background:#f8fafc;
    border:1px solid var(--border);
    border-radius:14px;
    padding:18px;
    display:flex;
    flex-direction:column;
    gap:8px;
}

.result-summary span{
    color:var(--muted);
    font-size:0.9rem;
    font-weight:600;
}

.result-summary strong{
    font-size:1.15rem;
    word-break:break-word;
}

/* PROCEDIMIENTO */

.procedure-box{
    background:#ffffff;
    border:1px solid var(--border);
    border-radius:14px;
    padding:20px;
    margin-bottom:24px;
    line-height:1.7;
}

.procedure-box p{
    margin-bottom:8px;
}

.formula{
    background:#f8fafc;
    border:1px solid var(--border);
    padding:12px 14px;
    border-radius:10px;
    font-weight:700;
    color:var(--primary);
    overflow-x:auto;
}

/* DESARROLLO DE ITERACIONES */

.iterations-procedure-section{
    background:#ffffff;
    border:1px solid var(--border);
    border-radius:14px;
    padding:20px;
    margin-bottom:24px;
}

.iterations-procedure-header{
    display:flex;
    justify-content:space-between;
    align-items:flex-start;
    gap:16px;
    margin-bottom:16px;
}

.iterations-procedure-header p{
    color:var(--muted);
    line-height:1.6;
    margin-top:4px;
}

.iterations-counter{
    flex-shrink:0;
    background:#eff6ff;
    color:var(--primary);
    padding:8px 12px;
    border-radius:999px;
    font-size:0.85rem;
    font-weight:700;
}

.iterations-procedure-list{
    display:flex;
    flex-direction:column;
    gap:14px;
}

.iteration-card{
    background:#f8fafc;
    border:1px solid var(--border);
    border-radius:14px;
    overflow:hidden;
}

.iteration-card-header{
    display:flex;
    justify-content:space-between;
    align-items:center;
    gap:12px;
    padding:14px 16px;
    border-bottom:1px solid var(--border);
    background:#ffffff;
}

.iteration-card-header h4{
    font-size:1rem;
    color:var(--text);
}

.iteration-card-header span{
    color:var(--primary);
    background:#eff6ff;
    padding:7px 10px;
    border-radius:999px;
    font-size:0.85rem;
    font-weight:700;
    white-space:nowrap;
}

.iteration-steps{
    padding:16px;
    display:flex;
    flex-direction:column;
    gap:10px;
    line-height:1.7;
}

.iteration-steps p{
    margin:0;
}

.iteration-formula{
    background:#ffffff;
    border:1px solid var(--border);
    color:var(--primary);
    padding:12px 14px;
    border-radius:10px;
    font-weight:700;
    overflow-x:auto;
}

.iterations-procedure-actions{
    margin-top:16px;
    display:flex;
    justify-content:center;
}

.iterations-procedure-actions .btn-secondary{
    min-width:220px;
}

/* TABLA ITERATIVA */

.table-section{
    margin-bottom:24px;
}

.iterations-table{
    min-width:850px;
}

.iterations-table td,
.iterations-table th{
    font-size:0.95rem;
}

/* GRAFICA */

.graph-section{
    margin-top:24px;
}

.graph-header{
    display:flex;
    justify-content:space-between;
    align-items:center;
    gap:16px;
    margin-bottom:16px;
    flex-wrap:wrap;
}

.graph-header .btn-secondary{
    border:none;
    cursor:pointer;
}

.graph-header .btn-secondary:disabled{
    background:#cbd5e1;
    cursor:not-allowed;
}

.graph-box{
    width:100%;
    max-width:100%;
    height:430px;
    min-height:430px;
    border:1px solid var(--border);
    border-radius:16px;
    background:#fff;
    display:block;
    overflow:hidden;
    color:var(--muted);
    text-align:center;
    line-height:430px;
    padding:0;
}

.graph-box > div{
    line-height:normal;
}

.graph-box .plot-container,
.graph-box .svg-container{
    line-height:normal;
}

/* HISTORIAL LATERAL */

.history-preview{
    display:flex;
    flex-direction:column;
    gap:12px;
    margin-bottom:18px;
}

.history-item{
    text-decoration:none;
    color:var(--text);
    border:1px solid var(--border);
    background:#f8fafc;
    border-radius:14px;
    padding:14px;
    display:flex;
    flex-direction:column;
    gap:6px;
    transition:0.2s;
}

.history-item:hover{
    border-color:var(--primary);
    background:#eff6ff;
}

.history-item strong{
    font-size:0.95rem;
    word-break:break-word;
}

.history-item span{
    color:var(--primary);
    font-weight:700;
    font-size:0.9rem;
}

.history-item small{
    color:var(--muted);
}

.btn-history-full{
    display:block;
    text-align:center;
    text-decoration:none;
    background:var(--primary);
    color:#fff;
    padding:13px;
    border-radius:12px;
    font-weight:700;
    transition:0.2s;
}

.btn-history-full:hover{
    background:var(--primary-hover);
}

/* BOTON DETALLE HISTORIAL */

.btn-small-link{
    display:inline-block;
    text-decoration:none;
    background:var(--primary);
    color:#fff;
    padding:9px 12px;
    border-radius:10px;
    font-weight:700;
    white-space:nowrap;
}

.btn-small-link:hover{
    background:var(--primary-hover);
}

/* RESPONSIVE */

@media(max-width:1100px){

    .app-layout{
        grid-template-columns:1fr;
    }

    .full-panel{
        grid-column:auto;
    }
}

@media(max-width:768px){

    .app-body{
        padding:16px;
    }

    .topbar{
        flex-direction:column;
        align-items:flex-start;
    }

    .topbar-actions{
        width:100%;
    }

    .btn-secondary,
    .btn-danger{
        width:100%;
        text-align:center;
    }

    .login-card{
        padding:30px 24px;
    }

    .panel{
        padding:20px;
    }

    .users-table{
        min-width:700px;
    }

    .calc-actions{
        flex-direction:column;
    }

    .btn-primary-action,
    .btn-clean{
        width:100%;
    }

    .graph-header{
        align-items:flex-start;
    }

    .graph-header .btn-secondary{
        width:100%;
        text-align:center;
    }

    .graph-box{
        height:330px;
        min-height:330px;
        line-height:330px;
    }

    .quick-group button,
    .example-buttons button{
        flex:1;
        min-width:90px;
    }

    .result-summary{
        grid-template-columns:1fr;
    }

    .iterations-procedure-header{
        flex-direction:column;
    }

    .iterations-counter{
        width:100%;
        text-align:center;
    }

    .iteration-card-header{
        flex-direction:column;
        align-items:flex-start;
    }

    .iteration-card-header span{
        width:100%;
        text-align:center;
    }

    .iterations-procedure-actions .btn-secondary{
        width:100%;
    }
}
.graph-box{
    width:100%;
    max-width:100%;
    height:430px;
    min-height:430px;
    border:1px solid var(--border);
    border-radius:16px;
    background:#fff;
    display:flex;
    align-items:center;
    justify-content:center;
    overflow:hidden;
    color:var(--muted);
    text-align:center;
    padding:0;
    line-height:normal;
}

.graph-box.graph-active{
    display:block;
    text-align:initial;
}

.graph-box.graph-active .js-plotly-plot,
.graph-box.graph-active .plot-container,
.graph-box.graph-active .svg-container{
    width:100% !important;
    max-width:100% !important;
}

.graph-box.graph-active .main-svg{
    max-width:100% !important;
}
.graph-box.graph-active{
    display:block;
    text-align:initial;
    line-height:normal;
    padding:0;
    overflow:hidden;
}

.graph-box.graph-active .js-plotly-plot,
.graph-box.graph-active .plot-container,
.graph-box.graph-active .svg-container{
    width:100% !important;
    max-width:100% !important;
    height:100% !important;
    line-height:normal !important;
}

.graph-box.graph-active .main-svg{
    max-width:100% !important;
}