/* ───────────────────────────────────────────────────────────
   Veloria — base.css (sistema de diseño)
   Tokens, reset, layout (shell/sidebar/topbar), componentes
   compartidos (botones, inputs, tablas, cards, badges) y el
   responsive global. Cada pantalla suma su modulo via extra_css.
   ─────────────────────────────────────────────────────────── */

:root {
  /* Tipografía */
  --font-display: "Spectral", "Newsreader", Georgia, serif;
  --font-sans: "Geist", "Inter", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", monospace;

  /* Paleta — sobrio cálido (default) */
  --bg: #f4f0e9;
  --surface: #fbf8f2;
  --surface-elev: #ffffff;
  --paper: #fffdf8;
  --ink: #1a1814;
  --ink-soft: #3d3830;
  --ink-muted: #6b6457;
  --ink-faint: #9a9387;
  --line: #e3ddd0;
  --line-strong: #cdc5b3;
  --line-soft: #ece6d8;

  /* Acento — vino sobrio */
  --accent: #5a1f2e;
  --accent-hover: #6e2839;
  --accent-soft: #f3e6e6;
  --accent-ink: #ffffff;

  /* Destructivo */
  --danger: #b91c1c;
  --danger-hover: #991b1b;

  /* Color de trazo de firma */
  --signature-color: #1a3a72;

  /* Estados */
  --status-firmado-bg: #e6efe7;
  --status-firmado-fg: #2d5a3a;
  --status-firmado-dot: #4a8159;
  --status-pendiente-bg: #f5ebd6;
  --status-pendiente-fg: #7a5a14;
  --status-pendiente-dot: #b8893a;
  --status-borrador-bg: #ece6d8;
  --status-borrador-fg: #5c574e;
  --status-borrador-dot: #8c8675;
  --status-vencido-bg: #f1dcd6;
  --status-vencido-fg: #7a2a1f;
  --status-vencido-dot: #a4392a;

  /* Espaciado base */
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 10px;
  --r-xl: 14px;

  /* Density */
  --row-h: 48px;
  --field-h: 38px;
}

/* ─── Base ─── */
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
}
body {
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  font-family: inherit;
  cursor: pointer;
}
input,
select,
textarea {
  font-family: inherit;
  color: inherit;
}
a {
  text-decoration: none;
}

