/* ══════════════════════════════════════════════════════════
   DSS Desk — hoja de estilo
   ══════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --surface-3: #e7eaef;
  --border: #e2e6ec;
  --border-2: #cdd4de;
  --text: #101828;
  --text-2: #5b6472;
  --text-3: #8b94a3;
  --accent: #4338ca;
  --accent-soft: #eef0fd;
  --accent-text: #3730a3;
  --green: #047857; --green-soft: #e7f6f0;
  --amber: #b45309; --amber-soft: #fdf3e3;
  --red: #b91c1c;   --red-soft: #fdeceb;
  --blue: #0369a1;  --blue-soft: #e6f3fb;
  --violet: #6d28d9;--violet-soft: #f0eafd;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.05);
  --shadow: 0 2px 8px rgba(16,24,40,.07), 0 1px 2px rgba(16,24,40,.04);
  --shadow-lg: 0 12px 32px rgba(16,24,40,.14);
  --sidebar-w: 232px;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}

[data-theme="dark"] {
  --bg: #0a0e1a;
  --surface: #121828;
  --surface-2: #182034;
  --surface-3: #202a42;
  --border: #253048;
  --border-2: #33405e;
  --text: #e8edf7;
  --text-2: #9aa6bd;
  --text-3: #6b7896;
  --accent: #818cf8;
  --accent-soft: #1e2544;
  --accent-text: #a5b0ff;
  --green: #34d399; --green-soft: #10291f;
  --amber: #fbbf24; --amber-soft: #2c2213;
  --red: #f87171;   --red-soft: #2e1717;
  --blue: #38bdf8;  --blue-soft: #0f2434;
  --violet: #a78bfa;--violet-soft: #221a3a;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow: 0 2px 8px rgba(0,0,0,.35);
  --shadow-lg: 0 16px 40px rgba(0,0,0,.5);
}

body {
  font-family: Inter, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
a { color: var(--accent); }

.screen { display: none; }
.screen.active { display: block; }
.muted { color: var(--text-2); }
.sm { font-size: 12.5px; }
.xs { font-size: 11.5px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }
.row { display: flex; align-items: center; gap: 10px; }
.row-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 4px; }
.hide { display: none !important; }

/* ── LOGIN ────────────────────────────────────────────── */
#login {
  min-height: 100vh;
  place-items: center;
  background:
    radial-gradient(900px 500px at 15% -10%, var(--accent-soft), transparent 65%),
    radial-gradient(700px 400px at 110% 110%, var(--blue-soft), transparent 60%),
    var(--bg);
}
#login.active { display: grid; }
.login-card {
  width: min(400px, calc(100vw - 32px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
}
.login-card h1 { font-size: 22px; letter-spacing: -.4px; margin-top: 26px; }
.login-card > .muted { margin-bottom: 22px; }

.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 38px; height: 38px; flex: none;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  border-radius: 10px;
  font-size: 12px; font-weight: 700; letter-spacing: .5px;
}
.brand-name { font-size: 15px; font-weight: 650; letter-spacing: -.2px; }
.brand-sub { font-size: 11.5px; color: var(--text-3); }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12.5px; font-weight: 550; color: var(--text-2); margin-bottom: 5px; }
.field input, .field select, .field textarea,
input.inp, select.inp, textarea.inp {
  width: 100%;
  padding: 9px 11px;
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  transition: border-color .12s, box-shadow .12s;
}
.field input:focus, .field select:focus, .field textarea:focus,
.inp:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 72px; }

/* ── BOTONES ──────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 13px; font-weight: 550;
  white-space: nowrap;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-outline { border-color: var(--border-2); background: var(--surface); }
.btn-outline:hover { background: var(--surface-2); }
.btn-ghost { color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.icon-btn {
  width: 30px; height: 30px; flex: none;
  display: grid; place-items: center;
  border-radius: 7px; color: var(--text-2);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ── LAYOUT ───────────────────────────────────────────── */
