:root {
    --verde: #0a6e3a;
    --verde-claro: #e8f5ee;
    --naranja: #e8590c;
    --rojo: #c0392b;
    --gris: #555;
    --borde: #dfe3e6;
    --fondo: #f4f6f7;
}

* { box-sizing: border-box; }
body {
    font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--fondo);
    margin: 0;
    color: #222;
}

.topbar {
    background: var(--verde);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    flex-wrap: wrap;
}
.brand-trex { font-weight: 800; font-size: 22px; letter-spacing: 1px; margin-right: 10px; }
.brand-sub { font-size: 13px; opacity: .85; }
.menu-toggle {
    display: none;
    background: none; border: none; color: #fff; font-size: 26px; cursor: pointer;
    padding: 4px 8px;
}
.topnav a {
    color: #fff;
    text-decoration: none;
    margin: 0 10px;
    font-size: 14px;
    padding: 6px 8px;
    border-radius: 4px;
}
.topnav a:hover { background: rgba(255,255,255,.15); }
.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.topbar-user-mobile { display: none; }
.btn-logout { background: rgba(255,255,255,.15); padding: 5px 10px; border-radius: 4px; }

.content { max-width: 1100px; margin: 20px auto; padding: 0 15px; }
h1 { font-size: 22px; color: var(--verde); }
.ref-doc { font-size: 13px; color: var(--gris); font-weight: normal; }

.card {
    background: #fff;
    border: 1px solid var(--borde);
    border-radius: 8px;
    padding: 18px;
    margin-bottom: 18px;
}
.card h3 { margin-top: 0; color: var(--verde); font-size: 16px; }
.card h4 { color: var(--gris); font-size: 14px; margin: 18px 0 6px; border-top: 1px solid var(--borde); padding-top: 14px; }

.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
}

.table-sm { width: 100%; border-collapse: collapse; font-size: 13px; }
.table-sm th, .table-sm td { padding: 6px 8px; border-bottom: 1px solid var(--borde); text-align: left; }
.table-sm th { background: var(--verde-claro); }

