:root {
  --bg: #f5f5f7;
  --elev: #ffffff;
  --ink: #1d1d1f;
  --muted: #86868b;
  --line: rgba(0, 0, 0, 0.08);
  --line-strong: #d2d2d7;
  --sidebar: #1d1d1f;
  --sidebar-2: #2c2c2e;
  --sidebar-text: #f5f5f7;
  --sidebar-muted: #98989d;
  --sidebar-line: #38383a;
  --up: #0071e3;
  --down: #d9480f;
  --up-soft: #e8f1fc;
  --down-soft: #fcede6;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
  --radius: 18px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  --display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- Estructura ---------- */
.app {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
}
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 22px 16px 16px;
  min-height: 100vh;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  text-decoration: none;
  padding: 0 8px 18px;
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #f5f5f7;
  color: #1d1d1f;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 18px;
}
.brand strong { display: block; font-size: 16px; letter-spacing: -0.02em; font-weight: 600; }
.brand span span { display: block; color: var(--sidebar-muted); font-size: 12px; margin-top: 1px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #d1d1d6;
  padding: 10px 12px;
  border-radius: 10px;
  font-weight: 500;
}
.nav a svg { opacity: 0.9; flex-shrink: 0; }
.nav a:hover { background: var(--sidebar-2); color: #f5f5f7; }
.nav a.is-active { background: #3a3a3c; color: #f5f5f7; }
.nav-label {
  color: var(--sidebar-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 16px 12px 4px;
}
.sidebar-foot {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--sidebar-line);
}
.who { display: flex; gap: 10px; align-items: center; padding: 10px 8px 8px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: #3a3a3c; color: #f5f5f7; display: grid; place-items: center;
  font-size: 12px; font-weight: 600; flex-shrink: 0;
}
.who strong { display: block; font-size: 13px; font-weight: 600; }
.who span { color: var(--sidebar-muted); font-size: 12px; }
.index-link {
  display: block;
  margin: 8px 8px 0;
  color: var(--sidebar-muted);
  font-size: 12px;
  text-decoration: none;
  background: none;
  border: 0;
  padding: 0;
}
.index-link:hover { color: #f5f5f7; }

.main { min-width: 0; background: var(--bg); }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  padding: 28px 32px 0;
}
.crumb { color: var(--muted); font-size: 13px; margin: 0 0 4px; }
h1 {
  font-family: var(--display);
  font-weight: 600;
  font-size: 34px;
  letter-spacing: -0.03em;
  margin: 0;
  line-height: 1.1;
}
.lede { color: var(--muted); margin: 8px 0 0; max-width: 62ch; }
.page { padding: 22px 32px 48px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; align-content: start; }

/* ---------- Botones ---------- */
.btn {
  border: 1px solid transparent;
  background: var(--ink);
  color: white;
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  line-height: 1;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn:hover { background: #000; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line-strong); }
.btn.ghost:hover { background: white; }
.btn.small { padding: 8px 12px; font-size: 13px; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.linkish { color: var(--ink); font-weight: 600; text-decoration: none; background: none; border: 0; padding: 0; }
.linkish:hover { text-decoration: underline; }
.linkish.subtle { color: var(--muted); font-weight: 500; }

/* ---------- Superficies ---------- */
.panel {
  background: var(--elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel-pad { padding: 18px; }
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.section-title h2 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.hint { color: var(--muted); font-size: 13px; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.status-note, .errors {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 0;
}
.errors ul { margin: 6px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; }

/* ---------- Métricas ---------- */
.hero {
  padding: 22px 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: end;
}
.hero-label { color: var(--muted); font-size: 13px; font-weight: 500; margin: 0; }
.hero-value {
  font-family: var(--display);
  font-size: 52px;
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 1.05;
  margin: 4px 0 6px;
  font-variant-numeric: tabular-nums;
}
.hero-meta { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); font-size: 13px; }
.hero-meta strong { color: var(--ink); font-weight: 600; }
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}
.stat { padding: 16px 18px; }
.stat-label { color: var(--muted); font-size: 13px; margin: 0; }
.stat-value {
  font-family: var(--display);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 2px 0 2px;
  font-variant-numeric: tabular-nums;
}
.stat-sub { font-size: 12.5px; color: var(--muted); }

.delta {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.delta::before {
  content: "";
  width: 0; height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
}
.delta.up::before { border-bottom: 6px solid var(--up); }
.delta.down::before { border-top: 6px solid var(--down); }
.delta.flat::before { width: 8px; height: 2px; border: 0; background: var(--line-strong); }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 600;
  background: var(--bg);
  white-space: nowrap;
}
.pill.up { background: var(--up-soft); }
.pill.down { background: var(--down-soft); }

.accounts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}
.account-card { padding: 18px; display: grid; gap: 12px; }
.account-card header { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.account-card h3 { margin: 0; font-size: 15px; font-weight: 600; }
.account-card .stat-value { font-size: 28px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin: 0; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Gráficas ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--line); }
.chart .axis text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .zero { stroke: var(--line-strong); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 0; border-top: 2px solid var(--up); display: block; }
.legend i.dashed { border-top: 2px dashed var(--muted); }
.legend i.bar { width: 10px; height: 10px; border: 0; border-radius: 3px; background: var(--up); }
.legend i.bar.down { background: var(--down); }
.tip {
  position: absolute;
  pointer-events: none;
  background: rgba(29, 29, 31, 0.94);
  color: #f5f5f7;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12.5px;
  line-height: 1.45;
  white-space: nowrap;
  transform: translate(-50%, calc(-100% - 12px));
  opacity: 0;
  transition: opacity 0.12s;
  z-index: 5;
}
.tip.is-on { opacity: 1; }
.tip b { font-weight: 600; }
.tip .row { display: flex; justify-content: space-between; gap: 14px; }
.tip .row span { color: #a1a1a6; }

/* ---------- Tablas ---------- */
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 16px; vertical-align: middle; }
th {
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { border-bottom: 1px solid var(--line); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafafa; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
tfoot td { font-weight: 600; border-top: 1px solid var(--line-strong); border-bottom: 0; background: #fbfbfd; }
.row-actions { display: flex; gap: 14px; justify-content: flex-end; align-items: center; }
.row-actions form { margin: 0; }
.carried { color: var(--muted); font-style: italic; }
.mv-list { display: flex; flex-direction: column; gap: 2px; font-size: 12.5px; color: var(--muted); }

/* ---------- Formularios ---------- */
.fields { display: grid; gap: 12px; }
.fields.cols { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.field label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.field .hint { display: block; margin-top: 4px; font-size: 12px; }
.control {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: #fbfbfd;
  border-radius: 12px;
  padding: 10px 12px;
  outline: none;
}
.control:focus {
  border-color: #1d1d1f;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(0, 0, 0, 0.06);
}
.money-input { position: relative; }
.money-input::before {
  content: "$";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
}
.money-input .control { padding-left: 24px; font-variant-numeric: tabular-nums; }
.form-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.field-error { font-size: 12px; font-weight: 600; margin: 4px 0 0; color: var(--down); }
.layout-2 {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filters .field { min-width: 150px; }
.filters .control { padding: 8px 12px; }

.seg {
  display: inline-flex;
  background: #e8e8ed;
  border-radius: 10px;
  padding: 2px;
  gap: 2px;
}
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label {
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  margin: 0;
}
.seg input:checked + label { background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); font-weight: 600; }
.seg input:focus-visible + label { outline: 2px solid var(--up); }

.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 500; }
.switch input { width: 16px; height: 16px; accent-color: var(--ink); }

.code {
  background: #1d1d1f;
  color: #f5f5f7;
  border-radius: 12px;
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 12.5px;
  overflow: auto;
  margin: 8px 0 0;
}

.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); font-size: 13px; }

/* ---------- Login ---------- */
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(420px, 100%); padding: 28px; }
.login-card h1 { font-size: 32px; }
.login-card .fields { margin-top: 18px; }
.cover-kicker {
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  margin: 0 0 6px;
}

/* ---------- Móvil ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .table-wrap td:first-child { white-space: nowrap; }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: 0;
    height: auto;
    flex-direction: row;
    align-items: center;
    padding: 10px 12px;
    gap: 8px;
    overflow-x: auto;
  }
  .brand { padding: 0 6px 0 0; }
  .brand span span, .nav-label, .sidebar-foot, .nav a span { display: none; }
  .nav { flex-direction: row; gap: 2px; }
  .nav a { padding: 9px 10px; }
  .topbar { padding: 20px 16px 0; flex-direction: column; align-items: flex-start; }
  .page { padding: 16px 16px 40px; }
  h1 { font-size: 28px; }
  .hero { grid-template-columns: 1fr; padding: 18px; }
  .hero-value { font-size: 40px; }
  .layout-2 { grid-template-columns: minmax(0, 1fr); }
  .hero-meta { gap: 4px 14px; }
  th, td { padding: 10px 12px; }
}
