/* Estilos del panel autenticado (compartido Web + Desktop)
 *
 * Lenguaje: superficies planas separadas por líneas de 1px, sin sombras, sin
 * degradados, radios cortos. Los colores salen de tokens.css.
 */

body {
    font-family: var(--font);
    background-color: var(--bg);
    color: var(--ink);
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

/* ---------- Estructura ---------- */
.shell {
    display: flex;
    min-height: 100vh;
}

.side {
    width: var(--side-w);
    flex-shrink: 0;
    background: linear-gradient(180deg, var(--side-bg) 0%, var(--side-bg-2) 100%);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* ---------- Header ----------
 * El título de la página vive acá, arriba a la izquierda; el usuario, a la
 * derecha. */
.topbar {
    height: 52px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 24px;
    background-color: var(--surface);
    border-bottom: 1px solid var(--line);
}

.top-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--ink);
    margin: 0;
    letter-spacing: -0.015em;
}

.top-user {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    color: var(--ink-2);
}

.body {
    padding: 24px;
    flex: 1;
}

/* ---------- Menú lateral (sobre pizarra) ---------- */
.menu {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow-y: auto;
}

.menu-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--side-line);
}

.brand-box {
    width: 28px;
    height: 28px;
    border-radius: var(--radius);
    background-color: var(--brand-ink);
    color: var(--brand);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 700;
    flex-shrink: 0;
}

.brand-text {
    font-size: 16px;
    font-weight: 600;
    color: var(--side-ink);
    letter-spacing: -0.01em;
}

.menu-list {
    padding: 10px 8px;
    flex: 1;
}

/* El texto crece, la caja no: el padding vertical se compensa. */
.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: var(--radius);
    font-size: 15px;
    color: var(--side-ink);
    text-decoration: none;
    margin-bottom: 1px;
    border-left: 2px solid transparent;
}

.menu-item:hover {
    background-color: var(--side-hover);
}

.menu-item.active {
    background-color: var(--side-active);
    font-weight: 500;
    border-left-color: var(--brand-on-dark);
}

.menu-item .nav-icon {
    font-size: 17px;
    width: 19px;
    text-align: center;
    color: var(--side-icon);
}

.menu-item.active .nav-icon {
    color: var(--brand-on-dark);
}

.menu-item:hover .nav-icon {
    color: var(--side-ink);
}

.menu-sep {
    border: 0;
    border-top: 1px solid var(--side-line);
    margin: 8px 10px;
}

/* ---------- Encabezado de página ----------
 * El título vive en el header (MainLayout); acá queda solo la fila de
 * acciones de la página. */
.pg-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 14px;
}

.pg-actions:empty {
    display: none;
}

/* ---------- Avisos dentro de la página ----------
 * El título de la página vive en el header; esto es para los avisos
 * (por ejemplo, acceso denegado). */
.pg-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--ink);
    margin: 0 0 4px;
}

.pg-sub {
    font-size: 13px;
    color: var(--muted);
    margin: 0;
}

.section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
    margin: 24px 0 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Más aire entre dos secciones densas dentro de la misma tarjeta. */
.section-title--gap {
    margin-top: 40px;
}

/* ---------- Superficies ---------- */
.card-panel {
    background-color: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    margin-bottom: 14px;
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
}

.card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
    margin: 0;
}

/* ---------- KPIs ----------
 * Una fila de cifras, no un tablero de tarjetas. El número manda; la
 * etiqueta y el contexto van debajo, sin iconos en recuadros. */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 0;
    background-color: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 14px;
}

.kpi {
    padding: 14px 18px;
    border-right: 1px solid var(--line-soft);
}

.kpi:last-child {
    border-right: none;
}

.kpi-value {
    font-size: 26px;
    font-weight: 600;
    color: var(--ink);
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}

.kpi-label {
    font-size: 12px;
    color: var(--muted);
    margin-top: 3px;
}

