@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500&display=swap');

:root {
    --primary: #0f766e;
    --primary-dark: #115e59;
    --primary-soft: #ccfbf1;
    --accent: #14b8a6;
    --bg: #eef2f6;
    --bg-elevated: #f8fafc;
    --surface: #ffffff;
    --sidebar-bg: #0f172a;
    --sidebar-bg-2: #1e293b;
    --sidebar-text: #cbd5e1;
    --sidebar-muted: #94a3b8;
    --border: #d8dee8;
    --border-strong: #b8c0ce;
    --text: #0f172a;
    --text-muted: #64748b;
    --danger: #dc2626;
    --success: #059669;
    --warning: #d97706;
    --info: #0284c8;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
    --radius: 10px;
    --radius-sm: 6px;
    --font: 'IBM Plex Sans', 'Segoe UI', sans-serif;
    --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

body {
    font-family: var(--font);
    background:
        radial-gradient(1200px 500px at 0% -10%, rgba(20, 184, 166, 0.08), transparent 55%),
        linear-gradient(180deg, #e8eef5 0%, var(--bg) 40%, #e9eef4 100%);
    margin: 0;
    color: var(--text);
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

/* ======== LOGIN ======== */
.login-container {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
             max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    background:
        linear-gradient(145deg, rgba(15, 23, 42, 0.92), rgba(15, 118, 110, 0.75)),
        url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"),
        #0f172a;
}

.login-card {
    background: var(--surface);
    border-radius: 14px;
    padding: 36px 32px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(255,255,255,0.12);
}

.login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    margin-bottom: 22px;
}

.login-mark {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: linear-gradient(145deg, #0f766e, #134e4a);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 18px;
    letter-spacing: 0.04em;
    box-shadow: 0 8px 20px rgba(15, 118, 110, 0.35);
}

.login-card h1 {
    text-align: center;
    color: var(--text);
    margin: 0;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.login-card .subtitle {
    text-align: center;
    color: var(--text-muted);
    margin: 0 0 8px;
    font-size: 13px;
    line-height: 1.4;
}

.login-card .logo { display: none; }

.login-meta {
    text-align: center;
    color: #94a3b8;
    font-size: 11px;
    margin-top: 20px;
}

/* ======== LAYOUT ======== */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 252px;
    background: linear-gradient(180deg, var(--sidebar-bg) 0%, #111827 55%, var(--sidebar-bg-2) 100%);
    color: var(--sidebar-text);
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
    overflow-y: auto;
    padding-bottom: env(safe-area-inset-bottom);
    border-right: 1px solid rgba(148, 163, 184, 0.12);
}

.sidebar-header {
    padding: 20px 18px 16px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.14);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-mark {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    background: linear-gradient(145deg, #0f766e, #0d9488);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 13px;
    flex-shrink: 0;
}

.sidebar-header h2 {
    margin: 0;
    color: #fff;
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.sidebar-header small {
    color: var(--sidebar-muted);
    font-size: 11px;
    display: block;
    margin-top: 2px;
    word-break: break-word;
}

.sidebar-nav { flex: 1; padding: 14px 10px; }

.nav-section {
    margin: 10px 10px 6px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #64748b;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    margin-bottom: 2px;
    border: none;
    border-radius: 8px;
    background: none;
    color: var(--sidebar-text);
    text-align: left;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    transition: background 0.15s ease, color 0.15s ease;
}

.nav-item:hover {
    background: rgba(148, 163, 184, 0.12);
    color: #fff;
}

.nav-item.active {
    background: rgba(20, 184, 166, 0.18);
    color: #fff;
    box-shadow: inset 3px 0 0 var(--accent);
}

.sidebar-footer {
    padding: 14px 16px 18px;
    border-top: 1px solid rgba(148, 163, 184, 0.14);
    font-size: 12px;
}

.sidebar-user {
    color: #e2e8f0;
    font-weight: 600;
    margin-bottom: 8px;
    word-break: break-word;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 90;
    opacity: 0;
    transition: opacity 0.25s ease;
    backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

body.sidebar-open { overflow: hidden; }

.main-content { flex: 1; margin-left: 252px; min-width: 0; }

.top-bar {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    padding: 12px 22px;
    padding-top: max(12px, env(safe-area-inset-top));
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}

.top-bar-start {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1;
}

.top-bar-titles { min-width: 0; flex: 1; }

.top-bar h1 {
    margin: 0;
    font-size: 18px;
    color: var(--text);
    font-weight: 700;
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.top-context {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.ctx-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
}

.ctx-chip strong {
    color: var(--text);
    font-weight: 600;
}

.menu-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 42px;
    height: 42px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    cursor: pointer;
    flex-shrink: 0;
}

.menu-toggle-bar {
    display: block;
    width: 100%;
    height: 2px;
    background: var(--text);
    border-radius: 1px;
}

.content-area {
    padding: 18px 20px 24px;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
}

/* ======== COMPONENTS ======== */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 14px;
    border: 1px solid var(--border);
}

.card-title {
    margin: 0 0 12px;
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 0.01em;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 12px;
}

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.form-control {
    padding: 8px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: inherit;
    width: 100%;
    background: #fff;
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

.btn {
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-block { width: 100%; margin-top: 8px; }

.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary-dark);
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary {
    background: #fff;
    color: var(--text);
    border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--bg-elevated); }

.btn-danger { background: var(--danger); color: #fff; border-color: #b91c1c; }
.btn-sm { padding: 5px 10px; font-size: 12px; font-weight: 600; }

.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 3px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

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

.tab-btn {
    border: none;
    background: transparent;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.tab-btn:hover { color: var(--text); background: rgba(15, 23, 42, 0.04); }
.tab-btn.active {
    background: var(--surface);
    color: var(--primary-dark);
    box-shadow: var(--shadow-sm);
}

.checkbox-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    cursor: pointer;
}

.table-scroll-full {
    overflow-x: auto;
    width: 100%;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 12.5px;
    min-width: 640px;
}

.data-table th,
.data-table td {
    border-bottom: 1px solid var(--border);
    border-right: 1px solid #eef2f6;
    padding: 8px 10px;
    text-align: left;
    vertical-align: middle;
}

.data-table th:last-child,
.data-table td:last-child { border-right: none; }

.data-table th {
    background: #f1f5f9;
    color: #334155;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 1;
}

.data-table tbody tr:nth-child(even) { background: #fafbfc; }
.data-table tbody tr:hover { background: #f0fdfa; }
.data-table input {
    width: 100%;
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    padding: 4px 6px;
    min-width: 48px;
    font-family: inherit;
}

.totals-panel {
    background: linear-gradient(180deg, #f8fafc, #f1f5f9);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    min-width: 0;
}

.totals-panel .row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    gap: 12px;
    font-size: 13px;
    color: var(--text-muted);
}

.totals-panel .row strong,
.totals-panel .row span:last-child {
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.totals-panel .total {
    font-size: 17px;
    font-weight: 700;
    color: var(--primary-dark);
    border-top: 1px solid var(--border);
    padding-top: 8px;
    margin-top: 8px;
}
.totals-panel .warn { color: var(--danger); font-weight: 600; }
.totals-panel .ok { color: var(--success); font-weight: 600; }

.factura-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 18px;
    align-items: start;
}

.factura-main {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.factura-meta-card {
    padding: 12px 14px;
    background: linear-gradient(180deg, #ffffff, #f8fafc);
}

.factura-meta-grid {
    margin: 0;
    gap: 10px 12px;
}

.factura-meta-grid .form-control[readonly] {
    background: #f1f5f9;
    color: #334155;
    border-color: #e2e8f0;
}

.factura-section-title {
    margin: 0 0 12px;
    font-size: 13px;
    font-weight: 700;
    color: var(--primary-dark);
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.factura-cabecera,
.factura-panel {
    padding: 16px;
}

.factura-flags {
    align-self: end;
    padding-bottom: 2px;
}

.factura-flags .checkbox-inline {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    width: 100%;
}

.factura-actions {
    position: sticky;
    top: 0;
    z-index: 8;
    margin: 0;
}

.factura-tabs {
    margin: 0;
}

.factura-hint {
    display: block;
    margin: 4px 0 0;
    font-size: 12px;
    line-height: 1.4;
}

.factura-loading {
    margin-top: 8px;
}

.producto-busqueda-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 10px 16px;
    margin-bottom: 10px;
}

.factura-mode-toggle {
    padding: 7px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: #fff;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
}

.factura-mode-toggle:has(input:checked) {
    border-color: #99f6e4;
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.form-control-lg {
    min-height: 42px;
    font-size: 15px;
    padding: 10px 12px;
}

.form-control-mono {
    font-family: var(--font-mono);
    font-size: 12.5px;
    letter-spacing: 0.02em;
}

.factura-detalle-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 16px 0 8px;
}

.factura-detalle-table {
    min-height: 120px;
    background: #fff;
}

.factura-pago-form {
    margin-bottom: 12px;
}

.factura-pago-actions {
    align-self: end;
}

.factura-pago-resumen {
    margin-top: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
}

.factura-pago-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    font-size: 12.5px;
    color: var(--text-muted);
}

.factura-pago-stats strong,
.factura-pago-stats .warn,
.factura-pago-stats .ok {
    font-variant-numeric: tabular-nums;
}

.factura-totals {
    position: sticky;
    top: 12px;
    box-shadow: var(--shadow-sm);
}

.factura-totals-title {
    margin: 0 0 12px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.factura-totals .total span:last-child {
    font-family: var(--font-mono);
    font-size: 18px;
}

.factura-producto-resultados {
    max-height: min(45vh, 360px);
}

.factura-modal-query {
    display: block;
    margin-top: 0;
}

.factura-producto-sel {
    margin-top: 14px;
    padding: 12px 14px;
    border: 1px solid #99f6e4;
    border-radius: var(--radius);
    background: linear-gradient(180deg, #f0fdfa, #ffffff);
}

.factura-producto-sel-label {
    margin: 0 0 10px;
    font-size: 13px;
    color: var(--text);
}

.factura-producto-sel-cod {
    opacity: 0.75;
    font-family: var(--font-mono);
    font-size: 12px;
}

.factura-producto-sel-fields {
    margin: 0;
    max-width: 360px;
}

.toolbar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.toolbar-top {
    margin-top: 0;
    margin-bottom: 12px;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.toolbar .btn { flex: 0 1 auto; min-width: 110px; }

.toast-container {
    position: fixed;
    right: 16px;
    bottom: max(16px, env(safe-area-inset-bottom));
    left: auto;
    z-index: 9999;
    max-width: calc(100vw - 32px);
}

.toast {
    background: #0f172a;
    color: #fff;
    padding: 10px 14px;
    border-radius: 8px;
    margin-top: 8px;
    font-size: 13px;
    box-shadow: var(--shadow-md);
    border-left: 3px solid var(--accent);
}

.toast-error { background: #7f1d1d; border-left-color: #f87171; }
.toast-success { background: #064e3b; border-left-color: #34d399; }

.busy-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
}
.busy-overlay.active { display: flex; }
.busy-box {
    background: #fff;
    border-radius: 12px;
    padding: 22px 28px;
    min-width: 220px;
    text-align: center;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}
.busy-spinner {
    width: 36px;
    height: 36px;
    margin: 0 auto 12px;
    border: 3px solid #e2e8f0;
    border-top-color: var(--accent, #0d9488);
    border-radius: 50%;
    animation: luna-spin 0.75s linear infinite;
}
.busy-text {
    font-size: 14px;
    font-weight: 600;
    color: var(--text, #0f172a);
}
@keyframes luna-spin {
    to { transform: rotate(360deg); }
}
body.busy-open { overflow: hidden; }

.autocomplete-list {
    position: absolute;
    background: #fff;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    max-height: 220px;
    overflow-y: auto;
    z-index: 20;
    width: 100%;
    box-shadow: var(--shadow-md);
}

.autocomplete-item {
    padding: 10px 12px;
    cursor: pointer;
    min-height: 42px;
    display: flex;
    align-items: center;
    font-size: 13px;
}

.autocomplete-item:hover { background: var(--primary-soft); }

.input-with-btn {
    display: flex;
    gap: 8px;
    align-items: stretch;
}

.input-with-btn .form-control { flex: 1; min-width: 0; }

.input-with-btn .btn {
    flex-shrink: 0;
    min-width: 44px;
    padding-left: 12px;
    padding-right: 12px;
}

.panel-subtitle {
    margin: 0 0 12px;
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 0.01em;
}

.producto-busqueda-panel {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 4px;
}

.producto-busqueda-form {
    margin-bottom: 0;
}

.producto-busqueda-form .form-group {
    margin-bottom: 0;
}

.producto-resultados-wrap {
    display: none;
    margin-top: 8px;
}

.producto-resultados-wrap.visible {
    display: block;
    max-height: 480px;
    overflow-y: auto;
}

.data-table-productos {
    min-width: 640px;
    font-size: 12px;
}

.producto-row { cursor: pointer; }

.producto-row:hover,
.producto-row.selected {
    background: var(--primary-soft);
}

.producto-row.selected td {
    font-weight: 600;
}

/* Acciones en consulta de documentos electrónicos */
.cd-acciones {
    white-space: normal;
    min-width: 220px;
    max-width: 340px;
}

.cd-acciones .btn {
    margin: 2px;
}

/* ======== MODAL (otros usos) ======== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
             max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: #fff;
    border-radius: 16px;
    width: 100%;
    max-width: 900px;
    max-height: 90vh;
    max-height: 90dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-productos { max-width: 960px; }

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

.modal-header h3 {
    margin: 0;
    font-size: 18px;
    color: var(--primary-dark);
}

.close-btn {
    background: none;
    border: none;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    color: #666;
    padding: 0 4px;
    min-width: 44px;
    min-height: 44px;
}

.modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}

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

.modal-hint {
    color: #6b7280;
    font-size: 13px;
    margin-bottom: 8px;
}

body.modal-open {
    overflow: hidden;
}

/* ======== RESPONSIVE ======== */
@media (max-width: 900px) {
    .factura-layout { grid-template-columns: 1fr; }
    .factura-totals {
        position: sticky;
        bottom: 0;
        top: auto;
        z-index: 5;
        border-radius: var(--radius) var(--radius) 0 0;
        box-shadow: 0 -6px 20px rgba(15, 23, 42, 0.08);
    }
    .factura-actions { top: 0; }
}

@media (max-width: 768px) {
    .menu-toggle { display: flex; }

    .sidebar {
        width: min(280px, 88vw);
        transform: translateX(-100%);
        box-shadow: none;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 8px 0 32px rgba(0, 0, 0, 0.2);
    }

    .nav-item {
        min-height: 44px;
        padding-top: 12px;
        padding-bottom: 12px;
    }

    .main-content {
        margin-left: 0;
        width: 100%;
    }

    .top-bar {
        padding-left: 16px;
        padding-right: 16px;
    }

    .top-bar h1 { font-size: 16px; }

    .top-context {
        font-size: 11px;
        white-space: normal;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .content-area { padding: 16px; }

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

    .form-group[style*="grid-column: span 2"] {
        grid-column: span 1 !important;
    }

    .btn {
        min-height: 44px;
        padding: 10px 16px;
    }

    .btn-sm {
        min-height: 36px;
        padding: 6px 12px;
    }

    .form-control {
        min-height: 44px;
        font-size: 16px;
    }

    .login-card { padding: 28px 20px; }

    .toolbar { flex-direction: column; }
    .toolbar .btn { width: 100%; }

    .tab-btn {
        min-height: 40px;
        padding: 10px 14px;
    }

    .toast-container {
        left: 16px;
        right: 16px;
    }

    .toast { width: 100%; }

    .modal-content {
        max-height: 92dvh;
        border-radius: 16px 16px 0 0;
        align-self: flex-end;
    }

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

    .data-table-modal { min-width: 600px; }
}

@media (max-width: 480px) {
    .data-table { font-size: 11px; }
    .data-table th, .data-table td { padding: 6px; }
}

/* ======== IMPRESIÓN DE DOCUMENTO ======== */
.print-doc {
    font-size: 13px;
    color: #111;
}

.print-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 2px solid #111;
    padding-bottom: 12px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.print-header h2 { margin: 0 0 4px; font-size: 16px; }

.print-doc-info {
    border: 1px solid #111;
    border-radius: 8px;
    padding: 10px 14px;
    min-width: 252px;
}

.print-doc-info h3 { margin: 0 0 6px; font-size: 14px; }

.print-doc-info .clave-acceso {
    margin-top: 6px;
    font-size: 10px;
    word-break: break-all;
}

.print-cliente {
    margin-bottom: 12px;
    display: grid;
    gap: 2px;
}

.print-detalle { margin-bottom: 12px; min-width: 0; }

.print-totales {
    max-width: 280px;
    margin-left: auto;
}

.print-totales .row,
.print-pagos .row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 4px;
}

.print-totales .print-total {
    font-size: 16px;
    font-weight: 700;
    border-top: 1px solid #111;
    padding-top: 6px;
    margin-top: 6px;
}

.print-pagos {
    margin-top: 12px;
    max-width: 280px;
}

.print-footer {
    margin-top: 16px;
    padding-top: 8px;
    border-top: 1px dashed #999;
    font-size: 11px;
    color: #555;
}

@media print {
    body.printing-doc * { visibility: hidden; }
    body.printing-doc .modal-overlay#cdModalPrint,
    body.printing-doc #cdModalPrint * { visibility: visible; }
    body.printing-doc #cdModalPrint {
        position: absolute;
        inset: 0;
        background: #fff;
        padding: 0;
        display: block;
    }
    body.printing-doc #cdModalPrint .modal-content {
        max-width: none;
        max-height: none;
        box-shadow: none;
        border-radius: 0;
    }
    body.printing-doc .no-print,
    body.printing-doc .no-print * { display: none !important; visibility: hidden !important; }

    body.printing-recibo * { visibility: hidden; }
    body.printing-recibo .modal-overlay#lunaModalReciboPrint,
    body.printing-recibo #lunaModalReciboPrint * { visibility: visible; }
    body.printing-recibo #lunaModalReciboPrint {
        position: absolute;
        inset: 0;
        background: #fff;
        padding: 0;
        display: block;
    }
    body.printing-recibo #lunaModalReciboPrint .modal-content {
        max-width: none;
        max-height: none;
        box-shadow: none;
        border-radius: 0;
    }
    body.printing-recibo .no-print,
    body.printing-recibo .no-print * { display: none !important; visibility: hidden !important; }

    body.printing-ride * { visibility: hidden; }
    body.printing-ride .modal-overlay#lunaModalRidePrint,
    body.printing-ride #lunaModalRidePrint * { visibility: visible; }
    body.printing-ride #lunaModalRidePrint {
        position: absolute;
        inset: 0;
        background: #fff;
        padding: 0;
        display: block;
    }
    body.printing-ride #lunaModalRidePrint .modal-content {
        max-width: none;
        max-height: none;
        box-shadow: none;
        border-radius: 0;
    }
    body.printing-ride .no-print,
    body.printing-ride .no-print * { display: none !important; visibility: hidden !important; }

    body.printing-ride .ride-doc {
        max-width: none;
        width: 100%;
    }
}

.login-error {
    color: #b91c1c;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius-sm);
    font-size: 13px;
    padding: 8px 10px;
    margin-bottom: 12px;
}

/* ======== BADGES ESTADO SRI ======== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border: 1px solid transparent;
}
.badge-success { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.badge-warning { background: #fffbeb; color: #b45309; border-color: #fde68a; }
.badge-danger { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.badge-info { background: #f0f9ff; color: #0369a1; border-color: #bae6fd; }

/* ======== RIDE ECUADOR — formato SRI (referencia PDF) ======== */
.ride-modal-content {
    max-width: 780px;
    width: min(780px, 98vw);
}

.ride-modal-body {
    overflow: auto;
    padding: 12px 16px;
}

.ride-print-area {
    min-width: 0;
}

.ride-doc {
    font-family: Arial, Helvetica, sans-serif;
    font-size: 11px;
    color: #000;
    line-height: 1.3;
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
}

.ride-doc.ride-b579811 {
    max-width: 190mm;
    font-family: Helvetica, Arial, sans-serif;
    font-size: 9pt;
}

.ride-doc.ride-b579811 .ride-top { width: 100%; }
.ride-doc.ride-b579811 .ride-box { border: 1px solid #000; padding: 6px 8px; }
.ride-doc.ride-b579811 .ride-tipo { font-size: 16pt; font-weight: 700; }
.ride-doc.ride-b579811 .ride-nro { font-size: 12pt; font-weight: 700; }
.ride-doc.ride-b579811 .ride-detalle { width: 100%; border-collapse: collapse; }
.ride-doc.ride-b579811 .ride-detalle th,
.ride-doc.ride-b579811 .ride-detalle td { border: 1px solid #000; padding: 3px 4px; }
.ride-doc.ride-b579811 .c-num { text-align: right; }

.ride-doc .ride-sri {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    margin-bottom: 0;
}

.ride-doc .ride-sri-box {
    border: 1px solid #000;
    padding: 8px 10px;
    vertical-align: top;
}

.ride-sri-cabecera .ride-sri-emisor { width: 50%; }
.ride-sri-cabecera .ride-sri-factura { width: 50%; }

.ride-sri-nombre {
    font-weight: 700;
    font-size: 12px;
    margin-bottom: 4px;
}

.ride-sri-tipo {
    font-weight: 700;
    font-size: 14px;
    margin: 4px 0;
}

.ride-sri-nro {
    font-weight: 700;
    margin-bottom: 6px;
}

.ride-sri-lbl {
    font-size: 10px;
    margin-top: 4px;
}

.ride-sri-auth,
.ride-sri-clave {
    font-size: 10px;
    word-break: break-all;
}

.ride-sri-barcode {
    display: block;
    max-width: 100%;
    height: 50px;
    margin: 4px 0;
}

.ride-sri-cliente {
    margin-top: -1px;
}

.ride-sri-cliente .ride-sri-box {
    border-top: none;
}

.ride-sri-detalle {
    margin-top: -1px;
}

.ride-sri-detalle col.col-codigo { width: 10%; }
.ride-sri-detalle col.col-desc { width: 40%; }
.ride-sri-detalle col.col-cant { width: 10%; }
.ride-sri-detalle col.col-precio { width: 13%; }
.ride-sri-detalle col.col-descu { width: 13%; }
.ride-sri-detalle col.col-total { width: 14%; }

.ride-sri-detalle th,
.ride-sri-detalle td {
    border: 1px solid #000;
    padding: 4px 5px;
    vertical-align: top;
}

.ride-sri-detalle th {
    font-weight: 700;
    text-align: center;
    font-size: 10px;
}

.ride-doc .ride-num {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.ride-sri-pie td {
    border: 1px solid #000;
    padding: 8px 6px;
    vertical-align: top;
}

.ride-sri-pie-izq {
    width: 50%;
}

.ride-sri-pie-der {
    width: 50%;
}

.ride-sri-son {
    font-size: 10px;
    margin-bottom: 10px;
    line-height: 1.35;
}

.ride-sri-pago {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.ride-sri-pago th,
.ride-sri-pago td {
    border: 1px solid #000;
    padding: 4px 6px;
    font-size: 10px;
}

.ride-sri-pago th {
    font-weight: 700;
    text-align: left;
}

.ride-sri-pago td:last-child {
    width: 28%;
}

.ride-sri-resumen {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.ride-sri-resumen td {
    padding: 2px 4px;
    font-size: 10px;
    border: none;
}

.ride-sri-resumen td:first-child {
    text-align: left;
    width: 62%;
}

.ride-sri-resumen td:last-child {
    text-align: right;
    width: 38%;
    font-variant-numeric: tabular-nums;
}

.ride-sri-valor-total td {
    font-weight: 700;
    padding-top: 4px;
}

.ride-sri-meta {
    margin-top: 10px;
    text-align: right;
    font-size: 10px;
    color: #333;
}

.ride-sri-meta div + div {
    margin-top: 2px;
}

/* ======== TABS MODAL PRODUCTO ======== */
.luna-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border, #e5e7eb);
}
.luna-tab {
    padding: 8px 14px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: #6b7280;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.luna-tab.active {
    color: var(--primary, #2563eb);
    border-bottom-color: var(--primary, #2563eb);
}
.luna-tab-panel { display: none; }
.luna-tab-panel.active { display: block; }

/* ======== PAGINACIÓN ======== */
.pagination-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border, #e5e7eb);
    font-size: 13px;
    color: #4b5563;
}
.pagination-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}
.pagination-size {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}
.pagination-per-page {
    width: auto;
    min-width: 72px;
    padding: 4px 8px;
    height: auto;
}
.pagination-page {
    min-width: 88px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.impersonation-banner {
    position: sticky;
    top: 0;
    z-index: 1200;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    background: #0f766e;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
}
body.has-impersonation-banner .app-layout {
    min-height: calc(100vh - 48px);
}

.kpi-grid, .stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
}
.stat-card, .kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
}
.stat-value, .kpi-value {
    font-size: 1.4rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.stat-label, .kpi-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}
.badge-success { background: #ecfdf5; color: #065f46; }
.badge-danger { background: #fef2f2; color: #991b1b; }
.badge-warning { background: #fffbeb; color: #92400e; }
.badge-secondary { background: #f1f5f9; color: #475569; }
.badge-info { background: #eff6ff; color: #1d4ed8; }
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(15, 23, 42, 0.45);
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal.active { display: flex; }
.modal-content {
    background: var(--surface);
    border-radius: var(--radius);
    width: min(560px, 100%);
    max-height: 90vh;
    overflow: auto;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
}
.modal-header, .modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.modal-footer { border-bottom: 0; border-top: 1px solid var(--border); }
.modal-body { padding: 16px; }
.modal-header h3 { margin: 0; font-size: 16px; }
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
.card-header h3 { margin: 0; }
.card-body { }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }

/* —— Dashboard / inicio —— */
.dash-welcome {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}
.dash-welcome h2 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}
.dash-eyebrow {
    margin: 0 0 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.dash-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}
.dash-kpi {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 108px;
}
.dash-kpi-warn {
    border-color: #fcd34d;
    background: linear-gradient(180deg, #fffbeb 0%, var(--surface) 70%);
}
.dash-kpi-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.dash-kpi-value {
    font-size: 1.45rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
    line-height: 1.15;
}
.dash-kpi-meta {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.35;
}
.dash-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}
.dash-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
.dash-section-head h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 650;
}
.dash-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}
.dash-ops {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.dash-ops-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.dash-ops-row:last-child { border-bottom: 0; padding-bottom: 0; }
.dash-ops-row strong { font-variant-numeric: tabular-nums; }
.text-danger { color: var(--danger); }

@media (max-width: 1100px) {
    .dash-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
    .dash-welcome { flex-direction: column; align-items: stretch; }
    .dash-grid { grid-template-columns: 1fr; }
    .dash-split { grid-template-columns: 1fr; }
}

@media print {
    body.printing-inv-report * { visibility: hidden; }
    body.printing-inv-report #ciModalReporte,
    body.printing-inv-report #ciModalReporte * { visibility: visible; }
    body.printing-inv-report #ciModalReporte {
        position: absolute; inset: 0; background: #fff; display: block;
    }
    body.printing-inv-report #ciModalReporte .modal-content {
        max-width: none; box-shadow: none; border-radius: 0;
    }
    body.printing-inv-report .no-print,
    body.printing-inv-report .no-print * { display: none !important; }
}
