/* ============================================================
   Galita — hoja de estilos
   ============================================================ */

:root {
  --bg: #fbf8f3;
  --surface: #ffffff;
  --surface-2: #f4efe7;
  --ink: #231f1c;
  --muted: #7e746c;
  --line: #eae2d8;
  --accent: #b5543a;
  --accent-ink: #ffffff;
  --accent-soft: #f7e8e2;
  --ok: #3f7d58;
  --warn: #b5873a;
  --danger: #a33a2f;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(35, 31, 28, .05), 0 6px 20px rgba(35, 31, 28, .06);
  --tab-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141110;
    --surface: #1f1b18;
    --surface-2: #2a241f;
    --ink: #f2ede6;
    --muted: #a09488;
    --line: #322b26;
    --accent: #e08363;
    --accent-ink: #1a1210;
    --accent-soft: #35221c;
    --ok: #74b58d;
    --warn: #d9ae63;
    --danger: #e0806f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  }
}

:root[data-theme="dark"] {
  --bg: #141110;
  --surface: #1f1b18;
  --surface-2: #2a241f;
  --ink: #f2ede6;
  --muted: #a09488;
  --line: #322b26;
  --accent: #e08363;
  --accent-ink: #1a1210;
  --accent-soft: #35221c;
  --ok: #74b58d;
  --warn: #d9ae63;
  --danger: #e0806f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; }

a { color: var(--accent); }

/* ---------- Estructura ---------- */

#app {
  max-width: 600px;
  margin: 0 auto;
  min-height: 100dvh;
}

.cabecera {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.cabecera h1 {
  font-size: 1.3rem;
  letter-spacing: -.02em;
  margin: 0;
  flex: 1;
}

.vista {
  padding: 16px 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px);
}

/* ---------- Barra de pestañas ---------- */

.tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.tabs a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: var(--tab-h);
  text-decoration: none;
  color: var(--muted);
  font-size: .68rem;
  letter-spacing: .01em;
  -webkit-tap-highlight-color: transparent;
}

.tabs a.activo { color: var(--accent); }
.tabs a svg { width: 23px; height: 23px; }

/* ---------- Tarjetas ---------- */