/* ---------- Tablas ---------- */
.tbl {
    width: 100%;
    border-collapse: collapse;
}

.tbl th {
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

.tbl td {
    padding: 9px 10px;
    font-size: 14px;
    color: var(--ink);
    border-bottom: 1px solid var(--line-soft);
    vertical-align: middle;
}

.tbl tr:last-child td {
    border-bottom: none;
}

.tbl tbody tr:hover td {
    background-color: var(--surface-2);
}

.tbl .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.tbl tfoot td {
    border-top: 1px solid var(--line);
    border-bottom: none;
    background-color: var(--surface-2);
    font-size: 13px;
    font-weight: 600;
    padding: 9px 10px;
}

/* Tabla con separador vertical entre columnas (misma línea gris que las filas). */
.tbl--cols th,
.tbl--cols td {
    border-right: 1px solid var(--line-soft);
}

.tbl--cols th:last-child,
.tbl--cols td:last-child {
    border-right: none;
}

/* ---------- Estados ----------
 * Punto de color + texto sobre fondo casi blanco. El color se lee del texto. */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: var(--radius);
    padding: 2px 8px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    line-height: 1.6;
}

.chip::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: currentColor;
    flex-shrink: 0;
}

.chip-ok { color: var(--ok-ink); background-color: var(--ok-bg); }
.chip-pend { color: var(--warn-ink); background-color: var(--warn-bg); }
.chip-info { color: var(--info-ink); background-color: var(--info-bg); }
.chip-brand { color: var(--brand); background-color: var(--brand-soft); }
.chip-muted { color: var(--muted); background-color: var(--surface-2); }
.chip-danger { color: var(--err-ink); background-color: var(--err-bg); }

button.chip {
    border: none;
    cursor: pointer;
    font-family: inherit;
}

button.chip:hover {
    filter: none;
    border: 1px solid currentColor;
}

/* ---------- Botones ---------- */
.btn-brand,
.btn-ghost,
.btn-danger,
.btn-sm {
    border-radius: var(--radius);
    font-family: inherit;
    font-weight: 500;
    font-size: 13px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.btn-brand {
    background-color: var(--brand);
    border: 1px solid var(--brand);
    color: var(--brand-ink);
    padding: 8px 14px;
}

.btn-brand:hover {
    background-color: var(--brand-dark);
    border-color: var(--brand-dark);
}

.btn-ghost {
    background-color: var(--surface);
    border: 1px solid var(--line);
    color: var(--ink-2);
    padding: 8px 13px;
}

.btn-ghost:hover {
    background-color: var(--surface-2);
    border-color: var(--muted);
    color: var(--ink);
}

.btn-danger {
    background-color: var(--surface);
    border: 1px solid var(--err-ink);
    color: var(--err-ink);
    padding: 8px 13px;
}

.btn-danger:hover {
    background-color: var(--err-bg);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
    background-color: var(--surface);
    border: 1px solid var(--line);
    color: var(--ink-2);
}

.btn-sm:hover {
    background-color: var(--surface-3);
    border-color: var(--muted);
    color: var(--ink);
}

.btn-sm.muted-action {
    background-color: transparent;
    border-color: var(--line);
    color: var(--muted);
}

.btn-sm.danger-action {
    background-color: transparent;
    border-color: transparent;
    color: var(--err-ink);
}

.btn-sm.danger-action:hover {
    background-color: var(--err-bg);
    border-color: var(--err-bg);
}

.btn-brand:focus-visible,
.btn-ghost:focus-visible,
.btn-danger:focus-visible,
.btn-sm:focus-visible,
.menu-item:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 1px;
}

.row-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
}

button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* ---------- Barra de búsqueda y filtros (sobre una tabla) ----------
 * Los controles van en fila; la barra se envuelve sola en pantallas angostas. */