::selection {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ─── App shell ─── */
.app {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}

/* ─── Sidebar ─── */
.sb {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sb-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 6px 14px;
  border-bottom: 1px solid var(--line-soft);
}
.sb-brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 17px;
  font-style: italic;
  letter-spacing: -0.02em;
}
.sb-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}
.sb-brand-text b {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 14.5px;
  letter-spacing: -0.005em;
}
.sb-brand-text span {
  font-size: 10.5px;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sb-section {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  padding: 0 8px 4px;
  font-weight: 500;
}
.sb-nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.sb-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--r-md);
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 13.5px;
  border: 0;
  background: transparent;
  text-align: left;
  width: 100%;
}
.sb-item:hover {
  background: var(--line-soft);
  color: var(--ink);
}
.sb-item.is-active {
  background: var(--surface-elev);
  color: var(--ink);
  font-weight: 500;
  box-shadow:
    0 0 0 1px var(--line) inset,
    0 1px 0 rgba(0, 0, 0, 0.02);
}
.sb-item-icon {
  width: 16px;
  height: 16px;
  opacity: 0.75;
  flex-shrink: 0;
}
.sb-item.is-active .sb-item-icon {
  opacity: 1;
  color: var(--accent);
}
.sb-item-count {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 100px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.sb-footer {
  margin-top: auto;
  padding: 10px 6px 0;
  border-top: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sb-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--line-strong);
  color: var(--ink-soft);
  display: grid;
  place-items: center;
  font-size: 11.5px;
  font-weight: 500;
  flex-shrink: 0;
}
.sb-user {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.sb-user-name {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sb-user-role {
  font-size: 11px;
  color: var(--ink-muted);
}
.sb-logout-form {
  margin-left: auto;
}
.sb-logout {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--ink-muted);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
.sb-logout:hover {
  background: var(--line-soft);
  color: var(--ink);
}
.sb-logout svg {
  flex-shrink: 0;
}

/* Botón de colapsar sidebar (escritorio) */
.sb-collapse {
  margin-left: auto;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: var(--r-md);
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  flex-shrink: 0;
}
.sb-collapse:hover {
  background: var(--line-soft);
  color: var(--ink);
}

/* ─── Sidebar colapsado (mini-rail, solo iconos) — solo escritorio ─── */
@media (min-width: 769px) {
  .sb-collapsed .app {
    grid-template-columns: 64px 1fr;
  }
  .sb-collapsed .sb {
    padding: 18px 10px;
  }
  .sb-collapsed .sb-brand {
    justify-content: center;
  }
  .sb-collapsed .sb-brand-mark,
  .sb-collapsed .sb-brand-text,
  .sb-collapsed .sb-section,
  .sb-collapsed .sb-item span,
  .sb-collapsed .sb-item-count,
  .sb-collapsed .sb-user,
  .sb-collapsed .sb-logout span {
    display: none;
  }
  .sb-collapsed .sb-collapse {
    margin-left: 0;
  }
  .sb-collapsed .sb-item {
    justify-content: center;
    padding: 8px;
  }
  .sb-collapsed .sb-footer {
    flex-direction: column;
    gap: 8px;
    padding: 10px 0 0;
  }
  .sb-collapsed .sb-logout-form {
    margin-left: 0;
  }
  /* En mini-rail, el chevron del brand apunta hacia afuera (expandir) */
  .sb-collapsed .sb-collapse {
    transform: rotate(180deg);
  }
}

/* ─── Main ─── */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar {
  height: 60px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.topbar-meta {
  display: contents;
}
.show-mobile {
  display: none !important;
}
.topbar-crumb {
  color: var(--ink-muted);
  font-size: 13px;
}
.topbar-crumb a {
  color: var(--ink-muted);
  text-decoration: none;
}
.topbar-crumb a:hover {
  color: var(--ink);
}
.topbar-spacer {
  flex: 1;
}
.topbar-sep {
  width: 1px;
  height: 22px;
  background: var(--line);
  flex-shrink: 0;
}
.content {
  padding: 28px;
  flex: 1;
  min-width: 0;
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  height: 36px;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  white-space: nowrap;
  text-decoration: none;
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover {
  background: var(--accent-hover);
}
.btn-primary:disabled,
.btn-secondary:disabled,
.btn[disabled] {
  opacity: 0.4 !important;
  cursor: not-allowed !important;
  pointer-events: none !important;
}
.btn-secondary {
  background: var(--surface-elev);
  border-color: var(--line);
  color: var(--ink);
}
.btn-secondary:hover {
  border-color: var(--line-strong);
  background: var(--surface);
}
.btn-ghost {
  color: var(--ink-soft);
}
.btn-ghost:hover {
  background: var(--line-soft);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}
.btn-sm {
  height: 30px;
  padding: 0 10px;
  font-size: 12.5px;
}
.btn-lg {
  height: 44px;
  padding: 0 20px;
  font-size: 14px;
}
.btn-icon {
  width: 36px;
  padding: 0;
  justify-content: center;
}
.btn-icon.btn-sm {
  width: 30px;
}

/* ─── Badges (estado) ─── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px 3px 7px;
  border-radius: 100px;
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
}
.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.8;
  flex-shrink: 0;
}
.badge-firmado {
  background: var(--status-firmado-bg);
  color: var(--status-firmado-fg);
}
.badge-pendiente {
  background: var(--status-pendiente-bg);
  color: var(--status-pendiente-fg);
}
.badge-borrador {
  background: var(--status-borrador-bg);
  color: var(--status-borrador-fg);
}
.badge-vencido {
  background: var(--status-vencido-bg);
  color: var(--status-vencido-fg);
}

/* ─── Inputs ─── */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.field-label {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-muted);
  letter-spacing: 0.02em;
}
.field-label-req::after {
  content: " *";
  color: var(--accent);
}
.field-hint {
  font-size: 11px;
  color: var(--ink-faint);
}
.input,
.select,
.textarea {
  height: var(--field-h);
  border: 1px solid var(--line);
  background: var(--surface-elev);
  border-radius: var(--r-md);
  padding: 0 11px;
  font-size: 13.5px;
  color: var(--ink);
  outline: none;
  font-family: inherit;
  width: 100%;
  min-width: 0;
}
.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--ink-soft);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.03);
}
.input::placeholder {
  color: var(--ink-faint);
}
.textarea {
  height: auto;
  padding: 9px 11px;
  min-height: 76px;
  resize: vertical;
  line-height: 1.45;
}
.select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'><path d='M2.5 4.5l3.5 3.5 3.5-3.5' stroke='%236b6457' stroke-width='1.4' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 11px center;
  padding-right: 30px;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.field-row-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.field-row-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

