/* =========================================================
   Design tokens
   ========================================================= */
:root {
  --bg: #F4F1FF;
  --paper: #FFFFFF;
  --ink: #241B33;
  --ink-soft: #746E8C;
  --ink-faint: #B4AFC9;
  --line: #ECE7FB;

  --brand-1: #FF3D71;
  --brand-2: #FFA63D;
  --brand-grad: linear-gradient(135deg, var(--brand-1), var(--brand-2));

  --danger: #E1436B;

  --cat-comida: #FF6B6B;
  --cat-transporte: #2EC4B6;
  --cat-ocio: #9B5DE5;
  --cat-compras: #FFC93C;
  --cat-facturas: #3A86FF;
  --cat-salud: #06D6A0;
  --cat-hogar: #FF8FA3;
  --cat-otros: #8D93A6;

  --font-display: 'Baloo 2', ui-rounded, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'Space Mono', ui-monospace, monospace;

  --radius-lg: 26px;
  --radius-md: 16px;
  --radius-sm: 10px;

  --shadow-card: 0 18px 40px -18px rgba(36, 27, 51, 0.28);
  --shadow-fab: 0 14px 26px -8px rgba(255, 61, 113, 0.55);
}

* { box-sizing: border-box; }

/* El atributo hidden debe ganar siempre, aunque el propio componente
   (auth-screen, sheet-overlay...) fije su display para cuando SÍ se
   muestra — si no, un empate de especificidad deja el hidden sin efecto. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button, input {
  font-family: inherit;
}

h1, h2 { font-family: var(--font-display); margin: 0; }

:focus-visible {
  outline: 3px solid #7C3AED;
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* =========================================================
   Shared bits
   ========================================================= */
.btn {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  border: none;
  border-radius: 999px;
  padding: 14px 22px;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, opacity .15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-block { width: 100%; }
.btn-primary {
  background: var(--brand-grad);
  color: white;
  box-shadow: 0 12px 22px -10px rgba(255, 61, 113, 0.6);
}
.btn-primary:disabled { opacity: .55; cursor: default; }
.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
}
.btn-danger { color: var(--danger); }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--paper);
  color: var(--ink-soft);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 6px 14px -8px rgba(36,27,51,.35);
}
.icon-btn:active { transform: scale(0.92); }

.link-btn {
  background: none;
  border: none;
  color: var(--brand-1);
  font-weight: 600;
  font-size: .92rem;
  cursor: pointer;
  padding: 8px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: .85rem;
  color: var(--ink-soft);
  font-weight: 600;
}
.field input {
  font-size: 1rem;
  font-weight: 500;
  color: var(--ink);
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--paper);
}
.field input:focus { border-color: var(--brand-1); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 12px);
  background: var(--ink);
  color: white;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: .9rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 200;
  box-shadow: 0 14px 30px -10px rgba(0,0,0,.4);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Perforated "ticket" line, reused a couple of places */
.perf {
  height: 14px;
  background-image: radial-gradient(circle at 7px 7px, var(--bg) 5.5px, transparent 6px);
  background-size: 18px 14px;
  background-repeat: repeat-x;
  background-position: center;
}

/* =========================================================
   Auth screen
   ========================================================= */
.auth-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(60% 50% at 15% 0%, #FFE3EC 0%, transparent 60%),
    radial-gradient(50% 40% at 100% 100%, #FFEAD1 0%, transparent 60%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--paper);
  border-radius: var(--radius-lg);
  padding: 34px 28px 28px;
  box-shadow: var(--shadow-card);
  text-align: center;
}
.auth-coin { margin-bottom: 6px; }
.auth-title {
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: .3px;
}
.auth-sub {
  color: var(--ink-soft);
  font-size: .92rem;
  line-height: 1.4;
  margin: 8px 0 24px;
}
.auth-form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.auth-error {
  color: var(--danger);
  background: #FFEBF0;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: .85rem;
  font-weight: 600;
  margin: 0;
}
#authSubmit { margin-top: 4px; }
.auth-screen .link-btn { margin-top: 18px; }

/* =========================================================
   App shell
   ========================================================= */
.app-screen {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--paper);
  position: relative;
  padding-bottom: 110px;
  box-shadow: var(--shadow-card);
}
@media (min-width: 560px) {
  body { padding: 28px 0; }
  .app-screen { min-height: calc(100dvh - 56px); border-radius: 28px; overflow: hidden; }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 6px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
}

.month-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 6px 20px 4px;
}
.month-label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  background: none;
  border: none;
  color: var(--ink);
  min-width: 168px;
  text-align: center;
  cursor: default;
}

/* =========================================================
   Hero / month total ticket
   ========================================================= */
