/* ============================================================
   RapidFact ERP — Sistema de diseño
   Paleta: azul/celeste de marca + neutros slate refinados
   Tipografía: Inter (UI) + JetBrains Mono (cifras y datos)
   ============================================================ */

:root {
    /* Marca */
    --azul: #0057A8;
    --azul-deep: #0B2A5B;
    --indigo: #0057A8;
    --celeste: #22C55E;

    /* Semánticos (refinados, no colores planos) */
    --verde: #00A86B;
    --verde-soft: #10B981;
    --rojo: #DC2626;
    --rojo-soft: #EF4444;
    --naranja: #D97706;
    --naranja-soft: #F59E0B;

    /* Neutros slate */
    --slate-950: #020617;
    --slate-900: #0F172A;
    --slate-800: #1E293B;
    --slate-700: #334155;
    --slate-500: #64748B;
    --slate-400: #94A3B8;
    --slate-200: #E2E8F0;
    --slate-100: #F1F5F9;
    --slate-50:  #F8FAFC;
    --white: #FFFFFF;

    --bg: #F4F7FC;
    --surface: var(--white);
    --surface-raised: var(--white);
    --text: var(--slate-900);
    --text-muted: var(--slate-500);
    --border: #D1DCF0;
    --sidebar-bg: #0B2A5B;
    --radius: 14px;
    --radius-sm: 9px;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow-md: 0 4px 16px -4px rgba(15, 23, 42, .10), 0 2px 6px -2px rgba(15, 23, 42, .06);
    --shadow-lg: 0 20px 40px -12px rgba(15, 23, 42, .18), 0 8px 16px -8px rgba(15, 23, 42, .08);
    --shadow-glow: 0 4px 14px -6px rgba(0,87,168,.35);

    --gradient-brand: linear-gradient(135deg, #0057A8 0%, #00A86B 100%);
    --rf-navy:#0B2A5B; --rf-grad: linear-gradient(90deg,#0B2A5B,#0057A8,#00A86B,#22C55E);
    --gradient-brand-soft: linear-gradient(135deg, rgba(0,87,168,.10), rgba(56,189,248,.10));

    --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

[data-theme="dark"] {
    --bg: #08111F;
    --surface: #0E1A2E;
    --surface-raised: #131B2E;
    --text: #E7ECF5;
    --text-muted: #8A98B5;
    --border: #1F3254;
    --sidebar-bg: #071A3B;
    --slate-100: #131B2E;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 4px 20px -4px rgba(0, 0, 0, .45);
    --shadow-lg: 0 24px 48px -12px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }

html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }

body {
    margin: 0;
    font-family: var(--font-ui);
    background: var(--bg);
    color: var(--text);
    transition: background .25s ease, color .25s ease;
    font-feature-settings: 'tnum' 1, 'cv11' 1, 'ss01' 1;
    font-size: 14.5px;
    line-height: 1.5;
}

::selection { background: rgba(0, 87, 168, .18); }

*:focus-visible {
    outline: 2px solid var(--azul);
    outline-offset: 2px;
    border-radius: 4px;
}

.app-shell { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
    width: 258px;
    background: var(--sidebar-bg);
    
    color: #CBD5E1;
    padding: 22px 14px;
    flex-shrink: 0;
    transition: transform .2s ease;
    border-right: 1px solid rgba(255,255,255,.05);
}
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 2px 8px 22px; }
.brand-mark {
    position: relative;
    width: 36px; height: 36px; border-radius: 10px;
    background: var(--gradient-brand);
    color: #fff; font-weight: 800; font-size: 15px;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 0 0 1px rgba(255,255,255,.08) inset, 0 6px 16px -4px rgba(0,87,168,.55);
    letter-spacing: -.02em;
}
.brand-name { color: #fff; font-weight: 700; font-size: 15.5px; letter-spacing: -.01em; }
.brand-name small { color: var(--celeste); font-weight: 600; font-size: 12px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-section {
    font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
    font-weight: 700; color: #4C5A78; margin: 18px 12px 7px;
}
.nav-item {
    position: relative;
    display: flex; align-items: center; gap: 11px;
    padding: 9px 12px; border-radius: var(--radius-sm); color: #B6C2DB; text-decoration: none;
    font-size: 13.5px; font-weight: 500;
    transition: background .15s ease, color .15s ease, transform .15s ease;
}
.nav-item i { width: 17px; height: 17px; flex-shrink: 0; stroke-width: 2px; opacity: .85; }
.nav-item:hover { background: rgba(255,255,255,.055); color: #fff; }
.nav-item:hover i { opacity: 1; }
.nav-item.active {
    background: linear-gradient(90deg, rgba(0,87,168,.22), rgba(0,87,168,.06));
    color: #fff;
    font-weight: 600;
}
.nav-item.active::before {
    content: ''; position: absolute; left: -14px; top: 50%; transform: translateY(-50%);
    width: 3px; height: 18px; border-radius: 0 4px 4px 0;
    background: var(--gradient-brand);
    box-shadow: 0 0 10px rgba(56,189,248,.7);
}
.nav-item.active i { opacity: 1; }
.nav-item.disabled { opacity: .35; pointer-events: none; }

/* ---------- Topbar ---------- */
.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
    height: 64px; background: var(--surface); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 14px; padding: 0 22px;
    position: sticky; top: 0; z-index: 10;
    backdrop-filter: saturate(1.4);
}
.icon-btn {
    width: 36px; height: 36px; border-radius: var(--radius-sm); border: none; background: transparent;
    display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text-muted);
    text-decoration: none; transition: background .15s ease, color .15s ease;
}
.icon-btn i { width: 18px; height: 18px; stroke-width: 2px; }
.icon-btn:hover { background: var(--slate-100); color: var(--text); }
.global-search {
    flex: 1; max-width: 420px; display: flex; align-items: center; gap: 9px;
    background: var(--bg); border: 1px solid var(--border); border-radius: 11px; padding: 9px 13px;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.global-search:focus-within { border-color: var(--azul); box-shadow: 0 0 0 3px rgba(0,87,168,.10); }
.global-search input { border: none; background: transparent; outline: none; width: 100%; color: var(--text); font-family: inherit; font-size: 13.5px; }
.global-search i { width: 16px; height: 16px; color: var(--text-muted); stroke-width: 2px; }
.topbar-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.empresa-switch select {
    border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 7px 11px;
    background: var(--surface); color: var(--text); font-family: inherit; font-size: 13px; font-weight: 500;
}
.user-menu { display: flex; align-items: center; gap: 9px; padding-left: 10px; border-left: 1px solid var(--border); margin-left: 6px; }
.user-menu span { font-size: 13.5px; font-weight: 600; }
.avatar {
    width: 32px; height: 32px; border-radius: 50%; background: var(--gradient-brand); color: #fff;
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
    box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px rgba(0,87,168,.35);
}

/* ---------- Content ---------- */
.content { padding: 26px 28px 40px; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
.page-header h1 { font-size: 21px; margin: 0 0 3px; font-weight: 700; letter-spacing: -.015em; }
.text-muted { color: var(--text-muted); font-size: 13px; margin: 0; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 7px; padding: 9px 16px; border-radius: var(--radius-sm);
    font-family: inherit; font-weight: 600; font-size: 13.5px; border: none; cursor: pointer; text-decoration: none;
    transition: transform .1s ease, box-shadow .15s ease, background .15s ease, filter .15s ease;
}
.btn i { width: 16px; height: 16px; stroke-width: 2.1px; }
.btn-primary {
    background: var(--gradient-brand); color: #fff;
    box-shadow: var(--shadow-glow);
}
.btn-primary:hover { filter: brightness(1.06); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-secondary { background: var(--slate-100); color: var(--text); }
.btn-secondary:hover { background: var(--slate-200); }
.btn-block { width: 100%; justify-content: center; }

/* ---------- KPI cards ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(228px, 1fr)); gap: 14px; margin-bottom: 22px; }
.kpi-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 18px 20px; display: flex; align-items: center; gap: 14px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow .18s ease, transform .18s ease, border-color .18s ease;
}
a .kpi-card:hover, .kpi-card:has(a):hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: rgba(0,87,168,.25); }
.kpi-icon {
    width: 42px; height: 42px; border-radius: 12px; display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; box-shadow: inset 0 0 0 1px rgba(0,0,0,.03);
}
.kpi-icon i { width: 20px; height: 20px; stroke-width: 2px; }
.kpi-blue   { background: linear-gradient(135deg, #DBEAFE, #EFF6FF); color: var(--azul-deep); }
.kpi-green  { background: linear-gradient(135deg, #D1FAE5, #ECFDF5); color: var(--verde); }
.kpi-orange { background: linear-gradient(135deg, #FEF3C7, #FFFBEB); color: var(--naranja); }
.kpi-red    { background: linear-gradient(135deg, #FEE2E2, #FEF2F2); color: var(--rojo); }
.kpi-gray   { background: var(--slate-100); color: var(--slate-500); }
.kpi-value { display: block; font-family: var(--font-mono); font-size: 19px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-label { display: block; font-size: 12px; color: var(--text-muted); margin-top: 2px; font-weight: 500; }

.info-panel {
    background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius);
    padding: 16px 18px; display: flex; gap: 13px; align-items: flex-start; color: var(--text-muted); font-size: 13px;
}
.info-panel i { color: var(--azul); flex-shrink: 0; margin-top: 2px; width: 18px; height: 18px; }
.info-panel strong { color: var(--text); display: block; margin-bottom: 4px; font-size: 13.5px; font-weight: 600; }

/* ---------- Tables ---------- */
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
    text-align: left; padding: 12px 18px; background: var(--slate-50); color: var(--text-muted);
    font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
    border-bottom: 1px solid var(--border);
}
[data-theme="dark"] .data-table th { background: rgba(255,255,255,.02); }
.data-table td { padding: 12px 18px; border-top: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.data-table tbody tr { transition: background .12s ease; }
.data-table tbody tr:hover { background: var(--slate-50); }
[data-theme="dark"] .data-table tbody tr:hover { background: rgba(255,255,255,.02); }
.empty-state { text-align: center; color: var(--text-muted); padding: 36px !important; font-size: 13px; }

.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 10px 3px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
    letter-spacing: .01em;
}
.badge::before {
    content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0;
}
.badge-green { background: #D1FAE5; color: #047857; }
.badge-red   { background: #FEE2E2; color: #B91C1C; }
.badge-blue  { background: #DBEAFE; color: #1D4ED8; }
.badge-orange{ background: #FEF3C7; color: #B45309; }
.badge-gray  { background: var(--slate-100); color: var(--text-muted); }

/* ---------- Forms ---------- */
.form-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; max-width: 720px; box-shadow: var(--shadow-sm); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.form-grid input, .form-grid select, .form-grid textarea {
    font-family: inherit; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--bg); color: var(--text); font-size: 13.5px; font-weight: 400;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus {
    outline: none; border-color: var(--azul); box-shadow: 0 0 0 3px rgba(0,87,168,.10);
}
.checkbox-label { flex-direction: row !important; align-items: center; gap: 8px !important; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.permiso-grupo { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.permiso-grupo legend { font-weight: 700; padding: 0 6px; font-size: 13px; }

/* ---------- Login ---------- */
.login-body {
    display: flex; min-height: 100vh; margin: 0; font-family: var(--font-ui); background: var(--slate-50);
}
.login-panel-brand {
    flex: 1.1; position: relative; overflow: hidden; display: none;
    background: #0B2A5B;
    background-image:
        radial-gradient(700px 500px at 15% 20%, rgba(0,87,168,.35), transparent 60%),
        radial-gradient(600px 500px at 85% 80%, rgba(34,197,94,.22), transparent 60%);
    color: #fff; padding: 56px;
    flex-direction: column; justify-content: space-between;
}
.login-panel-brand .brand-mark { width: 46px; height: 46px; font-size: 18px; border-radius: 13px; }
.login-panel-brand h2 { font-size: 30px; font-weight: 700; letter-spacing: -.02em; line-height: 1.25; max-width: 420px; margin: 40px 0 14px; }
.login-panel-brand p { color: #9BAAC9; font-size: 14.5px; max-width: 380px; line-height: 1.6; }
.login-panel-brand .login-quote { border-top: 1px solid rgba(255,255,255,.1); padding-top: 20px; font-size: 12.5px; color: #7B8CAD; }
.login-panel-form { flex: 1; display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.login-card { background: var(--surface); border-radius: 18px; padding: 40px; width: 380px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); }
.login-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 6px; }
.login-brand h1 { font-size: 18px; margin: 0; font-weight: 700; letter-spacing: -.01em; }
.login-brand h1 small { color: var(--azul); font-weight: 600; }
.login-subtitle { color: var(--text-muted); font-size: 13px; margin: 0 0 24px; }
.login-form { display: flex; flex-direction: column; gap: 15px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--slate-700); }
.login-form input {
    padding: 11px 13px; border: 1px solid var(--slate-200); border-radius: var(--radius-sm); font-family: inherit; font-size: 13.5px;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.login-form input:focus { outline: none; border-color: var(--azul); box-shadow: 0 0 0 3px rgba(0,87,168,.10); }
.alert { padding: 11px 13px; border-radius: var(--radius-sm); font-size: 13px; display: flex; align-items: center; gap: 8px; margin-bottom: 16px; font-weight: 500; }
.alert i { width: 16px; height: 16px; flex-shrink: 0; }
.alert-error { background: #FEF2F2; color: #B91C1C; }

@media (min-width: 860px) {
    .login-panel-brand { display: flex; }
}

@media (max-width: 860px) {
    .sidebar { position: fixed; z-index: 20; height: 100%; transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .form-grid { grid-template-columns: 1fr; }
    .content { padding: 18px 16px 32px; }
}

/* ---------- Identidad RapidFact (alineada a BodegaPOS) ---------- */
body::before{content:"";position:fixed;top:0;left:0;right:0;height:3px;background:var(--rf-grad);z-index:200}
.nav-item.active{background:var(--gradient-brand)!important;color:#fff!important;box-shadow:0 4px 12px -6px rgba(0,0,0,.4)}
.nav-item.active::before{display:none}
.nav-item,.nav-section{color:#DCE6F7}
.nav-item i{opacity:1}
.brand-mark{border-radius:12px;background:var(--gradient-brand)}
.brand-name small{color:#22C55E}
.kpi-blue{background:linear-gradient(135deg,#DCEBFA,#F1F7FD);color:#0057A8}
.badge-sunat-pendiente{background:#FEF3C7;color:#B45309}
.badge-sunat-aceptado{background:#DCFCE7;color:#15803D}
.badge-sunat-rechazado{background:#FEE2E2;color:#B91C1C}
.card-sunat{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:20px;margin-bottom:16px}
.card-sunat h3{margin:0 0 4px;color:var(--rf-navy);font-size:15px}
[data-theme="dark"] .card-sunat h3{color:#fff}
.modo-pill{display:inline-block;padding:3px 10px;border-radius:99px;font-size:11.5px;font-weight:700}
.modo-beta{background:#FEF3C7;color:#B45309}.modo-prod{background:#DCFCE7;color:#15803D}
a.kpi-card, a.kpi-card:visited { text-decoration: none; color: inherit; }
a.kpi-card .kpi-value { color: var(--text); }
.data-table a:not(.icon-btn) { color: var(--azul); text-decoration: none; font-weight: 600; }
.data-table a:not(.icon-btn):hover { text-decoration: underline; }
.badge-orange { background: #FEF3C7; color: #B45309; }