/* ─── Card / sections ─── */
.card {
  background: var(--surface-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.card-hd {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-hd h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 500;
  letter-spacing: -0.005em;
}
.card-hd-actions {
  display: flex;
  gap: 6px;
}
.card-bd {
  padding: 18px;
}
.card-bd-tight {
  padding: 0;
}

/* ─── Tables ─── */
.tbl-wrap {
  background: var(--surface-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
}

/* Menú de acciones por fila (kebab). El popover es position:fixed y se ubica
   por JS para no recortarse contra el overflow de la tabla. */
.row-menu {
  position: relative;
  display: inline-flex;
}
.row-menu-pop {
  position: fixed;
  z-index: 100;
  min-width: 160px;
  padding: 4px;
  background: var(--surface-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  display: none;
}
.row-menu-pop.is-open {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.row-menu-pop a,
.row-menu-pop button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  font-family: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.row-menu-pop a:hover,
.row-menu-pop button:hover {
  background: var(--line-soft);
}
.row-menu-danger {
  color: var(--danger);
}
.row-menu-danger:hover {
  background: rgba(185, 28, 28, 0.08);
}
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.tbl thead th {
  text-align: left;
  font-weight: 500;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  padding: 12px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.tbl tbody td {
  padding: 0 14px;
  height: var(--row-h);
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
.tbl tbody tr:last-child td {
  border-bottom: 0;
}
.tbl tbody tr:hover {
  background: var(--surface);
  cursor: default;
}
.tbl tbody tr.is-active {
  background: var(--accent-soft);
}
.tbl th.num,
.tbl td.num {
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.tbl-folio {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--ink-soft);
}
.tbl-name {
  font-weight: 500;
  color: var(--ink);
}
.tbl-sub {
  font-size: 12px;
  color: var(--ink-muted);
  margin-top: 1px;
}
.tbl-stack {
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1.3;
}

/* ─── Filter bar ─── */
.filterbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.filterbar-search {
  position: relative;
  flex: 1;
  min-width: 240px;
  max-width: 420px;
}
.filterbar-search input {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  background: var(--surface-elev);
  border-radius: var(--r-md);
  padding: 0 12px 0 34px;
  font-size: 13px;
  outline: none;
  color: var(--ink);
}
.filterbar-search input:focus {
  border-color: var(--ink-soft);
}
.filterbar-search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-faint);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 11px;
  height: 30px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface-elev);
  font-size: 12.5px;
  color: var(--ink-soft);
}
.chip:hover {
  border-color: var(--line-strong);
}
.chip.is-active {
  border-color: var(--ink-soft);
  color: var(--ink);
  background: var(--surface);
}
.chip-x {
  color: var(--ink-faint);
  margin-left: 2px;
}
.chip-x:hover {
  color: var(--ink);
}

/* ─── Page header (lista) ─── */
.page-hd {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 22px;
  gap: 18px;
}
.page-hd-title {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 500;
  letter-spacing: -0.015em;
  margin: 0 0 4px;
  color: var(--ink);
}
.page-hd-sub {
  color: var(--ink-muted);
  font-size: 13.5px;
}
.page-hd-actions {
  display: flex;
  gap: 8px;
}

/* ─── Stat cards ─── */
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}
.stat {
  background: var(--surface-elev);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 14px 16px;
}
.stat-label {
  font-size: 11.5px;
  color: var(--ink-muted);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-weight: 500;
}
.stat-value {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 500;
  letter-spacing: -0.01em;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.stat-delta {
  font-size: 11.5px;
  color: var(--ink-muted);
  margin-top: 2px;
}
.stat-delta b {
  color: var(--status-firmado-fg);
  font-weight: 500;
}

/* ─── Misc ─── */
.divider {
  height: 1px;
  background: var(--line-soft);
  margin: 14px 0;
}
.muted {
  color: var(--ink-muted);
}
.file-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-elev);
  text-decoration: none;
  color: var(--ink);
  font-size: 13px;
}
.file-link:hover {
  border-color: var(--line-strong);
}
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--r-lg);
  font-size: 13px;
  z-index: 1000;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  white-space: pre-wrap;
  word-break: break-all;
}
.alert-ok {
  background: var(--status-firmado-bg);
  color: var(--status-firmado-fg);
  border-radius: var(--r-md);
  padding: 10px 14px;
  font-size: 13px;
}
.field-label-note {
  font-size: 10px;
  color: var(--ink-faint);
  font-weight: 400;
}
.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.amount {
  font-variant-numeric: tabular-nums;
}
/* Empty state */
.empty {
  padding: 42px 20px;
  text-align: center;
  color: var(--ink-muted);
  font-size: 13px;
}

