/* Foodshop — estilos propios sobre el UIKit compartido */

/* ── PWA iOS (viewport-fit=cover: zonas seguras) ──
   El contenido llega hasta el borde físico: el topbar tiene que dejar sitio a
   la barra de estado (si no, queda debajo) y el fondo nunca debe ser blanco. */
html { background: var(--dark); }

/* Sin zoom por doble toque (iOS): la app es una UI de toques rápidos, no un documento. */
html, body { touch-action: manipulation; }

.tf-topbar {
  box-sizing: border-box;
  height: calc(var(--topbar-height) + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
}

.tf-main {
  margin-top: calc(var(--topbar-height) + env(safe-area-inset-top));
}


.tf-sidebar {
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top);
}

.fs-page {
  padding-bottom: calc(6rem + env(safe-area-inset-bottom)); /* deja hueco para la barra de búsqueda fija */
}

/* ── Cabecera: selector de lista + agrupar ── */
.fs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

.fs-list-switcher {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.fs-list-switcher select {
  min-width: 160px;
}

#groupToggleBtn.active {
  background: var(--gold-subtle);
  border-color: var(--gold);
  color: var(--gold-light);
}

/* ── Estado de conexión ── */
.fs-net {
  background: var(--dark-3);
  border: 1px solid var(--border-muted);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius);
  padding: .45rem .75rem;
  margin-bottom: var(--space-3);
  font-size: .8rem;
  color: var(--text-muted);
}

.fs-net[hidden] { display: none; }

/* Ítem de texto libre (sin producto de catálogo) */
.fs-tile--custom {
  border-style: dashed;
}

/* ── Totales ── */
.fs-totals {
  margin-bottom: var(--space-4);
}

.fs-totals__row {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}

.fs-totals__chip {
  background: var(--dark-3);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius);
  padding: .4rem .75rem;
  font-size: .85rem;
  color: var(--text-muted);
}

.fs-totals__chip strong {
  color: var(--text);
}

.fs-totals__chip--total {
  border-color: var(--gold);
  color: var(--gold-light);
}

/* ── Secciones ── */
.fs-section {
  margin-bottom: var(--space-5);
}

.fs-section-title {
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-dim);
  margin-bottom: var(--space-3);
}

.fs-group {
  margin-bottom: var(--space-4);
}

.fs-group__header {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  color: var(--text);
  padding: .4rem 0;
  border-bottom: 1px solid var(--border-muted);
  margin-bottom: var(--space-3);
}

/* ── Tiles ── */
.fs-tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-3);
}

.fs-tile {
  position: relative;
  background: var(--dark-3);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius);
  padding: var(--space-3);
  cursor: pointer;
  transition: all var(--transition-sm);
  text-align: center;
}

.fs-tile:hover {
  border-color: var(--gold);
  transform: translateY(-2px);
}

