:root {
  color-scheme: light;
  --bg: #f4f5f5;
  --surface: #ffffff;
  --text: #1c2628;
  --muted: #566568;
  --line: #dce1e2;
  --line-strong: #c3cbcd;
  --accent: #0d5457;
  --accent-dark: #093e40;
  --accent-soft: #e4f0f0;
  --red: #a4231a;
  --red-soft: #fbe7e4;
  --amber: #7d5200;
  --amber-soft: #fbefd2;
  --green: #1a6538;
  --green-soft: #e1f2e7;
  --gray: #4c585b;
  --gray-soft: #e9ecec;
  --blue: #1f4f86;
  --blue-soft: #e4edf8;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
a:hover { color: var(--accent-dark); }
h1 { font-size: 1.4rem; line-height: 1.25; margin: 0; }
h2 { font-size: 1.02rem; margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
main:focus { outline: none; }

/* Barra superior */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 20px;
  background: var(--accent); color: #fff; padding: 8px 20px;
}
.brand { color: #fff; font-weight: 650; text-decoration: none; white-space: nowrap; }
.brand:hover { color: #fff; }
.nav { display: flex; gap: 2px; flex: 1 1 auto; overflow-x: auto; }
.nav a {
  color: #dcecec; text-decoration: none; padding: 6px 10px; border-radius: 5px; white-space: nowrap;
}
.nav a:hover { color: #fff; background: rgba(255, 255, 255, .1); }
.nav a[aria-current="page"] { color: #fff; background: var(--accent-dark); font-weight: 600; }
.nav a:focus-visible, .topbar .brand:focus-visible, .session .btn:focus-visible { outline-color: #fff; }
.session { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.who { font-size: .9rem; color: #dcecec; }
.session .btn { background: transparent; border-color: rgba(255, 255, 255, .5); color: #fff; }
.session .btn:hover { background: rgba(255, 255, 255, .12); }

/* Estructura */
.page { max-width: 1240px; margin: 0 auto; padding: 20px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 14px; }
.page-head .actions { margin-left: auto; }
.title-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; margin-bottom: 14px; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.state-msg { color: var(--muted); padding: 18px 4px; margin: 0; }
.empty { color: var(--muted); padding: 12px 2px; margin: 0; }

/* Banner */
.banner {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  max-width: 1200px; margin: 14px auto 0; padding: 10px 14px; border-radius: 6px;
  background: var(--red-soft); color: var(--red); border: 1px solid #eebdb7; font-weight: 500;
}
.banner.ok { background: var(--green-soft); color: var(--green); border-color: #b5dcc3; }
.banner button { background: none; border: 0; color: inherit; font: inherit; cursor: pointer; text-decoration: underline; padding: 0; }

/* Botones */
.btn {
  display: inline-block; font: inherit; font-size: .92rem; line-height: 1.3; text-decoration: none; cursor: pointer;
  background: var(--surface); color: var(--text); border: 1px solid var(--line-strong); border-radius: 6px; padding: 7px 12px;
}
.btn:hover { background: #eef1f1; color: var(--text); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); color: #fff; }
.btn-danger { color: var(--red); border-color: #dfa9a2; }
.btn-danger:hover { background: var(--red-soft); color: var(--red); }
.btn-small { padding: 4px 9px; font-size: .84rem; }
.btn[disabled] { opacity: .55; cursor: default; }

/* Indicadores */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 14px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px; }
.tile .label { color: var(--muted); font-size: .86rem; }
.tile .value { font-size: 1.5rem; font-weight: 650; line-height: 1.3; font-variant-numeric: tabular-nums; }
.tile .sub { color: var(--muted); font-size: .82rem; }
.tile.alert .value { color: var(--red); }

/* Tablas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; white-space: nowrap; background: #fafbfb; }
tbody tr:hover { background: #f7f9f9; }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.row-actions { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.row-cancelled td { color: var(--muted); }
.row-cancelled td:not(.keep) { text-decoration: line-through; }
.row-cancelled td a { color: var(--muted); }
.total-row td { font-weight: 650; border-top: 2px solid var(--line-strong); }

/* Etiquetas de estado */
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: .78rem; font-weight: 600;
  white-space: nowrap; border: 1px solid transparent; text-decoration: none;
}
.b-red { background: var(--red-soft); color: var(--red); border-color: #eebdb7; }
.b-amber { background: var(--amber-soft); color: var(--amber); border-color: #e9d291; }
.b-green { background: var(--green-soft); color: var(--green); border-color: #b5dcc3; }
.b-blue { background: var(--blue-soft); color: var(--blue); border-color: #bcd0ea; }
.b-teal { background: var(--accent-soft); color: var(--accent); border-color: #b5d3d3; }
.b-gray { background: var(--gray-soft); color: var(--gray); border-color: #cfd5d6; }

/* Formularios */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; }
.filters .grow { flex: 1 1 220px; }
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field label { font-size: .84rem; font-weight: 600; color: #36444a; }
.req { color: var(--red); margin-left: 2px; }
.help { color: var(--muted); font-size: .8rem; }
input, select, textarea {
  font: inherit; color: var(--text); background: #fff; width: 100%;
  border: 1px solid var(--line-strong); border-radius: 6px; padding: 7px 9px;
}
textarea { min-height: 70px; resize: vertical; }
input[type="checkbox"] { width: auto; margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 14px; }
.span-all { grid-column: 1 / -1; }
.check-field { flex-direction: row; align-items: center; gap: 8px; align-self: end; min-height: 36px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding-top: 10px; }

/* Ficha */
.dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px 16px; margin: 0; }
.dl > div { min-width: 0; }
.dl dt { color: var(--muted); font-size: .78rem; font-weight: 600; }
.dl dd { margin: 0; overflow-wrap: anywhere; white-space: pre-line; }
.audit-list summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.audit-changes { font-size: .82rem; overflow-wrap: anywhere; }
.audit-changes div { margin-bottom: 2px; }
.plain-list { list-style: none; margin: 0; padding: 0; }
.plain-list li { padding: 3px 0; }

/* Nuevo pago */
.pay-layout { max-width: 780px; }
.picked { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 9px 12px; background: var(--accent-soft); border-radius: 6px; }
.typeahead { list-style: none; margin: 6px 0 0; padding: 0; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.typeahead:empty { display: none; }
.typeahead button {
  display: block; width: 100%; text-align: left; font: inherit; background: #fff; border: 0;
  border-bottom: 1px solid var(--line); padding: 8px 10px; cursor: pointer;
}
.typeahead li:last-child button { border-bottom: 0; }
.typeahead button:hover, .typeahead button:focus-visible { background: var(--accent-soft); }
.charge-check { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.charge-check:last-child { border-bottom: 0; }
.charge-check .grow { flex: 1 1 auto; min-width: 0; }
.charge-check input { flex: none; width: 18px; height: 18px; }
.charge-order {
  flex: none; width: 20px; height: 20px; line-height: 20px; text-align: center; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: .74rem; font-weight: 700;
}
.charge-order:empty { background: transparent; }
.hint { padding: 8px 12px; border-radius: 6px; background: var(--accent-soft); color: var(--accent-dark); font-size: .9rem; margin: 0; }
.hint.warn { background: var(--amber-soft); color: var(--amber); }

/* Recibo */
.receipt { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 24px 28px; max-width: 760px; margin: 0 auto 14px; }
.receipt-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px 20px; border-bottom: 2px solid var(--accent); padding-bottom: 12px; margin-bottom: 16px; }
.receipt-org { font-weight: 700; color: var(--accent); font-size: 1.1rem; }
.receipt-folio { text-align: right; }
.receipt-folio strong { display: block; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.receipt-amount { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; margin: 14px 0; }
.receipt h2 { margin: 18px 0 6px; }
.receipt-note { color: var(--muted); font-size: .82rem; border-top: 1px solid var(--line); margin: 20px 0 0; padding-top: 10px; }
.cancel-box { background: var(--red-soft); color: var(--red); border: 1px solid #eebdb7; border-radius: 6px; padding: 9px 12px; margin-bottom: 14px; font-weight: 500; overflow-wrap: anywhere; }
.struck { text-decoration: line-through; color: var(--muted); }

/* Acceso */
.login-wrap { max-width: 360px; margin: 8vh auto 0; }
.login-title { color: var(--accent); margin: 0 0 16px; font-size: 1.25rem; }
.login-wrap form { display: grid; gap: 12px; }

/* Diálogos */
dialog { border: 1px solid var(--line-strong); border-radius: 10px; padding: 18px 20px; width: min(440px, calc(100vw - 32px)); color: var(--text); }
dialog::backdrop { background: rgba(20, 30, 32, .45); }
dialog form { display: grid; gap: 12px; }
dialog h2 { font-size: 1.1rem; }
dialog p { margin: 0; }
.dialog-error { color: var(--red); font-weight: 500; font-size: .9rem; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

@media (max-width: 640px) {
  .topbar { padding: 8px 12px; }
  .nav { order: 3; flex-basis: 100%; }
  .page { padding: 14px 12px; }
  .banner { margin: 10px 12px 0; }
  .page-head .actions { margin-left: 0; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .tile { padding: 10px 12px; }
  .tile .value { font-size: 1.18rem; }
  .filters > .field { flex: 1 1 100%; }
  .filters > .field.half { flex: 1 1 calc(50% - 6px); }
  .form-grid, .dl { grid-template-columns: 1fr; }
  .dl { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  input, select, textarea { font-size: 16px; }
  .btn { padding: 9px 12px; }
  .btn-small { padding: 6px 10px; }
  .receipt { padding: 16px; }
}

@media print {
  @page { margin: 14mm; }
  body { background: #fff; font-size: 12px; color: #000; }
  .no-print, .topbar, .banner, dialog, details { display: none !important; }
  .page { max-width: none; padding: 0; }
  .card, .receipt, .tile { border: 0; padding: 0; margin: 0 0 12px; max-width: none; break-inside: avoid-page; }
  .table-wrap { overflow: visible; }
  th { background: none; }
  a { color: inherit; text-decoration: none; }
  .badge { border-color: #666; background: none !important; color: #000 !important; }
  .cancel-box { background: none; color: #000; border: 2px solid #000; }
  .dl { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  tr { break-inside: avoid; }
}