/* Pagination */
.pagi {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  font-size: 12.5px;
  color: var(--ink-muted);
}
.pagi-nav {
  display: flex;
  gap: 4px;
}
.pagi-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  min-width: 28px;
  padding: 0 8px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface-elev);
  font-size: 12px;
  color: var(--ink-soft);
  text-decoration: none;
  line-height: 1;
}
.pagi-btn.is-active {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}
.pagi-btn:hover:not(.is-active) {
  border-color: var(--line-strong);
}

/* ─── Mobile brand (visible only on small screens) ─── */
.mobile-brand {
  display: none;
}

/* ─── Responsive: mobile breakpoint ─── */
@media (max-width: 768px) {
  /* App shell: single column, sidebar hidden */
  .app {
    grid-template-columns: 1fr;
  }
  .sb {
    display: none;
  }

  /* Show mobile brand bar */
  .mobile-brand {
    display: flex;
    align-items: center;
    height: 48px;
    padding: 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    font-family: var(--font-display);
    font-size: 15px;
    font-weight: 500;
    letter-spacing: -0.005em;
    color: var(--ink);
    position: sticky;
    top: 0;
    z-index: 10;
  }

  /* Topbar adjustments */
  .topbar {
    padding: 0 12px;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    height: auto;
    min-height: 52px;
  }
  .topbar-crumb {
    font-size: 12px;
  }
  .topbar-meta {
    display: none;
  }
  .hide-mobile {
    display: none;
  }
  .show-mobile {
    display: inline-flex;
  }

  /* Content padding */
  .content,
  .form-shell {
    padding: 16px 14px;
  }

  /* Field grids: single column */
  .field-row,
  .field-row-3,
  .field-row-4 {
    grid-template-columns: 1fr;
  }

  /* Override field-row span-2 on mobile so they don't overflow */
  .field-row [style*="grid-column:span 2"],
  .field-row [style*="grid-column: span 2"] {
    grid-column: span 1;
  }

  /* Stats: 2x2 grid */
  .stats {
    grid-template-columns: 1fr 1fr;
  }

  /* Form checks: 2 columns */
  .form-checks {
    grid-template-columns: 1fr;
  }

  /* Date/time inputs: prevent native picker from overflowing */
  .field {
    overflow: hidden;
    min-width: 0;
  }
  .input,
  .select,
  .textarea {
    box-sizing: border-box;
    max-width: 100%;
  }

  /* Preview page: sin padding lateral para maximizar ancho */
  .preview-body {
    padding: 16px 0;
    align-items: flex-start;
  }

  /* Detail layout: stacked, PDF panel hidden */
  .detail {
    display: flex;
    flex-direction: column;
    gap: 16px;
    grid-template-columns: unset;
    min-height: unset;
  }
  .detail-pdf {
    display: none;
  }
  .detail-side {
    border-left: none;
    border-top: 1px solid var(--line);
    max-height: none;
    overflow-y: visible;
  }

  /* Table: horizontal scroll */
  .tbl-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Signature canvas: taller on mobile for easier signing */
  .sig-canvas {
    min-height: 200px;
  }

  /* Touch targets: 44px minimum (WCAG 2.5.5) */
  .btn {
    height: 44px;
    padding: 0 18px;
  }
  .btn-sm {
    height: 44px;
    padding: 0 14px;
    font-size: 13px;
  }
  .btn-icon {
    width: 44px;
    padding: 0;
  }
  .btn-icon.btn-sm {
    width: 44px;
    height: 44px;
  }
  .chip {
    height: 44px;
    padding: 0 16px;
  }
  .pagi-btn {
    height: 44px;
    min-width: 44px;
  }
  .topbar {
    min-height: 60px;
    height: auto;
    padding: 8px 12px;
    gap: 6px;
  }

  /* iOS: prevent auto-zoom on input focus (requires font-size >= 16px) */
  .input,
  .select,
  .textarea {
    font-size: 16px;
    height: 48px;
  }

  /* Paper contract: scrollable on mobile */
  .paper {
    padding: 24px 20px;
    min-width: 520px;
  }
  .paper-hd-contact {
    white-space: normal;
  }
  .paper-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .paper-checks {
    grid-template-columns: repeat(2, 1fr);
  }
  .paper-totals {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .paper-signs {
    gap: 16px;
  }
}

/* ── Transiciones interactivas ───────────────────────────────────────────── */
.btn,
.sb-item,
.chip,
.form-check,
.pagi-btn {
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease,
    opacity 0.15s ease;
}

/* ── Puntos de carga ─────────────────────────────────────────────────────── */
@keyframes dotBounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.3;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}
.ldots {
  display: inline-flex;
  gap: 3px;
  align-items: center;
  vertical-align: middle;
  margin-left: 3px;
}
.ldots span {
  display: inline-block;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  animation: dotBounce 1.2s ease-in-out infinite;
}
.ldots span:nth-child(2) {
  animation-delay: 0.2s;
}
.ldots span:nth-child(3) {
  animation-delay: 0.4s;
}

