/* Shard Money — hoja única, compartida por el login y la app. */

:root {
  --bg: #0e1116;
  --surface: #161b23;
  --surface-2: #1d232d;
  --line: #2a323f;
  --text: #e6ebf2;
  --muted: #8b98ab;
  --accent: #4f9cf9;
  --accent-soft: rgba(79, 156, 249, 0.14);
  --green: #3fbf7f;
  --red: #f2686a;
  --amber: #e8a33d;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
a { color: var(--accent); }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.tabular { font-variant-numeric: tabular-nums; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.hidden { display: none !important; }

/* ── Login ─────────────────────────────────────────────────────────────────── */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: var(--shadow);
}

.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.login-card .sub { color: var(--muted); font-size: 14px; margin-bottom: 24px; }

/* ── Layout ────────────────────────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: rgba(14, 17, 22, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 600; font-size: 16px; white-space: nowrap; }
.brand span { color: var(--accent); }

.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }

.nav button {
  background: none;
  border: 0;
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  white-space: nowrap;
}

.nav button:hover { color: var(--text); background: var(--surface); }
.nav button.active { color: var(--text); background: var(--accent-soft); }
.nav button svg { display: none; }

main { max-width: 1080px; margin: 0 auto; padding: 24px 20px 80px; }

/* En el celular la navegación baja: el pulgar llega al borde inferior, no al superior. */
@media (max-width: 640px) {
  /* El backdrop-filter del topbar crearía un bloque contenedor para position:fixed y la
     barra quedaría anclada al header en vez del viewport. Acá no hace falta. */
  .topbar { backdrop-filter: none; background: var(--bg); }
  .topbar .brand { flex: 1; }

  .nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    gap: 4px;
    overflow: visible;
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
  }

  .nav button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 8px 4px;
    font-size: 12px;
    border-radius: 10px;
  }

  .nav button svg {
    display: block;
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  /* Espacio para que el último movimiento no quede tapado por la barra. */
  main { padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
}

.section { margin-bottom: 32px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-head h2 { font-size: 15px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.grid { display: grid; gap: 12px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }

/* ── Meses ─────────────────────────────────────────────────────────────────── */

.months {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 20px;
  scrollbar-width: thin;
}

.month-chip {
  flex: 0 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  color: var(--muted);
  font: inherit;
  text-align: left;
  min-width: 128px;
}

.month-chip:hover { border-color: var(--accent); }
.month-chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.month-chip .m-name { display: block; font-weight: 600; text-transform: capitalize; }
.month-chip .m-net { display: block; font-size: 13px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.month-chip .m-tag { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--accent); }

/* ── Totales ───────────────────────────────────────────────────────────────── */

.total-card { display: flex; flex-direction: column; gap: 10px; }
.total-card .cur { font-size: 12px; letter-spacing: 0.08em; color: var(--muted); text-transform: uppercase; }
.total-row { display: flex; justify-content: space-between; align-items: baseline; }
.total-row .label { color: var(--muted); font-size: 14px; }
.total-row .value { font-variant-numeric: tabular-nums; font-size: 15px; }
.total-row.net { border-top: 1px solid var(--line); padding-top: 10px; }
.total-row.net .value { font-size: 20px; font-weight: 600; }

/* ── Cuentas ───────────────────────────────────────────────────────────────── */

.account-card { display: flex; flex-direction: column; gap: 8px; }
.account-card .head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.account-card .name { font-weight: 600; }
.account-card .balance { font-variant-numeric: tabular-nums; font-size: 18px; font-weight: 600; }

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--line);
  text-transform: capitalize;
  white-space: nowrap;
}

.badge.credito { color: var(--amber); border-color: rgba(232, 163, 61, 0.4); }
.badge.proyectado { color: var(--accent); border-color: rgba(79, 156, 249, 0.4); }
.badge.cuota { color: var(--amber); border-color: rgba(232, 163, 61, 0.4); }
.badge.transferencia { color: var(--muted); }

.bar { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar > i.over { background: var(--red); }

/* ── Movimientos ───────────────────────────────────────────────────────────── */

.items { display: flex; flex-direction: column; }

.item {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-bottom: 0;
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  width: 100%;
}

.item:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.item:last-child { border-bottom: 1px solid var(--line); border-radius: 0 0 var(--radius) var(--radius); }
.item:only-child { border-radius: var(--radius); }
.item:hover { background: var(--surface-2); }
.item .day { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.item .title { font-weight: 500; }
.item .meta { color: var(--muted); font-size: 13px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.item .amount { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.item.is-projected { opacity: 0.82; }

.empty { color: var(--muted); text-align: center; padding: 32px 16px; border: 1px dashed var(--line); border-radius: var(--radius); }

/* ── Formularios ───────────────────────────────────────────────────────────── */

.tabs { display: flex; gap: 6px; margin-bottom: 20px; background: var(--surface); padding: 5px; border-radius: 10px; border: 1px solid var(--line); }

.tabs button {
  flex: 1;
  padding: 10px;
  border: 0;
  background: none;
  color: var(--muted);
  border-radius: 7px;
  cursor: pointer;
  font: inherit;
}

.tabs button.active { background: var(--accent-soft); color: var(--text); font-weight: 500; }

.field { margin-bottom: 16px; }
.field > label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 6px; }

input[type="text"], input[type="password"], input[type="number"], input[type="datetime-local"],
input[type="month"], input[type="date"], select, textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  font: inherit;
}

input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[type="number"] { font-variant-numeric: tabular-nums; }

.check { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }
.check span { font-size: 14px; }

.row { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
@media (max-width: 560px) { .row { grid-template-columns: 1fr; } }

/* El calendario de cuotas: en qué mes cae cada una. */
.cuota-schedule { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.cuota-schedule:empty { display: none; }

.cuota-chip {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}

.cuota-chip b { color: var(--accent); font-weight: 600; margin-right: 2px; }

.input-money { position: relative; }
.input-money .sym { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-money input { padding-left: 42px; }

button.primary, button.ghost, button.danger {
  padding: 11px 18px;
  border-radius: 9px;
  font: inherit;
  cursor: pointer;
  border: 1px solid transparent;
}

button.primary { background: var(--accent); color: #08111d; font-weight: 600; border: 0; }
button.primary:hover { filter: brightness(1.08); }
button.primary:disabled { opacity: 0.55; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--muted); border-color: var(--line); }
button.ghost:hover { color: var(--text); border-color: var(--accent); }
button.danger { background: transparent; color: var(--red); border-color: rgba(242, 104, 106, 0.4); }
button.danger:hover { background: rgba(242, 104, 106, 0.1); }

.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.notice { padding: 10px 14px; border-radius: 9px; font-size: 14px; margin-bottom: 16px; }
.notice.error { background: rgba(242, 104, 106, 0.12); color: var(--red); border: 1px solid rgba(242, 104, 106, 0.3); }
.notice.ok { background: rgba(63, 191, 127, 0.12); color: var(--green); border: 1px solid rgba(63, 191, 127, 0.3); }
.notice.info { background: var(--accent-soft); color: var(--accent); border: 1px solid rgba(79, 156, 249, 0.3); }

/* ── Modal ─────────────────────────────────────────────────────────────────── */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 8, 12, 0.7);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 460px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.modal h3 { font-size: 17px; margin-bottom: 4px; }
.modal .modal-sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv:last-of-type { border-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-variant-numeric: tabular-nums; text-align: right; }
