@import url('https://fonts.googleapis.com/css2?family=Barlow:wght@400;500;600;700;900&family=Barlow+Condensed:wght@600;700;900&display=swap');

/* ── VARIABLES ─────────────────────────────────── */
:root {
    --green:       #2d6a4f;
    --green-light: #52b788;
    --green-dim:   #1b4332;
    --accent:      #d8f3dc;
    --gold:        #f4a261;
    --red:         #e63946;
    --bg:          #0f1410;
    --surface:     #161d18;
    --surface2:    #1e2820;
    --surface3:    #242e26;
    --border:      #2a3a2d;
    --text:        #e8f0e9;
    --text-dim:    #7a9e82;
    --text-muted:  #4a6650;
    --radius:      6px;
    --radius-lg:   12px;
}

/* ── RESET ──────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Barlow', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 15px;
    line-height: 1.5;
}

/* ── LAYOUT ─────────────────────────────────────── */
.app {
    display: grid;
    grid-template-rows: auto 1fr;
    min-height: 100vh;
}

/* ── TOPBAR ─────────────────────────────────────── */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-logo {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

.topbar-title {
    font-family: 'Barlow Condensed', sans-serif;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text);
}

.topbar-title span {
    color: var(--green-light);
}

.topbar-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-btn {
    padding: 7px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-dim);
    font-family: 'Barlow', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s;
    letter-spacing: 0.03em;
}

.nav-btn:hover {
    background: var(--surface2);
    color: var(--text);
    border-color: var(--green);
}

.nav-btn.active {
    background: var(--green-dim);
    color: var(--green-light);
    border-color: var(--green);
}

.nav-btn.danger {
    border-color: transparent;
    color: var(--text-muted);
}

.nav-btn.danger:hover {
    background: rgba(230, 57, 70, 0.1);
    color: var(--red);
    border-color: var(--red);
}

/* ── MAIN ───────────────────────────────────────── */
.main {
    padding: 24px;
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
}

/* ── PAGE HEADER ────────────────────────────────── */
.page-header {
    margin-bottom: 24px;
}

.page-header h1 {
    font-family: 'Barlow Condensed', sans-serif;
    font-size: 2rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text);
    line-height: 1;
}

.page-header p {
    color: var(--text-dim);
    font-size: 0.9rem;
    margin-top: 4px;
}

/* ── STAT CARDS ─────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-top: 24px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: var(--green-light);
    opacity: 0.5;
}

.stat-card.accent::before { background: var(--gold); }
.stat-card.red::before    { background: var(--red); }

.stat-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.stat-value {
    font-family: 'Barlow Condensed', sans-serif;
    font-size: 1.9rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}

.stat-value.green  { color: var(--green-light); }
.stat-value.gold   { color: var(--gold); }

.stat-unit {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ── GRID DOS COLUMNAS ──────────────────────────── */
.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

@media (max-width: 700px) {
    .two-col { grid-template-columns: 1fr; }
}

/* ── CARD ───────────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.card-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface2);
}

.card-title {
    font-family: 'Barlow Condensed', sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text);
}

.card-body {
    padding: 20px;
}

/* ── FORM ELEMENTS ──────────────────────────────── */
.field-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

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

.field-row input,
.field-row select {
    flex: 1;
}

