/* Paleta */
:root {
    --red: #B92117;
    --mustard: #D4AC0D;
    --orange: #D35400;
    --white: #FFFFFF;
    --text: #1f2937;
    --muted: #6b7280;
    --bg: #f8fafc;
    --card: #ffffff;
    --shadow: 0 10px 25px rgba(0, 0, 0, .08);
    --radius: 16px;
}

/* Base */
* {
    box-sizing: border-box
}

html,
body {
    height: 100%
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    color: var(--text);
    background: linear-gradient(135deg, #fff 0%, var(--bg) 100%);
}

.wrap {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 16px
}

/* Topbar */
.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: linear-gradient(90deg, var(--red), var(--orange));
    color: var(--white);
    box-shadow: var(--shadow);
}

.topbar-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 18px
}

.logo {
    font-size: 22px
}

.actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto
}

.actions form {
    margin: 0
}

.btn {
    border: 1px solid #e5e7eb;
    background: #fff;
    color: var(--text);
    padding: 9px 14px;
    border-radius: 10px;
    cursor: pointer;
    transition: transform .15s ease, box-shadow .15s ease, background-color .12s ease, border-color .12s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 16px 30px rgba(0, 0, 0, .12)
}

.btn.ghost {
    background: transparent;
    color: var(--white);
    border: 1px solid rgba(255, 255, 255, .6);
    border-radius: 999px;
    padding: 8px 12px;
}

.btn.ghost:hover {
    background: rgba(255, 255, 255, .15)
}

.btn.primary {
    background: linear-gradient(90deg, var(--red), var(--orange));
    color: #fff;
    border-color: transparent
}

.btn.danger {
    background: #fff5f5;
    color: #b91c1c;
    border-color: #fecaca
}

.menu-toggle {
    display: none
}

/* Título */
h1 {
    text-align: center;
    margin: 24px 0 12px
}

/* Filtros */
.search-form {
    background: #fff;
    border: 1px solid #eef2f7;
    box-shadow: var(--shadow);
    border-radius: 12px;
    padding: 12px;
    margin: 16px 0 22px;
}

