/* ============================================================
   Sistema visual unificado para vistas index del panel (admin)
   Tema: carpinteria / madera rústica (coherente con pedidos, backups, landing)
   ============================================================ */

:root {
    --wood-900: #2f2016;
    --wood-800: #4b3121;
    --wood-700: #6a442c;
    --wood-600: #8b5e3c;
    --wood-500: #b17647;
    --wood-400: #c08b52;
    --wood-300: #d6b08f;
    --wood-200: #edd8c4;
    --wood-100: #f8efe6;
    --wood-50: #fdf6ee;
    --wood-grain: linear-gradient(135deg, #8b5e3c 0%, #a06b3f 55%, #7a4b2c 100%);
    --ink-900: #2b231d;
    --ink-700: #54483c;
    --ink-600: #6a5b4f;
    --ok: #2f7d55;
    --warn: #c78512;
    --danger: #b6403a;
    --surface: #fffdfa;
    --radius-lg: 18px;
    --radius-md: 12px;
    --shadow-soft: 0 10px 30px rgba(47, 32, 22, 0.08);
}

/* ── PANEL BASE ─────────────────────────────────────────────── */
.admin-index-page .card,
.listado-panel {
    border: 1px solid rgba(139, 94, 60, 0.18);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    overflow: hidden;
    background: var(--surface);
}

.admin-index-page .card + .card,
.listado-panel + .listado-panel {
    margin-top: 1rem;
}

/* ── HERO HEADER (cabecera dinámica por módulo) ─────────────── */
.listado-hero {
    background:
        radial-gradient(circle at right top, rgba(214, 176, 143, 0.5), transparent 50%),
        linear-gradient(130deg, rgba(139, 94, 60, 0.10), rgba(255, 255, 255, 0.96));
    border-bottom: 1px solid rgba(139, 94, 60, 0.16);
    padding: 1.15rem 1.3rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.listado-hero__main {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    min-width: 0;
}

.listado-hero__icon {
    flex-shrink: 0;
    width: 46px;
    height: 46px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    font-size: 1.5rem;
    color: #fff;
    background: var(--wood-grain);
    box-shadow: 0 6px 16px rgba(122, 78, 34, 0.28);
}

.listado-hero__icon i {
    line-height: 1;
}

.listado-hero__title {
    margin: 0;
    color: var(--ink-900);
    font-size: 1.35rem;
    line-height: 1.1;
    font-weight: 700;
}

.listado-hero__subtitle {
    color: var(--ink-600);
    font-size: 0.88rem;
    margin: 0.15rem 0 0;
}

.listado-hero__side {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    flex-wrap: wrap;
}

.listado-count-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: #fff;
    border: 1px solid rgba(139, 94, 60, 0.3);
    color: var(--wood-800);
    border-radius: 999px;
    padding: 0.42rem 0.85rem;
    font-size: 0.8rem;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(47, 32, 22, 0.06);
}

.listado-count-badge i {
    font-size: 1rem;
    color: var(--wood-500);
}

.listado-cta {
    border: 0;
    border-radius: 999px;
    white-space: nowrap;
    background: var(--wood-grain);
    color: #fff;
    font-weight: 600;
    padding: 0.6rem 1.05rem;
    box-shadow: 0 8px 18px rgba(139, 94, 60, 0.28);
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: transform 0.16s ease, box-shadow 0.16s ease, filter 0.16s ease;
}

.listado-cta:hover,
.listado-cta:focus {
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 12px 22px rgba(122, 78, 34, 0.34);
    filter: brightness(1.05);
}

.listado-cta i {
    font-size: 1.05rem;
    line-height: 1;
}

/* ── CUERPO ─────────────────────────────────────────────────── */
.admin-index-page .card-body,
.listado-panel .card-body {
    padding: 1.1rem 1.3rem;
}

.admin-index-page .alert,
.listado-panel .alert {
    border-radius: var(--radius-md);
    border-width: 1px;
    border-style: solid;
    font-weight: 500;
}

.admin-index-page .alert-success {
    background: rgba(47, 125, 85, 0.10);
    border-color: rgba(47, 125, 85, 0.28);
    color: #1f5f3f;
}

.admin-index-page .alert-danger {
    background: rgba(182, 64, 58, 0.10);
    border-color: rgba(182, 64, 58, 0.28);
    color: #8e2c28;
}

.admin-index-page .alert-info {
    background: rgba(26, 115, 232, 0.10);
    border-color: rgba(26, 115, 232, 0.28);
    color: #0a4a8a;
}

.admin-index-page .alert-warning {
    background: rgba(199, 133, 18, 0.10);
    border-color: rgba(199, 133, 18, 0.28);
    color: #8f6200;
}

/* ── TABLA ──────────────────────────────────────────────────── */
.listado-table-wrap {
    border: 1px solid rgba(139, 94, 60, 0.16);
    border-radius: var(--radius-md);
    background: #fff;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.listado-table {
    width: 100%;
    min-width: 0;
    margin-bottom: 0;
    font-size: 0.87rem;
    table-layout: fixed;
}

.listado-table thead th {
    background: #f8eee3;
    color: var(--wood-900);
    font-size: 0.71rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
    border-bottom: 1px solid rgba(139, 94, 60, 0.24);
    padding: 0.62rem 0.55rem;
    vertical-align: middle;
    overflow-wrap: anywhere;
}

.listado-table tbody td {
    padding: 0.5rem 0.7rem;
    border-color: rgba(139, 94, 60, 0.08);
    vertical-align: middle;
    min-width: 0;
    overflow-wrap: anywhere;
    color: var(--ink-700);
}

.listado-table tbody tr {
    transition: background 0.16s ease;
}

.listado-table tbody tr:hover {
    background: rgba(237, 216, 196, 0.26);
}

.listado-table tbody tr:last-child td {
    border-bottom: 0;
}

.listado-table .listing-strong {
    color: var(--ink-900);
    font-weight: 600;
}

.listado-table .listing-muted {
    color: var(--ink-600);
}

/* Chips para IDs y cantidades */
.listing-id {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    border-radius: 999px;
    padding: 0.2rem 0.5rem;
    background: rgba(139, 94, 60, 0.12);
    color: var(--wood-900);
    font-weight: 700;
    font-size: 0.75rem;
}

.listing-qty {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    border-radius: 10px;
    padding: 0.18rem 0.42rem;
    background: #f4f0ea;
    color: var(--ink-900);
    font-weight: 700;
}

/* Badges */
.badge.listing-badge {
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.72rem;
    padding: 0.32rem 0.6rem;
}

.listing-badge--success { background: rgba(47, 125, 85, 0.16); color: #1f5f3f; }
.listing-badge--warning { background: rgba(199, 133, 18, 0.16); color: #8f6200; }
.listing-badge--danger   { background: rgba(182, 64, 58, 0.16); color: #8e2c28; }
.listing-badge--info     { background: rgba(26, 115, 232, 0.14); color: #0a4a8a; }
.listing-badge--neutral  { background: rgba(95, 95, 95, 0.14); color: #525252; }

/* Precios / valores */
.listing-money {
    color: var(--wood-800);
    font-weight: 700;
    white-space: nowrap;
}

.listing-money--ok { color: var(--ok); }

/* Ajuste responsivo: el contenido envuelve dentro de cada celda y la
   tabla nunca supera el ancho del contenedor (evita scroll lateral). */
.listado-table td {
    overflow-wrap: anywhere;
    min-width: 0;
}

table.dataTable {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
}

table.dataTable td {
    overflow-wrap: anywhere;
    min-width: 0;
}

table.dataTable th {
    overflow-wrap: anywhere;
    min-width: 0;
}

/* Columnas de ancho fijo dentro del layout fijo:
   el resto del espacio se reparte entre las demás columnas. */
.listado-table thead th:first-child {
    width: 70px;
}

.listado-table .actions-cell {
    width: 142px;
}

/* ── BOTONES DE ACCIÓN (iconos interactivos) ────────────────── */
.actions-cell {
    width: 142px;
}

.btn-group-action {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    flex-wrap: wrap;
}

.btn-acci {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.14s ease, background 0.14s ease, color 0.14s ease, box-shadow 0.14s ease;
}

.btn-acci i {
    line-height: 1;
}

.btn-acci:hover {
    transform: translateY(-1px);
}

/* Ver */
.btn-acci--ver {
    color: #0a4a8a;
    border-color: rgba(26, 115, 232, 0.32);
    background: rgba(26, 115, 232, 0.10);
}
.btn-acci--ver:hover {
    color: #fff;
    background: #1a73e8;
    border-color: #1a73e8;
    box-shadow: 0 6px 14px rgba(26, 115, 232, 0.3);
}

/* Editar */
.btn-acci--editar {
    color: #7a4b00;
    border-color: rgba(224, 160, 32, 0.35);
    background: rgba(224, 160, 32, 0.14);
}
.btn-acci--editar:hover {
    color: #fff;
    background: #d19c1d;
    border-color: #d19c1d;
    box-shadow: 0 6px 14px rgba(209, 156, 29, 0.3);
}

/* Eliminar */
.btn-acci--eliminar {
    color: #962b26;
    border-color: rgba(182, 64, 58, 0.32);
    background: rgba(182, 64, 58, 0.12);
}
.btn-acci--eliminar:hover {
    color: #fff;
    background: #b6403a;
    border-color: #b6403a;
    box-shadow: 0 6px 14px rgba(182, 64, 58, 0.3);
}

/* Acción terciaria (PDF, Costeo, etc.) - usa madera */
.btn-acci--wood {
    color: var(--wood-800);
    border-color: rgba(139, 94, 60, 0.35);
    background: rgba(139, 94, 60, 0.12);
}
.btn-acci--wood:hover {
    color: #fff;
    background: var(--wood-600);
    border-color: var(--wood-600);
    box-shadow: 0 6px 14px rgba(139, 94, 60, 0.3);
}

/* ── VACÍO ──────────────────────────────────────────────────── */
.listado-empty {
    border: 1px dashed rgba(139, 94, 60, 0.4);
    border-radius: var(--radius-md);
    background: rgba(253, 246, 238, 0.6);
    padding: 2.2rem 1rem;
    text-align: center;
    color: var(--ink-600);
}

.listado-empty i {
    display: block;
    font-size: 2.2rem;
    color: var(--wood-400);
    margin-bottom: 0.4rem;
}

/* ── DataTables ─────────────────────────────────────────────── */
.admin-index-page .dataTables_filter input,
.admin-index-page .dataTables_length select,
.listado-panel .dataTables_filter input,
.listado-panel .dataTables_length select {
    border: 1px solid rgba(139, 94, 60, 0.35);
    border-radius: 10px;
    background: #fff;
    padding: 0.38rem 0.6rem;
}

.admin-index-page .dataTables_filter input:focus,
.admin-index-page .dataTables_length select:focus {
    outline: none;
    border-color: var(--wood-600);
    box-shadow: 0 0 0 3px rgba(139, 94, 60, 0.16);
}

.admin-index-page .dataTables_wrapper .dataTables_paginate .paginate_button,
.listado-panel .dataTables_wrapper .dataTables_paginate .paginate_button {
    border-radius: 10px !important;
}

.admin-index-page .dataTables_wrapper .dataTables_info {
    color: var(--ink-600);
    font-size: 0.85rem;
}

/* DataTables (bootstrap5) genera filas .row con el gutter negativo de
   Bootstrap; eso las saca 12px del contenedor y provoca scroll lateral. */
.listado-table-wrap .dataTables_wrapper > .row {
    --bs-gutter-x: 0;
    margin-left: 0;
    margin-right: 0;
}

/* ── KPIs / métricas para balances y resúmenes ──────────────── */
.listing-kpi-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.7rem;
    margin-bottom: 1rem;
}

.listing-kpi {
    border: 1px solid rgba(139, 94, 60, 0.2);
    border-radius: 14px;
    padding: 0.8rem 0.9rem;
    background: #fff;
    box-shadow: 0 4px 14px rgba(47, 32, 22, 0.05);
    min-width: 0;
}

.listing-kpi__label {
    display: block;
    color: var(--ink-600);
    font-size: 0.76rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    margin-bottom: 0.2rem;
}

.listing-kpi__value {
    display: block;
    color: var(--ink-900);
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1.1;
    overflow-wrap: anywhere;
}

.listing-kpi__value--ok { color: var(--ok); }
.listing-kpi__value--danger { color: var(--danger); }

/* Banner (fuera de tarjeta, para páginas con estructura propia) */
.listado-hero--banner {
    border: 1px solid rgba(139, 94, 60, 0.18);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    background:
        radial-gradient(circle at right top, rgba(214, 176, 143, 0.5), transparent 50%),
        linear-gradient(130deg, rgba(139, 94, 60, 0.10), rgba(255, 255, 255, 0.96));
    margin-bottom: 1rem;
}

/* ── BOTÓN FANTASMA (acciones secundarias) ──────────────────── */
.listado-btn-ghost {
    border: 1px solid rgba(139, 94, 60, 0.4);
    background: #fff;
    color: var(--wood-700);
    border-radius: 999px;
    font-weight: 600;
    padding: 0.55rem 1rem;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
    transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
}

.listado-btn-ghost:hover,
.listado-btn-ghost:focus {
    background: var(--wood-50);
    color: var(--wood-800);
    border-color: var(--wood-500);
    transform: translateY(-1px);
    box-shadow: 0 8px 18px rgba(47, 32, 22, 0.08);
}

.listado-btn-ghost i {
    font-size: 1.05rem;
    line-height: 1;
}

/* ── GRILLA DE DETALLE (vistas show) ────────────────────────── */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1.1rem 1.6rem;
}

.detail-item {}
.detail-item dt {
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
    color: var(--ink-600);
    margin-bottom: 0.25rem;
}

.detail-item dd {
    color: var(--ink-900);
    font-weight: 600;
    font-size: 0.97rem;
    margin-bottom: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.detail-item dd .listing-money {
    font-size: 1.1rem;
}

/* Presentación de moneda larga dentro de detalle */
.detail-money {
    font-weight: 800;
    color: var(--wood-800);
}

/* ── FORMULARIO ──────────────────────────────────────────────── */
.form-section-title {
    color: var(--ink-900);
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.form-section-title i {
    color: var(--wood-500);
}

.listado-form .form-control,
.listado-form .form-select {
    border-radius: 10px;
}

.listado-form .form-label {
    font-weight: 600;
    color: var(--ink-700);
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-top: 1.4rem;
    padding-top: 1.1rem;
    border-top: 1px solid rgba(139, 94, 60, 0.16);
}

.form-actions .listado-cta,
.form-actions .listado-btn-ghost {
    padding: 0.62rem 1.2rem;
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 992px) {
    .listing-kpi-row {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .listado-hero {
        padding: 1rem 1.05rem;
    }

    .admin-index-page .card-body,
    .listado-panel .card-body {
        padding: 0.9rem 1rem;
    }
}

@media (max-width: 768px) {
    .listado-hero__main {
        align-items: flex-start;
    }

    .listado-hero__icon {
        width: 40px;
        height: 40px;
        font-size: 1.25rem;
        border-radius: 12px;
    }

    .listado-hero__title {
        font-size: 1.15rem;
    }

    .listado-hero__subtitle {
        font-size: 0.82rem;
    }

    .listado-hero__side {
        width: 100%;
        justify-content: space-between;
    }

    .listado-cta {
        flex: 1;
        justify-content: center;
    }

    .listing-kpi-row {
        grid-template-columns: 1fr 1fr;
    }

    .listado-table {
        font-size: 0.86rem;
    }

    .btn-group-action {
        gap: 0.25rem;
    }
}

@media (max-width: 480px) {
    .listing-kpi-row {
        grid-template-columns: 1fr;
    }

    .listado-hero__side {
        flex-direction: column;
        align-items: stretch;
    }

    .listado-count-badge,
    .listado-cta,
    .listado-btn-ghost {
        width: 100%;
        justify-content: center;
    }
}

/* ── DATA TABLES: evitar parpadeo (FOUC) ──────────────────── */
/* La tabla cruda queda oculta hasta que DataTables la inicializa y     */
/* le agrega la clase .dataTable. Si el CDN falla, el fallback JS       */
/* agrega .dt-sin-js y la tabla se muestra con su contenido completo.  */
table.js-datatable-bs:not(.dataTable):not(.dt-sin-js) {
    visibility: hidden;
}
