/* =========================================================================
   ROCKTREE — tema de la aplicación (JAMAT INGENIERÍA)
   Se carga DESPUÉS de Bootstrap 5.3 y es la única hoja propia del proyecto.
   Reemplaza al build de Tailwind (css/app.css), que solo aportaba colisiones
   de nombres con Bootstrap (.collapse, .container, img{height:auto}).
   ========================================================================= */

:root {
    /* Marca, tomada del logo de JAMAT y del acento del login. */
    --brand-navy: #332C61;
    --brand-navy-700: #2A2450;
    --brand-navy-900: #1E1938;
    --brand-orange: #FA5F12;

    /* Superficies y líneas. */
    --surface: #FFFFFF;
    --surface-muted: #F7F8FA;
    --line: #E6E8EF;
    --ink: #1F2333;
    --ink-muted: #6B7183;

    --radius: 14px;
    --radius-sm: 10px;
    --shadow-sm: 0 1px 2px rgba(16, 20, 40, .04), 0 1px 3px rgba(16, 20, 40, .06);
    --shadow-md: 0 4px 6px -1px rgba(16, 20, 40, .05), 0 10px 20px -6px rgba(16, 20, 40, .10);

    /* Repinta las utilidades de Bootstrap que ya usan las vistas
       (.bg-primary, .text-primary, .btn-primary) con el azul de marca. */
    --bs-primary: var(--brand-navy);
    --bs-primary-rgb: 51, 44, 97;
    --bs-body-color: var(--ink);
    --bs-body-bg: var(--surface-muted);
    --bs-border-color: var(--line);
    --bs-link-color: var(--brand-navy);
    --bs-link-hover-color: var(--brand-orange);
    --bs-font-sans-serif: "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

body {
    background-color: var(--surface-muted);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
}

/* Bootstrap oculta .collapse con `display`, nunca con `visibility`.
   Se mantiene como red de seguridad por si vuelve a entrar una hoja con
   una utilidad `.collapse{visibility:collapse}` (Tailwind la define así). */
.navbar-collapse { visibility: visible; }

/* ---------------------------------------------------------------- Navbar */
.site-navbar {
    background-color: var(--surface);
    border-bottom: 1px solid var(--line);
    padding-top: .625rem;
    padding-bottom: .625rem;
}
.site-navbar .navbar-brand img {
    height: 34px;
    width: auto;
}
.site-navbar .nav-link {
    position: relative;
    color: var(--ink) !important;
    font-weight: 600;
    font-size: .82rem;
    letter-spacing: .06em;
    padding: .5rem .95rem;
    border-radius: var(--radius-sm);
    transition: color .15s ease, background-color .15s ease;
}
.site-navbar .nav-link:hover,
.site-navbar .nav-link:focus-visible {
    color: var(--brand-navy) !important;
    background-color: var(--surface-muted);
}
/* Subrayado naranja para la sección activa. */
.site-navbar .nav-item > .nav-link.is-active::after {
    content: "";
    position: absolute;
    left: .95rem;
    right: .95rem;
    bottom: .1rem;
    height: 2px;
    border-radius: 2px;
    background-color: var(--brand-orange);
}
.site-navbar .dropdown-menu {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    padding: .35rem;
}
.site-navbar .dropdown-menu .nav-link { font-size: .8rem; }

.btn-logout {
    background-color: var(--brand-navy);
    border: 1px solid var(--brand-navy);
    color: #fff;
    font-weight: 600;
    font-size: .78rem;
    letter-spacing: .06em;
    padding: .5rem 1rem;
    border-radius: var(--radius-sm);
}
.btn-logout:hover,
.btn-logout:focus-visible {
    background-color: var(--brand-orange);
    border-color: var(--brand-orange);
    color: #fff;
}

/* ----------------------------------------------------------------- Cards */
.card {
    background-color: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: box-shadow .18s ease, transform .18s ease;
}
.card:hover { box-shadow: var(--shadow-md); }

/* Las vistas usan .card-header.bg-primary; aquí se convierte en una cabecera
   sobria con una línea de acento, en vez de un bloque de color saturado. */
.card-header {
    border-bottom: 1px solid var(--line);
    padding: 1rem 1.25rem;
}
.card-header.bg-primary {
    background-color: var(--brand-navy) !important;
    border-bottom: 3px solid var(--brand-orange);
}
.card-header.bg-primary h5 {
    margin: 0;
    font-size: 1rem;
    letter-spacing: .06em;
    text-transform: uppercase;
}
.card-body { padding: 1.25rem; }

/* ---------------------------------------------------------------- Títulos */
h1.fs-2 {
    color: var(--brand-navy);
    letter-spacing: -.01em;
}
h5.text-secondary {
    color: var(--ink-muted) !important;
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .09em;
    text-transform: uppercase;
    margin-bottom: .75rem;
}

/* ---------------------------------------------------------------- Tablas */
.table {
    --bs-table-bg: transparent;
    margin-bottom: 0;
}
.table > thead th {
    background-color: var(--surface-muted);
    color: var(--ink-muted);
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--line);
}
.table.table-bordered > :not(caption) > * > * {
    border-color: var(--line);
}
.table > tbody > tr:hover > * {
    background-color: rgba(51, 44, 97, .03);
}

