:root {
    --bg: #f5f5f0;
    --surface: #ffffff;
    --border: #e0ddd4;
    --text: #2c2c2a;
    --muted: #6b6a64;
    --primary: #185fa5;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.6;
}

/* ===== TOPBAR ===== */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 56px;
}
.brand { font-weight: 600; text-decoration: none; color: var(--text); }
.topbar nav { display: flex; align-items: center; gap: 16px; }
.topbar nav a { text-decoration: none; color: var(--muted); }
.topbar nav a:hover { color: var(--text); }
.topbar .user { font-size: 13px; color: var(--muted); }
.inline { display: inline; margin: 0; }
.linkbtn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 15px; padding: 0; }
.linkbtn:hover { color: var(--text); }

/* Botón hamburguesa — oculto en escritorio */
.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    margin-left: 8px;
    flex-shrink: 0;
}
.nav-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: background .2s;
}

/* ===== LAYOUT ===== */
.container { max-width: 980px; margin: 0 auto; padding: 24px 20px 60px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.page-head h1 { font-size: 24px; font-weight: 600; margin: 0; }
.muted { color: var(--muted); }

/* ===== BOTONES ===== */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    font-size: 14px;
    white-space: nowrap;
}
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn:hover { opacity: .9; }

/* ===== TABLA ===== */
table.grid { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: 10px; overflow: hidden; }
table.grid th, table.grid td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); }
table.grid th { font-size: 13px; color: var(--muted); font-weight: 500; }
table.grid a { color: var(--primary); text-decoration: none; }

/* ===== BADGE ===== */
.badge { display: inline-block; padding: 3px 10px; border-radius: 6px; color: #fff; font-size: 13px; font-weight: 500; }

/* ===== LOGIN ===== */
.login-card { max-width: 380px; margin: 60px auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card form { display: flex; flex-direction: column; gap: 6px; margin-top: 18px; }
.login-card label { font-size: 13px; color: var(--muted); margin-top: 8px; }
.login-card .check { display: flex; flex-direction: row; align-items: center; gap: 6px; margin-top: 8px; }
.login-card .check input[type="checkbox"] { width: auto; flex-shrink: 0; }

/* ===== INPUTS ===== */
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); width: 100%; }
button { font: inherit; }
.error { color: #a32d2d; font-size: 14px; }

/* ===== FORMULARIO EN GRID ===== */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; background: var(--surface); padding: 20px; border-radius: 12px; border: 1px solid var(--border); }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 4px; }
.form-grid .actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ===== ESTADO GENERAL ===== */
.estado-general { text-align: right; }
.estado-general label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.estado-general select { width: auto; border-radius: 8px; }

/* ===== STATS ===== */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 20px 0; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; }
.stat .lbl { font-size: 13px; color: var(--muted); }
.stat .val { font-size: 24px; font-weight: 600; }

/* ===== FICHA ===== */
.ficha { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; margin-bottom: 16px; }
.ficha summary { cursor: pointer; font-weight: 500; user-select: none; }
.ficha-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 24px; margin-top: 12px; }
.ficha-grid .k { color: var(--muted); display: inline-block; min-width: 130px; }

/* ===== APARTADOS / ÍTEMS ===== */
.apartado { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; margin-bottom: 16px; }
.apartado-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.apartado-head h2 { font-size: 17px; font-weight: 600; margin: 0; }
.apartado-head .pct { font-size: 13px; color: var(--muted); font-weight: 500; white-space: nowrap; flex-shrink: 0; }
.bar { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; margin: 10px 0 14px; }
.bar-fill { height: 100%; background: #1D9E75; transition: width .3s; }

.item { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--border); }
.item-txt { font-size: 14px; }
.estado-item { width: auto; border-radius: 8px; min-width: 130px; }
.obs { grid-column: 1 / -1; font-size: 13px; }
.obs-ro { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }

