:root {
  --bg: #201c16;
  --bg2: #2a2620;
  --card: rgba(50, 45, 38, 0.92);
  --card-2: #262219;
  --line: rgba(255, 255, 255, 0.09);
  --text: #f1ede4;
  --muted: #a89e8c;
  --accent: #c8862f;
  --accent-contrast: #201a10;
  --success: #7fd4a0;
  --danger: #e5484d;
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-size: 12px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(200, 134, 47, 0.08), transparent 32%),
    radial-gradient(circle at bottom right, rgba(127, 212, 160, 0.04), transparent 28%),
    var(--bg);
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: linear-gradient(rgba(255,255,255,0.035) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,0.035) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: radial-gradient(circle at center, black 35%, transparent 100%);
  pointer-events: none;
}

.shell {
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 32px;
}

.shell .panel {
  width: 100%;
  max-width: 420px;
}

.hero, .panel {
  border: 1px solid var(--line);
  background: var(--card);
  backdrop-filter: blur(18px);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
}

.hero {
  border-radius: 28px;
  padding: 40px;
  min-height: 620px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.brand {
  width: fit-content;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(200, 134, 47, 0.12);
  border: 1px solid rgba(200, 134, 47, 0.3);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--accent);
}

.brand.brand-logo-wrap {
  width: 100%;
  max-width: 170px;
  margin: 0 auto;
  padding: 10px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.75);
}

.brand-logo {
  display: block;
  width: 100%;
  height: auto;
}

.powered-by {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
}

.powered-by span {
  font-size: 10px;
  font-style: italic;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
  white-space: nowrap;
}

.powered-by-logo {
  height: 116px;
  width: auto;
  display: block;
  filter: drop-shadow(0 3px 10px rgba(200, 134, 47, 0.25));
}

.hero h1 {
  font-size: clamp(3rem, 6vw, 5.4rem);
  line-height: 0.95;
  margin: 0;
  max-width: 10ch;
}

.hero p {
  max-width: 54ch;
  font-size: 1.05rem;
  color: var(--muted);
  line-height: 1.7;
}

.hero-card {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-top: 24px;
}

.hero-card > div, .panel {
  border-radius: 24px;
}

.hero-card > div {
  padding: 18px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.09);
}

.kicker, .eyebrow {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  margin-bottom: 8px;
}

.panel {
  padding: 32px;
}

.panel-header h2 {
  margin: 0 0 10px;
  font-size: 2rem;
}

.panel-header p {
  margin: 0 0 24px;
  color: var(--muted);
  line-height: 1.6;
}

.login-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

.login-panel .login-logo {
  margin: 0;
}

.login-panel .panel-header {
  text-align: center;
}

.login-panel .panel-header p {
  margin: 0;
}

.login-panel .form {
  width: 100%;
}

.login-panel .powered-by {
  flex-direction: row;
  gap: 12px;
}

.login-powered-logo {
  height: 100px;
}

.form {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 8px;
  font-size: 0.95rem;
  color: var(--text);
}

input:not([type="checkbox"], [type="radio"]),
select {
  width: 100%;
  min-width: 0;
  padding: 16px 18px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: var(--card-2);
  color: var(--text);
  outline: none;
  font-size: 1rem;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
}

input:disabled,
select:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

input:focus,
select:focus {
  border-color: rgba(200, 134, 47, 0.75);
  box-shadow: 0 0 0 4px rgba(200, 134, 47, 0.18);
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 22px) calc(50% - 2px), calc(100% - 16px) calc(50% - 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 36px;
}

button {
  margin-top: 6px;
  padding: 15px 18px;
  border: 0;
  border-radius: 16px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

button:disabled {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.35);
  cursor: not-allowed;
}

.links {
  display: flex;
  gap: 16px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.links a {
  color: var(--muted);
  text-decoration: none;
}

.links a:hover {
  color: var(--text);
}

.status-ok { color: var(--success); }
.status-error { color: var(--danger); }

.dashboard-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 320px 1fr;
  align-items: start;
  gap: 24px;
  padding: 24px;
}