/* --------------------------------------------------------- Barra de salud */
.progress {
    background-color: var(--line);
    border-radius: 999px;
    overflow: hidden;
}
.progress-bar {
    font-weight: 700;
    letter-spacing: .02em;
}

/* --------------------------------- Chip de salud y enlace de sistema */
.salud-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 52px;
    padding: .4rem .55rem;
    border-radius: 999px;
    font-weight: 700;
    font-size: .95rem;
    line-height: 1;
}
.salud-chip--ok {
    background-color: rgba(25, 135, 84, .1);
    color: #146c43;
    border: 1px solid rgba(25, 135, 84, .25);
}
.salud-chip--riesgo {
    background-color: rgba(220, 53, 69, .1);
    color: #b02a37;
    border: 1px solid rgba(220, 53, 69, .25);
}

.sistema-link {
    display: block;
    width: 100%;
    padding: .6rem .75rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    border: 1px solid var(--line);
    background-color: var(--surface);
    color: var(--brand-navy);
    transition: border-color .15s ease, background-color .15s ease;
}
.sistema-link:hover,
.sistema-link:focus-visible {
    border-color: var(--brand-navy);
    background-color: rgba(51, 44, 97, .04);
    color: var(--brand-navy);
}
/* La condición del sistema se comunica con una barra lateral, no tiñendo
   todo el texto: mantiene legible el nombre del sistema. */
.sistema-link--ok { border-left: 4px solid #198754; }
.sistema-link--riesgo { border-left: 4px solid #dc3545; }

/* -------------------------------------------------------------- Botones */
.btn {
    border-radius: var(--radius-sm);
    font-weight: 600;
}
.btn-sm { border-radius: 8px; }

/* ---------------------------------------------------------------- Alertas */
.alert {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: .88rem;
}
.alert-primary {
    background-color: rgba(51, 44, 97, .05);
    border-color: rgba(51, 44, 97, .15);
    color: var(--brand-navy);
}

/* ----------------------------------------------------------------- Footer */
.site-footer {
    background-color: var(--surface);
    border-top: 1px solid var(--line);
    color: var(--ink-muted);
}
.site-footer__logo { height: 58px; width: auto; }
.site-footer__heading {
    color: var(--brand-navy);
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    margin-bottom: 1rem;
}
.site-footer__heading::after {
    content: "";
    display: block;
    width: 28px;
    height: 2px;
    margin-top: .5rem;
    border-radius: 2px;
    background-color: var(--brand-orange);
}
.site-footer__list { list-style: none; margin: 0; padding: 0; }
.site-footer__list li + li { margin-top: .5rem; }
.site-footer a {
    color: var(--ink-muted);
    text-decoration: none;
    transition: color .15s ease;
}
.site-footer a:hover,
.site-footer a:focus-visible { color: var(--brand-orange); }

.site-footer__social {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem .9rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    font-weight: 600;
    color: var(--brand-navy);
    background-color: var(--surface);
}
.site-footer__social:hover,
.site-footer__social:focus-visible {
    color: var(--brand-orange);
    border-color: var(--brand-orange);
    background-color: rgba(250, 95, 18, .05);
}

.site-footer__bottom {
    background-color: var(--surface-muted);
    border-top: 1px solid var(--line);
    color: var(--ink-muted);
    font-size: .82rem;
}

/* Accesibilidad: foco visible y consistente en toda la app. */
a:focus-visible,
.btn:focus-visible,
.nav-link:focus-visible {
    outline: 2px solid var(--brand-orange);
    outline-offset: 2px;
}

/* ============================================================ Asistente (chat) */
.chat-caja {
    margin-top: 1.5rem;
    background-color: var(--surface);
    border: 1px solid var(--line);
    border-left: 4px solid var(--brand-orange);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1.15rem 1.25rem;
}

.chat-caja__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: .9rem;
}
.chat-caja__titulo {
    display: flex;
    align-items: center;
    gap: .7rem;
}
.chat-caja__icono {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    border-radius: 999px;
    background-color: var(--brand-navy);
    color: #fff;
}
.chat-caja__titulo strong {
    display: block;
    color: var(--brand-navy);
    font-size: .95rem;
    letter-spacing: .02em;
}
.chat-caja__sub {
    display: block;
    color: var(--ink-muted);
    font-size: .76rem;
}
.chat-btn-limpiar {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--ink-muted);
    border-radius: var(--radius-sm);
    font-size: .74rem;
    font-weight: 600;
    padding: .35rem .7rem;
}
.chat-btn-limpiar:hover { border-color: var(--brand-orange); color: var(--brand-orange); }

