/* ============================================================
   Cuentas — tema "crudo" / brutalist / monoespaciado.
   Sin degradados, sin sombras, sin esquinas redondeadas.
   Todo con bordes duros y tipografía de código.
   ============================================================ */
:root {
  --bg: #eee;
  --fg: #111;
  --dim: #666;
  --line: #111;
  --box: #fafafa;
  --accent: #111;      /* activo = invertido */
  --accent-fg: #fafafa;
  --pos: #0a7d2c;      /* verde deber */
  --neg: #b00020;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b0b;
    --fg: #e6e6e6;
    --dim: #888;
    --line: #444;
    --box: #141414;
    --accent: #e6e6e6;
    --accent-fg: #0b0b0b;
    --pos: #3ddc84;
    --neg: #ff5b6e;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
  line-height: 1.5;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; font-size: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 16px; color: var(--fg); background: var(--box); }
h1, h2, h3 { margin: 0; font-weight: 700; }
.muted { color: var(--dim); }
.small { font-size: 12px; }
.center { text-align: center; }
[hidden] { display: none !important; }

/* selección de texto tipo editor */
::selection { background: var(--fg); color: var(--bg); }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(var(--safe-top) + 14px) 16px 10px;
  border-bottom: 1.5px solid var(--line);
}
.topbar h1 { font-size: 15px; font-weight: 700; letter-spacing: 0; }
.topbar h1::before { content: "// "; color: var(--dim); }
.icon-btn {
  width: 34px; height: 34px; border: 1.5px solid var(--line); font-size: 15px;
  display: grid; place-items: center; color: var(--fg); background: var(--box);
}
.icon-btn:active { background: var(--fg); color: var(--bg); }

/* ---------- Balance ---------- */
.balance-card {
  margin: 16px; padding: 16px;
  border: 1.5px solid var(--line); background: var(--box);
}
.balance-label { font-size: 11px; color: var(--dim); text-transform: lowercase; letter-spacing: 0; }
.balance-label::before { content: "> "; }
.balance-main { font-size: 26px; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; line-height: 1.2; }
.balance-sub { font-size: 13px; color: var(--dim); margin-top: 4px; }
.balance-sub::before { content: "# "; color: var(--dim); }
.btn-settle {
  margin-top: 14px; width: 100%; background: var(--accent); color: var(--accent-fg);
  padding: 11px; border: 1.5px solid var(--line); font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
}
.btn-settle::before { content: "[ "; }
.btn-settle::after { content: " ]"; }
.btn-settle:active { opacity: .7; }

