/* =========================================================
   FACTURACIÓN MAUS3D · hoja de estilos
   Estética sobria y profesional (grafito / azul profundo)
   ========================================================= */
:root {
    --bg: #eef1f5;
    --bg-soft: #f6f8fb;
    --panel: #ffffff;
    --ink: #1b2430;
    --muted: #6b7787;
    --line: #e3e8ef;
    --brand: #1f3a5f;
    --brand-2: #2f6fb0;
    --brand-ink: #ffffff;
    --ok: #1f8a57;
    --ok-bg: #eaf7ef;
    --warn: #a9770d;
    --warn-bg: #fdf5e5;
    --danger: #b23b3b;
    --danger-bg: #fdecec;
    --field: #f7f9fb;
    --field-border: #d9e0e9;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 12px 34px rgba(20, 35, 60, .08);
    --shadow-sm: 0 4px 14px rgba(20, 35, 60, .06);
    --font: 'Segoe UI', Aptos, system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
}

body.theme-grafito { --brand: #2b3138; --brand-2: #55606b; }
body.theme-esmeralda { --brand: #14532d; --brand-2: #1f8a57; }
body.theme-indigo { --brand: #26326b; --brand-2: #4b5bd0; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    font-size: 15px;
    line-height: 1.5;
}
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; font-weight: 650; }
p { margin: 0 0 .8em; }

/* ── Estructura ─────────────────────────────────────────── */
.app-shell { display: flex; flex-direction: column; min-height: 100vh; }
.content { width: 100%; max-width: 1240px; margin: 0 auto; padding: 24px 22px 40px; }
.content-wide { max-width: 1440px; }

/* ── Barra superior ─────────────────────────────────────── */
.app-topbar {
    position: sticky; top: 0; z-index: 40;
    display: flex; align-items: center; gap: 14px;
    padding: 12px 22px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 1px 0 rgba(20, 35, 60, .03);
}
.app-brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--ink); }
.brand-logo { width: 40px; height: 40px; object-fit: contain; }
.brand-copy { display: flex; flex-direction: column; line-height: 1.05; }
.brand-copy strong { font-size: 15px; letter-spacing: .05em; color: var(--brand); }
.brand-copy small { font-size: 10.5px; letter-spacing: .16em; color: var(--muted); }
.topbar-stat {
    display: none; align-items: baseline; gap: 6px;
    padding: 6px 12px; border-radius: 999px;
    background: var(--bg-soft); border: 1px solid var(--line);
}
.topbar-stat strong { font-size: 14px; color: var(--brand); }
.topbar-stat span { font-size: 10px; letter-spacing: .12em; color: var(--muted); }
.top-nav { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.top-nav-link {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 9px 13px; border-radius: var(--radius-sm);
    color: #4b5665; font-size: 14px; font-weight: 550;
}
.top-nav-link:hover { background: var(--bg-soft); color: var(--brand); text-decoration: none; }
.top-nav-link.active { background: var(--brand); color: var(--brand-ink); }
.top-nav-logout { color: var(--muted); }
.icon-btn {
    display: none; margin-left: auto;
    background: none; border: 1px solid var(--line); border-radius: 10px;
    width: 40px; height: 38px; align-items: center; justify-content: center;
    color: var(--ink); cursor: pointer;
}

/* ── Encabezado de página ───────────────────────────────── */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-title { font-size: 1.45rem; margin: 0; }
.page-sub { color: var(--muted); font-size: .92rem; margin: 4px 0 0; }

/* ── Tarjetas ───────────────────────────────────────────── */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-pad { padding: 20px 22px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.card-head h2, .card-head h3 { margin: 0; font-size: 1.05rem; }

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }

.card.stat { display: flex; align-items: center; gap: 14px; padding: 16px 18px; min-height: 84px; }
.card.stat .stat-ic { flex: none; width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center; background: var(--bg-soft); color: var(--brand); }
.card.stat .stat-body { display: flex; flex-direction: column; }
.card.stat .stat-value { font-size: 1.5rem; font-weight: 700; color: var(--ink); line-height: 1.1; }
.card.stat .stat-label { font-size: .78rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

/* ── Botones ────────────────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 16px; border-radius: var(--radius-sm);
    border: 1px solid var(--line); background: var(--panel); color: var(--ink);
    font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none;
    transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--bg-soft); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: color-mix(in srgb, var(--brand) 88%, #000); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--brand-2); }
.btn-ghost:hover { background: var(--bg-soft); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, var(--line)); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-sm { padding: 7px 11px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-icon { padding: 8px; }

/* ── Formularios ────────────────────────────────────────── */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: .82rem; font-weight: 600; color: #43505f; margin-bottom: 6px; }
.input, input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
    width: 100%; padding: 11px 13px; border: 1px solid var(--field-border); border-radius: var(--radius-sm);
    background: var(--field); font-family: inherit; font-size: 14.5px; color: var(--ink);
}
.input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand-2); background: #fff; box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-2) 18%, transparent); }
textarea { resize: vertical; min-height: 84px; }
.form-grid { display: grid; gap: 14px; }
.form-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.hint { color: var(--muted); font-size: .8rem; margin-top: 4px; }
.check { display: inline-flex; align-items: center; gap: 9px; font-size: 14px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--brand); }