.chat-form { display: flex; gap: .5rem; }
.chat-input {
    flex: 1;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: .65rem .85rem;
    font-size: .9rem;
    background-color: var(--surface-muted);
}
.chat-input:focus {
    outline: none;
    background-color: var(--surface);
    border-color: var(--brand-navy);
    box-shadow: 0 0 0 3px rgba(51, 44, 97, .12);
}
.chat-input:disabled { opacity: .7; }
.chat-enviar {
    background-color: var(--brand-navy);
    border: 1px solid var(--brand-navy);
    color: #fff;
    font-weight: 600;
    font-size: .82rem;
    letter-spacing: .04em;
    border-radius: var(--radius-sm);
    padding: .65rem 1.35rem;
    white-space: nowrap;
}
.chat-enviar:hover:not(:disabled) { background-color: var(--brand-navy-700); }
.chat-enviar:disabled { opacity: .6; }

.chat-sugerencias {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
    margin-top: .75rem;
}
.chat-chip {
    background-color: var(--surface);
    border: 1px solid var(--line);
    color: var(--brand-navy);
    border-radius: 999px;
    font-size: .76rem;
    font-weight: 600;
    padding: .35rem .75rem;
}
.chat-chip:hover {
    border-color: var(--brand-orange);
    background-color: rgba(250, 95, 18, .06);
}

.chat-mensajes {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--line);
    max-height: 520px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: .6rem;
}
.chat-mensajes[hidden] { display: none; }
.chat-msg {
    padding: .65rem .85rem;
    border-radius: var(--radius-sm);
    font-size: .88rem;
    line-height: 1.5;
    max-width: 88%;
    white-space: pre-wrap;      /* el modelo responde en texto plano con saltos */
    overflow-wrap: anywhere;
}
.chat-msg--bot {
    background-color: var(--surface-muted);
    border: 1px solid var(--line);
    color: var(--ink);
    align-self: flex-start;
}
.chat-msg--user {
    background-color: var(--brand-navy);
    color: #fff;
    align-self: flex-end;
}
.chat-msg--error {
    background-color: #FDECEC;
    border: 1px solid #F5C2C7;
    color: #b02a37;
    align-self: flex-start;
}
.chat-msg--pensando { opacity: .65; font-style: italic; }

.chat-aviso {
    margin: .8rem 0 0;
    color: var(--ink-muted);
    font-size: .7rem;
}

@media (max-width: 575.98px) {
    .chat-form { flex-direction: column; }
    .chat-enviar { width: 100%; }
}

/* ------------------------------------------- Gráficos dentro del asistente */
.chat-grafico {
    align-self: stretch;
    margin: .3rem 0;
    background-color: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: .85rem;
}
.chat-grafico__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    margin-bottom: .6rem;
    flex-wrap: wrap;
}
.chat-grafico__titulo {
    color: var(--brand-navy);
    font-size: .82rem;
    font-weight: 700;
}
.chat-grafico__acciones { display: flex; gap: .3rem; }
.btn-descarga {
    background-color: var(--surface);
    border: 1px solid var(--line);
    color: var(--brand-navy);
    border-radius: var(--radius-sm);
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .04em;
    padding: .25rem .6rem;
}
.btn-descarga:hover { border-color: var(--brand-orange); background-color: rgba(250, 95, 18, .06); }
.chat-grafico__lienzo { position: relative; height: 300px; }