input, select {
    width: 100%;
    padding: 10px 14px;
    background: var(--surface3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: 'Barlow', sans-serif;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.15s;
    appearance: none;
}

input::placeholder { color: var(--text-muted); }

input:focus, select:focus {
    border-color: var(--green-light);
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%237a9e82' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

/* ── BUTTONS ────────────────────────────────────── */
.btn {
    padding: 10px 20px;
    border-radius: var(--radius);
    border: none;
    font-family: 'Barlow', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.15s;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
    background: var(--green);
    color: #fff;
    width: 100%;
}

.btn-primary:hover:not(:disabled) { background: var(--green-dim); }

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
}

.btn-outline:hover:not(:disabled) {
    border-color: var(--green-light);
    color: var(--text);
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    padding: 6px 10px;
    font-size: 0.8rem;
}

.btn-ghost:hover { color: var(--red); }

.btn-danger {
    background: rgba(230, 57, 70, 0.12);
    color: var(--red);
    border: 1px solid rgba(230, 57, 70, 0.3);
}

.btn-danger:hover:not(:disabled) { background: rgba(230, 57, 70, 0.2); }

.btn-gold {
    background: var(--gold);
    color: #1a0a00;
    width: 100%;
    font-size: 1rem;
    padding: 13px;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.btn-gold:hover:not(:disabled) { opacity: 0.9; }

/* ── TABLE ──────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

thead tr {
    background: var(--surface2);
}

th {
    padding: 10px 14px;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: middle;
}

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

tbody tr:hover { background: var(--surface2); }

td.mono {
    font-family: 'Barlow Condensed', sans-serif;
    font-size: 1rem;
}

td.green { color: var(--green-light); font-weight: 600; }
td.gold  { color: var(--gold); font-weight: 600; }
td.dim   { color: var(--text-muted); font-size: 0.82rem; }

/* ── TOTALS BAR ─────────────────────────────────── */
.totals-bar {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.totals-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.totals-item .label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.totals-item .value {
    font-family: 'Barlow Condensed', sans-serif;
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--green-light);
    line-height: 1;
}

/* ── ADMIN LIST ─────────────────────────────────── */
.material-row {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.material-row:last-child { border-bottom: none; }

.material-row input { flex: 1; }
.material-row input:first-child { flex: 2; }

/* ── HISTORIAL ──────────────────────────────────── */
.compra-row { cursor: pointer; }
.compra-row.open { background: var(--surface2); }

.compra-detalle {
    background: var(--surface3);
}

.compra-detalle td {
    padding: 0;
}

.detalle-inner {
    padding: 12px 20px;
    font-size: 0.82rem;
    color: var(--text-dim);
}

.detalle-inner table {
    width: 100%;
    margin-top: 6px;
}

.detalle-inner th {
    font-size: 0.68rem;
    padding: 6px 10px;
}

.detalle-inner td {
    padding: 6px 10px;
    font-size: 0.82rem;
    border-bottom: 1px solid var(--border);
}

/* ── TABS ───────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0;
}

.tab {
    padding: 10px 20px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-family: 'Barlow', sans-serif;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: all 0.15s;
    letter-spacing: 0.03em;
}

.tab:hover { color: var(--text); }

.tab.active {
    color: var(--green-light);
    border-bottom-color: var(--green-light);
}

/* ── EMPTY STATE ────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-state .icon {
    font-size: 2.5rem;
    margin-bottom: 8px;
    opacity: 0.4;
}

.empty-state p {
    font-size: 0.88rem;
}

/* ── BADGE ──────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.badge-green {
    background: rgba(82, 183, 136, 0.15);
    color: var(--green-light);
}

/* ── SEARCH ─────────────────────────────────────── */
.search-wrap {
    position: relative;
}

.search-wrap input {
    padding-left: 36px;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.9rem;
    pointer-events: none;
}

/* ── SCROLLBAR ──────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── MODAL ──────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    /* Evita que el grid padre lo atrape */
    transform: none;
}

.modal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 440px;
    overflow: hidden;
    position: relative;
    z-index: 10000;
    /* Sombra para destacar sobre el overlay */
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface2);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-height: 60vh;
    overflow-y: auto;
}