#app.active { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 22px;
  padding: 20px 14px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 11px;
  border-radius: 8px;
  font-size: 13.5px; font-weight: 500;
  color: var(--text-2);
  text-align: left;
}
.nav-item .ico { width: 16px; font-size: 13px; opacity: .8; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.nav-badge {
  margin-left: auto;
  font-size: 11px; font-weight: 600;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}
.nav-badge.warn:not(:empty) {
  background: var(--red-soft); color: var(--red);
  padding: 1px 6px; border-radius: 20px;
}
.sidebar-foot { display: flex; flex-direction: column; gap: 3px; }
.sidebar-foot .btn { justify-content: flex-start; }

.main { min-width: 0; padding: 26px 28px 60px; }
.view { display: none; }
.view.active { display: block; }

.mobnav { display: none; }

/* ── ENCABEZADOS ──────────────────────────────────────── */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  margin-bottom: 20px;
}
.page-title { font-size: 24px; font-weight: 680; letter-spacing: -.5px; }
.page-sub { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.section-title {
  font-size: 12px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-3);
  margin: 26px 0 10px;
}
.section-title:first-child { margin-top: 0; }

/* ── TARJETAS ─────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 16px 18px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
}
.card-head h3 { font-size: 14px; font-weight: 620; }

.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-2-1 { grid-template-columns: 2fr 1fr; }
.g-1-2 { grid-template-columns: 1fr 2fr; }

/* KPI */
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 15px 17px;
  box-shadow: var(--shadow-sm);
}
.kpi-label {
  font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-3);
}
.kpi-value {
  font-size: 25px; font-weight: 680; letter-spacing: -.7px;
  margin-top: 5px;
  font-variant-numeric: tabular-nums;
}
.kpi-foot { font-size: 12px; color: var(--text-2); margin-top: 3px; }
.kpi.accent { background: var(--accent-soft); border-color: transparent; }
.kpi.accent .kpi-value, .kpi.accent .kpi-label { color: var(--accent-text); }
.kpi.danger { background: var(--red-soft); border-color: transparent; }
.kpi.danger .kpi-value, .kpi.danger .kpi-label { color: var(--red); }
.kpi.good { background: var(--green-soft); border-color: transparent; }
.kpi.good .kpi-value, .kpi.good .kpi-label { color: var(--green); }

/* ── TABLAS ───────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: left; font-size: 11.5px; font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase; color: var(--text-3);
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr.clickable:hover { background: var(--surface-2); }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── BADGES ───────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11.5px; font-weight: 600;
  white-space: nowrap;
}
.b-gray   { background: var(--surface-3); color: var(--text-2); }
.b-green  { background: var(--green-soft); color: var(--green); }
.b-amber  { background: var(--amber-soft); color: var(--amber); }
.b-red    { background: var(--red-soft); color: var(--red); }
.b-blue   { background: var(--blue-soft); color: var(--blue); }
.b-violet { background: var(--violet-soft); color: var(--violet); }
.b-accent { background: var(--accent-soft); color: var(--accent-text); }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; }
.d-verde { background: var(--green); }
.d-amarillo { background: var(--amber); }
.d-rojo { background: var(--red); }

/* ── BARRAS / PROGRESO ────────────────────────────────── */
.bar { height: 6px; background: var(--surface-3); border-radius: 20px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 20px; }
.bar.green > i { background: var(--green); }
.bar.red > i { background: var(--red); }
.bar.amber > i { background: var(--amber); }

/* ── LISTAS ───────────────────────────────────────────── */
.list { display: flex; flex-direction: column; }
.list-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-item.clickable { cursor: pointer; }
.list-item.clickable:hover { background: var(--surface-2); }
.list-title { font-size: 13.5px; font-weight: 520; }
.list-sub { font-size: 12px; color: var(--text-2); }

.check {
  width: 18px; height: 18px; flex: none;
  border: 1.5px solid var(--border-2);
  border-radius: 5px;
  display: grid; place-items: center;
  font-size: 11px; color: transparent;
  transition: background .12s, border-color .12s;
}
.check:hover { border-color: var(--accent); }
.check.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── KANBAN FUNNEL ────────────────────────────────────── */
.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; }
.kcol {
  flex: 0 0 262px;
  background: var(--surface-2);
  border-radius: var(--radius-lg);
  padding: 10px;
  min-height: 180px;
}
.kcol.drop { outline: 2px dashed var(--accent); outline-offset: -3px; }
.kcol-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 9px; }
.kcol-name { font-size: 12px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; color: var(--text-2); }
.kcol-sum { font-size: 11.5px; font-weight: 600; color: var(--text-3); font-variant-numeric: tabular-nums; }
.kcard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 11px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
  cursor: grab;
}
.kcard:active { cursor: grabbing; }
.kcard.dragging { opacity: .4; }
.kcard-title { font-size: 13px; font-weight: 570; line-height: 1.35; }
.kcard-acc { font-size: 11.5px; color: var(--text-2); margin-top: 2px; }
.kcard-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; gap: 6px; }
.kcard-amt { font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; }