.search-form form {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

.search-form input[type="text"],
.search-form input[type="date"],
.search-form select {
    padding: 10px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #fff;
    color: var(--text);
}

.search-form input:focus,
.search-form select:focus {
    border-color: var(--orange);
    box-shadow: 0 0 0 3px rgba(211, 84, 0, .12);
    outline: none;
}

/* Grid de tarjetas */
.historial-grid {
    display: grid;
    gap: 16px;
    /* ❌ antes: repeat(auto-fit, minmax(280px, 1fr)) */
    grid-template-columns: repeat(3, minmax(280px, 1fr));
    margin: 16px 0 24px;
    align-items: stretch;   /* que todas tengan misma altura por fila */
}

/* En tablet: 2 por fila */
@media (max-width: 1024px){
  .historial-grid {
    grid-template-columns: repeat(2, minmax(260px, 1fr));
  }
}

/* En móvil: 1 por fila */
@media (max-width: 640px){
  .historial-grid {
    grid-template-columns: 1fr;
  }
}


.caja-pedido {
    background: var(--card);
    border: 1px solid #eef2f7;
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 10px;
    /* ya no es clickeable toda la card */
    cursor: default;
    transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}

.caja-pedido:hover {
    transform: translateY(-2px);
    box-shadow: 0 16px 30px rgba(0, 0, 0, .12);
    border-color: #e2e8f0
}

.caja-pedido h3 {
    margin: 0;
    font-size: 18px;
    color: var(--orange);
    border-bottom: 2px solid #f2f2f2;
    padding-bottom: 6px;
}

.caja-pedido p {
    margin: 0;
    display: flex;
    gap: 8px;
    justify-content: space-between
}

.caja-pedido p strong {
    color: #334155
}

/* Acciones dentro de la card */
.card-actions {
    margin-top: 6px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* Estados */
.estado-PENDIENTE {
    color: var(--mustard);
    font-weight: 800
}

.estado-ENTREGADO {
    color: #16a34a;
    font-weight: 800
}

.estado-CANCELADO {
    color: #b91c1c;
    font-weight: 800
}

.badge {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 999px;
    margin-left: 8px;
    vertical-align: middle;
}

.badge-wa-pending {
    background: #fef3c7;
    color: #92400e;
    font-weight: 700;
}

.badge-wa-ok {
    background: #dcfce7;
    color: #166534;
}

.estados-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.estado-badge {
    font-size: 12px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 8px;
}

.estado-pago-PAGADO, .estado-entrega-ENTREGADO { background: #dcfce7; color: #166534; }
.estado-pago-PENDIENTE, .estado-pago-EFECTIVO_PENDIENTE { background: #fef9c3; color: #854d0e; }
.estado-pago-RECHAZADO, .estado-entrega-CANCELADO { background: #fee2e2; color: #b91c1c; }
.estado-entrega-EN_PREPARACION { background: #e0f2fe; color: #0369a1; }
.estado-entrega-EN_CAMINO { background: #ede9fe; color: #5b21b6; }
.estado-entrega-PENDIENTE { background: #f3f4f6; color: #374151; }

.btn-link-maps {
    color: var(--red);
    font-weight: 600;
    text-decoration: none;
}

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
}

.modal-wide .modal-content {
    width: min(720px, 94vw);
    text-align: left;
}

.modal-content-left {
    text-align: left;
}

.detalle-resumen {
    background: #f8fafc;
    padding: 12px 14px;
    border-radius: 10px;
    margin-bottom: 14px;
    font-size: 14px;
    line-height: 1.5;
}

.detalle-resumen p { margin: 6px 0; }

/* Modal */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, .4);
    padding: 24px;
}

.modal-content {
    background: #fff;
    width: min(520px, 92vw);
    margin: 40px auto;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 18px;
    text-align: center;
}

.close-button {
    background: transparent;
    border: 0;
    font-size: 28px;
    line-height: 1;
    color: #64748b;
    cursor: pointer;
    float: right;
}

.modal-content h2 {
    margin-top: 0;
    color: var(--orange)
}

.modal-content form {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.modal-content select {
    width: 100%;
    max-width: 320px;
    padding: 10px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
}

#statusMessage {
    margin-top: 6px;
}

/* Mobile */
@media (max-width:720px) {
    .menu-toggle {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        margin-left: auto;
        color: var(--white);
        text-decoration: none;
        border: 1px solid rgba(255, 255, 255, .6);
        padding: 8px 12px;
        border-radius: 999px;
        background: transparent;
        cursor: pointer;
    }

    .topbar .actions {
        position: absolute;
        left: 12px;
        right: 12px;
        top: calc(60px + 8px);
        display: none;
        flex-direction: column;
        gap: 8px;
        background: linear-gradient(90deg, var(--red), var(--orange));
        border: 1px solid rgba(255, 255, 255, .25);
        border-radius: 12px;
        padding: 10px;
        box-shadow: var(--shadow);
    }

    .topbar .actions.show {
        display: flex
    }

    .topbar .actions .btn {
        width: 100%;
        text-align: left;
        padding: 10px 12px
    }

    .topbar .actions form {
        width: 100%
    }

    .topbar .actions .btn.danger {
        text-align: center
    }

    .caja-pedido p {
        flex-direction: column;
        align-items: flex-start
    }

    .card-actions {
        justify-content: stretch
    }

    .card-actions .btn {
        width: 100%
    }
}

/* ===== Modal Detalle del pedido ===== */
.detalle-header {
    display: flex;
    flex-direction: column;
    gap: 2px;
    color: #334155;
    margin: 8px 0 12px;
}

.table-wrap {
    overflow: auto
}

.tabla-detalle {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.tabla-detalle thead th {
    background: #f8fafc;
    border-bottom: 1px solid #e5e7eb;
    padding: 8px 10px;
    text-align: left;
}

.tabla-detalle tbody td {
    border-bottom: 1px solid #eef2f7;
    padding: 8px 10px;
}

.tabla-detalle tfoot th {
    border-top: 2px solid #e5e7eb;
    padding: 10px;
}

.right {
    text-align: right
}

.err {
    color: #b91c1c
}

/* ===== Mobile: que "Nombre o teléfono" y "Todos los estados" vayan en la misma fila ===== */
@media (max-width: 720px) {

    /* el form sigue siendo flex con wrap */
    .search-form form {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 10px;
    }

    /* los dos primeros controles van 50/50 */
    .search-form form>input[name="busqueda"],
    .search-form form>input[name="nombre_o_telefono"],
    /* también para la vista de Agenda */
    .search-form form>select[name="estado"] {
        flex: 1 1 48%;
    }

    /* el resto ocupa toda la fila */
    .search-form form>select[name="orden"],
    .search-form form>select[name="mes"],
    .search-form form>select[name="anio"],
    .search-form form>button {
        flex: 1 1 100%;
    }

    /* que cada control llene su cajita flex */
    .search-form form>input,
    .search-form form>select,
    .search-form form>button {
        width: 100%;
    }
}