.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    background: var(--surface2);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* Reutilizar estilos de login para los campos del modal */
.modal-body .login-field label {
    color: var(--text-dim);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

.modal-body .login-field input,
.modal-body .login-field select {
    background: var(--surface3);
    border-color: var(--border);
    color: var(--text);
}

.modal-body .login-field input:focus,
.modal-body .login-field select:focus {
    border-color: var(--green-light);
    box-shadow: 0 0 0 3px rgba(82,183,136,0.1);
}

/* ── BADGES DE ROL ──────────────────────────────── */
.badge-superadmin {
    background: rgba(244, 162, 97, 0.15);
    color: var(--gold);
    border: 1px solid rgba(244, 162, 97, 0.3);
}

.badge-admin {
    background: rgba(82, 183, 136, 0.15);
    color: var(--green-light);
    border: 1px solid rgba(82, 183, 136, 0.3);
}

.badge-operador {
    background: rgba(122, 158, 130, 0.15);
    color: var(--text-dim);
    border: 1px solid var(--border);
}

.badge-inactivo {
    background: rgba(230, 57, 70, 0.1);
    color: var(--red);
    border: 1px solid rgba(230, 57, 70, 0.3);
}

/* ══════════════════════════════════════════════════
   RESPONSIVE — MÓVIL
   ══════════════════════════════════════════════════ */

@media (max-width: 768px) {

    /* ── BODY ───────────────────────────────────── */
    body {
        font-size: 14px;
    }

    /* ── TOPBAR ─────────────────────────────────── */
    .topbar {
        height: auto;
        padding: 10px 16px;
        flex-wrap: wrap;
        gap: 10px;
    }

    .topbar-brand {
        flex: 1;
    }

    .topbar-title {
        font-size: 0.95rem;
    }

    .topbar-logo {
        width: 26px;
        height: 26px;
    }

    .topbar-nav {
        width: 100%;
        flex-wrap: wrap;
        gap: 6px;
        justify-content: flex-start;
    }

    #sesion-info {
        width: 100%;
        padding: 4px 0;
        border-bottom: 1px solid var(--border);
        margin-bottom: 2px;
    }

    .nav-btn {
        padding: 6px 12px;
        font-size: 0.78rem;
        flex: 1;
        justify-content: center;
        min-width: 80px;
    }

    /* ── MAIN ───────────────────────────────────── */
    .main {
        padding: 14px;
    }

    /* ── PAGE HEADER ────────────────────────────── */
    .page-header h1 {
        font-size: 1.5rem;
    }

    .page-header {
        margin-bottom: 16px;
    }

    /* ── STATS GRID ─────────────────────────────── */
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin-top: 16px;
    }

    .stat-card {
        padding: 12px 14px;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    /* ── DOS COLUMNAS → UNA ─────────────────────── */
    .two-col {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    /* ── CARD ───────────────────────────────────── */
    .card-header {
        padding: 12px 14px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .card-body {
        padding: 14px;
    }

    /* ── TABS ───────────────────────────────────── */
    .tabs {
        gap: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .tabs::-webkit-scrollbar { display: none; }

    .tab {
        padding: 10px 14px;
        font-size: 0.82rem;
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* ── TABLA ──────────────────────────────────── */
    th, td {
        padding: 9px 10px;
        font-size: 0.82rem;
    }

    /* Ocultar columnas menos importantes en móvil */
    .hide-mobile {
        display: none;
    }

    /* ── TOTALS BAR ─────────────────────────────── */
    .totals-bar {
        padding: 12px 14px;
        gap: 12px;
    }

    .totals-item .value {
        font-size: 1.3rem;
    }

    /* ── BOTONES ────────────────────────────────── */
    .btn {
        padding: 9px 14px;
        font-size: 0.85rem;
    }

    .btn-gold {
        font-size: 0.95rem;
        padding: 12px;
    }

    /* ── MATERIAL ROW ───────────────────────────── */
    .material-row {
        flex-wrap: wrap;
    }

    /* ── MODAL ──────────────────────────────────── */
    .modal-card {
        max-width: 100%;
        margin: 0;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
    }

    .modal-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .modal-body {
        max-height: 55vh;
    }

    /* ── CAMPO BUSQUEDA ─────────────────────────── */
    .field-group {
        gap: 8px;
    }

    /* ── BADGE ──────────────────────────────────── */
    .badge {
        font-size: 0.68rem;
        padding: 2px 6px;
    }
}

/* Pantallas muy pequeñas */
@media (max-width: 380px) {

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .topbar-title {
        font-size: 0.85rem;
    }

    .nav-btn {
        font-size: 0.72rem;
        padding: 5px 8px;
    }
}

/* ══════════════════════════════════════════════════
   HAMBURGER MENU
   ══════════════════════════════════════════════════ */

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Hamburger — oculto en desktop */
.hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 36px;
    height: 36px;
    padding: 6px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.15s;
}

.hamburger:hover {
    border-color: var(--green-light);
}

.hamburger span {
    display: block;
    height: 2px;
    background: var(--text-dim);
    border-radius: 2px;
    transition: all 0.25s ease;
    transform-origin: center;
}

/* Animación X al abrir */
.hamburger.open span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}
.hamburger.open span:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}
.hamburger.open span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* Menú móvil — panel desplegable */
.menu-title{
    margin: 20px auto;
    border-bottom: 1px solid var(--border);
}

.mobile-menu {
    display: none;
    position: fixed;
    top: 0;
    right: -280px;
    width: 260px;
    height: 100vh;
    background: var(--surface);
    border-left: 1px solid var(--border);
    z-index: 500;
    flex-direction: column;
    padding: 0px 0px 70px;
    gap: 4px;
    transition: right 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.4);
}

.mobile-menu.open {
    right: 0;
}

.mobile-nav-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 24px;
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-family: 'Barlow', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    letter-spacing: 0.03em;
    border-left: 3px solid transparent;
    width: 100%;
    text-align: left;
}

.mobile-nav-btn:hover {
    background: var(--surface2);
    color: var(--text);
    border-left-color: var(--green);
}

.mobile-nav-btn.active {
    background: var(--surface2);
    color: var(--green-light);
    border-left-color: var(--green-light);
}

.mobile-nav-btn.danger {
    color: var(--text-muted);
    margin-top: auto;
}

.mobile-nav-btn.danger:hover {
    background: rgba(230, 57, 70, 0.08);
    color: var(--red);
    border-left-color: var(--red);
}

/* Overlay oscuro detrás del menú */
.mobile-menu-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 499;
    opacity: 0;
    transition: opacity 0.28s ease;
}

.mobile-menu-overlay.open {
    opacity: 1;
}

/* ── RESPONSIVE ACTIVACIÓN ──────────────────────── */
@media (max-width: 768px) {

    .hamburger {
        display: flex;
    }

    .desktop-nav {
        display: none !important;
    }

    .mobile-menu {
        display: flex;
    }

    .mobile-menu-overlay {
        display: block;
    }

    /* sesion-info fuera del menú, en el topbar */
    #sesion-info {
        width: auto;
        border-bottom: none;
        margin-bottom: 0;
        padding: 0;
    }

    .topbar {
        height: 56px;
        padding: 0 16px;
        flex-wrap: nowrap;
    }

    .topbar-right {
        gap: 8px;
    }
}
