@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Source+Serif+4:opsz,wght@8..60,500;8..60,600&display=swap');

:root {
  /* paleta calida, minimalista - terracota/arcilla en vez de coral saturado */
  --coral: #C2694F;
  --coral-dark: #A8543D;
  --teal: #6B8F71;
  --teal-dark: #56745C;
  --honey: #D4A24C;
  --cream: #F7F4EC;
  --card: #FFFEFB;
  --ink: #2B2A26;
  --ink-soft: #7A7568;
  --green: #5A8F5E;
  --amber: #C99A3E;
  --red: #B8543F;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(43, 42, 38, 0.06), 0 1px 2px rgba(43, 42, 38, 0.04);
  --border: 1px solid #EAE5D8;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--cream);
  color: var(--ink);
  min-height: 100vh;
}

a, button, .btn, .fab, .nav a, .bottom-nav a {
  touch-action: manipulation;
}

h1, h2, h3, .brand {
  font-family: 'Source Serif 4', Georgia, serif;
  font-weight: 600;
}

a { color: var(--coral-dark); text-decoration: none; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--card);
  box-shadow: var(--shadow);
  border: var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-size: 22px;
  color: var(--coral-dark);
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand .dot { color: var(--honey); }

.nav {
  display: flex;
  gap: 6px;
  align-items: center;
}

.nav a {
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--ink-soft);
  font-weight: 700;
  font-size: 14px;
}
.nav a.active {
  background: var(--coral);
  color: white;
}
/* :hover solo en dispositivos que de verdad tienen mouse - si no, en touch
   (iOS/Android) el primer tap solo dispara el estado :hover y hace falta un
   segundo tap para navegar. Esto es lo que causaba el "doble click". */
@media (hover: hover) and (pointer: fine) {
  .nav a:hover { background: var(--coral); color: white; }
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px 6px 6px;
  border-radius: 999px;
  background: var(--cream);
  font-weight: 700;
  font-size: 14px;
}
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 800; font-size: 13px;
  flex-shrink: 0;
}

.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.hero {
  text-align: center;
  margin-bottom: 24px;
}
.hero h1 { font-size: 28px; margin: 0 0 4px; }
.hero p { color: var(--ink-soft); margin: 0; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}
.summary-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  text-align: center;
}
.summary-card .label { font-size: 13px; color: var(--ink-soft); font-weight: 700; text-transform: uppercase; letter-spacing: .03em;}
.summary-card .value { font-size: 24px; font-weight: 800; margin-top: 4px; }
.summary-card.income .value { color: var(--teal-dark); }
.summary-card.expense .value { color: var(--coral-dark); }
.summary-card.left .value { color: var(--ink); }