.fs-tile[data-client-id] {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.fs-tile__priority {
  position: absolute;
  top: .3rem;
  left: .3rem;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  z-index: 2;
}

.fs-priority-urgent { background: rgba(217, 20, 60, .18); color: #f87171; }
.fs-priority-low { background: rgba(148, 163, 184, .18); color: #cbd5e1; }
.fs-tile--urgent { border-color: #f87171; }
.fs-tile--low { opacity: .65; }

.fs-editor__image {
  display: block;
  width: 100%;
  height: min(50vh, 320px);
  object-fit: contain;
  margin-bottom: var(--space-3);
}

.fs-editor__meta {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: .6rem;
  margin-bottom: var(--space-3);
}

.fs-editor__priorities {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

.fs-editor__priority {
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: .6rem;
  font-weight: 600;
}

.fs-editor__priority[aria-pressed="true"] { border-color: currentColor; }

.fs-editor__assign {
  width: 100%;
  justify-content: center;
  margin-top: var(--space-3);
}

.fs-tile__remove {
  position: absolute;
  top: .3rem;
  right: .3rem;
  background: var(--dark-4);
  border: none;
  color: var(--text-muted);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: .7rem;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.fs-tile__remove:hover {
  color: var(--danger-light);
}

.fs-tile__image {
  width: 100%;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-2);
  font-size: 2rem;
  color: var(--text-dim);
}

.fs-tile__image img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.fs-tile__name {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: .35rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.2em; /* reserva 2 líneas siempre, si no las tarjetas quedan de alturas distintas */
}

.fs-tile__meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .25rem;
}

.fs-tile__price {
  font-size: .85rem;
  font-weight: 700;
  color: var(--gold-light);
}

.fs-qty {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  margin-top: .4rem;
}

.fs-qty__btn {
  width: 1.8rem;
  height: 1.8rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: var(--dark-4);
  border: 1px solid var(--border-muted);
  border-radius: 50%;
  color: var(--text);
  font-size: 1rem;
  line-height: 1;
}

.fs-qty__btn[aria-disabled="true"] { opacity: .35; }

.fs-qty__value {
  min-width: 1.4rem;
  text-align: center;
  font-size: .85rem;
  font-weight: 700;
  color: var(--text);
}

/* Badges por supermercado */
.fs-badge-mercadona { background: rgba(0, 154, 68, .15); color: #4ade80; }
.fs-badge-carrefour { background: rgba(0, 103, 177, .15); color: #5ab4ee; }
.fs-badge-bonpreu { background: rgba(217, 20, 60, .15); color: #f87171; }
.fs-badge-bonarea { background: rgba(245, 158, 11, .15); color: #fbbf24; }



/* ── Barra de búsqueda fija ── */
.fs-search-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: var(--space-3) var(--space-4);
  /* iPhone en modo standalone (PWA instalada): deja hueco bajo el home indicator */
  padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom));
  background: var(--dark-2);
  border-top: 1px solid var(--border-muted);
  z-index: 250;
}

/* Formulario del modal "añadir por URL" */
.fs-url-form input { width: 100%; }
.fs-url-hint { margin-top: .5rem; font-size: .75rem; color: var(--text-dim); }

.fs-search-inner {
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: .6rem;
}

.fs-search-add {
  flex-shrink: 0;
  width: 2.75rem;
  height: 2.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: var(--gold-subtle);
  border: 1px solid var(--gold);
  border-radius: 50%;
  color: var(--gold-light);
  font-size: 1.1rem;
}

.fs-search-input-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: .6rem;
  background: var(--dark-4);
  border: 1px solid var(--border-muted);
  border-radius: 999px;
  padding: .6rem 1rem;
  color: var(--text-dim);
}

.fs-search-input-wrap input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: .95rem;
}

.fs-search-input-wrap input::placeholder {
  color: var(--text-dim);
}

/* ── Panel de búsqueda a pantalla completa ── */
.fs-search-panel {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--fs-vh, 100%); /* con teclado, la zona visible (viewport.js) */
  z-index: 600;
  flex-direction: column;
  background: var(--dark);
  padding-top: env(safe-area-inset-top);
}

.fs-search-panel__head {
  flex-shrink: 0;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: var(--space-3) var(--space-4);
}

.fs-search-back {
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1.25rem;
}

.fs-search-panel__results {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 var(--space-4) var(--space-4);
}

/* La barra inferior es un botón con aspecto de input (no un input real). */
.fs-search-fake {
  text-align: left;
  font-size: .95rem;
  color: var(--text-dim);
}

.fs-search-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: .6rem var(--space-3);
  cursor: pointer;
  border-bottom: 1px solid var(--border-muted);
}

.fs-search-row:last-child {
  border-bottom: none;
}

.fs-search-row:hover {
  background: var(--dark-4);
}

.fs-search-row__image {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 1.2rem;
}

.fs-search-row__image img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.fs-search-row__info {
  flex: 1;
  min-width: 0;
}

.fs-search-row__name {
  font-size: .85rem;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fs-search-row__brand {
  font-size: .75rem;
  color: var(--text-dim);
}

.fs-search-row__price {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: .25rem;
  flex-shrink: 0;
  font-size: .85rem;
  font-weight: 700;
  color: var(--gold-light);
}

.fs-search-note {
  padding: .5rem var(--space-4);
  font-size: .75rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-muted);
}

.fs-search-row--custom .fs-search-row__image {
  color: var(--gold-light);
}

.fs-search-empty {
  padding: var(--space-4);
  text-align: center;
  color: var(--text-muted);
  font-size: .85rem;
}

@media (max-width: 768px) {
  .fs-tile-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  }
}

/* ── Móvil: shell estático (solo scrollea el contenido) ── */
@media (max-width: 768px) {
  /* iOS hace zoom automático al enfocar un campo con fuente < 16px (y deja la
     página desplazada/ampliada al cerrar el teclado). */
  input, select, textarea,
  .fs-search-input-wrap input,
  .form-control, .form-select, .form-select-sm, .form-control-sm {
    font-size: 16px !important;
  }

  html:has(body.fs-app),
  body.fs-app {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }

  body.fs-app .tf-dash {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    min-height: 0;
  }

  /* topbar y buscador se anclan al shell, no a la ventana */
  body.fs-app .tf-topbar,
  body.fs-app .fs-search-bar {
    position: absolute;
  }

  body.fs-app .tf-main {
    position: absolute;
    top: calc(var(--topbar-height) + env(safe-area-inset-top));
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  /* El teclado solo se abre dentro del panel de búsqueda o de un modal: ambos se acotan a la zona visible. */
  html.fs-keyboard .tf-modal-backdrop { height: var(--fs-vh); bottom: auto; }
}

body.fs-search-open { overflow: hidden; }
