:root {
  --bg: #f6f4f1;
  --surface: #ffffff;
  --text: #1c1a18;
  --muted: #7a746d;
  --line: #e7e2dc;
  --accent: #c2410c;
  --accent-text: #ffffff;
  --owe: #b42318;      /* Debés */
  --owed: #067647;     /* Te deben */
  --danger: #b42318;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141312;
    --surface: #1f1d1b;
    --text: #f3efea;
    --muted: #9a938b;
    --line: #2f2c29;
    --accent: #fb923c;
    --accent-text: #1c1a18;
    --owe: #f97066;
    --owed: #47cd89;
    --danger: #f97066;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
  background: var(--bg);
}
body {
  margin: 0;
  min-height: 100dvh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg);
}
#app { max-width: 560px; margin: 0 auto; min-height: 100dvh; }

a { color: inherit; text-decoration: none; }
button, a, [role="button"], select, label { touch-action: manipulation; }
button, [role="button"] {
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  font: inherit; color: inherit; cursor: pointer;
}
input, textarea, select { font: inherit; font-size: 16px; color: var(--text); }

/* Barra superior */
.topbar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 12px 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar .left { display: flex; align-items: center; gap: 4px; min-width: 0; }
.topbar .right { display: flex; align-items: center; gap: 4px; flex: none; }
.topbar h1 { font-size: 20px; font-weight: 700; margin: 0; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar h1 .me { color: var(--muted); font-weight: 500; }
.icon-btn {
  flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0;
  display: grid; place-items: center; background: transparent;
  transition: transform 120ms ease-out, background 120ms;
}
.icon-btn:active { transform: scale(0.92); background: var(--line); }
.icon-btn.primary { background: var(--accent); color: var(--accent-text); }
.icon-btn.primary:active { background: var(--accent); }
.icon-btn svg { width: 22px; height: 22px; }

.content { padding: 12px 16px calc(env(safe-area-inset-bottom, 0px) + 24px); }

/* Lista de amigos */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 14px;
  width: 100%; padding: 14px 16px; border: 0; background: transparent; text-align: left;
  border-bottom: 1px solid var(--line);
  transition: background 120ms;
}
.list li:last-child .row { border-bottom: 0; }
.row:active { background: var(--line); }
.row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.amt { display: flex; flex-direction: column; align-items: flex-end; min-width: 70px; }
.amt small { font-size: 12px; color: var(--muted); }
.amt b { font-weight: 650; font-variant-numeric: tabular-nums; }
.amt.owe b { color: var(--owe); }
.amt.owed b { color: var(--owed); }
.amt.zero b { color: var(--muted); font-weight: 500; opacity: 0.75; }

.empty { color: var(--muted); text-align: center; padding: 40px 16px; }

/* Detalle */
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.total { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.total small { display: block; color: var(--muted); font-size: 13px; }
.total b { font-size: 22px; font-variant-numeric: tabular-nums; }
.total.owe b { color: var(--owe); }
.total.owed b { color: var(--owed); }
.total.zero b { color: var(--muted); }
.entry { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.list li:last-child .entry { border-bottom: 0; }
.entry .tag { font-size: 13px; font-weight: 600; }
.entry .tag.owe { color: var(--owe); }
.entry .tag.owed { color: var(--owed); }
.entry .amount { font-weight: 650; font-variant-numeric: tabular-nums; text-align: right; }
.entry .meta { grid-column: 1 / -1; font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.entry .actions { grid-column: 1 / -1; display: flex; gap: 12px; justify-content: flex-end; align-items: center; }
.link-btn { border: 0; background: transparent; padding: 8px 4px; color: var(--muted); font-size: 14px; min-height: 40px; }
.link-btn.danger { color: var(--danger); font-weight: 600; }

/* Formularios */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 16px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 14px; font-weight: 600; }
.field input, .field select {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); outline: none; min-height: 48px;
}
.field input:focus-visible, .field select:focus-visible { border-color: var(--accent); }
.hint { font-size: 13px; color: var(--muted); }
.error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 0 10px; }
.btn {
  width: 100%; min-height: 50px; border: 0; border-radius: 12px;
  background: var(--accent); color: var(--accent-text); font-weight: 650;
  transition: transform 120ms ease-out, opacity 120ms;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; }
.btn.secondary { background: transparent; color: var(--text); border: 1px solid var(--line); margin-top: 10px; }

.brand { text-align: center; padding: calc(env(safe-area-inset-top, 0px) + 40px) 16px 20px; }
.brand h1 { font-size: 34px; margin: 0; letter-spacing: -0.02em; }
.brand p { margin: 6px 0 0; color: var(--muted); }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--line); border-radius: 12px; padding: 4px; margin-bottom: 16px; }
.tabs button { border: 0; background: transparent; padding: 10px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); }

.loading { display: grid; place-items: center; min-height: 60dvh; color: var(--muted); padding: 16px; text-align: center; }

@media (hover: hover) and (pointer: fine) {
  .row:hover { background: color-mix(in srgb, var(--line) 50%, transparent); }
  .icon-btn:hover { background: var(--line); }
  .icon-btn.primary:hover { background: var(--accent); filter: brightness(1.06); }
  .link-btn:hover { color: var(--text); }
}
