:root {
    --primary: #D4A574;
    --primary-dark: #B8824F;
    --brown: #5d4037;
    --brown-light: #795548;
    --text: #333;
    --text-light: #666;
    --white: #fff;
    --bg: #f5f5f5;
    --border: #ddd;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Sora', sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; }

.hist-page { overflow-x: hidden; }

.hist-container {
    max-width: min(1600px, 96vw);
    margin: 0 auto;
    padding: 0 16px 40px;
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
}

.hist-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--white);
    padding: 20px 16px;
    margin: 0 -16px 24px;
}
.header-content {
    max-width: min(1600px, 96vw);
    margin: 0 auto;
}
.hist-header h1 { font-size: 1.5rem; display: flex; align-items: center; gap: 10px; }

/* Header layout / navegación */
.hist-header-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}
.hist-header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
}
.hist-header-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    width: 100%;
}
.hist-nav-menu { position: relative; }
.hist-nav-menu > summary { list-style: none; cursor: pointer; }
.hist-nav-menu > summary::-webkit-details-marker { display: none; }
.hist-nav-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 8px;
}
.hist-nav-toggle:hover { background: rgba(255, 255, 255, 0.28); }
.hist-nav-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 300;
    min-width: 220px;
    padding: 8px;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
    border: 1px solid #e8e8e8;
}
.hist-nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    color: #333;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    border-radius: 8px;
}
.hist-nav-link:hover { background: #f5f0eb; color: #4e342e; }
.hist-nav-link i { width: 18px; color: #8d6e63; text-align: center; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    font-family: inherit;
}
.btn-pdf { background: #c62828; color: #fff; }
.btn-pdf:hover { background: #b71c1c; }
.btn-back {
    background: rgba(255,255,255,0.15);
    color: var(--white);
    border: 2px solid rgba(255,255,255,0.35);
}
.btn-back:hover { background: rgba(255,255,255,0.28); color: var(--white); }
.hist-btn-toolbar-clear { cursor: pointer; font-family: inherit; }

/* Filtros */
.filters-section {
    background: var(--white);
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.filters-section h2 { font-size: 1rem; margin-bottom: 8px; color: var(--primary-dark); }
.filters-hint { font-size: 13px; color: var(--text-light); margin-bottom: 16px; }
.hist-hint-inline { margin: -4px 0 12px; }
.filters-grid { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; }
.filter-group label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
.filter-group select {
    min-width: 200px;
    min-height: 44px;
    padding: 10px 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
}
.filter-group select:focus { outline: none; border-color: var(--primary); }
.filter-group.filter-actions { display: flex; align-items: flex-end; }
.btn-borrar-filtros {
    min-height: 44px;
    min-width: 160px;
    padding: 10px 14px;
    border: 2px solid var(--border);
    background: #fafafa;
    color: var(--text);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.btn-borrar-filtros:hover { background: #eee; border-color: #bbb; }

/* Tarjetas resumen */
.reporte-section { margin-top: 8px; }
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}
.summary-card {
    background: var(--white);
    border-radius: 10px;
    padding: 14px 18px;
    border-left: 4px solid var(--primary);
    box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.summary-card strong { display: block; font-size: 11px; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.03em; }
.summary-card span { font-size: 1.2rem; font-weight: 700; color: var(--primary-dark); }
.summary-card--total { border-left-color: #2e7d32; }
.summary-card--total span { color: #2e7d32; }
.summary-card--mes { border-left-color: var(--brown); }
.summary-card--mes span { color: var(--brown); font-size: 1.05rem; }
.summary-card--manual { border-left-color: #9e9e9e; }
.summary-card--manual span { color: #757575; font-size: 1.05rem; }

/* Bloques de tablas */
.reporte-bloque { margin-bottom: 28px; }
.reporte-bloque-titulo {
    font-size: 1.05rem;
    color: var(--brown);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.reporte-detalle-count { font-size: 0.85rem; color: var(--text-light); font-weight: 500; }

.table-wrap {
    overflow-x: auto;
    background: var(--white);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,.06);
}
.hist-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 720px; }
.hist-table th, .hist-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.hist-table th { background: #efebe9; font-weight: 600; color: var(--brown); }
.hist-table th.hist-num, .hist-table td.hist-num { text-align: right; font-variant-numeric: tabular-nums; }
.hist-table tbody tr:hover { background: #faf7f4; }
.hist-num-total { font-weight: 700; color: #2e7d32; }
.hist-col-manual { color: #9e9e9e; }
.hist-td-vacio { text-align: center; color: var(--text-light); font-style: italic; }
.hist-fila-total td { background: #f3ede9; font-weight: 700; border-top: 2px solid var(--primary); border-bottom: none; }
.hist-row-manual td { background: #fbfbfb; color: #888; }
.hist-row-manual:hover td { background: #f4f4f4; }

/* Badges de método */
.hist-metodo {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}
.hist-metodo--efectivo { background: #e8f5e9; color: #2e7d32; }
.hist-metodo--transfer { background: #e3f2fd; color: #1565c0; }
.hist-metodo--cobros { background: #fff3e0; color: #e65100; }
.hist-metodo--manual { background: #eeeeee; color: #757575; }
.hist-tag-suspendido { display: inline-block; margin-left: 6px; padding: 2px 6px; border-radius: 4px; font-size: 10px; font-weight: 600; background: #fff3e0; color: #e65100; vertical-align: middle; }

.loading, .empty-state { text-align: center; padding: 40px 20px; color: var(--text-light); }
.loading i { font-size: 32px; color: var(--primary); display: block; margin-bottom: 10px; }
.empty-state i { font-size: 48px; color: #ccc; display: block; margin-bottom: 12px; }

.hidden { display: none !important; }

.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 14px 20px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    z-index: 9999;
    display: none;
}
.toast.show { display: block; }
.toast.error { background: #c62828; color: #fff; }
.toast.success { background: #2e7d32; color: #fff; }

/* ========== Responsive ========== */
@media (min-width: 900px) {
    .hist-header-content {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: center;
    }
    .hist-header-top { width: auto; flex: 0 1 auto; }
    .hist-header-toolbar { width: auto; flex: 1 1 auto; justify-content: flex-end; }
    .hist-btn-toolbar-clear { display: none; }
}

@media (max-width: 768px) {
    .hist-container { padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px)); }
    .hist-header { margin-bottom: 16px; }
    .hist-header h1 { font-size: 1.2rem; }

    .hist-header-toolbar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 250;
        margin: 0;
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
        background: #fff;
        border-top: 1px solid #e0dcd8;
        box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.12);
        justify-content: center;
        width: 100%;
    }
    .hist-header-toolbar .btn {
        min-height: 44px;
        flex: 1 1 auto;
        max-width: 180px;
        justify-content: center;
    }
    .hist-btn-label { display: none; }
    .hist-filter-actions-desktop { display: none; }

    .filters-grid { flex-direction: column; align-items: stretch; }
    .filter-group select { min-width: 0; width: 100%; }

    .summary-cards { grid-template-columns: 1fr 1fr; }

    .toast { left: 12px; right: 12px; bottom: calc(88px + env(safe-area-inset-bottom, 0px)); }
}

@media (max-width: 480px) {
    .hist-header h1 { font-size: 1.05rem; }
    .summary-cards { grid-template-columns: 1fr; }
}