/* ── GRÁFICAS ─────────────────────────────────────────── */
.chart { width: 100%; display: block; overflow: visible; }
.chart text { font-family: Inter, sans-serif; fill: var(--text-2); }
.chart .axis { stroke: var(--border); stroke-width: 1; }
.chart .grid-l { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 4; opacity: .7; }
.chart .lbl { font-size: 10.5px; }
.chart .vlbl { font-size: 10.5px; font-weight: 600; fill: var(--text); }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 10px 18px 14px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }

/* ── FICHA DE CUENTA ──────────────────────────────────── */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab {
  padding: 9px 14px;
  font-size: 13px; font-weight: 550;
  color: var(--text-2);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-text); border-bottom-color: var(--accent); }
.tabpane { display: none; }
.tabpane.active { display: block; }

.back-link {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12.5px; color: var(--text-2);
  margin-bottom: 12px;
}
.back-link:hover { color: var(--text); }

/* ── ESTADO VACÍO ─────────────────────────────────────── */
.empty { text-align: center; padding: 40px 20px; color: var(--text-3); }
.empty-ico { font-size: 26px; opacity: .5; }
.empty-title { font-size: 14px; font-weight: 600; color: var(--text-2); margin-top: 8px; }
.empty-sub { font-size: 12.5px; margin-top: 2px; }

/* ── MODAL ────────────────────────────────────────────── */
.modal-back {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(16,24,40,.45);
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
  padding: 16px;
}
.modal {
  width: min(560px, 100%);
  max-height: calc(100vh - 60px);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal.wide { width: min(860px, 100%); }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 16px; font-weight: 640; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 13px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.modal-foot:empty { display: none; }

/* ── TOASTS ───────────────────────────────────────────── */
.toasts { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 10px 15px;
  background: var(--text); color: var(--bg);
  border-radius: 9px;
  font-size: 13px; font-weight: 520;
  box-shadow: var(--shadow-lg);
  animation: rise .18s ease-out;
  max-width: 340px;
}
.toast.err { background: var(--red); color: #fff; }
.toast.ok { background: var(--green); color: #fff; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ── ALERTAS ──────────────────────────────────────────── */
.alert { padding: 9px 12px; border-radius: 8px; font-size: 12.5px; margin-bottom: 12px; }
.alert.err { background: var(--red-soft); color: var(--red); }
.alert.warn { background: var(--amber-soft); color: var(--amber); }
.alert.info { background: var(--blue-soft); color: var(--blue); }

/* ── SPINNER ──────────────────────────────────────────── */
.spinner {
  width: 15px; height: 15px;
  border: 2px solid currentColor; border-top-color: transparent;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { padding: 36px; text-align: center; color: var(--text-3); font-size: 13px; }

/* ── FILTROS ──────────────────────────────────────────── */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
.filters .inp { width: auto; min-width: 150px; }
.chip {
  padding: 5px 11px;
  border: 1px solid var(--border-2);
  border-radius: 20px;
  font-size: 12.5px; font-weight: 520;
  background: var(--surface);
  color: var(--text-2);
}
.chip:hover { background: var(--surface-2); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── RESPONSIVE ───────────────────────────────────────── */
@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-2-1, .g-1-2, .g3 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  #app.active { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 16px 14px 90px; }
  .page-title { font-size: 20px; }
  .g2, .g4 { grid-template-columns: 1fr; }
  .kpi-value { font-size: 22px; }
  .mobnav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .mob-item {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 5px 2px;
    font-size: 10.5px; font-weight: 520;
    color: var(--text-3);
    border-radius: 8px;
  }
  .mob-item span { font-size: 16px; }
  .mob-item.active { color: var(--accent-text); }
  .modal { max-height: calc(100vh - 24px); }
  .toasts { left: 14px; right: 14px; bottom: 80px; }
  .toast { max-width: none; }
}