.section-title {
  font-size: 18px;
  margin: 28px 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.cat-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.cat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.cat-name { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.cat-amounts { font-size: 13px; color: var(--ink-soft); margin-bottom: 8px; }
.cat-amounts b { color: var(--ink); }

.progress-track {
  background: #F1EFEA;
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 999px;
  transition: width .3s ease;
}
.progress-fill.ok { background: var(--green); }
.progress-fill.warn { background: var(--amber); }
.progress-fill.over { background: var(--red); }

.badge {
  font-size: 11px;
  font-weight: 800;
  padding: 3px 9px;
  border-radius: 999px;
  color: white;
}
.badge.ok { background: var(--green); }
.badge.warn { background: var(--amber); }
.badge.over { background: var(--red); }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  margin-bottom: 18px;
}

.btn {
  display: inline-block;
  background: var(--coral);
  color: white;
  border: none;
  padding: 12px 22px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 15px;
  cursor: pointer;
  transition: transform .15s ease, background .15s ease;
}
.btn.secondary { background: var(--teal); }
.btn.ghost { background: transparent; color: var(--ink-soft); box-shadow: none; border: 2px solid #E7E3DB; }
.btn.danger { background: var(--red); }
.btn.small { padding: 7px 14px; font-size: 13px; }
@media (hover: hover) and (pointer: fine) {
  .btn:hover { background: var(--coral-dark); transform: translateY(-1px); }
  .btn.secondary:hover { background: var(--teal-dark); }
}

.fab {
  position: fixed;
  bottom: 26px;
  right: 26px;
  width: 60px; height: 60px;
  border-radius: 50%;
  background: var(--coral);
  color: white;
  font-size: 30px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 10px 24px rgba(194, 105, 79, .45);
  border: none;
  cursor: pointer;
  z-index: 20;
}
@media (hover: hover) and (pointer: fine) {
  .fab:hover { background: var(--coral-dark); }
}

form .field { margin-bottom: 16px; }
form label { display: block; font-weight: 700; font-size: 13px; margin-bottom: 6px; color: var(--ink-soft); }
form input, form select, form textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid #EFEAE0;
  font-family: inherit;
  font-size: 15px;
  background: #FFFDFA;
}
form input:focus, form select:focus, form textarea:focus {
  outline: none;
  border-color: var(--coral);
}
.kind-toggle { display: flex; gap: 8px; margin-bottom: 16px; }
.kind-toggle label {
  flex: 1;
  text-align: center;
  padding: 10px;
  border-radius: 12px;
  border: 2px solid #EFEAE0;
  cursor: pointer;
  font-weight: 700;
  color: var(--ink-soft);
}
.kind-toggle input { display: none; }
.kind-toggle input:checked + span { color: white; }
.kind-toggle label:has(input:checked) { background: var(--coral); border-color: var(--coral); color: white; }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; min-width: 480px; }
table th { text-align: left; font-size: 12px; text-transform: uppercase; color: var(--ink-soft); padding: 8px 10px; border-bottom: 2px solid #F1EFEA; white-space: nowrap; }
table td { padding: 10px; border-bottom: 1px solid #F5F3EE; font-size: 14px; }
@media (hover: hover) and (pointer: fine) {
  table tr:hover td { background: #FFFBF6; }
}

.pill { padding: 3px 10px; border-radius: 999px; background: var(--cream); font-size: 12px; font-weight: 700; }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--card);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 40px 34px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.login-card .brand { justify-content: center; font-size: 30px; margin-bottom: 6px; }
.login-card p.tagline { color: var(--ink-soft); margin-top: 0; margin-bottom: 26px; }
.user-pick {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}
.user-pick .opt {
  flex: 1;
  padding: 14px 8px;
  border-radius: 16px;
  border: 2px solid #EFEAE0;
  cursor: pointer;
  text-align: center;
}
.user-pick input { display: none; }
.user-pick label:has(input:checked) { border-color: var(--coral); background: #FFF1EC; }
.user-pick .av { width: 40px; height: 40px; border-radius: 50%; margin: 0 auto 6px; display:flex; align-items:center; justify-content:center; color:white; font-weight:800; }

.flash { padding: 12px 16px; border-radius: 14px; margin-bottom: 16px; font-weight: 700; font-size: 14px; }
.flash.error { background: #FBE7E3; color: #8C3A28; }
.flash.ok { background: #E7F0E3; color: #3D6B3F; }
.flash.warn { background: #FBF0DA; color: #8A6416; }

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

.row-actions a { margin-right: 10px; font-weight: 700; font-size: 13px; }

.footer-note { text-align: center; color: var(--ink-soft); font-size: 12px; margin-top: 40px; }

/* =========================================================
   Navegacion inferior para movil (oculta en escritorio/tablet ancha)
   ========================================================= */
.bottom-nav {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--card);
  border-top: var(--border);
  box-shadow: 0 -2px 10px rgba(43,42,38,0.06);
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav-inner {
  display: flex;
  justify-content: space-around;
  align-items: stretch;
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px 2px 6px;
  color: var(--ink-soft);
  font-size: 10.5px;
  font-weight: 700;
  min-height: 56px;
}
.bottom-nav a .icon { font-size: 20px; line-height: 1; }
.bottom-nav a.active { color: var(--coral-dark); }

/* =========================================================
   Responsive: tablet y celular
   ========================================================= */
@media (max-width: 768px) {
  .nav { display: none; }
  .bottom-nav { display: block; }
  .container { padding: 18px 14px 90px; }
  .fab { bottom: 78px; right: 18px; width: 54px; height: 54px; font-size: 26px; }
  .topbar { padding: 12px 16px; }
  .summary-grid { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
  .cat-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
  .hero h1 { font-size: 22px; }
  .card { padding: 16px; }
  .login-card { padding: 30px 22px; }
}

@media (max-width: 480px) {
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .cat-grid { grid-template-columns: 1fr; }
  .user-chip span:not(.avatar) { display: none; }
  .brand .dot { display: inline; }
  form input, form select, form textarea { font-size: 16px; } /* evita zoom automatico en iOS */
}

/* En pantallas grandes, un poco mas de aire */
@media (min-width: 1100px) {
  .container { max-width: 1080px; }
}