/* ── Toast de advertencia ────────────────────────────────────────────────── */
.toast-warn {
  background: var(--accent);
  color: #fff;
}

/* ── Errores de formulario ───────────────────────────────────────────────── */
.form-error-banner {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  border-radius: var(--r-md);
  color: #991b1b;
  font-size: 13px;
  padding: 12px 16px;
  margin-bottom: 20px;
}
.field-error {
  font-size: 11.5px;
  color: var(--danger, #b91c1c);
  margin-top: 3px;
}
.field-error ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

/* ── Tabla — fila completa clickeable ─────────────────────────────────────── */
.tbl-row-link-row,
.tbl-row-link-row td {
  cursor: pointer;
}
.tbl-row-link {
  color: inherit;
}

/* ── Hamburger / sidebar drawer mobile ───────────────────────────────────── */
.sb-close {
  display: none;
}
.sb-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  z-index: 149;
  cursor: pointer;
}
.sb-overlay.sb-open {
  display: block;
}

@media (max-width: 768px) {
  /* El encabezado de pantalla es flex en fila: con acciones al lado (Reportes
     y Lista), el botón de la derecha se salía del borde en un teléfono. */
  .page-hd {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .page-hd-actions {
    width: 100%;
    flex-wrap: wrap;
  }
}

@media (max-width: 768px) {
  .sb.sb-open {
    display: flex !important;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 150;
    width: 232px;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.18);
  }
  .sb-close {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    background: none;
    border: none;
    padding: 4px;
    color: var(--ink-muted);
    cursor: pointer;
    border-radius: var(--r-sm);
  }
  .sb-close:hover {
    background: var(--line-soft);
    color: var(--ink);
  }
  .sb-collapse {
    display: none;
  }
  .mobile-brand {
    gap: 10px;
  }
}

/* ═══════════════════════════════════════════════════════════
   Diseño aplicado — Tabs, avatares, Reportes (charts), Configuración
   Portado desde el mockup de referencia (src/) sobre la base
   responsive/branding existente. Módulos que antes no existían.
   ═══════════════════════════════════════════════════════════ */

