:root {
  --navy: #1e3a5f; --navy-2: #2c5282; --navy-3: #16304f; --bg: #f4f4f2; --card: #fff; --line: #e3e3df; --text: #1f2933; --muted: #6b7680;
  --ok: #1f7a4d; --ok-bg: #e5f4ec; --bad: #b42318; --bad-bg: #fdecea; --warn: #8a5a00; --warn-bg: #fdf3d8; --info: #1c5d99; --info-bg: #e3effa;
  --sb-w: 248px; --radius: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
a { color: var(--navy-2); }
h1 { font-size: 1.5rem; margin: 1.2rem 0 .8rem; line-height: 1.25; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .6rem; }
.card h2 { margin-top: 0; }
.icon { flex: none; }

/* ---------- Estructura ---------- */
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 24px 56px; }
.shell { min-height: 100vh; }
.with-nav .shell { margin-left: var(--sb-w); }

/* Barra lateral */
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sb-w); background: var(--navy); color: #d6e2f0; display: flex; flex-direction: column; z-index: 40; overflow-y: auto; }
.sb-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 16px 14px; }
.sb-brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; line-height: 1.2; }
.sb-logo { width: 34px; height: 34px; border-radius: 8px; background: #fff; color: var(--navy); display: grid; place-items: center; font-size: .85rem; font-weight: 800; flex: none; }
.sb-close { display: none; background: none; border: 0; color: #fff; padding: 6px; cursor: pointer; }
.sb-nav { padding: 4px 10px; flex: 1; }
.sb-title { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #8fa6c2; padding: 16px 10px 6px; }
.sb-link { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px; margin: 2px 0; border-radius: 8px; color: #d6e2f0; text-decoration: none; font: inherit; background: none; border: 0; cursor: pointer; text-align: left; }
.sb-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.sb-link.on { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.sb-badge { margin-left: auto; background: #f2b01e; color: #3b2a00; font-size: .72rem; font-weight: 700; border-radius: 999px; padding: 1px 8px; }
.sb-foot { border-top: 1px solid rgba(255,255,255,.12); padding: 12px 10px 16px; }
.sb-foot form { margin: 0; }
.sb-user { display: flex; align-items: center; gap: 10px; padding: 6px 12px 10px; }
.sb-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--navy-2); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.sb-name { color: #fff; font-weight: 600; font-size: .9rem; line-height: 1.2; }
.sb-role { font-size: .78rem; color: #8fa6c2; }
.backdrop { display: none; }

/* Barra superior (solo móvil, o sin sesión) */
.topbar { display: none; align-items: center; gap: 8px; background: var(--navy); color: #fff; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); position: sticky; top: 0; z-index: 30; }
.no-nav .topbar { display: flex; padding-left: 24px; }
.tb-brand { color: #fff; text-decoration: none; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-menu { position: relative; background: none; border: 0; color: #fff; padding: 8px; margin: -4px 0; border-radius: 8px; cursor: pointer; display: grid; place-items: center; }
.tb-menu:active { background: rgba(255,255,255,.15); }
.tb-dot { position: absolute; top: 6px; right: 6px; width: 9px; height: 9px; border-radius: 50%; background: #f2b01e; border: 2px solid var(--navy); }
.tb-right { margin-left: auto; }
.topbar .link { color: #fff; }

/* ---------- Componentes ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 14px; }
.card summary { cursor: pointer; list-style-position: outside; }
details.card[open] summary { margin-bottom: 12px; }
.narrow { max-width: 420px; margin: 40px auto; }
.narrow-left { max-width: 560px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 14px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.row > label { flex: 1; min-width: 160px; }
.between { justify-content: space-between; align-items: center; }
.right { text-align: right; }
.inline { display: inline; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .88rem; font-weight: 600; color: #3e4c59; }
.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
input, select { font: inherit; padding: 9px 10px; border: 1px solid #c9ccd1; border-radius: 6px; background: #fff; min-width: 0; min-height: 40px; }
input[type=checkbox] { min-height: 0; width: 18px; height: 18px; }
input:focus, select:focus { outline: 2px solid var(--navy-2); outline-offset: -1px; }
.btn { font: inherit; font-weight: 600; padding: 9px 16px; min-height: 40px; border-radius: 6px; border: 1px solid #c9ccd1; background: #fff; color: var(--text); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:hover { background: #f0f0ee; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-2); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.bad { background: #fff; border-color: var(--bad); color: var(--bad); }
.btn.bad:hover { background: var(--bad-bg); }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: .82rem; }
.btn.muted-btn { border-style: dashed; color: var(--muted, #6b7280); }
td.files { white-space: nowrap; }
td.files .btn + .btn, td.files .btn + form { margin-left: 4px; }
button.link { background: none; border: 0; padding: 0; font: inherit; text-decoration: underline; cursor: pointer; }
.flash { padding: 10px 14px; border-radius: 8px; margin: 12px 0; border: 1px solid transparent; }
.flash.ok { background: var(--ok-bg); color: var(--ok); border-color: #bfe3cf; }
.flash.bad { background: var(--bad-bg); color: var(--bad); border-color: #f5c2bd; }
.flash.warn { background: var(--warn-bg); color: var(--warn); border-color: #f1dc9e; }
.badge { background: #ececea; color: #52606d; display: inline-block; font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.info { background: var(--info-bg); color: var(--info); }
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.big { font-size: 1.6rem; font-weight: 700; margin: 4px 0; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: .02em; word-break: break-all; }
.ok-text { color: var(--ok); }
.bad-text { color: var(--bad); }
.amount { font-size: 1.15rem; font-weight: 700; }
.bank { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.bank dt { color: var(--muted); }
.bank dd { margin: 0; font-weight: 600; }
.copy { font-size: .78rem; padding: 3px 10px; margin-left: 6px; border: 1px solid #c9ccd1; border-radius: 4px; background: #fff; cursor: pointer; }
.list .charge { border-left: 4px solid var(--line); }
.charge.pendiente { border-left-color: #e0a800; }
.charge.en_revision { border-left-color: var(--info); }
.charge.pagado { border-left-color: var(--ok); }
.charge.rechazado { border-left-color: var(--bad); }
.charge .right .badge { margin-top: 4px; }
.upload { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.upload input[type=text] { flex: 1; min-width: 160px; }
.table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 14px; }
.table th, .table td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table thead th { background: #fafaf8; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.table tfoot td { font-weight: 700; background: #fafaf8; }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table tr.inactive td { opacity: .6; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.actions form { margin: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 18px 0 10px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-decoration: none; color: inherit; display: flex; flex-direction: column; gap: 4px; }
.tile:hover { border-color: var(--navy-2); }
.tile-title { font-weight: 700; }
.tile-value { font-size: 1.2rem; font-weight: 700; margin-top: auto; }
.receipts { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: 12px; }
img.receipt { max-width: 100%; max-height: 420px; border-radius: 6px; margin-top: 8px; border: 1px solid var(--line); }
.crumbs { margin-bottom: 10px; overflow-wrap: anywhere; }
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-bottom: 14px; }
.scroll .table { margin-bottom: 0; }
.grid-status td { text-align: center; padding: 6px 4px; }
.dot { display: inline-block; width: 24px; height: 24px; line-height: 24px; border-radius: 50%; font-size: .72rem; font-weight: 700; text-decoration: none; margin: 1px; }
.dot.ok { background: var(--ok-bg); color: var(--ok); }
.dot.bad { background: var(--bad-bg); color: var(--bad); }
.dot.warn { background: var(--warn-bg); color: var(--warn); }
.dot.info { background: var(--info-bg); color: var(--info); }
hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

/* ---------- Móvil y tableta ---------- */
@media (max-width: 960px) {
  .with-nav .shell { margin-left: 0; }
  .with-nav .topbar { display: flex; }
  .sidebar { transform: translateX(-100%); visibility: hidden; transition: transform .22s ease, visibility 0s linear .22s; width: min(86vw, 300px); padding-bottom: env(safe-area-inset-bottom); }
  .sb-close { display: grid; }
  .nav-open .sidebar { transform: none; visibility: visible; transition: transform .22s ease; box-shadow: 0 0 30px rgba(0,0,0,.25); }
  .nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(15,23,35,.45); z-index: 35; }
  .nav-open { overflow: hidden; }
  .sb-link { padding: 12px; }
}
@media (max-width: 700px) {
  .wrap { padding: 0 14px 40px; }
  h1 { font-size: 1.3rem; margin-top: 1rem; }
  input, select, textarea { font-size: 16px; } /* evita el zoom automático en iOS */
  .card { padding: 14px; }
  .row > label { min-width: 100%; }
  .row > .btn, .stack > .btn, .upload .btn { width: 100%; }
  .upload input { width: 100%; }
  .filters > * { flex: 1 1 140px; }
  .tiles { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .tile { padding: 12px; }
  .bank { grid-template-columns: 1fr; gap: 0; }
  .bank dt { font-size: .8rem; margin-top: 8px; }
  .big { font-size: 1.4rem; }

  /* Tablas como tarjetas: cada fila es una tarjeta y cada celda muestra su encabezado */
  .table.cards, .table.cards tbody, .table.cards tr, .table.cards td { display: block; width: 100%; }
  .table.cards { background: none; border: 0; }
  .table.cards thead { display: none; }
  .table.cards tbody tr { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; padding: 8px 12px; }
  .table.cards td { border: 0; padding: 5px 0; display: flow-root; text-align: right; }
  .table.cards td::before { content: attr(data-label); float: left; margin-right: 12px; padding-top: 2px; font-size: .78rem; font-weight: 600; color: var(--muted); text-align: left; }
  .table.cards td:not([data-label])::before, .table.cards td[data-label=""]::before { content: none; }
  .table.cards td:first-child { font-size: 1rem; }
  .table.cards td.actions, .table.cards td.right { display: flex; justify-content: flex-start; flex-wrap: wrap; gap: 6px; padding-top: 8px; text-align: left; }
  .table.cards td.actions::before, .table.cards td.right::before { content: none; }
  .table.cards td.right .btn { flex: 1; }
  .table.cards td .inline select { max-width: 60vw; }
  .table.cards tfoot { display: block; }
  .table.cards tfoot tr { display: flex; justify-content: space-between; background: #fafaf8; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
  .table.cards tfoot td { display: block; width: auto; border: 0; padding: 0; background: none; }
  .table.cards tfoot td:empty { display: none; }
}