.filters {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.filters-search {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 220px;
}

.filters-search input {
    flex: 1;
    min-width: 0;
}

/* La lupa queda a la derecha del campo, fuera de él (no se superpone al texto). */
.filters-search i {
    color: var(--muted);
    font-size: 16px;
}

.filters select {
    min-width: 150px;
}

.filters-count {
    font-size: 12px;
    color: var(--muted);
    margin-left: auto;
}

/* ---------- Formularios ---------- */
.field {
    margin-bottom: 12px;
}

.field-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--ink-2);
    margin-bottom: 5px;
}

.field input,
.field select,
.field textarea,
.filters input,
.filters select {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 7px 10px;
    font-size: 14px;
    font-family: inherit;
    color: var(--ink);
    background-color: var(--surface);
    outline: none;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
    box-sizing: border-box;
}

/* En un formulario ocupan todo el ancho; en la barra de filtros cada control mide lo suyo. */
.field input,
.field select,
.field textarea {
    width: 100%;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.filters input:focus,
.filters select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 2px var(--brand-soft);
}

.field-row {
    display: flex;
    gap: 10px;
}

.field-row .field {
    flex: 1;
}

.form-error {
    color: var(--err-ink);
    font-size: 13px;
    margin-bottom: 10px;
}

.alert {
    border: 1px solid var(--info-bg);
    background-color: var(--info-bg);
    color: var(--info-ink);
    border-radius: var(--radius);
    padding: 9px 12px;
    font-size: 13px;
    margin-bottom: 12px;
}

.alert-info {
    border-color: var(--info-bg);
    background-color: var(--info-bg);
    color: var(--info-ink);
}

/* ---------- Modal ---------- */
.modal-mask {
    position: fixed;
    inset: 0;
    background-color: rgba(23, 25, 29, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1050;
    padding: 16px;
}

.modal-box {
    background-color: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 20px;
}

.modal-box.wide {
    max-width: 680px;
}

.modal-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--ink);
    margin: 0 0 3px;
}

.modal-sub {
    font-size: 13px;
    color: var(--muted);
    margin: 0 0 16px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
    flex-wrap: wrap;
}

/* ---------- Progreso / envíos ---------- */
.progress {
    height: 6px;
    background-color: var(--line-soft);
    border-radius: 3px;
    overflow: hidden;
}

.progress > i {
    display: block;
    height: 100%;
    background-color: var(--brand);
    border-radius: 3px;
    transition: width 0.3s ease;
}

.envio-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
    gap: 12px;
}

.envio-card {
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    background-color: var(--surface);
}

.envio-card h4 {
    margin: 0 0 2px;
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
}

.meta {
    font-size: 12px;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

/* Celda de una sola línea: evita que el contenido se parta y despareje las filas. */
.nowrap {
    white-space: nowrap;
}

/* ---------- Listas y utilidades ---------- */
.chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.muted {
    color: var(--muted);
    font-size: 13px;
}

.empty {
    text-align: center;
    color: var(--muted);
    padding: 28px 16px;
    font-size: 13px;
}

.empty-state {
    text-align: center;
    color: var(--muted);
    padding: 24px 16px;
    font-size: 13px;
}

.detail-block {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 10px;
    background-color: var(--surface);
}

.detail-block .detail-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.detail-block .detail-name {
    font-weight: 600;
    color: var(--ink);
    font-size: 13px;
}

.table-scroll {
    overflow-x: auto;
    margin: 0 -6px;
    padding: 0 6px;
}

/* ---------- Listas de selección ---------- */
.check-list {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 4px;
    max-height: 190px;
    overflow-y: auto;
    background-color: var(--surface);
}

.check-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 6px 8px;
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--ink);
    cursor: pointer;
    margin: 0;
    font-weight: 400;
}

.check-item:hover {
    background-color: var(--surface-3);
}

.check-item input[type="checkbox"] {
    width: 15px;
    height: 15px;
    accent-color: var(--brand);
    cursor: pointer;
    flex-shrink: 0;
}

