/* Apple HIG: color del sistema, tipografía, 44pt mínimo, cuadrícula de 8pt,
   modo oscuro, Dynamic Type (rem), áreas seguras y reduce-motion. */
:root {
  --tint: #007aff;
  --destructive: #ff3b30;
  --bg: #f2f2f7;
  --surface: #ffffff;
  --label: #000000;
  --label-secondary: rgba(60, 60, 67, 0.6);
  --label-tertiary: rgba(60, 60, 67, 0.3);
  --separator: rgba(60, 60, 67, 0.29);
  --material: rgba(249, 249, 249, 0.94);
  --radius: 10px;
  --space: 8px;
  --hit: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --tint: #0a84ff;
    --destructive: #ff453a;
    --bg: #000000;
    --surface: #1c1c1e;
    --label: #ffffff;
    --label-secondary: rgba(235, 235, 245, 0.6);
    --label-tertiary: rgba(235, 235, 245, 0.3);
    --separator: rgba(84, 84, 88, 0.6);
    --material: rgba(29, 29, 30, 0.94);
  }
}

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

html { font-size: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--label);
  font: 1.0625rem/1.29 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.screen {
  max-width: 640px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) calc(16px + env(safe-area-inset-right))
           calc(190px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
}

.nav { display: flex; justify-content: flex-end; min-height: var(--hit); align-items: center; }

.large-title {
  margin: 0;
  font-size: 2.125rem;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: 0.37px;
}

.subtitle { margin: 4px 0 24px; color: var(--label-secondary); font-size: 0.9375rem; }

.text-button {
  min-height: var(--hit);
  min-width: var(--hit);
  padding: 0 var(--space);
  background: none;
  border: 0;
  color: var(--tint);
  cursor: pointer;
}

/* Lista agrupada e inset */
.group { list-style: none; margin: 0; padding: 0; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.group.hidden { display: none; }

.section-header {
  margin: 24px 16px 6px; font-size: 0.8125rem; font-weight: 400;
  text-transform: uppercase; color: var(--label-secondary);
}
section.hidden { display: none; }
.screen > section:first-of-type .section-header { margin-top: 0; }

/* Fila deslizable */
.swipe { position: relative; overflow: hidden; }
.swipe + .swipe::before {
  content: ""; position: absolute; top: 0; right: 0; left: 16px; z-index: 2;
  border-top: 0.5px solid var(--separator); pointer-events: none;
}
.items .swipe + .swipe::before { left: 52px; }
.swipe-action { position: absolute; top: 0; right: 0; bottom: 0; width: 88px; background: var(--destructive); visibility: hidden; }
/* El fondo rojo solo existe mientras la fila esta desplazada: en reposo se asomaba
   como una linea roja en el borde derecho por el redondeo de subpixeles. */
.swipe.open .swipe-action { visibility: visible; }
.swipe-delete {
  width: 100%; height: 100%; border: 0; background: none; color: #fff;
  font-weight: 600; cursor: pointer;
}
.swipe-content {
  position: relative; z-index: 1; display: flex; align-items: center;
  min-height: var(--hit); padding-left: 16px; background: var(--surface);
  touch-action: pan-y; transition: transform 0.25s ease;
}
.swipe-content.dragging { transition: none; }

.row { flex: 1; display: flex; align-items: center; min-width: 0; }
.nav-row {
  flex: 1; display: flex; align-items: center; gap: 8px; min-height: var(--hit);
  padding: 8px 16px 8px 0; background: none; border: 0; text-align: left; cursor: pointer;
}
.nav-row .label { flex: 1; }
.detail { color: var(--label-secondary); }
.chevron {
  width: 8px; height: 8px; margin-left: 4px; border: solid var(--label-tertiary);
  border-width: 2px 2px 0 0; transform: rotate(45deg);
}
.qty { padding-right: 16px; color: var(--label-secondary); font-variant-numeric: tabular-nums; }
.stepper { display: flex; align-items: center; padding-right: 4px; }
.stepper button {
  width: var(--hit); height: var(--hit); border: 0; background: none;
  color: var(--tint); font-size: 1.5rem; cursor: pointer;
}
.stepper span { min-width: 24px; text-align: center; font-variant-numeric: tabular-nums; }

.check {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px;
  min-height: var(--hit); padding: 8px 16px 8px 0;
  background: none; border: 0; text-align: left; cursor: pointer;
}

.circle {
  flex: none; width: 24px; height: 24px; border-radius: 50%;
  border: 1.5px solid var(--label-tertiary);
  display: grid; place-items: center;
  transition: background-color 0.2s, border-color 0.2s;
}
.done .circle { background: var(--tint); border-color: var(--tint); }
.done .circle::after {
  content: ""; width: 6px; height: 11px; margin-top: -2px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.done .label { color: var(--label-secondary); text-decoration: line-through; }

.delete {
  flex: none; width: var(--hit); height: var(--hit); margin-left: -16px; margin-right: 0;
  background: none; border: 0; cursor: pointer; display: grid; place-items: center;
}
.delete span {
  width: 22px; height: 22px; border-radius: 50%; background: var(--destructive); color: #fff;
  display: grid; place-items: center; font-weight: 700; line-height: 1;
}

.empty { text-align: center; padding: 48px 16px; color: var(--label-secondary); }
.empty h2 { margin: 0 0 4px; font-size: 1.25rem; color: var(--label); }
.empty p { margin: 0; }

/* Barra inferior con material translúcido */
.composer {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; flex-wrap: wrap; gap: var(--space); align-items: center;
  padding: 8px calc(16px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  background: var(--material);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
}
.field {
  flex: 1; min-height: var(--hit); padding: 0 12px;
  background: var(--surface); border: 0.5px solid var(--separator);
  border-radius: var(--radius); font-size: 1.0625rem; /* ≥16px evita zoom en iOS */
}
.field::placeholder { color: var(--label-tertiary); }
.primary {
  min-height: var(--hit); padding: 0 16px; border: 0; border-radius: var(--radius);
  background: var(--tint); color: #fff; font-weight: 600; cursor: pointer;
}
.primary:disabled { opacity: 0.4; cursor: default; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(72px + env(safe-area-inset-bottom));
  max-width: 608px; margin: 0 auto;
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 0 8px 0 16px; min-height: var(--hit);
  background: var(--material); border-radius: 14px; border: 0.5px solid var(--separator);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
}

:focus-visible { outline: 3px solid var(--tint); outline-offset: 2px; }

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


.composer-row { flex: 1 1 100%; display: flex; align-items: center; gap: var(--space); }
.composer-row .stepper { background: var(--surface); border-radius: var(--radius); padding: 0; }
.select {
  flex: 1; min-width: 0; min-height: var(--hit); padding: 0 8px;
  background: var(--surface); border: 0.5px solid var(--separator); border-radius: var(--radius);
}
.toast.tall { bottom: calc(128px + env(safe-area-inset-bottom)); }

.field.wide { flex: 1 1 100%; }