/* ─── Contenido a ancho completo ─── */
.content-wide {
  padding: 0;
}

/* ─── Topbar search ─── */
.topbar-search {
  position: relative;
  width: 320px;
}
.topbar-search input {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  background: var(--surface-elev);
  border-radius: var(--r-md);
  padding: 0 12px 0 34px;
  font-size: 13px;
  outline: none;
  color: var(--ink);
}
.topbar-search input::placeholder {
  color: var(--ink-faint);
}
.topbar-search input:focus {
  border-color: var(--ink-soft);
}
.topbar-search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-faint);
}

/* ─── Tabs ─── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
}
.tab {
  padding: 9px 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  font-size: 13px;
  color: var(--ink-muted);
  margin-bottom: -1px;
}
.tab:hover {
  color: var(--ink);
}
.tab.is-active {
  border-bottom-color: var(--accent);
  color: var(--ink);
  font-weight: 500;
}

/* ─── Avatar helper ─── */
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12.5px;
  font-weight: 600;
  flex-shrink: 0;
  background: var(--accent-soft);
  color: var(--accent);
}
.avatar-sm {
  width: 28px;
  height: 28px;
  font-size: 11px;
}
.avatar-lg {
  width: 56px;
  height: 56px;
  font-size: 19px;
  font-family: var(--font-display);
  font-weight: 500;
}

/* ─── Responsive para los módulos nuevos ─── */
@media (max-width: 768px) {
  .rep-span-8,
  .rep-span-6,
  .rep-span-4,
  .rep-span-12 {
    grid-column: span 12;
  }
  .cfg-layout {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .cfg-nav {
    position: static;
    flex-direction: row;
    overflow-x: auto;
  }
  .topbar-search {
    width: auto;
    flex: 1;
    min-width: 0;
  }
}

/* ─── Banners de aviso ─────────────────────────────────────────
   Las tres franjas que aparecen sobre el contenido (fin de período, correo
   sin verificar y mensajes). Estaban con los estilos escritos a mano en el
   atributo style de cada una.
   ─────────────────────────────────────────────────────────── */
.banner {
  position: relative;
  padding: 10px 20px;
  font-size: 13px;
  text-align: center;
  font-family: inherit;
}
.banner-pago {
  background: #7a3a1a;
  color: #fff;
}
.banner-email {
  background: #7a5a14;
  color: #fff;
}
.banner-msg {
  background: var(--surface-elev);
  color: var(--ink);
  border-bottom: 1px solid var(--line);
}
.banner-link {
  color: inherit;
  text-decoration: underline;
}
.banner-form {
  display: inline;
}
.banner-link-btn {
  background: none;
  border: 0;
  padding: 0 2px;
  font: inherit;
  cursor: pointer;
}
.banner-cerrar {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: 0;
  padding: 0 4px;
  color: inherit;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.8;
}
.banner-cerrar:hover {
  opacity: 1;
}

/* ─── Pantallas de estado a página completa ────────────────────
   Servicio suspendido, cuenta cerrada: una tarjeta centrada y nada más.
   ─────────────────────────────────────────────────────────── */
.pantalla-centrada {
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.pantalla-centrada-card {
  max-width: 460px;
  width: 100%;
  text-align: center;
}
.pantalla-centrada-bd {
  padding: 52px 44px;
}
.pantalla-centrada-mark {
  width: 52px;
  height: 52px;
  font-size: 24px;
  margin: 0 auto 28px;
}
.pantalla-centrada-icono {
  font-size: 36px;
  margin-bottom: 16px;
}
.pantalla-centrada-titulo {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  color: var(--accent);
  margin: 0 0 12px;
}
.pantalla-centrada-texto {
  font-size: 14px;
  line-height: 1.7;
}
.pantalla-centrada-acciones {
  margin-top: 26px;
}
.pantalla-centrada-divisor {
  margin: 28px 0;
}
.pantalla-centrada-pie {
  font-size: 13px;
  line-height: 1.8;
}
.pantalla-centrada-pie b {
  color: var(--ink);
  display: block;
  margin-bottom: 2px;
}