.sidebar,
.content,
.timeline-panel {
  border: 1px solid var(--line);
  background: var(--card);
  backdrop-filter: blur(18px);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
}

.sidebar {
  border-radius: 28px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  position: sticky;
  top: 24px;
}

.sidebar-toggle {
  display: none;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.sidebar-collapsible {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.sidebar h1,
.topbar h1,
.content-hero h2,
.timeline-panel h3 {
  margin: 0;
}

#sessionInfo {
  margin: 14px 0 0;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}

.menu-grid {
  display: grid;
  gap: 6px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text);
  padding: 9px 16px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
  transition: border-color 0.15s ease, background-color 0.15s ease, transform 0.15s ease;
}

.menu-item:hover {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  transform: translateX(2px);
}

.menu-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  color: var(--muted);
  transition: color 0.15s ease;
}

.menu-icon svg {
  width: 100%;
  height: 100%;
}

.menu-item.active {
  border-color: rgba(200, 134, 47, 0.4);
  background: rgba(200, 134, 47, 0.14);
  box-shadow: inset 0 0 0 1px rgba(200, 134, 47, 0.2);
}

.menu-item.active .menu-icon {
  color: var(--accent);
}

.menu-item.active span,
.menu-item.active strong {
  color: #f2c281;
}

.menu-item span {
  color: var(--muted);
  font-size: 0.85rem;
}

.menu-item strong {
  font-size: 1rem;
}

.logout-btn {
  width: 100%;
}

.content {
  border-radius: 28px;
  padding: 28px;
  display: grid;
  gap: 24px;
}

.dashboard-module-host {
  grid-template-rows: auto 1fr;
  min-height: calc(100vh - 48px);
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.content-hero.compact {
  align-items: center;
}

.content-hero.compact h2 {
  margin-top: 8px;
}

.module-frame-wrap {
  border-radius: 0;
  border: 0;
  overflow: hidden;
  background: transparent;
  min-height: 0;
}

#moduleFrame {
  width: 100%;
  height: 680px;
  min-height: 680px;
  border: 0;
  display: block;
  overflow: hidden;
}

.content-hero {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
}

.content-hero p,
.timeline span,
.dashboard-card p {
  color: var(--muted);
  line-height: 1.6;
}

.status-chip {
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(127, 212, 160, 0.4);
  color: var(--success);
  background: rgba(127, 212, 160, 0.12);
  font-size: 0.9rem;
  white-space: nowrap;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.dashboard-card {
  padding: 20px;
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  min-height: 180px;
}

.dashboard-card span {
  display: block;
  margin-bottom: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.8rem;
}

.dashboard-card strong {
  display: block;
  font-size: 1.3rem;
  margin-bottom: 10px;
}

.accent-a { background: linear-gradient(145deg, rgba(200, 134, 47, 0.16), rgba(255,255,255,0.02)); }
.accent-b { background: linear-gradient(145deg, rgba(127, 212, 160, 0.14), rgba(255,255,255,0.02)); }
.accent-c { background: linear-gradient(145deg, rgba(229, 72, 77, 0.14), rgba(255,255,255,0.02)); }

.timeline-panel {
  border-radius: 24px;
  padding: 24px;
}

.timeline {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.timeline > div {
  padding: 16px 18px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.09);
}

.timeline strong {
  display: block;
  margin-bottom: 4px;
}

.page-shell {
  min-height: 100vh;
  padding: 24px;
}

body.embedded-module .page-shell {
  min-height: auto;
  padding: 0;
}

body.embedded-module .page-layout {
  max-width: none;
  margin: 0;
  gap: 12px;
}

.page-layout {
  max-width: 1360px;
  margin: 0 auto;
  display: grid;
  gap: 16px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  border: 1px solid var(--line);
  background: var(--card);
  backdrop-filter: blur(18px);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  border-radius: 28px;
  padding: 10px 20px;
}

.topbar-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.ghost-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  border-radius: 16px;
  color: var(--text);
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
}