.hero {
  margin: 14px 16px 6px;
  background: var(--brand-grad);
  border-radius: var(--radius-lg);
  position: relative;
  overflow: hidden;
}
.hero-inner {
  padding: 22px 24px 18px;
  color: white;
  text-align: center;
}
.hero-label {
  margin: 0;
  font-size: .82rem;
  font-weight: 600;
  opacity: .9;
}
.hero-total {
  margin: 4px 0 2px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 2.5rem;
  letter-spacing: -1px;
}
.hero-delta {
  margin: 0;
  font-size: .8rem;
  font-weight: 600;
  opacity: .95;
}

.breakdown {
  margin: 0 16px 6px;
  padding: 16px 18px 4px;
}

.cat-bar {
  display: flex;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--line);
}
.cat-bar span { height: 100%; }

.cat-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 12px;
}
.cat-legend .leg-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--ink-soft);
}
.cat-legend .dot {
  width: 9px; height: 9px; border-radius: 50%;
  flex-shrink: 0;
}

.hero-tear {
  height: 12px;
  background-image: radial-gradient(circle at 7px 6px, var(--paper) 5.5px, transparent 6px);
  background-size: 18px 12px;
  background-repeat: repeat-x;
  background-position: center bottom;
}

/* =========================================================
   Expense list
   ========================================================= */
.list-wrap { padding: 10px 16px 4px; }

.day-group { margin-top: 18px; }
.day-heading {
  font-size: .84rem;
  font-weight: 700;
  color: var(--ink-soft);
  padding-bottom: 8px;
  border-bottom: 1.5px dashed var(--line);
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
}

.expense-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  background: none;
  border-left: none; border-right: none; border-top: none;
  width: 100%;
  text-align: left;
}
.expense-row:last-child { border-bottom: none; }
.expense-row:active { background: var(--bg); border-radius: var(--radius-sm); }

.cat-badge {
  width: 40px;
  height: 40px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  font-size: 1.15rem;
  flex-shrink: 0;
}

.expense-main { flex: 1; min-width: 0; }
.expense-desc {
  font-weight: 600;
  font-size: .95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.expense-cat {
  font-size: .78rem;
  color: var(--ink-soft);
}

.expense-amount {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1rem;
  flex-shrink: 0;
}

.empty-state {
  text-align: center;
  padding: 50px 20px 30px;
  color: var(--ink-soft);
}
.empty-emoji { font-size: 2.4rem; margin: 0 0 8px; }
.empty-title { font-weight: 700; color: var(--ink); margin: 0 0 4px; }
.empty-sub { font-size: .88rem; margin: 0; }

/* =========================================================
   Floating action button
   ========================================================= */
.fab {
  position: fixed;
  right: 24px;
  bottom: 28px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--brand-grad);
  color: white;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-fab);
  cursor: pointer;
  z-index: 60;
  transition: transform .15s ease;
}
.fab:active { transform: scale(0.9); }
@media (min-width: 560px) {
  .fab { right: calc(50% - 240px + 24px); }
}

/* =========================================================
   Bottom sheet (add / edit)
   ========================================================= */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(36, 27, 51, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
@media (min-width: 560px) {
  .sheet-overlay { align-items: center; }
}

.sheet {
  background: var(--paper);
  width: 100%;
  max-width: 480px;
  max-height: 88dvh;
  overflow-y: auto;
  border-radius: 26px 26px 0 0;
  padding: 10px 22px 26px;
  animation: sheet-up .22s ease;
}
@media (min-width: 560px) {
  .sheet { border-radius: 26px; margin-bottom: 20px; }
}
@keyframes sheet-up {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet-handle {
  width: 40px; height: 5px;
  background: var(--line);
  border-radius: 999px;
  margin: 6px auto 14px;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.sheet-head h2 { font-size: 1.2rem; font-weight: 700; }

.sheet-form { display: flex; flex-direction: column; gap: 16px; }

.amount-field {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  padding: 10px 0 18px;
  border-bottom: 2px dashed var(--line);
}
.amount-currency {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--ink-faint);
}
.amount-field input {
  border: none;
  outline: none;
  font-family: var(--font-mono);
  font-size: 2.6rem;
  font-weight: 700;
  width: 100%;
  max-width: 220px;
  text-align: center;
  color: var(--ink);
  background: none;
}

.cat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.cat-chip {
  border: 2px solid var(--line);
  background: var(--paper);
  border-radius: var(--radius-md);
  padding: 10px 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.cat-chip .emoji {
  width: 32px; height: 32px;
  border-radius: 10px;
  display: grid; place-items: center;
  font-size: 1rem;
}
.cat-chip span.label {
  font-size: .68rem;
  font-weight: 600;
  color: var(--ink-soft);
  text-align: center;
  line-height: 1.15;
}
.cat-chip[aria-checked="true"] {
  border-color: var(--chip-color, var(--brand-1));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--chip-color, var(--brand-1)) 22%, transparent);
  transform: translateY(-1px);
}
.cat-chip:active { transform: scale(0.95); }

.sheet-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
}
.sheet-actions .btn-danger { flex-shrink: 0; }