.fila-critico { background: #fdecea; }
.fila-aviso { background: #fff8e1; }
.texto-critico { color: var(--rojo); font-weight: bold; }
.texto-aviso { color: var(--naranja); font-weight: bold; }

.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; font-size: 14px; }
.alert-critico { background: #fdecea; color: var(--rojo); border: 1px solid #f5c6cb; }
.alert-aviso { background: #fff8e1; color: #8a6500; border: 1px solid #ffe08a; }
.alert-ok { background: var(--verde-claro); color: var(--verde); border: 1px solid #b7e0c8; }

.badge { padding: 2px 8px; border-radius: 10px; font-size: 12px; }
.badge-critico { background: var(--rojo); color: #fff; }
.badge-aviso { background: var(--naranja); color: #fff; }
.badge-ok { background: var(--verde); color: #fff; }

form label { display: block; margin: 10px 0 4px; font-size: 13px; font-weight: 600; color: var(--gris); }
form input, form textarea, form select {
    width: 100%; padding: 8px; border: 1px solid var(--borde); border-radius: 4px; font-size: 14px;
}
.form-row { display: flex; gap: 16px; flex-wrap: wrap; }
.form-row > div { flex: 1; min-width: 150px; }
.checkboxes label { display: flex; align-items: center; gap: 6px; font-weight: normal; }
.checkboxes input { width: auto; }

.btn-primary {
    background: var(--verde); color: #fff; border: none; padding: 10px 18px;
    border-radius: 5px; font-size: 14px; cursor: pointer; margin-top: 14px;
}
.btn-primary:hover { background: #085530; }
.btn-secondary {
    display: inline-block; margin-top: 10px; color: var(--verde); text-decoration: none; font-size: 13px; font-weight: 600;
}

.footer { text-align: center; font-size: 12px; color: #999; margin: 30px 0; }

.acciones-top { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.btn-secondary-btn {
    display: inline-block; background: #fff; border: 1px solid var(--verde); color: var(--verde);
    padding: 9px 16px; border-radius: 5px; font-size: 14px; text-decoration: none; cursor: pointer;
}
.btn-secondary-btn:hover { background: var(--verde-claro); }

/* -------- Vistas de documento imprimible (Fo 5xx-GR) -------- */
.doc-body { background: #ddd; }
.doc-toolbar { text-align: center; padding: 10px; }
.doc-toolbar button {
    background: var(--verde); color: #fff; border: none; padding: 8px 18px; border-radius: 5px; cursor: pointer; font-size: 14px;
}
.doc-hoja {
    background: #fff; max-width: 800px; margin: 0 auto 40px; padding: 40px;
    box-shadow: 0 0 8px rgba(0,0,0,.2); font-size: 14px; color: #111;
}
.doc-header { text-align: right; font-size: 13px; margin-bottom: 10px; }
.doc-titulo { text-align: center; color: var(--verde); border-bottom: 2px solid var(--verde); padding-bottom: 8px; }
.doc-tabla { width: 100%; border-collapse: collapse; margin: 14px 0; }
.doc-tabla th, .doc-tabla td { border: 1px solid #333; padding: 6px 10px; text-align: left; font-size: 13px; }
.doc-tabla th { background: #eee; }
.doc-nota { font-size: 12px; font-style: italic; margin-top: 20px; }
.doc-firma { margin-top: 40px; display: flex; justify-content: space-between; font-size: 13px; }
.doc-firma-dos-cols { display: flex; justify-content: space-between; margin-top: 50px; gap: 40px; }
.doc-firma-dos-cols > div { flex: 1; text-align: center; }
.doc-linea-firma { border-top: 1px solid #333; margin-top: 40px; padding-top: 6px; }

.doc-footer-real {
    display: flex; justify-content: space-between; align-items: flex-end;
    border-top: 1px solid #999; margin-top: 30px; padding-top: 8px; font-size: 10px; color: #333;
}
.doc-footer-real .col { flex: 1; }
.doc-footer-real .col.centro { text-align: center; }
.doc-footer-real .col.derecha { text-align: right; }

.doc-tabla-form { width: 100%; border-collapse: collapse; font-size: 12px; margin: 10px 0; }
.doc-tabla-form td, .doc-tabla-form th { border: 1px solid #000; padding: 4px 6px; vertical-align: top; }
.doc-tabla-form th { background: #f2f2f2; text-align: left; }
.doc-checkbox { font-size: 14px; margin-right: 4px; }
.doc-campo-linea { border-bottom: 1px solid #000; display: inline-block; min-width: 160px; }
.doc-titulo-verde { color: #0a6e3a; }
.doc-encabezado-flex { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.doc-encabezado-flex .titulo-bloque { font-weight: 700; font-size: 15px; }
.doc-encabezado-flex .institucion { font-size: 11px; text-align: right; }
.doc-monotabla th, .doc-monotabla td { text-align: center; font-size: 11px; }

@media print {
    .no-print, .doc-toolbar { display: none !important; }
    .doc-body { background: #fff; }
    .doc-hoja { box-shadow: none; margin: 0; }
    thead { display: table-header-group; }
    tr { page-break-inside: avoid; }
}

/* -------- Línea de tiempo de trazabilidad -------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
    display: flex; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--borde);
}
.timeline li:last-child { border-bottom: none; }
.timeline-icono { font-size: 20px; width: 30px; text-align: center; flex-shrink: 0; }
.timeline-cuerpo { flex: 1; }
.timeline-fecha { font-size: 12px; color: var(--gris); }
.timeline-titulo { font-weight: 600; font-size: 14px; margin: 2px 0; }
.timeline-detalle { font-size: 13px; color: #444; }

/* ============================================================
   RESPONSIVE / MÓVIL
   ============================================================ */

/* Las tablas mantienen su comportamiento normal en escritorio; en móvil (ver más abajo)
   se vuelven desplazables horizontalmente para no romper el layout. */
@media (max-width: 768px) {
    input, select, textarea { font-size: 16px; }
}

@media (max-width: 900px) {
    .content { padding: 0 10px; }
    .grid-cards { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .topbar { padding: 10px 14px; }
    .brand-sub { display: none; }

    .menu-toggle { display: block; }

    .topnav {
        display: none;
        flex-direction: column;
        width: 100%;
        order: 3;
        margin-top: 10px;
        gap: 2px;
    }
    .topnav.abierto { display: flex; }
    .topnav a {
        margin: 0; padding: 12px 10px; border-radius: 6px;
        border-bottom: 1px solid rgba(255,255,255,.12);
    }

    .topbar-user-desktop { display: none; }
    .topbar-user-mobile {
        display: flex; justify-content: space-between; align-items: center;
        margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(255,255,255,.2);
    }

    h1 { font-size: 19px; }
    .card { padding: 14px; }

    .form-row { flex-direction: column; gap: 8px; }
    .form-row > div { min-width: 100%; }
    .checkboxes { flex-direction: column; gap: 10px !important; }

    .acciones-top { flex-direction: column; }
    .acciones-top a, .acciones-top .btn-primary, .acciones-top .btn-secondary-btn { text-align: center; }

    button.btn-primary, .btn-primary, .btn-secondary-btn { width: 100%; box-sizing: border-box; }

    /* En formularios donde el botón va junto a otros elementos en línea, no forzar 100% */
    .doc-toolbar button { width: auto; }

    .table-sm th, .table-sm td { padding: 8px 10px; font-size: 13px; }

    /* Tablas con muchas columnas: scroll horizontal en lugar de desbordar la pantalla */
    .table-sm { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
    .table-sm thead, .table-sm tbody { display: table; width: 100%; }

    .grid-cards { gap: 12px; }

    /* Documentos imprimibles: menos margen en pantallas pequeñas (siguen pensados para imprimir desde PC) */
    .doc-hoja { padding: 16px; font-size: 13px; }
    .doc-toolbar { position: sticky; top: 0; background: #ddd; z-index: 10; padding: 8px; }
}

@media (max-width: 480px) {
    .login-box { width: 90%; padding: 20px; }
    .brand-trex { font-size: 20px; }
}

/* Login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--verde); }
.login-box { background: #fff; padding: 30px; border-radius: 10px; width: 340px; }
.login-brand { text-align: center; margin-bottom: 20px; }
.login-brand p { font-size: 13px; color: var(--gris); }