.query-panel {
  border: 1px solid var(--line);
  background: var(--card);
  backdrop-filter: blur(18px);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
  border-radius: 28px;
  padding: 16px;
  display: grid;
  gap: 12px;
}

.query-panel h2 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text);
}

.backlog-list {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.backlog-list strong {
  color: var(--text);
}

.backlog-list code {
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.85em;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr)) auto;
  gap: 16px;
  align-items: end;
}

.toolbar > label,
.toolbar > .toolbar-actions {
  min-width: 0;
}

.toolbar-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.facturas-toolbar {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.facturas-toolbar .toolbar-actions {
  display: block;
}

.facturas-toolbar .toolbar-actions button {
  width: 100%;
  margin-top: 0;
}

.facturas-toolbar label {
  font-size: 0.88rem;
  gap: 6px;
}

.facturas-toolbar input {
  padding: 10px 12px;
  font-size: 0.9rem;
  border-radius: 12px;
}

.facturas-toolbar button {
  padding: 11px 14px;
  font-size: 0.88rem;
}

.recibos-toolbar {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.recibos-toolbar .toolbar-actions {
  display: block;
}

.recibos-toolbar .toolbar-actions button {
  width: 100%;
  margin-top: 0;
}

.recibos-toolbar label {
  font-size: 0.88rem;
  gap: 6px;
}

.recibos-toolbar input {
  padding: 10px 12px;
  font-size: 0.9rem;
  border-radius: 12px;
}

.recibos-toolbar button {
  padding: 11px 14px;
  font-size: 0.88rem;
}

.saldos-toolbar {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.saldos-toolbar .toolbar-actions {
  display: block;
}

.saldos-toolbar .toolbar-actions button {
  width: 100%;
  margin-top: 0;
}

.saldos-toolbar label {
  font-size: 0.88rem;
  gap: 6px;
}

.saldos-toolbar input {
  padding: 10px 12px;
  font-size: 0.9rem;
  border-radius: 12px;
}

.saldos-toolbar button {
  padding: 11px 14px;
  font-size: 0.88rem;
}

.date-field {
  position: relative;
}

.date-field::after {
  content: '';
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23a89e8c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='18' rx='2' ry='2'/%3E%3Cline x1='16' y1='2' x2='16' y2='6'/%3E%3Cline x1='8' y1='2' x2='8' y2='6'/%3E%3Cline x1='3' y1='10' x2='21' y2='10'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: contain;
  pointer-events: none;
  opacity: 0.7;
}

.date-field input[type="text"] {
  padding-right: 38px;
  cursor: pointer;
}

.file-field {
  position: relative;
}

.file-field input {
  padding-right: 34px;
}

.file-field input::-webkit-outer-spin-button,
.file-field input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.file-field input[type="number"] {
  -moz-appearance: textfield;
}

.file-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  margin: 0;
  padding: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  font-weight: 400;
  letter-spacing: normal;
  text-transform: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.file-clear:hover {
  background: rgba(255, 255, 255, 0.16);
  color: var(--text);
}

.export-btn {
  width: fit-content;
  margin-top: 8px;
  padding: 9px 16px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.export-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.filter-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  margin-bottom: 4px;
}

.filter-row label {
  font-size: 0.88rem;
  gap: 6px;
}

.filter-row input[type="text"] {
  max-width: 220px;
  padding: 10px 12px;
  font-size: 0.9rem;
  border-radius: 12px;
}

.filter-row-nombre {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
  flex: 0 1 160px;
  white-space: nowrap;
}

.filter-row-nombre input[type="text"] {
  flex: none;
  min-width: 120px;
  max-width: 160px;
  width: 160px;
}

.inline-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
}

.inline-checkbox input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin: 0;
  flex-shrink: 0;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: var(--card-2);
  cursor: pointer;
  position: relative;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.inline-checkbox input[type="checkbox"]:hover {
  border-color: rgba(255, 255, 255, 0.4);
}

.inline-checkbox input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.inline-checkbox input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 9px;
  border: solid var(--accent-contrast);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.filter-counts {
  font-size: 0.85rem;
  color: var(--muted);
}

.filter-counts strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.helper-text {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.helper-text:empty {
  display: none;
}

.helper-text.warning {
  color: #d9a441;
}

.table-panel {
  overflow: hidden;
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  background: var(--card-2);
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 16px 14px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  white-space: nowrap;
}

th {
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
}

th.sortable-col {
  cursor: pointer;
  user-select: none;
}

th.sortable-col:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
}

th.sortable-col::after {
  content: '';
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 6px;
  vertical-align: middle;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 5px solid currentColor;
  opacity: 0.3;
}

th.sortable-col.sort-desc::after {
  border-bottom: none;
  border-top: 5px solid currentColor;
}

th.sortable-col.sort-asc::after,
th.sortable-col.sort-desc::after {
  opacity: 0.9;
}

tbody tr:hover {
  background: rgba(200, 134, 47, 0.08);
}

tbody tr.row-alert {
  color: #ff8a80;
}

.facturas-grid {
  table-layout: fixed;
  width: 100%;
}

.facturas-grid th,
.facturas-grid td {
  white-space: nowrap;
  word-break: normal;
  overflow-wrap: normal;
  padding: 6px 10px;
}

.facturas-grid th:nth-child(1),
.facturas-grid td:nth-child(1) {
  width: 11%;
}

.facturas-grid th:nth-child(2),
.facturas-grid td:nth-child(2) {
  width: 7%;
}

.facturas-grid th:nth-child(3),
.facturas-grid td:nth-child(3) {
  width: 13%;
}

.facturas-grid th:nth-child(4),
.facturas-grid td:nth-child(4) {
  width: 8%;
}

.facturas-grid th:nth-child(5),
.facturas-grid td:nth-child(5) {
  width: 24%;
}

.facturas-grid th:nth-child(6),
.facturas-grid td:nth-child(6) {
  width: 13%;
}

.facturas-grid th:nth-child(7),
.facturas-grid td:nth-child(7) {
  width: 14%;
  text-align: center;
}

.facturas-grid th.ref-pax-col,
.facturas-grid td.ref-pax-cell {
  white-space: normal !important;
  overflow-wrap: anywhere !important;
  word-break: break-word !important;
  line-height: 1.25;
  max-width: 0;
}

.facturas-grid th.ref-pax-col {
  width: 20%;
}

.facturas-grid td.ref-pax-cell {
  font-size: 0.88rem;
}

.facturas-grid .entity-cell,
.facturas-grid .entidad-col {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}


.facturas-grid.entity-visible th:nth-child(1),
.facturas-grid.entity-visible td:nth-child(1) { width: 10%; }

.facturas-grid.entity-visible th:nth-child(2),
.facturas-grid.entity-visible td:nth-child(2) { width: 6%; }

.facturas-grid.entity-visible th:nth-child(3),
.facturas-grid.entity-visible td:nth-child(3) { width: 7%; }

.facturas-grid.entity-visible th:nth-child(4),
.facturas-grid.entity-visible td:nth-child(4) { width: 12%; }

.facturas-grid.entity-visible th:nth-child(5),
.facturas-grid.entity-visible td:nth-child(5) { width: 8%; }

.facturas-grid.entity-visible th:nth-child(6),
.facturas-grid.entity-visible td:nth-child(6) { width: 15%; }

.facturas-grid.entity-visible th:nth-child(7),
.facturas-grid.entity-visible td:nth-child(7) { width: 20%; }

.facturas-grid.entity-visible th:nth-child(8),
.facturas-grid.entity-visible td:nth-child(8) { width: 12%; }

.facturas-grid.entity-visible th:nth-child(9),
.facturas-grid.entity-visible td:nth-child(9) { width: 10%; text-align: center; }

.recibos-grid {
  table-layout: fixed;
  width: 100%;
}

.recibos-grid th,
.recibos-grid td {
  white-space: nowrap;
  word-break: normal;
  overflow-wrap: normal;
  padding: 6px 10px;
}

.recibos-grid th:nth-child(1),
.recibos-grid td:nth-child(1) {
  width: 13%;
}

.recibos-grid th:nth-child(2),
.recibos-grid td:nth-child(2) {
  width: 9%;
}

.recibos-grid th:nth-child(3),
.recibos-grid td:nth-child(3) {
  width: 15%;
}

.recibos-grid th:nth-child(4),
.recibos-grid td:nth-child(4) {
  width: 15%;
}

.recibos-grid th:nth-child(5),
.recibos-grid td:nth-child(5) {
  width: 9%;
  text-align: center;
}

.recibos-grid th:nth-child(6),
.recibos-grid td:nth-child(6) {
  width: 13%;
  text-align: right;
}

.recibos-grid th:nth-child(7),
.recibos-grid td:nth-child(7) {
  width: 12%;
}

.recibos-grid th:nth-child(8),
.recibos-grid td:nth-child(8) {
  width: 14%;
  text-align: center;
}

.recibos-grid th.recibos-files-col,
.recibos-grid td.recibos-files-cell {
  white-space: normal !important;
  overflow-wrap: anywhere !important;
  word-break: break-word !important;
  line-height: 1.25;
  max-width: 0;
}

.saldos-grid {
  table-layout: fixed;
  width: 100%;
}

.saldos-grid th,
.saldos-grid td {
  white-space: nowrap;
  word-break: normal;
  overflow-wrap: normal;
  padding: 12px 10px;
}

.saldos-grid th:nth-child(1),
.saldos-grid td:nth-child(1) {
  width: 10%;
}

.saldos-grid th:nth-child(2),
.saldos-grid td:nth-child(2) {
  width: 14%;
}

.saldos-grid th:nth-child(3),
.saldos-grid td:nth-child(3) {
  width: 46%;
}

.saldos-grid th:nth-child(4),
.saldos-grid td:nth-child(4) {
  width: 7%;
}

.saldos-grid th:nth-child(5),
.saldos-grid td:nth-child(5) {
  width: 9%;
}

.saldos-grid th:nth-child(6),
.saldos-grid td:nth-child(6) {
  width: 14%;
  text-align: center;
}

.saldos-grid th.saldos-nombre-col,
.saldos-grid td.saldos-nombre-cell {
  white-space: normal !important;
  overflow-wrap: anywhere !important;
  word-break: break-word !important;
  line-height: 1.35;
}

.liquidaciones-toolbar {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.liquidaciones-toolbar .toolbar-actions {
  display: block;
}

.liquidaciones-toolbar .toolbar-actions button {
  width: 100%;
  margin-top: 0;
}

.liquidaciones-toolbar label {
  font-size: 0.88rem;
  gap: 6px;
}

.liquidaciones-toolbar input {
  padding: 10px 12px;
  font-size: 0.9rem;
  border-radius: 12px;
}

.liquidaciones-toolbar button {
  padding: 11px 14px;
  font-size: 0.88rem;
}

.liquidaciones-grid {
  table-layout: auto;
  width: 100%;
}

.liquidaciones-grid th,
.liquidaciones-grid td {
  padding: 6px 8px;
  font-size: 0.88rem;
  white-space: nowrap;
}

.liquidaciones-grid th {
  font-size: 0.78rem;
}

.liquidaciones-grid .nombre-col,
.liquidaciones-grid .nombre-cell {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.25;
  min-width: 140px;
  max-width: 260px;
}

.liquidaciones-grid .moneda-col,
.liquidaciones-grid .moneda-cell {
  width: 64px;
  padding-right: 4px;
  text-align: right;
}

.liquidaciones-grid .total-col,
.liquidaciones-grid .total-cell {
  width: 90px;
  padding-left: 4px;
  text-align: right;
}

.liquidaciones-grid .vendedor-col,
.liquidaciones-grid .vendedor-cell {
  text-align: right;
}

.cell-muted {
  color: var(--muted);
}

.inline-button {
  margin: 0;
  padding: 10px 14px;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  border-radius: 12px;
}

.inline-button:disabled {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.35);
  cursor: not-allowed;
}

.status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.pager {
  display: flex;
  gap: 12px;
  align-items: center;
  width: var(--pager-width, auto);
}

.pager button {
  margin: 0;
  padding: 11px 14px;
  font-size: 0.88rem;
  flex: 1 1 0;
}

.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
}

.ghost-btn {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.ghost-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.usuarios-toolbar {
  grid-template-columns: minmax(0, 1fr) auto;
}

.usuarios-toolbar .toolbar-actions {
  display: flex;
  gap: 12px;
}

.usuarios-toolbar .toolbar-actions button {
  margin-top: 0;
}

.usuarios-grid {
  table-layout: auto;
  width: 100%;
}

.usuarios-grid th,
.usuarios-grid td {
  padding: 10px 12px;
  font-size: 0.9rem;
  white-space: nowrap;
}

.configuracion-toolbar {
  grid-template-columns: minmax(0, 220px) auto;
}

.configuracion-toolbar .toolbar-actions {
  display: flex;
  gap: 12px;
}

.configuracion-toolbar .toolbar-actions button {
  margin-top: 0;
}

.configuracion-grid {
  table-layout: auto;
  width: 100%;
}

.configuracion-grid th,
.configuracion-grid td {
  padding: 10px 12px;
  font-size: 0.9rem;
  white-space: nowrap;
}

.configuracion-grid .select-col {
  width: 40px;
  text-align: center;
}

.clientes-sin-compras-toolbar {
  grid-template-columns: minmax(0, 220px) auto;
}

.clientes-sin-compras-toolbar .toolbar-actions {
  display: flex;
  gap: 12px;
}

.clientes-sin-compras-toolbar .toolbar-actions button {
  margin-top: 0;
}

.clientes-sin-compras-grid {
  table-layout: auto;
  width: 100%;
}

.clientes-sin-compras-grid th,
.clientes-sin-compras-grid td {
  padding: 10px 12px;
  font-size: 0.9rem;
  white-space: nowrap;
}

.configuracion-grid input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.deuda-currency-block + .deuda-currency-block {
  margin-top: 20px;
}

.deuda-currency-block h2 {
  margin: 0 0 16px;
  font-size: 1.1rem;
}

.deuda-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.deuda-kpi {
  padding: 16px 18px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  background: rgba(255, 255, 255, 0.03);
}

.deuda-kpi span {
  display: block;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 10px;
}

.deuda-kpi strong {
  display: block;
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.deuda-kpi--danger { border-color: rgba(229, 72, 77, 0.35); }
.deuda-kpi--danger strong { color: var(--danger); }

.deuda-kpi--warning { border-color: rgba(217, 164, 65, 0.35); }
.deuda-kpi--warning strong { color: #d9a441; }

.deuda-kpi--good { border-color: rgba(127, 212, 160, 0.35); }
.deuda-kpi--good strong { color: var(--success); }

.deuda-kpi--total { border-color: rgba(200, 134, 47, 0.4); background: rgba(200, 134, 47, 0.08); }
.deuda-kpi--total strong { color: var(--accent); }

.deuda-bars {
  display: grid;
  gap: 10px;
  margin-bottom: 24px;
}

.deuda-bar-row {
  display: grid;
  grid-template-columns: 70px 1fr auto;
  align-items: center;
  gap: 12px;
}

.deuda-bar-label {
  font-size: 0.85rem;
  color: var(--muted);
}

.deuda-bar-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.deuda-bar-fill {
  height: 100%;
  border-radius: 999px;
}

.deuda-bar-fill--danger { background: var(--danger); }
.deuda-bar-fill--warning { background: #d9a441; }
.deuda-bar-fill--good { background: var(--success); }

.deuda-bar-value {
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  text-align: right;
  min-width: 130px;
}

.deudas-grid {
  table-layout: auto;
  width: 100%;
}

.deudas-grid th,
.deudas-grid td {
  padding: 10px 12px;
  font-size: 0.88rem;
  white-space: nowrap;
}

.deudas-grid td.amount {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.deudas-grid th.amount-col {
  text-align: right;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
}

.modal-panel {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 24px;
  border: 1px solid var(--line);
  background: var(--card-2);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
  padding: 28px;
}

.modal-panel h2 {
  margin: 0 0 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.modal-form .field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.modal-actions button {
  margin-top: 0;
  width: auto;
}

@media (max-width: 480px) {
  .modal-form .field-row {
    grid-template-columns: 1fr;
  }

  .modal-panel {
    padding: 20px;
  }
}

@media (max-width: 980px) {
  .dashboard-shell {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .deuda-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #moduleFrame {
    height: 240px;
    min-height: 240px;
  }

  .dashboard-module-host {
    min-height: auto;
  }

  .hero {
    min-height: auto;
  }

  .cards-grid {
    grid-template-columns: 1fr;
  }

  .content-hero {
    flex-direction: column;
  }

  .sidebar {
    padding: 14px 18px;
    gap: 0;
    top: 12px;
    z-index: 40;
  }

  .brand.brand-logo-wrap {
    max-width: 110px;
    margin: 0;
  }

  .sidebar-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .sidebar-toggle {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 4px;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.05);
  }

  .sidebar-toggle span {
    display: block;
    width: 18px;
    height: 2px;
    border-radius: 2px;
    background: var(--text);
    transition: transform 0.2s ease, opacity 0.2s ease;
  }

  .sidebar.open .sidebar-toggle span:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
  }

  .sidebar.open .sidebar-toggle span:nth-child(2) {
    opacity: 0;
  }

  .sidebar.open .sidebar-toggle span:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
  }

  .sidebar-collapsible {
    display: none;
  }

  .sidebar.open .sidebar-collapsible {
    display: flex;
    flex-direction: column;
    gap: 14px;
    position: absolute;
    top: calc(100% + 8px);
    left: auto;
    right: 0;
    width: min(300px, 85vw);
    padding: 18px;
    border-radius: 20px;
    border: 1px solid var(--line);
    background: var(--card);
    backdrop-filter: blur(18px);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
    z-index: 41;
    max-height: calc(100vh - 100px);
    overflow-y: auto;
  }

  #sessionInfo {
    margin-top: 0;
  }

  .menu-item {
    padding: 12px 16px;
  }

  .powered-by-logo {
    height: 52px;
  }
}

@media (max-width: 640px) {
  .shell {
    padding: 16px;
  }

  .hero, .panel {
    padding: 22px;
    border-radius: 20px;
  }

  .hero-card {
    grid-template-columns: 1fr;
  }

  .page-shell {
    padding: 16px;
  }

  .topbar,
  .query-panel {
    border-radius: 20px;
    padding: 20px;
  }

  .topbar,
  .topbar-actions,
  .toolbar,
  .toolbar-actions,
  .status-row,
  .pager {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  .brand.brand-logo-wrap {
    max-width: 180px;
  }

  /* iOS Safari hace zoom automático al enfocar inputs con font-size < 16px */
  input:not([type="checkbox"], [type="radio"]),
  select,
  .facturas-toolbar input,
  .recibos-toolbar input,
  .saldos-toolbar input,
  .liquidaciones-toolbar input {
    font-size: 16px;
  }

  .table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .facturas-grid,
  .recibos-grid,
  .saldos-grid {
    width: auto;
    min-width: 640px;
  }

  .liquidaciones-grid,
  .usuarios-grid,
  .configuracion-grid,
  .deudas-grid {
    min-width: 560px;
  }

  .deuda-kpi-grid {
    grid-template-columns: 1fr;
  }

  .deuda-bar-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .deuda-bar-value {
    text-align: left;
  }
}

@media (max-width: 420px) {
  .page-shell,
  .dashboard-shell {
    padding: 10px;
  }

  .topbar,
  .query-panel,
  .sidebar {
    padding: 14px;
    border-radius: 16px;
  }

  .powered-by-logo {
    height: 44px;
  }

  .login-powered-logo {
    height: 60px;
  }

  .login-panel .powered-by {
    flex-direction: column;
    gap: 6px;
  }
}