/* ---------- Historial ---------- */
.history { padding: 0 16px calc(120px + var(--safe-bottom)); }
.month-group { margin-top: 22px; }
.month-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 0 0 6px; font-size: 12px; color: var(--dim);
  border-bottom: 1.5px solid var(--line); text-transform: lowercase;
}
.month-head span:first-child::before { content: "## "; }
.exp-list { border: 1.5px solid var(--line); border-top: none; }
.exp {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-bottom: 1px dashed var(--line);
}
.exp:last-child { border-bottom: none; }
.exp:active { background: var(--fg); color: var(--bg); }
.exp:active .exp-meta, .exp:active .exp-orig { color: var(--bg); }
.exp-emoji {
  width: 30px; height: 30px; flex: 0 0 30px; border: 1.5px solid var(--line);
  display: grid; place-items: center; font-size: 15px; background: var(--bg);
}
.exp-mid { flex: 1; min-width: 0; }
.exp-title { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.exp-meta { font-size: 11.5px; color: var(--dim); margin-top: 1px; }
.exp-right { text-align: right; flex: 0 0 auto; }
.exp-amount { font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; }
.exp-amount.individual { color: var(--dim); font-weight: 400; }
.exp-amount.individual::after { content: " ·ind"; font-size: 10px; }
.exp-orig { font-size: 11px; color: var(--dim); }
.tag-ind { font-size: 10px; text-transform: uppercase; color: var(--dim); }
.empty { text-align: center; color: var(--dim); padding: 50px 16px; border: 1.5px dashed var(--line); margin-top: 22px; }
.empty .big { display: none; }
.empty::before { content: "// "; }

/* ---------- FAB (botón cuadrado, plano) ---------- */
.fab {
  position: fixed; right: 16px; bottom: calc(20px + var(--safe-bottom));
  width: 54px; height: 54px; border: 1.5px solid var(--line);
  background: var(--accent); color: var(--accent-fg);
  font-size: 26px; font-weight: 400; line-height: 1; display: grid; place-items: center;
  z-index: 30;
}
.fab:active { opacity: .7; }

/* ---------- Sheets ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.sheet-body {
  position: relative; width: 100%; max-height: 94vh; overflow-y: auto;
  background: var(--bg); border-top: 1.5px solid var(--line);
  padding: 6px 16px calc(20px + var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
}
@media (min-width: 560px) {
  .sheet { align-items: center; justify-content: center; }
  .sheet-body { max-width: 460px; border: 1.5px solid var(--line); }
}
.sheet-handle { width: 46px; height: 4px; background: var(--line); margin: 8px auto 12px; }
.sheet-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1.5px solid var(--line); }
.sheet-header h2 { font-size: 15px; }
.sheet-header h2::before { content: "// "; color: var(--dim); }

/* Onboarding pantalla completa */
.sheet-screen { position: fixed; inset: 0; z-index: 60; background: var(--bg); display: grid; place-items: center; padding: 16px; }
.sheet-screen .sheet-body { border: 1.5px solid var(--line); max-width: 420px; }
.sheet-screen h2 { font-size: 18px; margin-bottom: 6px; }

/* ---------- Formulario ---------- */
.field { display: flex; flex-direction: column; gap: 5px; margin: 12px 0; }
.field > span { font-size: 12px; color: var(--dim); }
.field > span::before { content: "> "; }
.field input, .field select, .add-cat-row input {
  background: var(--box); border: 1.5px solid var(--line); border-radius: 0;
  padding: 11px 12px; width: 100%; outline: none;
}
.field input:focus, .field select:focus { outline: 2px solid var(--fg); outline-offset: -1px; }
.field.inline { flex-direction: row; align-items: center; gap: 8px; margin: 0; }
.field.inline > span { font-size: 14px; color: var(--fg); }
.field.inline > span::before { content: ""; }

.amount-row { display: flex; gap: 8px; align-items: stretch; margin: 6px 0 4px; }
.amount-input {
  flex: 1; min-width: 0; font-size: 30px; font-weight: 700; text-align: right;
  background: var(--box); border: 1.5px solid var(--line); border-radius: 0;
  padding: 8px 12px; outline: none; letter-spacing: -.02em;
}
.amount-input:focus { outline: 2px solid var(--fg); outline-offset: -1px; }
.currency-select {
  background: var(--box); border: 1.5px solid var(--line); border-radius: 0;
  padding: 0 8px; font-size: 15px; font-weight: 700; min-width: 78px; outline: none;
}
.currency-select.wide { padding: 11px 12px; width: 100%; }
.convert-row { display: flex; justify-content: space-between; align-items: center; margin: 2px 0 8px; }
.convert-row .muted::before { content: ""; }
.rate-row { margin: 4px 0 10px; background: var(--box); border: 1.5px solid var(--line); padding: 10px 12px; }
.rate-input { width: 120px; background: var(--bg); border: 1.5px solid var(--line); border-radius: 0; padding: 7px 10px; text-align: right; }

.seg-label { font-size: 12px; color: var(--dim); margin: 16px 0 7px; }
.seg-label::before { content: "> "; }
.payer-row { display: flex; gap: 8px; }
.payer-btn {
  flex: 1; padding: 13px 8px; border: 1.5px solid var(--line);
  background: var(--box); font-weight: 700; font-size: 15px;
}
.payer-btn.active { background: var(--accent); color: var(--accent-fg); }

.toggle-row { display: flex; gap: 8px; margin-top: 14px; }
.toggle-opt { flex: 1; padding: 11px; border: 1.5px solid var(--line); background: var(--box); color: var(--dim); font-weight: 700; }
.toggle-opt.active { background: var(--accent); color: var(--accent-fg); }

.split-block { margin-top: 16px; }
.split-head { display: flex; justify-content: space-between; align-items: center; }
.split-control { margin-top: 10px; border: 1.5px solid var(--line); padding: 10px 12px; background: var(--box); }
.split-labels { display: flex; justify-content: space-between; font-size: 12px; color: var(--dim); margin-bottom: 6px; font-variant-numeric: tabular-nums; }
#btnSplitToggle { border: 1.5px solid var(--line); padding: 3px 8px; background: var(--box); font-weight: 700; }
input[type=range] { width: 100%; accent-color: var(--fg); height: 26px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 8px 12px; border-radius: 0; background: var(--box);
  border: 1.5px solid var(--line); font-size: 13px; font-weight: 400;
}
.chip.active { background: var(--accent); color: var(--accent-fg); }
.chip .x { margin-left: 8px; color: inherit; font-weight: 700; }

.sheet-actions { display: flex; gap: 8px; margin-top: 20px; }
.link-btn { color: var(--fg); text-decoration: underline; font-weight: 400; font-size: 13px; }

/* ---------- Botones ---------- */
.btn-primary, .btn-secondary, .btn-danger {
  padding: 13px 16px; border: 1.5px solid var(--line); border-radius: 0;
  font-weight: 700; font-size: 15px; flex: 1; text-transform: uppercase; letter-spacing: .03em;
}
.btn-primary { background: var(--accent); color: var(--accent-fg); width: 100%; }
.btn-primary::before { content: "[ "; }
.btn-primary::after { content: " ]"; }
.btn-primary:active { opacity: .7; }
.btn-secondary { background: var(--box); color: var(--fg); text-transform: none; letter-spacing: 0; }
.btn-danger { background: var(--box); color: var(--neg); border-color: var(--neg); }
.btn-danger.wide, .btn-primary.wide { width: 100%; }

/* ---------- Ajustes ---------- */
.settings-group { padding: 16px 0; border-bottom: 1.5px solid var(--line); }
.settings-group h3 { font-size: 13px; margin-bottom: 10px; text-transform: lowercase; }
.settings-group h3::before { content: "## "; color: var(--dim); }
.settings-actions { display: flex; gap: 8px; }
.add-cat-row { display: flex; gap: 8px; margin-top: 10px; }
.add-cat-row input { flex: 1; }
.add-cat-row .btn-secondary { flex: 0 0 auto; }
.settlement-list { display: flex; flex-direction: column; gap: 6px; }
.settlement-item { background: var(--box); border: 1.5px solid var(--line); padding: 10px 12px; font-size: 13px; }
.settlement-item .s-main { font-weight: 700; }
.settlement-item .s-main::before { content: "$ "; color: var(--dim); }
.settlement-item .s-date { color: var(--dim); font-size: 11.5px; margin-top: 2px; }

/* ---------- Sync ---------- */
#pairShow {
  width: 100%; background: var(--box); border: 1.5px solid var(--line); border-radius: 0;
  padding: 10px 12px; font-size: 12px; color: var(--dim); overflow-x: auto;
}
#syncStatus { color: var(--pos); font-weight: 700; margin: 0 0 10px; }
#syncStatus:empty { display: none; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(84px + var(--safe-bottom));
  background: var(--fg); color: var(--bg); padding: 10px 14px; border-radius: 0;
  font-size: 13px; z-index: 100; text-align: left;
}
.toast::before { content: "$ "; opacity: .6; }
