:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #16202a;
  --ink-soft: #5c6b7a;
  --line: #e2e8ef;
  --brand: #0f766e;
  --brand-dark: #0b5c56;
  --brand-soft: #e6f4f2;
  --danger: #b42318;
  --danger-soft: #fdeceb;
  --ok: #17663f;
  --ok-soft: #e7f6ee;
  --warn: #8a5a00;
  --warn-soft: #fdf3e0;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 32, 48, .06), 0 6px 18px rgba(16, 32, 48, .05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--brand); }

/* ---------- Cabecera ---------- */
.topbar {
  background: var(--brand);
  color: #fff;
  padding-top: env(safe-area-inset-top);
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .08);
}
.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { color: #fff; font-weight: 700; text-decoration: none; font-size: 1.05rem; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 12px; font-size: .85rem; }
.who { opacity: .9; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-link {
  background: none; border: 0; padding: 0; margin: 0;
  color: #fff; text-decoration: underline; cursor: pointer;
  font: inherit; opacity: .92;
}
.inline { display: inline; }

.tabs {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 8px 8px;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  color: #fff;
  text-decoration: none;
  padding: 7px 13px;
  border-radius: 999px;
  font-size: .9rem;
  white-space: nowrap;
  opacity: .82;
}
.tab.is-active { background: rgba(255, 255, 255, .2); opacity: 1; font-weight: 600; }

/* ---------- Estructura ---------- */
.wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 16px calc(48px + env(safe-area-inset-bottom));
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 4px; font-size: 1.05rem; }
.card h2 + .sub { margin-top: 0; }
.sub { color: var(--ink-soft); font-size: .88rem; margin: 0 0 14px; }
h1 { font-size: 1.35rem; margin: 4px 0 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 160px; }
.right { text-align: right; }
.muted { color: var(--ink-soft); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }

/* ---------- Formularios ---------- */
label { display: block; font-size: .85rem; font-weight: 600; color: var(--ink-soft); margin-bottom: 5px; }
input, select, textarea {
  width: 100%;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: 0;
  border-color: var(--brand);
}
.field { margin-bottom: 14px; }
.amount-input {
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
  padding: 14px;
  letter-spacing: .5px;
}
.hint { font-size: .8rem; color: var(--ink-soft); margin-top: 5px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 18px;
  border: 0;
  border-radius: 11px;
  background: var(--brand);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s ease;
}
.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.big { padding: 16px 20px; font-size: 1.05rem; }
.btn.ghost { background: #fff; color: var(--brand); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--brand-soft); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #90170f; }
.btn.small { padding: 8px 12px; font-size: .85rem; }

/* Botones rápidos de importe */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  font-size: .9rem;
  cursor: pointer;
}
.chip:hover { background: var(--brand-soft); border-color: var(--brand); }
.chip.is-on { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------- Cifras ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat .k { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); }
/* La cifra se encoge antes que partirse en dos líneas. */
.stat .v { font-size: clamp(1.1rem, 2.1vw, 1.5rem); font-weight: 700; margin-top: 4px; white-space: nowrap; }
.stat.accent { background: var(--brand); border-color: var(--brand); color: #fff; }
.stat.accent .k { color: rgba(255, 255, 255, .85); }

/* ---------- Tablas y listas ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th, td { padding: 11px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.item:last-child { border-bottom: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 600; }
.item .meta { font-size: .82rem; color: var(--ink-soft); }
.item .money { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

.pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  background: var(--brand-soft);
  color: var(--brand-dark);
}
.pill.grey { background: #eef1f4; color: var(--ink-soft); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- Avisos ---------- */
.banner {
  padding: 12px 14px;
  border-radius: 11px;
  margin-bottom: 14px;
  font-size: .92rem;
  border: 1px solid transparent;
}
.banner.ok { background: var(--ok-soft); color: var(--ok); border-color: #c7e8d6; }
.banner.error { background: var(--danger-soft); color: var(--danger); border-color: #f6cfcc; }
.banner.warn { background: var(--warn-soft); color: var(--warn); border-color: #f0dcb4; }
.banner a { color: inherit; }

.empty { text-align: center; color: var(--ink-soft); padding: 26px 10px; }

/* ---------- Login ---------- */
.login-wrap { max-width: 380px; margin: 8vh auto 0; padding: 0 16px; }
.login-logo { text-align: center; font-size: 2.4rem; margin-bottom: 6px; }
.login-title { text-align: center; margin: 0 0 22px; font-size: 1.2rem; }

/* ---------- Detalles ---------- */
details.box { border: 1px solid var(--line); border-radius: 11px; padding: 10px 14px; margin-top: 12px; background: #fbfcfd; }
details.box summary { cursor: pointer; font-weight: 600; font-size: .9rem; }
details.box > *:not(summary) { margin-top: 10px; }

.divider { height: 1px; background: var(--line); margin: 16px 0; border: 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }

.tier-row { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 10px; }
.tier-row > div { flex: 1; }
.tier-row button { flex: 0 0 auto; }

@media (max-width: 560px) {
  .who { display: none; }
  /* En el móvil no cabe todo: se esconde lo accesorio antes que recortar cifras. */
  .hide-narrow { display: none; }
  .card { padding: 15px; }
  .stat .v { font-size: 1.3rem; }
  th, td { padding: 10px 8px; }
}

@media print {
  .topbar, .btn, .actions, .no-print { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
}
