/* ==========================================================================
   FacturaTech · Sistema de diseño
   ========================================================================== */

:root {
  --bg: #f3f5fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e6e9f2;
  --border-strong: #d7dcea;
  --text: #0f172a;
  --text-soft: #334155;
  --muted: #64748b;
  --muted-2: #94a3b8;

  --primary: #4f46e5;
  --primary-2: #7c3aed;
  --primary-soft: #eef2ff;
  --accent: #06b6d4;
  --success: #10b981;
  --success-soft: #ecfdf5;
  --warning: #f59e0b;
  --warning-soft: #fffbeb;
  --danger: #ef4444;
  --danger-soft: #fef2f2;
  --info: #0ea5e9;
  --info-soft: #f0f9ff;
  --violet: #8b5cf6;
  --dark: #1e293b;

  --sidebar-w: 264px;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 12px 28px -18px rgba(16, 24, 40, .35);
  --shadow-lg: 0 24px 60px -24px rgba(16, 24, 40, .38);
  --font: "Inter", "Segoe UI", ui-sans-serif, system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.015em; color: var(--text); }
p { margin: 0 0 12px; }
img { max-width: 100%; }

.icon { flex: none; }

.mono { font-family: ui-monospace, "SF Mono", Consolas, "Liberation Mono", monospace; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.bold { font-weight: 650; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.nowrap { white-space: nowrap; }
.w-100 { width: 100%; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ------------------------------------------------------------------ Estructura */

.app { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 400px at -20% -10%, rgba(99, 102, 241, .38), transparent 60%),
    radial-gradient(900px 500px at 120% 110%, rgba(6, 182, 212, .22), transparent 55%),
    linear-gradient(178deg, #0b1220 0%, #0e1730 55%, #0a1122 100%);
  color: #cbd5e1;
  z-index: 60;
  transition: transform .28s cubic-bezier(.4, 0, .2, 1);
  border-right: 1px solid rgba(148, 163, 184, .12);
}

.brand {
  display: flex; align-items: center; gap: 11px;
  padding: 20px 20px 16px;
  color: #fff;
}
.brand-mark {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  box-shadow: 0 8px 22px -8px rgba(99, 102, 241, .9);
  color: #fff;
}
.brand-name { font-size: 16.5px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.brand-tag { font-size: 11px; color: #7c8db5; letter-spacing: .04em; text-transform: uppercase; }

.nav { flex: 1; overflow-y: auto; padding: 8px 14px 20px; }
.nav::-webkit-scrollbar { width: 6px; }
.nav::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, .25); border-radius: 8px; }

.nav-group { margin-top: 18px; }
.nav-group-title {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .13em;
  color: #64748b; padding: 0 10px 8px; font-weight: 700;
}
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9.5px 11px; margin-bottom: 3px;
  border-radius: 10px; color: #a9b7d0; font-weight: 500;
  transition: background .16s, color .16s, transform .16s;
  position: relative;
}
.nav-item:hover { background: rgba(148, 163, 184, .12); color: #fff; }
.nav-item.is-active {
  background: linear-gradient(90deg, rgba(99, 102, 241, .95), rgba(124, 58, 237, .82));
  color: #fff;
  box-shadow: 0 10px 22px -14px rgba(99, 102, 241, 1);
}
.nav-item.is-active::before {
  content: ""; position: absolute; left: -14px; top: 20%; height: 60%; width: 3px;
  background: var(--accent); border-radius: 0 4px 4px 0;
}
.nav-badge {
  margin-left: auto; font-size: 10.5px; font-weight: 700;
  background: rgba(6, 182, 212, .18); color: #67e8f9;
  padding: 1.5px 7px; border-radius: 999px;
}

.sidebar-user {
  margin: 12px 14px 16px; padding: 12px;
  background: rgba(148, 163, 184, .1);
  border: 1px solid rgba(148, 163, 184, .16);
  border-radius: 14px;
  display: flex; align-items: center; gap: 10px;
}
.sidebar-user .avatar { background: linear-gradient(135deg, var(--primary-2), var(--primary)); color: #fff; }
.sidebar-user-name { color: #fff; font-weight: 600; font-size: 13.5px; line-height: 1.2; }
.sidebar-user-role { font-size: 11.5px; color: #7c8db5; }

.avatar {
  width: 36px; height: 36px; border-radius: 11px; flex: none;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700; letter-spacing: .02em;
  background: linear-gradient(135deg, #e0e7ff, #c7d2fe);
  color: #4338ca;
}

.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 14px;
  padding: 13px 26px;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { font-size: 16px; font-weight: 650; letter-spacing: -.02em; }
.topbar-sub { font-size: 12px; color: var(--muted); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.content { flex: 1; padding: 26px; max-width: 1500px; width: 100%; margin: 0 auto; }

.footer {
  padding: 16px 26px; color: var(--muted-2); font-size: 12px;
  border-top: 1px solid var(--border); display: flex; gap: 14px; flex-wrap: wrap;
}

.scrim {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5);
  opacity: 0; visibility: hidden; transition: .25s; z-index: 55; backdrop-filter: blur(2px);
}
body.sidebar-open .scrim { opacity: 1; visibility: visible; }

/* ------------------------------------------------------------------ Botones */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 15px; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: 13.5px; cursor: pointer;
  background: var(--surface); color: var(--text-soft);
  border-color: var(--border-strong);
  transition: transform .14s ease, box-shadow .14s ease, background .14s, border-color .14s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--primary); color: var(--primary); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: 3px solid rgba(79, 70, 229, .3); outline-offset: 2px; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; border-color: transparent;
  box-shadow: 0 10px 24px -14px rgba(79, 70, 229, 1);
}
.btn-primary:hover { color: #fff; filter: brightness(1.07); box-shadow: 0 14px 28px -14px rgba(79, 70, 229, 1); }

.btn-success { background: linear-gradient(135deg, #059669, #10b981); color: #fff; border-color: transparent; }
.btn-success:hover { color: #fff; filter: brightness(1.06); }
.btn-danger { background: #fff; color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--primary); border-color: transparent; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; }

.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center;
  border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--muted); cursor: pointer;
  transition: .15s;
}
.icon-btn:hover { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }
.icon-btn.bare { border-color: transparent; background: transparent; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ------------------------------------------------------------------- Tarjetas */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 18px; }
.card-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-title { font-size: 14.5px; font-weight: 650; letter-spacing: -.01em; }
.card-sub { font-size: 12.5px; color: var(--muted); }
.card-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card-body { padding: 20px; }
.card-body.tight { padding: 0; }

.page-header {
  display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-title { font-size: 23px; font-weight: 700; letter-spacing: -.03em; }
.page-sub { color: var(--muted); font-size: 13.5px; margin-top: 3px; }
.page-actions { margin-left: auto; display: flex; gap: 9px; flex-wrap: wrap; }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid-1-1 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.stack { display: flex; flex-direction: column; gap: 18px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.gap-sm { gap: 8px; }
.mt-0 { margin-top: 0; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 14px; } .mt-4 { margin-top: 22px; }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 14px; }

/* ---------------------------------------------------------------------- KPIs */

.kpi {
  position: relative; overflow: hidden;
  padding: 18px 18px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.kpi::after {
  content: ""; position: absolute; right: -34px; top: -34px;
  width: 110px; height: 110px; border-radius: 50%;
  background: radial-gradient(circle, rgba(99, 102, 241, .16), transparent 68%);
}
.kpi-top { display: flex; align-items: center; gap: 10px; }
.kpi-icon {
  width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary);
}
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 560; }
.kpi-value { font-size: 26px; font-weight: 720; letter-spacing: -.035em; margin-top: 10px; line-height: 1.1; }
.kpi-foot { margin-top: 8px; font-size: 12.3px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi.up .kpi-icon { background: var(--success-soft); color: var(--success); }
.kpi.warn .kpi-icon { background: var(--warning-soft); color: var(--warning); }
.kpi.bad .kpi-icon { background: var(--danger-soft); color: var(--danger); }
.kpi.accent .kpi-icon { background: #ecfeff; color: var(--accent); }

.trend { display: inline-flex; align-items: center; gap: 3px; font-weight: 700; }
.trend.up { color: var(--success); }
.trend.down { color: var(--danger); }

/* ------------------------------------------------------------------- Tablas */

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.6px; }
.table th {
  text-align: left; font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); font-weight: 700; padding: 12px 16px;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: #fafbff; }
.table tbody tr:last-child td { border-bottom: none; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; }
.table-link { font-weight: 620; color: var(--text); }
.table-link:hover { color: var(--primary); }
.table-sub { font-size: 12px; color: var(--muted); }

.pagination { display: flex; gap: 6px; align-items: center; padding: 16px 20px; flex-wrap: wrap; }
.page-btn {
  min-width: 32px; height: 32px; padding: 0 9px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border-strong); border-radius: 8px;
  font-size: 13px; font-weight: 600; color: var(--text-soft); background: var(--surface);
  transition: .14s;
}
a.page-btn:hover { border-color: var(--primary); color: var(--primary); }
.page-btn.is-current { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-btn.is-disabled { opacity: .4; }
.page-ellipsis { color: var(--muted-2); padding: 0 2px; }

/* ------------------------------------------------------------------ Badges */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .02em;
  background: var(--surface-2); color: var(--muted);
  border: 1px solid transparent; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge.plain::before { display: none; }
.badge-success { background: var(--success-soft); color: #047857; border-color: #a7f3d0; }
.badge-danger { background: var(--danger-soft); color: #b91c1c; border-color: #fecaca; }
.badge-warning { background: var(--warning-soft); color: #b45309; border-color: #fde68a; }
.badge-info { background: var(--info-soft); color: #0369a1; border-color: #bae6fd; }
.badge-violet { background: #f5f3ff; color: #6d28d9; border-color: #ddd6fe; }
.badge-muted { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
.badge-dark { background: #1e293b; color: #e2e8f0; border-color: #1e293b; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px;
  border-radius: 999px; background: var(--primary-soft); color: var(--primary);
  font-size: 12.5px; font-weight: 650;
}

/* ------------------------------------------------------------------- Forms */

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: span 2; }
.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: 12.5px; font-weight: 650; color: var(--text-soft); }
.label .req { color: var(--danger); }

.input, .select, .textarea {
  width: 100%; padding: 9.5px 12px;
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  transition: border-color .14s, box-shadow .14s, background .14s;
}
.input::placeholder, .textarea::placeholder { color: var(--muted-2); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3.5px rgba(79, 70, 229, .14);
}
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-2); color: var(--muted); }
.input[type="file"] { padding: 8px 10px; background: var(--surface-2); color: var(--muted); }
.input[type="file"]::file-selector-button {
  margin: 0 10px 0 0; padding: 6.5px 12px;
  font: inherit; font-size: 13px; font-weight: 650; color: var(--text-soft);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 8px; cursor: pointer;
  transition: border-color .14s, color .14s, background .14s;
}
.input[type="file"]::file-selector-button:hover { color: var(--primary); border-color: var(--primary); }
.input[type="file"]::file-selector-button:active { background: var(--primary-soft); }
.textarea { min-height: 92px; resize: vertical; }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 34px;
}
.input.is-invalid, .select.is-invalid, .textarea.is-invalid {
  border-color: var(--danger); background: #fffafa;
  box-shadow: 0 0 0 3.5px rgba(239, 68, 68, .12);
}
.error-text { font-size: 12px; color: var(--danger); font-weight: 600; }
.hint { font-size: 12px; color: var(--muted); }

.error-summary {
  background: var(--danger-soft); border: 1px solid #fecaca;
  border-left: 4px solid var(--danger);
  border-radius: 10px; padding: 13px 16px; margin-bottom: 18px;
}
.error-summary h4 { font-size: 13.5px; color: #b91c1c; margin-bottom: 6px; }
.error-summary ul { margin: 0; padding-left: 18px; font-size: 13px; color: #b91c1c; }

.form-actions {
  display: flex; gap: 10px; justify-content: flex-end;
  padding-top: 18px; margin-top: 20px; border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.check { display: flex; align-items: flex-start; gap: 9px; font-size: 13.5px; }
.check input { width: 16px; height: 16px; margin-top: 2px; accent-color: var(--primary); }

.search-bar { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }
.search-bar .input { min-width: 220px; }

/* ------------------------------------------------------------------- Filtros */

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { min-width: 150px; }

/* ----------------------------------------------------------------- Dropdowns */

.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 8px);
  min-width: 230px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-lg); padding: 7px;
  opacity: 0; visibility: hidden; transform: translateY(-6px);
  transition: .16s ease; z-index: 70;
}
.dropdown.open .dropdown-menu { opacity: 1; visibility: visible; transform: translateY(0); }
.dropdown-menu a, .dropdown-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 11px; border-radius: 8px; border: none; background: none;
  font: inherit; font-size: 13.5px; color: var(--text-soft); cursor: pointer; text-align: left;
}
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--primary-soft); color: var(--primary); }
.dropdown-menu .divider { height: 1px; background: var(--border); margin: 6px 4px; }
.dropdown-title { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); padding: 8px 11px 4px; font-weight: 700; }

.user-chip { display: flex; align-items: center; gap: 9px; padding: 5px 9px 5px 5px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; }
.user-chip:hover { border-color: var(--primary); }
.user-chip .avatar { width: 29px; height: 29px; border-radius: 50%; font-size: 11.5px; }

.company-switch {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface);
}
.company-switch .select { border: none; background: transparent; font-size: 13.3px; font-weight: 600; padding: 2px 24px 2px 2px; box-shadow: none; min-width: 165px; }
.company-switch .select:focus { box-shadow: none; }

/* -------------------------------------------------------------------- Toasts */

.toast-stack {
  position: fixed; right: 20px; bottom: 20px; z-index: 90;
  display: flex; flex-direction: column; gap: 10px; max-width: 380px;
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 13px 15px; border-radius: 12px;
  background: #0f172a; color: #e2e8f0;
  box-shadow: var(--shadow-lg); font-size: 13.5px;
  border-left: 4px solid var(--primary);
  animation: toast-in .3s cubic-bezier(.2, .9, .3, 1.3);
}
.toast.success { border-left-color: var(--success); }
.toast.danger { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast.info { border-left-color: var(--info); }
.toast strong { color: #fff; }
.toast .icon { margin-top: 1px; }
.toast-close { margin-left: auto; background: none; border: none; color: #94a3b8; cursor: pointer; padding: 0 2px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(14px) scale(.97); } to { opacity: 1; transform: none; } }

/* -------------------------------------------------------------------- Modal */

.modal {
  position: fixed; inset: 0; z-index: 95;
  display: none; align-items: center; justify-content: center; padding: 20px;
  background: rgba(15, 23, 42, .55); backdrop-filter: blur(3px);
}
.modal.is-open { display: flex; animation: fade .2s ease; }
.modal-panel {
  background: var(--surface); border-radius: 16px; width: 100%; max-width: 520px;
  box-shadow: var(--shadow-lg); overflow: hidden; animation: pop .24s cubic-bezier(.2, .9, .3, 1.2);
  max-height: 90vh; overflow-y: auto;
}
.modal-lg { max-width: 760px; }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.modal-body { padding: 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; background: var(--surface-2); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.97); } to { opacity: 1; transform: none; } }

/* --------------------------------------------------------------------- Tabs */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding: 0 6px; overflow-x: auto; }
.tab {
  padding: 11px 15px; font-size: 13.5px; font-weight: 620; color: var(--muted);
  border-bottom: 2px solid transparent; cursor: pointer; background: none; border-top: none;
  border-left: none; border-right: none; font-family: inherit; white-space: nowrap;
}
.tab:hover { color: var(--primary); }
.tab.is-active { color: var(--primary); border-bottom-color: var(--primary); }
[data-panel] { display: none; }
[data-panel].is-active { display: block; }

/* -------------------------------------------------------------- Empty state */

.empty {
  text-align: center; padding: 46px 24px; color: var(--muted);
}
.empty-icon {
  width: 62px; height: 62px; margin: 0 auto 14px; border-radius: 18px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary-soft), #ecfeff); color: var(--primary);
}
.empty h3 { font-size: 16px; margin-bottom: 6px; }
.empty p { max-width: 440px; margin: 0 auto 16px; font-size: 13.5px; }

/* ------------------------------------------------------------------- Charts */

.chart-card { position: relative; }
.chart-wrap { position: relative; width: 100%; }
.chart-wrap canvas { display: block; width: 100%; }
.chart-tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: #0f172a; color: #fff; font-size: 12px;
  padding: 6px 9px; border-radius: 8px; white-space: nowrap;
  transform: translate(-50%, -130%); opacity: 0; transition: opacity .12s;
  box-shadow: var(--shadow-lg);
}
.chart-tooltip.show { opacity: 1; }
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 14px; font-size: 12.5px; color: var(--muted); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.mini-bar { height: 7px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.mini-bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 99px; }

/* ------------------------------------------------------------------- Listas */

.list { display: flex; flex-direction: column; }
.list-item {
  display: flex; align-items: center; gap: 13px;
  padding: 13px 20px; border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: #fafbff; }
.list-icon {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary); flex: none;
}
.list-main { min-width: 0; flex: 1; }
.list-title { font-weight: 620; font-size: 13.6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-sub { font-size: 12.2px; color: var(--muted); }
.list-value { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* --------------------------------------------------------------- Detalles */

.detail-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px 22px; }
.detail-item .label { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; }
.detail-item .value { font-size: 14px; font-weight: 600; margin-top: 3px; word-break: break-word; }

.totals {
  margin-left: auto; min-width: 290px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 15px 17px;
}
.totals .line { display: flex; justify-content: space-between; gap: 20px; padding: 5px 0; font-size: 13.5px; }
.totals .line span:last-child { font-variant-numeric: tabular-nums; font-weight: 620; }
.totals .line.grand {
  border-top: 1px dashed var(--border-strong); margin-top: 8px; padding-top: 11px;
  font-size: 16.5px; font-weight: 750; letter-spacing: -.02em;
}
.totals .line.grand span:last-child { color: var(--primary); }

/* --------------------------------------------------------------- Facturas */

.lines-table { width: 100%; border-collapse: collapse; font-size: 13.4px; }
.lines-table th {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
  padding: 9px 8px; text-align: left; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.lines-table td { padding: 7px 5px; border-bottom: 1px solid var(--border); vertical-align: top; }
.lines-table td.num, .lines-table th.num { text-align: right; }
.lines-table .input, .lines-table .select { padding: 7px 9px; font-size: 13.3px; border-radius: 8px; }
.lines-table col.c-qty { width: 96px; }
.lines-table col.c-price { width: 124px; }
.lines-table col.c-disc { width: 92px; }
.lines-table col.c-tax { width: 150px; }
.lines-table col.c-total { width: 124px; }
.lines-table col.c-del { width: 42px; }

.line-total { font-variant-numeric: tabular-nums; font-weight: 650; padding-top: 9px; display: block; }

.stamp {
  font-family: ui-monospace, Consolas, monospace; font-size: 12.5px;
  background: var(--surface-2); border: 1px dashed var(--border-strong);
  padding: 9px 12px; border-radius: 9px; word-break: break-all; color: var(--text-soft);
}

.verify-ok {
  background: linear-gradient(135deg, #ecfdf5, #f0fdfa);
  border: 1px solid #a7f3d0; border-radius: 14px; padding: 18px;
}
.verify-bad {
  background: linear-gradient(135deg, #fef2f2, #fff7ed);
  border: 1px solid #fecaca; border-radius: 14px; padding: 18px;
}

/* ------------------------------------------------------------- Auth / 404 */

.guest-body {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 26px;
  background:
    radial-gradient(900px 500px at 12% 8%, rgba(99, 102, 241, .35), transparent 60%),
    radial-gradient(900px 600px at 88% 92%, rgba(6, 182, 212, .3), transparent 55%),
    linear-gradient(160deg, #0b1220, #111a33 60%, #0a1122);
  color: #cbd5e1;
}
.guest-card {
  width: 100%; max-width: 440px;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(148, 163, 184, .22);
  border-radius: 20px; padding: 34px;
  backdrop-filter: blur(18px);
  box-shadow: 0 30px 80px -40px rgba(0, 0, 0, .9);
}
.guest-card.wide { max-width: 720px; }
.guest-card h1 { color: #fff; font-size: 24px; letter-spacing: -.03em; }
.guest-card .label { color: #cbd5e1; }
.guest-card .input {
  background: rgba(255, 255, 255, .08); border-color: rgba(148, 163, 184, .3); color: #fff;
}
.guest-card .input::placeholder { color: #7c8db5; }
.guest-card .input:focus { background: rgba(255, 255, 255, .12); border-color: var(--accent); box-shadow: 0 0 0 3.5px rgba(6, 182, 212, .2); }
.guest-card .error-text { color: #fca5a5; }
.guest-card .btn-primary { background: linear-gradient(135deg, var(--primary), var(--accent)); }

.auth-visual {
  position: fixed; inset: 0; pointer-events: none; overflow: hidden;
}
.auth-visual span {
  position: absolute; border-radius: 50%; filter: blur(70px); opacity: .5;
}
.guest-footer {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  /* margen negativo: la franja llega a los bordes de la tarjeta */
  margin: 26px -34px -34px;
  padding: 13px 20px 15px; text-align: center;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-top: 3px solid rgba(255, 255, 255, .35);
  border-radius: 0 0 19px 19px;
  box-shadow: 0 12px 26px -20px rgba(0, 0, 0, .95);
}
.guest-footer-brand { font-size: 13px; color: #fff; font-weight: 500; letter-spacing: -.01em; }
.guest-footer-brand strong { font-weight: 700; }
.guest-footer-year {
  font-size: 11.5px; color: rgba(255, 255, 255, .85);
  letter-spacing: .1em; text-transform: uppercase;
}

.auth-features { list-style: none; padding: 0; margin: 22px 0 0; display: flex; flex-direction: column; gap: 11px; }
.auth-features li { display: flex; gap: 10px; align-items: center; font-size: 13.5px; color: #a9b7d0; }
.auth-features .icon { color: var(--accent); }

.error-page { text-align: center; }
.error-code {
  font-size: 92px; font-weight: 800; letter-spacing: -.06em; line-height: 1;
  background: linear-gradient(135deg, #fff, var(--accent));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* ---------------------------------------------------------------- Responsive */

.menu-btn { display: none; }

@media (max-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2-1, .grid-1-1 { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-btn { display: grid; }
  .content { padding: 18px; }
  .topbar { padding: 12px 18px; }
}

@media (max-width: 760px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .form-grid, .form-grid.three { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span-2 { grid-column: auto; }
  .page-title { font-size: 20px; }
  .kpi-value { font-size: 23px; }
  .totals { min-width: 0; width: 100%; }
  .company-switch .select { min-width: 120px; }
  .table td, .table th { padding: 11px 12px; }
}

/* ------------------------------------------------------------------- Print */

@media print {
  .sidebar, .topbar, .footer, .page-actions, .toast-stack, .scrim, .no-print { display: none !important; }
  .main { margin-left: 0; }
  body { background: #fff; }
  .content { padding: 0; max-width: none; }
  .card { border: none; box-shadow: none; }
}

@media print {
  .print-sheet { padding: 0 !important; }
}