.tarjeta {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.tarjeta.plana { box-shadow: none; }

.seccion-titulo {
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
  font-weight: 600;
  margin: 22px 2px 10px;
}

.seccion-titulo:first-child { margin-top: 4px; }

/* ---------- Resumen del día ---------- */

.resumen {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.metrica {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.metrica .valor {
  font-size: 1.85rem;
  font-weight: 650;
  letter-spacing: -.03em;
  line-height: 1.1;
}

.metrica .valor .u {
  font-size: .95rem;
  font-weight: 500;
  color: var(--muted);
  margin-left: 2px;
}

.metrica .etiqueta {
  font-size: .76rem;
  color: var(--muted);
  margin-top: 3px;
}

.metrica .pie {
  font-size: .72rem;
  color: var(--muted);
  margin-top: 7px;
  padding-top: 7px;
  border-top: 1px solid var(--line);
}

/* ---------- Listas ---------- */

.lista { display: flex; flex-direction: column; gap: 8px; }

.fila {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  text-align: left;
  width: 100%;
}

.fila .ppal { flex: 1; min-width: 0; }
.fila .nombre { font-weight: 550; letter-spacing: -.01em; }
.fila .sub { font-size: .79rem; color: var(--muted); margin-top: 1px; }
.fila .der { text-align: right; flex-shrink: 0; }
.fila .cifra { font-weight: 600; font-variant-numeric: tabular-nums; }

.punto {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--accent);
}
.punto.pienso { background: #c08a3e; }
.punto.lata { background: #9c5a7a; }
.punto.snack { background: #5a8c9c; }
.punto.suplemento { background: #6b8c5a; }

.vacio {
  text-align: center;
  color: var(--muted);
  padding: 28px 16px;
  font-size: .9rem;
}

/* ---------- Botones ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
  padding: 11px 18px;
  font-weight: 550;
  font-size: .94rem;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(.985); }

.btn.ppal {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.btn.ancho { width: 100%; }
.btn.sutil { background: transparent; border-color: transparent; color: var(--muted); }
.btn.peligro { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); background: transparent; }
.btn:disabled { opacity: .5; }

.fab {
  position: fixed;
  right: max(16px, calc(50% - 300px + 16px));
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px);
  z-index: 25;
  width: 58px; height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 40%, transparent);
  display: grid;
  place-items: center;
}
.fab svg { width: 26px; height: 26px; }

/* ---------- Chips ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: .88rem;
  white-space: nowrap;
}

.chip.sel {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* ---------- Formularios ---------- */

.campo { margin-bottom: 14px; }

.campo label {
  display: block;
  font-size: .8rem;
  color: var(--muted);
  margin-bottom: 5px;
  font-weight: 550;
}

.campo input, .campo select, .campo textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
  font-size: 1rem; /* 16px evita el zoom automático de iOS */
}

.campo textarea { min-height: 76px; resize: vertical; }

.campo input:focus, .campo select:focus, .campo textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 1px;
}

.fila-campos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.ayuda { font-size: .76rem; color: var(--muted); margin-top: 5px; }

.stepper { display: flex; align-items: center; gap: 10px; }
.stepper input { text-align: center; font-size: 1.3rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stepper button {
  width: 46px; height: 46px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 1.25rem;
  font-weight: 500;
}

/* ---------- Hoja modal ---------- */

.velo {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(20, 15, 12, .45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: aparecer .18s ease;
}

@keyframes aparecer { from { opacity: 0 } to { opacity: 1 } }
@keyframes subir { from { transform: translateY(18px) } to { transform: translateY(0) } }

.hoja {
  background: var(--bg);
  width: 100%;
  max-width: 600px;
  max-height: 92dvh;
  overflow-y: auto;
  border-radius: 22px 22px 0 0;
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 20px);
  animation: subir .2s ease;
}

.hoja-barra {
  position: sticky;
  top: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0 14px;
  z-index: 2;
}

.hoja-barra h2 { font-size: 1.1rem; margin: 0; flex: 1; letter-spacing: -.02em; }

.asa {
  width: 38px; height: 4px;
  background: var(--line);
  border-radius: 2px;
  margin: 6px auto 0;
}

/* ---------- Gráficas ---------- */

.grafica { width: 100%; display: block; overflow: visible; }
.grafica .linea { fill: none; stroke: var(--accent); stroke-width: 2.25; stroke-linecap: round; stroke-linejoin: round; }
.grafica .area { fill: var(--accent); opacity: .09; }
.grafica .pto { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.grafica .reja { stroke: var(--line); stroke-width: 1; }
.grafica .eje { fill: var(--muted); font-size: 10px; }
.grafica .banda { fill: var(--ok); opacity: .16; }
.grafica .borde-banda { stroke: var(--ok); stroke-width: 1; stroke-dasharray: 3 3; opacity: .55; }

/* ---------- Varios ---------- */

.insignia {
  display: inline-block;
  font-size: .7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}
.insignia.alta { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.insignia.baja { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.insignia.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }

.estado-sync {
  font-size: .72rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 5px;
}
.estado-sync .led { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.estado-sync .led.off { background: var(--muted); }
.estado-sync .led.err { background: var(--danger); }

.aviso {
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  color: var(--ink);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  font-size: .85rem;
  margin-bottom: 14px;
}

.aviso.error {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}

.estrellas { color: var(--warn); letter-spacing: 1px; font-size: .85rem; }

/* ---------- Login ---------- */

.login {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}

.login img { width: 84px; height: 84px; border-radius: 20px; margin-bottom: 18px; }
.login h1 { font-size: 1.6rem; margin: 0 0 4px; letter-spacing: -.03em; }
.login p.sub { color: var(--muted); margin: 0 0 26px; font-size: .92rem; }
.login form { width: 100%; max-width: 330px; text-align: left; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 80px);
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: .87rem;
  font-weight: 500;
  z-index: 60;
  box-shadow: var(--shadow);
  animation: aparecer .15s ease;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