/* ---------- Usuarios por rol ---------- */
.role-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

.role-box {
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 12px 14px;
    background-color: var(--surface);
}

.role-box-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

.role-list {
    list-style: none;
    margin: 4px 0 0;
    padding: 0;
}

.role-list li {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    padding: 5px 0;
    border-bottom: 1px solid var(--line-soft);
    font-size: 13px;
    color: var(--ink);
}

.role-list li:last-child {
    border-bottom: none;
}

/* ---------- Documento (previsualización de orden de compra) ---------- */
.doc {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px 16px;
    background-color: var(--surface);
}

.doc-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding-bottom: 10px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--line);
}

.doc-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
}

/* ---------- Órdenes activas (Inicio) ----------
 * Tarjeta con columna lateral (número, nombre, plazo y cierre), el grid de
 * sucursales a la izquierda y el contador de envíos a la derecha. */
.orden-card {
    display: flex;
    gap: 24px;
}

.orden-lateral {
    width: 198px;
    flex: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    border-right: 1px solid var(--line);
    padding-right: 24px;
}

.orden-numero { font-size: 14px; color: var(--orden-muted); }
.orden-nombre { margin: 0; font-size: 24px; color: var(--ink); }
.orden-plazo { margin-top: 18px; font-size: 22px; font-weight: 600; color: var(--orden-plazo); }
.orden-plazo--vencido { color: var(--orden-plazo-vencido); }
.orden-limite { margin-top: 2px; font-size: 11px; color: var(--orden-muted); }

.btn-sm.orden-cerrar { height: 34px; padding: 0 12px; font-size: 13px; }

.orden-sucursales {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    align-content: start;
}

.orden-suc {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background-color: var(--orden-suc-bg);
}

/* La sucursal que ya envió es un botón: abre el detalle de qué pidió. */
button.orden-suc {
    cursor: pointer;
    font-family: inherit;
    text-align: left;
    transition: border-color 0.12s ease;
}

button.orden-suc:hover {
    border-color: var(--muted);
}

.orden-suc-nombre { font-size: 13px; font-weight: 500; }
.orden-suc-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.orden-suc--pendiente .orden-suc-dot { background-color: var(--orden-dot-pend); box-shadow: 0 0 0 3px var(--orden-dot-pend-halo); }
.orden-suc--enviada .orden-suc-dot { background-color: var(--orden-dot-ok); box-shadow: 0 0 0 3px var(--orden-dot-ok-halo); }

.orden-progreso { width: 64px; text-align: center; }
.orden-progreso-cifra { font-size: 27px; font-weight: 600; line-height: 1; }
.orden-progreso-label { margin-top: 4px; font-size: 12px; color: var(--orden-muted); }

/* Botón de acción de página alineado a la izquierda (Inicio). */
.pg-actions--start {
    justify-content: flex-start;
}

/* ---------- Pantallas angostas ---------- */
@media (max-width: 860px) {
    .shell {
        flex-direction: column;
    }

    .side {
        width: 100%;
        height: auto;
        position: static;
        border-right: none;
        border-bottom: 1px solid var(--line);
    }

    .menu-list {
        display: flex;
        overflow-x: auto;
        padding: 8px;
    }

    .menu-item {
        white-space: nowrap;
    }

    .body {
        padding: 16px;
    }

    /* La tarjeta de orden se apila: lateral arriba, sucursales en 2 columnas. */
    .orden-card {
        flex-direction: column;
        gap: 16px;
    }

    .orden-lateral {
        width: 100%;
        flex-direction: row;
        align-items: center;
        gap: 12px;
        border-right: none;
        border-bottom: 1px solid var(--line);
        padding-right: 0;
        padding-bottom: 14px;
    }

    .orden-plazo {
        margin-top: 6px;
    }

    .orden-sucursales {
        grid-template-columns: repeat(2, 1fr);
    }
}