/* Interruptor (toggle) */
.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; user-select: none; }
.field > label.switch { display: flex; width: 100%; align-items: center; margin-bottom: 0; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 52px; height: 28px; border-radius: 999px; background: #c7cfda; position: relative; transition: background .18s; flex: 0 0 auto; box-shadow: inset 0 1px 3px rgba(0,0,0,.18); }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .18s; box-shadow: 0 2px 4px rgba(0,0,0,.28); }
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track::after { transform: translateX(24px); }
.switch input:focus-visible + .track { outline: 2px solid var(--brand); outline-offset: 2px; }
.switch .switch-label { font-weight: 600; font-size: 14px; white-space: nowrap; }
.switch .switch-status { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: #eef1f5; color: var(--muted); margin-left: auto; }
.switch input:checked ~ .switch-status { background: rgba(34,197,94,.14); color: var(--ok); }

/* ── Tablas ─────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; padding: 11px 14px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--line); background: var(--bg-soft); }
table.data td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--bg-soft); }
.cell-actions { display: flex; gap: 6px; justify-content: flex-end; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono-num { font-variant-numeric: tabular-nums; }

.prod-thumb { width: 42px; height: 42px; border-radius: 10px; object-fit: cover; border: 1px solid var(--line); background: var(--bg-soft); }
.thumb-placeholder { display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }
.prod-name { font-weight: 600; }
.prod-desc { color: var(--muted); font-size: .84rem; }

/* ── Insignias ──────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-neutral { background: var(--bg-soft); color: var(--muted); border: 1px solid var(--line); }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-brand { background: color-mix(in srgb, var(--brand) 12%, #fff); color: var(--brand); }

/* ── Alertas ────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; border: 1px solid transparent; transition: opacity .28s ease, transform .28s ease, max-height .28s ease, margin .28s ease, padding .28s ease; max-height: 120px; overflow: hidden; }
.alert-error { background: var(--danger-bg); border-color: #f3c3c3; color: #a13636; }
.alert-success { background: var(--ok-bg); border-color: #bfe6cd; color: #1f7a4d; }
.alert-warn { background: var(--warn-bg); border-color: #f0dcb0; color: var(--warn); }
.alert-info { background: var(--bg-soft); border-color: var(--line); color: #4b5665; }
.alert.alert-dismissing { opacity: 0; transform: translateY(-5px); max-height: 0; margin-top: 0; margin-bottom: 0; padding-top: 0; padding-bottom: 0; border-width: 0; }

/* Confirmación integrada para acciones destructivas */
.confirm-overlay { position: fixed; inset: 0; z-index: 1200; display: grid; place-items: center; padding: 20px; background: rgba(20, 31, 48, .48); backdrop-filter: blur(3px); animation: confirm-fade-in .16s ease-out; }
.confirm-dialog { width: min(100%, 440px); padding: 24px; background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 24px 80px rgba(17, 27, 42, .24); animation: confirm-pop-in .18s ease-out; }
.confirm-heading { display: flex; align-items: center; gap: 12px; }
.confirm-heading h2 { margin: 0; font-size: 1.08rem; }
.confirm-icon { display: grid; place-items: center; flex: none; width: 34px; height: 34px; border-radius: 50%; background: var(--danger-bg); color: var(--danger); font-weight: 800; }
.confirm-message { margin: 18px 0 24px; color: var(--muted); font-size: .95rem; line-height: 1.5; overflow-wrap: anywhere; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 10px; }
.confirm-accept { background: var(--danger); border-color: var(--danger); color: #fff; }
.confirm-accept:hover { background: color-mix(in srgb, var(--danger) 86%, #000); color: #fff; }
@keyframes confirm-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes confirm-pop-in { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@media (prefers-reduced-motion: reduce) {
    .alert, .confirm-overlay, .confirm-dialog { transition: none; animation: none; }
}

/* ── Barra de herramientas / buscador ───────────────────── */
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.search-box { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 12px; min-width: 260px; flex: 1; max-width: 420px; }
.search-box svg { color: var(--muted); flex: none; }
.search-box input { border: none; background: none; padding: 2px 0; font-size: 14.5px; }
.search-box input:focus { outline: none; }
.invoice-filters { align-items: flex-end; }
.invoice-date-filter { display: grid; gap: 4px; color: #43505f; font-size: .78rem; font-weight: 600; }
.invoice-date-filter .input { width: 165px; }

/* ── Estado vacío ───────────────────────────────────────── */
.empty { text-align: center; padding: 52px 20px; color: var(--muted); }
.empty .empty-ic { color: #c3ccd8; margin-bottom: 10px; }

/* ── Autenticación ──────────────────────────────────────── */
body.bare { background: radial-gradient(1200px 600px at 50% -10%, color-mix(in srgb, var(--brand) 16%, #eef1f5), var(--bg)); }
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 30px 18px; }
.auth-logo-wrap { margin-bottom: 22px; }
.auth-brand-logo { width: 96px; height: 96px; object-fit: contain; }
.auth-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); width: 100%; max-width: 392px; padding: 30px 30px 26px; }
.auth-brand-label { display: block; text-align: center; font-size: 11px; letter-spacing: .2em; color: var(--muted); margin-bottom: 6px; }
.auth-title { text-align: center; font-size: 1.35rem; margin: 0 0 20px; }
.auth-card .field > label { text-align: left; }

/* ── Pie ────────────────────────────────────────────────── */
.app-foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 16px 22px; color: var(--muted); font-size: .78rem; border-top: 1px solid var(--line); background: var(--panel); margin-top: auto; }

/* ── Factura (vista) ────────────────────────────────────── */
.invoice-sheet { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 30px 34px; box-shadow: var(--shadow-sm); max-width: 900px; margin: 0 auto; }
.inv-top { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; padding-bottom: 16px; border-bottom: 2px solid var(--brand); }
.inv-logo { width: 90px; height: auto; max-height: 64px; object-fit: contain; }
.inv-brand-name { font-size: 1.1rem; font-weight: 700; color: var(--brand); }
.inv-company { color: var(--muted); font-size: .84rem; line-height: 1.5; }
.inv-title { text-align: right; }
.inv-title h2 { font-size: 1.6rem; color: var(--brand); letter-spacing: .04em; margin: 0; }
.inv-meta { color: var(--muted); font-size: .86rem; margin-top: 6px; }
.inv-client { background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px 16px; margin: 18px 0; }
.inv-client .lbl { font-size: 10.5px; letter-spacing: .14em; color: var(--muted); text-transform: uppercase; }
.inv-client .nm { font-weight: 700; font-size: 1.02rem; }
table.inv-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 14px; }
table.inv-table th { background: var(--brand); color: #fff; padding: 10px 12px; text-align: left; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
table.inv-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); }
table.inv-table tbody tr:nth-child(even) { background: var(--bg-soft); }
.inv-totals { margin-left: auto; width: 320px; margin-top: 16px; }
.inv-totals .row { display: flex; justify-content: space-between; padding: 5px 0; }
.inv-totals .row.total { border-top: 2px solid var(--brand); margin-top: 6px; padding-top: 8px; font-size: 1.2rem; font-weight: 700; color: var(--brand); }
.inv-foot { margin-top: 26px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: .8rem; text-align: center; }

/* ── Calculadora ────────────────────────────────────────── */
.calc-result { position: sticky; top: 90px; }
.calc-line { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.calc-line:last-child { border-bottom: none; }
.calc-line span:first-child { color: var(--muted); }
.calc-final { margin-top: 12px; padding-top: 12px; border-top: 2px solid var(--brand); }
.calc-final .big { font-size: 1.9rem; font-weight: 750; color: var(--brand); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--bg-soft); border: 1px solid var(--line); font-size: 12.5px; }

/* ── Cliente autocompletado ─────────────────────────────── */
.suggest { position: relative; }
.suggest-list { position: absolute; z-index: 30; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow); max-height: 260px; overflow: auto; display: none; }
.suggest-list.open { display: block; }
.suggest-item { padding: 9px 12px; cursor: pointer; font-size: 14px; }
.suggest-item:hover, .suggest-item.active { background: var(--bg-soft); }
.suggest-item .s-sub { color: var(--muted); font-size: .8rem; }

/* ── Utilidades ─────────────────────────────────────────── */
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-2 { margin-bottom: 16px; }
.text-muted { color: var(--muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.flex { display: flex; } .between { justify-content: space-between; } .center { align-items: center; }
.gap-1 { gap: 8px; } .gap-2 { gap: 14px; }
.nowrap { white-space: nowrap; }
.full { width: 100%; }
.hidden { display: none !important; }

@media (min-width: 980px) {
    .topbar-stat { display: inline-flex; }
}
@media (max-width: 860px) {
    .icon-btn { display: inline-flex; }
    .top-nav {
        position: absolute; top: 100%; right: 12px; left: 12px;
        flex-direction: column; align-items: stretch;
        background: var(--panel); border: 1px solid var(--line);
        border-radius: var(--radius); box-shadow: var(--shadow);
        padding: 10px; margin-top: 8px; display: none;
    }
    .top-nav.open { display: flex; }
    .top-nav-link { padding: 12px 14px; }
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-3, .grid-2 { grid-template-columns: 1fr; }
    .form-grid.cols-2, .form-grid.cols-3 { grid-template-columns: 1fr; }
    .inv-totals { width: 100%; }
}
@media (max-width: 520px) {
    .content { padding: 18px 14px 32px; }
    .grid-4 { grid-template-columns: 1fr 1fr; }
    .card.stat .stat-value { font-size: 1.25rem; }
}