/* ===== LOG ===== */
.log-box { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; }
.log-box h2 { font-size: 17px; margin: 0 0 10px; }
.log { list-style: none; padding: 0; margin: 0; max-height: 300px; overflow: auto; }
.log li { font-size: 13px; color: var(--muted); padding: 6px 0; border-bottom: 1px solid var(--border); }
.log li strong { color: var(--text); }

/* ===================================================================
   RESPONSIVE — pantallas ≤640px (móvil)
   =================================================================== */
@media (max-width: 640px) {

    /* --- Topbar: menú hamburguesa --- */
    .topbar {
        height: auto;
        min-height: 52px;
        flex-wrap: wrap;
        padding: 0 14px;
        align-items: center;
    }
    .brand {
        flex: 1;
        min-width: 0;
        padding: 14px 0;
        font-size: 14px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .nav-toggle {
        display: flex;
    }
    /* El nav está oculto por defecto y abre al pulsar hamburguesa */
    .topbar nav {
        display: none;
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        border-top: 1px solid var(--border);
        padding: 4px 0 8px;
    }
    .topbar nav.open {
        display: flex;
    }
    .topbar nav a {
        display: block;
        padding: 12px 0;
        font-size: 15px;
        border-bottom: 1px solid var(--border);
        color: var(--text);
    }
    .topbar nav .user {
        display: block;
        padding: 12px 0;
        font-size: 14px;
        color: var(--muted);
        border-bottom: 1px solid var(--border);
    }
    .topbar nav form.inline {
        display: block;
        border-bottom: 1px solid var(--border);
    }
    .topbar nav .linkbtn {
        display: block;
        width: 100%;
        text-align: left;
        padding: 12px 0;
        font-size: 15px;
        color: var(--muted);
    }

    /* --- Contenedor --- */
    .container { padding: 16px 14px 60px; }

    /* --- Cabecera de página --- */
    .page-head { flex-direction: column; gap: 10px; }
    .page-head h1 { font-size: 20px; }
    .estado-general { text-align: left; }
    .estado-general select { width: 100%; min-height: 44px; }

    /* --- Stats: cuadrícula 2×2 en vez de 4×1 --- */
    .stats { grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 12px 0; }
    .stat .val { font-size: 20px; }

    /* --- Ficha resumen --- */
    .ficha-grid { grid-template-columns: 1fr; gap: 6px; }
    .ficha-grid .k { min-width: unset; display: block; font-size: 12px; margin-bottom: 1px; }

    /* --- Formulario: columna única --- */
    .form-grid { grid-template-columns: 1fr; padding: 14px; }

    /* --- Tablas → tarjetas apiladas --- */
    table.grid {
        display: block;
        background: transparent;
        border-radius: 0;
        overflow: visible;
    }
    table.grid thead { display: none; }
    table.grid tbody { display: flex; flex-direction: column; gap: 12px; }
    table.grid tr {
        display: block;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 10px;
        padding: 10px 14px;
    }
    table.grid td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 7px 0;
        border-top: none;
        border-left: none;
        border-right: none;
        border-bottom: 1px solid var(--border);
        font-size: 14px;
        gap: 8px;
    }
    table.grid td:last-child { border-bottom: none; }
    /* Etiqueta generada desde data-label */
    table.grid td[data-label]::before {
        content: attr(data-label);
        font-size: 12px;
        color: var(--muted);
        font-weight: 500;
        flex-shrink: 0;
        min-width: 68px;
    }
    /* Celda de acciones sin etiqueta */
    table.grid td[data-label=""] { justify-content: flex-end; }
    table.grid td[data-label=""]::before { display: none; }

    /* --- Checklist ítems: apilados en columna --- */
    .item {
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 12px 0;
    }
    .estado-item {
        width: 100%;
        min-width: unset;
        min-height: 44px;
    }

    /* --- Targets táctiles: mínimo 44px --- */
    .btn {
        padding: 10px 16px;
        font-size: 15px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    input, select, textarea {
        min-height: 44px;
        padding: 10px 12px;
    }

    /* --- Login --- */
    .login-card {
        margin: 20px 12px;
        padding: 20px;
    }

    /* --- Apartados --- */
    .apartado { padding: 14px; }
}
