/* =============================================================
   AIRE (by DEVELOPMENT SOFT) — hoja de estilos común (todas las vistas)
   Breakpoints: ≤1100 tablet horizontal · ≤900 tablet · ≤600 móvil
   ============================================================= */
:root {
    --sb-width: 260px;
    --accent-primary: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-light: #eff6ff;
    --bg-base: #f1f5f9;
    --bg-surface: #ffffff;
    --border-color: #e2e8f0;
    --border-strong: #cbd5e1;
    --text-primary: #0f172a;
    --text-muted: #64748b;
    --ok-bg: #dcfce7;  --ok-fg: #166534;
    --err-bg: #fee2e2; --err-fg: #991b1b;
    --warn-bg: #fffbeb; --warn-fg: #92400e; --warn-bd: #fde68a;
    --radius-sm: 8px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.04);
    --topbar-h: 56px;
}

*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg-base);
    font-family: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}
img { max-width: 100%; }
button, input, select, textarea { font-family: inherit; }

/* ---------------- Layout ---------------- */
.app-layout { display: flex; min-height: 100vh; width: 100%; }
.main-content { flex: 1; min-width: 0; padding: 22px 28px; }

/* ---------------- Sidebar ---------------- */
.app-sidebar {
    width: var(--sb-width);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 60;
}
.sb-brand { padding: 20px 18px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border-color); }
.sb-brand-icon {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #fff; width: 44px; height: 44px; border-radius: 12px;
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.25);
}
.sb-brand-icon.sm { width: 32px; height: 32px; border-radius: 9px; }
.sb-brand-icon svg { width: 20px; height: 20px; }
.sb-brand-icon.sm svg { width: 16px; height: 16px; }
.sb-brand-title { font-size: 1.1rem; font-weight: 800; margin: 0; line-height: 1.2; }
.sb-brand-badge { font-size: 0.7rem; font-weight: 800; color: var(--accent-primary); text-transform: uppercase; letter-spacing: 0.05em; display: block; margin-top: 2px; }
.app-sidebar .sb-cerrar { display: none; margin-left: auto; }
.sb-nav { padding: 14px 12px; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; flex: 1; }
.sb-section-label { font-size: 0.68rem; font-weight: 800; color: #94a3b8; padding: 14px 12px 6px; text-transform: uppercase; letter-spacing: 0.06em; }
.sb-link {
    display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: var(--radius-md);
    color: var(--text-muted); text-decoration: none; font-size: 0.9rem; font-weight: 700; transition: background .15s, color .15s;
}
.sb-link svg { width: 19px; height: 19px; flex-shrink: 0; }
.sb-link:hover { background: #f8fafc; color: var(--text-primary); }
.sb-link.active { background: var(--accent-light); color: var(--accent-primary); box-shadow: inset 0 0 0 1.5px rgba(37, 99, 235, 0.2); }
/* ---------------- Marca: AIRE (sistema) + tienda del cliente ---------------- */
.logo-sistema { width: 44px; height: 44px; border-radius: 12px; flex-shrink: 0; box-shadow: 0 4px 10px rgba(37, 99, 235, 0.25); }
.logo-sistema.sm { width: 32px; height: 32px; border-radius: 9px; box-shadow: none; }
.sb-brand-title { letter-spacing: 0.08em; }
.sb-tienda { display: flex; align-items: center; gap: 10px; margin: 12px 12px 0; padding: 8px 10px; border: 1px solid var(--border-color); border-radius: 10px; background: #f8fafc; min-width: 0; }
.sb-tienda-logo { width: 34px; height: 34px; object-fit: contain; border-radius: 8px; background: #fff; flex-shrink: 0; }
.sb-tienda-logo.vacio { display: inline-flex; align-items: center; justify-content: center; color: var(--text-muted); border: 1px dashed var(--border-strong); }
.sb-tienda-logo.vacio svg { width: 18px; height: 18px; }
.sb-tienda-nombre { font-size: 0.82rem; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.firma-dev { font-size: 0.7rem; color: #94a3b8; text-align: center; padding: 8px 12px 12px; letter-spacing: 0.02em; }
.firma-dev strong { color: #64748b; font-weight: 800; }
.pie-panel { margin-top: 24px; border-top: 1px solid var(--border-color); }
.app-sidebar .firma-dev { padding-top: 0; }
.sb-badge { margin-left: auto; background: #ef4444; color: #fff; font-size: 0.72rem; font-weight: 800; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; }
.sb-punto { position: absolute; top: 6px; right: 6px; width: 10px; height: 10px; border-radius: 999px; background: #ef4444; border: 2px solid #fff; }
[hidden] { display: none !important; }
.sb-footer { padding: 14px 16px; border-top: 1px solid var(--border-color); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sb-user-name { font-size: 0.84rem; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-user-status { font-size: 0.7rem; color: #10b981; font-weight: 800; text-transform: uppercase; display: block; margin-top: 2px; }
.sb-btn-logout { color: #ef4444; background: var(--err-bg); padding: 8px; border-radius: 8px; display: flex; text-decoration: none; }
.sb-btn-logout:hover { background: #fecaca; }
.sb-btn-logout svg { width: 17px; height: 17px; }

.topbar-movil, .sb-fondo { display: none; }

/* ---------------- Encabezado de página ---------------- */
.page-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-title { font-size: 1.5rem; font-weight: 800; margin: 0; letter-spacing: -0.02em; line-height: 1.2; }
.page-subtitle { font-size: 0.86rem; color: var(--text-muted); margin: 4px 0 0; }
.header-acciones { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pill-bcv {
    background: var(--warn-bg); border: 1.5px solid var(--warn-bd); color: var(--warn-fg);
    padding: 6px 14px; border-radius: 999px; font-weight: 800; font-size: 0.84rem; white-space: nowrap;
    display: inline-flex; align-items: center; gap: 6px;
}

/* ---------------- Tarjetas y grids ---------------- */
.card { background: var(--bg-surface); border: 1px solid var(--border-color); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-card); margin-bottom: 18px; }
.card-titulo { margin: 0 0 14px; font-size: 1.1rem; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.card-titulo svg { color: var(--accent-primary); }
.grid-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi { background: #fff; border: 1px solid var(--border-color); border-radius: var(--radius-lg); padding: 18px 20px; box-shadow: var(--shadow-card); border-left-width: 5px; }
.kpi-label { font-size: 0.74rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; }
.kpi-valor { margin: 6px 0 4px; font-size: 1.7rem; font-weight: 800; overflow-wrap: anywhere; }
.grid-2col { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 20px; align-items: start; }

/* ---------------- Tablas ---------------- */
.tabla-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }
.tabla { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.tabla th { padding: 12px 10px; border-bottom: 2px solid var(--border-color); text-align: left; color: var(--text-muted); font-size: 0.74rem; text-transform: uppercase; font-weight: 800; white-space: nowrap; }
.tabla td { padding: 13px 10px; border-bottom: 1px solid var(--border-color); vertical-align: middle; }
.tabla .num { text-align: right; white-space: nowrap; }
.tabla .vacio { text-align: center; padding: 30px; color: var(--text-muted); }

/* ---------------- Formularios ---------------- */
.campo { margin-bottom: 12px; min-width: 0; }
.campo label, .label { display: block; font-size: 0.8rem; font-weight: 700; margin-bottom: 4px; }
.inp {
    width: 100%; min-height: 42px; padding: 8px 12px; border: 1.5px solid var(--border-color); border-radius: var(--radius-md);
    font-size: 0.92rem; background: #fff; color: var(--text-primary); outline: none; transition: border-color .15s, box-shadow .15s;
}
.inp:focus { border-color: var(--accent-primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }
.inp-sm { min-height: 36px; padding: 6px 10px; font-size: 0.85rem; }
textarea.inp { min-height: 70px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-full { grid-column: 1 / -1; }
.filtros { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.filtros .campo { margin: 0; flex: 1 1 170px; }

/* ---------------- Botones ---------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px;
    padding: 8px 16px; border-radius: var(--radius-md); border: 1.5px solid transparent;
    font-weight: 800; font-size: 0.88rem; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s;
}
.btn svg { width: 16px; height: 16px; }
.btn-primario { background: var(--accent-primary); color: #fff; }
.btn-primario:hover { background: var(--accent-hover); }
.btn-exito { background: #059669; color: #fff; }
.btn-exito:hover { background: #047857; }
.btn-excel { background: #16a34a; color: #fff; }
.btn-secundario { background: #fff; color: #334155; border-color: var(--border-strong); }
.btn-secundario:hover { background: #f8fafc; }
.btn-suave { background: var(--accent-light); color: #1d4ed8; border-color: #bfdbfe; }
.btn-peligro { background: var(--err-bg); color: var(--err-fg); border-color: #fecaca; }
.btn-sm { min-height: 32px; padding: 5px 10px; font-size: 0.8rem; }
.btn-bloque { width: 100%; }
.btn-lg { min-height: 50px; font-size: 1rem; }
.btn[disabled] { opacity: .6; cursor: not-allowed; }
.btn-icono { background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 8px; border-radius: 8px; display: inline-flex; text-decoration: none; }
.btn-icono:hover { background: #f1f5f9; }
.btn-icono.peligro { color: #ef4444; }

/* ---------------- Alertas y badges ---------------- */
.alerta { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-weight: 700; font-size: 0.9rem; display: flex; align-items: center; gap: 10px; }
.alerta svg { flex-shrink: 0; width: 18px; height: 18px; }
.alerta-exito { background: var(--ok-bg); color: var(--ok-fg); border: 1px solid #bbf7d0; }
.alerta-error { background: var(--err-bg); color: var(--err-fg); border: 1px solid #fecaca; }
.alerta-info { background: var(--accent-light); color: #1e40af; border: 1px solid #bfdbfe; }
.badge { display: inline-block; padding: 3px 8px; border-radius: 6px; font-weight: 800; font-size: 0.74rem; text-transform: uppercase; white-space: nowrap; }
.badge-ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge-err { background: var(--err-bg); color: var(--err-fg); }
.badge-warn { background: #fef3c7; color: var(--warn-fg); }
.badge-info { background: var(--accent-light); color: #1d4ed8; }
.badge-gris { background: #f1f5f9; color: #334155; }
.muted { color: var(--text-muted); }
.txt-sm { font-size: 0.8rem; }

/* ---------------- Modales ---------------- */
.modal-overlay {
    display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, 0.65); backdrop-filter: blur(4px);
    z-index: 200; align-items: center; justify-content: center; padding: 16px;
}
.modal-overlay.visible { display: flex; }
.modal-card { background: #fff; border-radius: var(--radius-lg); padding: 20px; max-width: 480px; width: 100%; max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 1.1rem; font-weight: 800; }
.modal-img { width: 100%; max-height: 50vh; object-fit: contain; border-radius: 8px; background: #f8fafc; border: 1px solid var(--border-color); }
.miniaturas { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
.miniaturas img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; border: 2px solid var(--border-color); cursor: pointer; }
.miniaturas img.activa { border-color: var(--accent-primary); }

/* ---------------- Responsive ---------------- */
@media (max-width: 1100px) {
    .main-content { padding: 18px 20px; }
    .grid-2col { grid-template-columns: 320px minmax(0, 1fr); }
}

@media (max-width: 900px) {
    .app-layout { flex-direction: column; }
    .main-content { padding: 16px; }

    .topbar-movil {
        display: flex; align-items: center; justify-content: space-between; gap: 8px;
        position: sticky; top: 0; z-index: 50; height: var(--topbar-h); padding: 0 8px;
        background: #fff; border-bottom: 1px solid var(--border-color);
    }
    .topbar-movil-brand { display: flex; align-items: center; gap: 8px; font-size: 1rem; }

    .app-sidebar {
        position: fixed; left: 0; top: 0; bottom: 0; height: 100%; width: min(84vw, 300px);
        transform: translateX(-100%); transition: transform .22s ease; z-index: 120;
        box-shadow: 0 0 40px rgba(15, 23, 42, 0.2);
    }
    body.sb-abierto .app-sidebar { transform: translateX(0); }
    body.sb-abierto { overflow: hidden; }
    .sb-fondo { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); z-index: 110; }
    body.sb-abierto .sb-fondo { display: block; }
    .app-sidebar .sb-cerrar { display: inline-flex; }

    .grid-2col { grid-template-columns: minmax(0, 1fr); }
    .page-title { font-size: 1.3rem; }
}

@media (max-width: 600px) {
    .main-content { padding: 12px; }
    .card { padding: 14px; border-radius: 12px; }
    .form-grid { grid-template-columns: 1fr; }
    .grid-kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
    .kpi { padding: 12px 14px; }
    .kpi-valor { font-size: 1.2rem; }
    .header-acciones { width: 100%; }
    .header-acciones .btn { flex: 1; }
    .filtros .campo, .filtros .btn { flex: 1 1 100%; }
    .tabla { font-size: 0.82rem; }
    .tabla th, .tabla td { padding: 10px 8px; }

    /* Tablas en formato tarjeta: cada celda muestra su encabezado (data-label) */
    .tabla-apilada thead { display: none; }
    .tabla-apilada, .tabla-apilada tbody, .tabla-apilada tr, .tabla-apilada td { display: block; width: 100%; }
    .tabla-apilada tr { border: 1px solid var(--border-color); border-radius: 10px; margin-bottom: 10px; padding: 6px 12px; background: #fff; }
    .tabla-apilada td { border: none; padding: 7px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: right; }
    .tabla-apilada td + td { border-top: 1px dashed var(--border-color); }
    .tabla-apilada td::before { content: attr(data-label); font-size: 0.7rem; font-weight: 800; color: var(--text-muted); text-transform: uppercase; text-align: left; flex-shrink: 0; }
    .tabla-apilada td.num { text-align: right; }
    .tabla-apilada td.vacio { display: block; text-align: center; }
    .tabla-apilada td.vacio::before { content: none; }
}

@media print {
    .app-sidebar, .topbar-movil, .no-print, .sb-fondo { display: none !important; }
    .main-content { padding: 0; }
    .card { box-shadow: none; break-inside: avoid; }
}
