/* =========================================================
   PALETA DE COLORES
   Todo el diseño usa estas variables: para cambiar el "look"
   de la web basta con tocar los valores de aquí.
   ========================================================= */
:root {
  --page-bg: #F4F6F3;
  /* fondo general de la página */
  --card-bg: #FFFFFF;
  /* fondo de las tarjetas de contenido */
  --ink: #1C2622;
  /* color principal del texto */
  --muted: #6C776D;
  /* texto secundario (fechas, ayudas, notas) */
  --line: #E1E6DD;
  /* líneas y bordes discretos */

  --brand: #1F6F54;
  /* verde principal de la marca: header, botones */
  --brand-dark: #154F3B;
  /* variante oscura para hover */
  --brand-bg: #E4F2EA;
  /* fondo suave a juego con el verde de marca */

  --accent: #C9932B;
  /* mostaza: detalles y barras destacadas */

  --danger: #B33951;
  /* rojo baya: eliminar, avisos */

  --save: #1F6F54;
  /* color de "precio más barato" */
  --save-bg: #E4F2EA;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--page-bg);
  font-family: 'Space Mono', monospace;
  color: var(--ink);
  min-height: 100vh;
}

/* Oculta visualmente un elemento pero lo deja disponible para
   lectores de pantalla (accesibilidad en formularios) */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* =========================================================
   CABECERA DEL SITIO
   Todo centrado: logo + nombre a la izquierda del grupo,
   y los botones de navegación justo al lado.
   ========================================================= */
.site-header {
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 16px 16px;
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cart-logo {
  font-size: 26px;
  line-height: 1;
}

.brand-title {
  font-family: 'Archivo Black', sans-serif;
  font-size: 19px;
  letter-spacing: 0.3px;
  color: var(--brand-dark);
}

.main-nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.nav-btn {
  font-family: inherit;
  font-size: 12px;
  padding: 8px 14px;
  background: none;
  border: 1.5px solid var(--line);
  color: var(--muted);
  border-radius: 999px;
  cursor: pointer;
}

.nav-btn:hover {
  border-color: var(--brand);
  color: var(--brand-dark);
}

.nav-btn.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 700;
}

/* Menú desplegable del perfil: icono de persona + nombre, con
   Dashboard, Mi lista de la compra y Cambiar de usuario dentro */
.profile-menu {
  position: relative;
}

.profile-menu-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: 12px;
  padding: 8px 14px;
  background: none;
  border: 1.5px solid var(--line);
  color: var(--muted);
  border-radius: 999px;
  cursor: pointer;
}

.profile-menu-btn:hover {
  border-color: var(--brand);
  color: var(--brand-dark);
}

.profile-menu-btn.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 700;
}

.profile-icon {
  font-size: 14px;
  line-height: 1;
}

.profile-menu-caret {
  font-size: 9px;
  margin-left: 1px;
}

.profile-menu-dropdown {
  display: none;
  flex-direction: column;
  gap: 2px;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 220px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 26px rgba(28, 38, 34, 0.14);
  padding: 6px;
  z-index: 20;
}

.profile-menu-dropdown.open {
  display: flex;
}

.profile-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 12.5px;
  padding: 9px 12px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--ink);
}

.profile-menu-item:hover {
  background: var(--brand-bg);
  color: var(--brand-dark);
}

.profile-menu-divider {
  height: 1px;
  background: var(--line);
  margin: 4px 2px;
}

.profile-menu-item-danger {
  color: var(--danger);
}

.profile-menu-item-danger:hover {
  background: #fbe8ec;
  color: var(--danger);
}

/* Barra fina con el perfil activo y el resumen de gasto */
.stats-bar {
  max-width: 960px;
  margin: 0 auto;
  padding: 10px 16px 0;
  display: flex;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
  font-size: 11.5px;
  color: var(--muted);
  text-align: center;
}

/* =========================================================
   CONTENEDOR PRINCIPAL Y TARJETAS
   Cada bloque de contenido es una "card" independiente,
   en vez del antiguo recibo de papel continuo.
   ========================================================= */
main {
  padding-bottom: 60px;
}

.wrap {
  max-width: 780px;
  margin: 0 auto;
  padding: 24px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.page-section {
  display: none;
  flex-direction: column;
  gap: 18px;
}

.page-section.active {
  display: flex;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px 22px;
}

.card-title {
  font-size: 12.5px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--muted);
  margin: 0 0 14px;
  font-weight: 700;
}

.card-subtitle {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin: 0 0 10px;
  font-weight: 700;
}

.section-hint {
  font-size: 11.5px;
  color: var(--muted);
  margin: 0 0 12px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.chip {
  background: var(--brand-bg);
  border: 1.5px solid var(--brand);
  color: var(--brand-dark);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chip button {
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  color: var(--danger);
  font-weight: 700;
  font-size: 13px;
  padding: 0;
}

/* Pestañas internas de la sección "Consultar compras anteriores" */
.tabs {
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.tab {
  background: none;
  border: 1.5px solid var(--line);
  padding: 7px 14px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  color: var(--muted);
  border-radius: 6px;
}

.tab.active {
  border-color: var(--brand);
  color: var(--brand-dark);
  font-weight: 700;
  background: var(--brand-bg);
}

input,
select {
  font-family: inherit;
  font-size: 13px;
  padding: 7px 9px;
  border: 1.5px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--brand);
}

input::placeholder {
  color: #a09c8f;
}

/* Botón principal, usado para todas las acciones "positivas" */
button.btn {
  font-family: inherit;
  font-size: 12px;
  padding: 9px 16px;
  background: var(--brand);
  color: #fff;
  border: none;
  cursor: pointer;
  letter-spacing: 0.3px;
  border-radius: 6px;
}

button.btn:hover {
  background: var(--brand-dark);
}

/* Variante de botón "secundaria" (p.ej. Importar copia) */
button.btn-outline {
  background: none;
  color: var(--brand-dark);
  border: 1.5px solid var(--brand);
}

button.btn-outline:hover {
  background: var(--brand-bg);
}

.addform {
  display: grid;
  grid-template-columns: 1.3fr 1fr 0.9fr 0.7fr 1fr 0.6fr 0.9fr auto;
  gap: 8px;
  margin-top: 4px;
  align-items: end;
}

.addform label {
  font-size: 9.5px;
  color: var(--muted);
  display: block;
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.addform input,
.addform select {
  width: 100%;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.day-group {
  margin-bottom: 14px;
}

.day-label {
  font-size: 10.5px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding-bottom: 5px;
  margin-bottom: 6px;
}

.line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12.5px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
  align-items: center;
}

.line .name {
  flex: 1;
}

.line .name b {
  display: block;
}

.line .meta {
  font-size: 10px;
  color: var(--muted);
}

.line .amount {
  white-space: nowrap;
  font-weight: 700;
}

.line .del {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  margin-left: 8px;
}

.running-total {
  display: flex;
  justify-content: space-between;
  padding-top: 14px;
  margin-top: 6px;
  border-top: 2px solid var(--ink);
  font-weight: 700;
  font-size: 15px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  margin-top: 6px;
  table-layout: fixed;
}

th,
td {
  padding: 9px 6px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  word-break: break-word;
}

th {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  border-bottom: 2px solid var(--ink);
}

.cheapest {
  color: var(--save);
  font-weight: 700;
}

/* Etiqueta "MÁS BARATO" junto al mejor precio */
.stamp {
  display: inline-block;
  border: 1.5px solid var(--save);
  color: var(--save);
  background: var(--save-bg);
  font-size: 9px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  letter-spacing: 0.3px;
  margin-left: 6px;
  white-space: nowrap;
}

.nodata {
  color: #b3bcb0;
}

/* Envuelve la tabla de comparación para que en móvil se pueda
   desplazar horizontalmente en vez de romper el diseño */
.table-scroll {
  overflow-x: auto;
}

.table-scroll table {
  min-width: 480px;
}

/* Aviso de que un precio lleva tiempo sin actualizarse */
.price-age {
  color: var(--muted);
}

.price-age.stale {
  color: var(--danger);
  font-weight: 700;
}

/* Fila de filtros de la vista "Comparar precios" */
.compare-filters select {
  min-width: 180px;
}

.bar-item {
  margin-bottom: 12px;
}

.bar-top {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  margin-bottom: 4px;
}

.bar-top .rank {
  color: var(--muted);
  font-size: 11px;
  margin-right: 6px;
}

.bar-track {
  height: 8px;
  background: #e4e9df;
  position: relative;
  border-radius: 4px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--brand);
}

.bar-fill.top1 {
  background: var(--accent);
}

.bar-sub {
  font-size: 10px;
  color: var(--muted);
  margin-top: 3px;
}

.empty {
  text-align: center;
  padding: 30px 10px;
  color: var(--muted);
  font-size: 13px;
}

.scanform {
  display: grid;
  grid-template-columns: 1fr 1fr 1.4fr auto;
  gap: 8px;
  align-items: end;
}

.scanform label {
  font-size: 9.5px;
  color: var(--muted);
  display: block;
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.scanform input,
.scanform select {
  width: 100%;
}

#scan-status {
  font-size: 12px;
  color: var(--muted);
  margin-top: 10px;
  min-height: 16px;
}

.scan-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  margin-top: 10px;
}

.scan-table th {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--muted);
  text-align: left;
  padding: 6px 4px;
  border-bottom: 2px solid var(--ink);
}

.scan-table td {
  padding: 5px 4px;
  border-bottom: 1px solid var(--line);
}

.scan-table input[type="text"] {
  width: 100%;
}

.scan-table input[type="number"] {
  width: 70px;
}

@media (max-width:700px) {
  .scanform {
    grid-template-columns: 1fr 1fr;
  }
}

.scan-photo-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.scan-photo-controls .btn {
  flex: 1;
  min-width: 120px;
  white-space: nowrap;
}

/* Overlay de cámara en vivo, a pantalla completa por encima de todo */
.camera-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 17, 0.88);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.camera-box {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 14px;
  max-width: 480px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.camera-box video {
  width: 100%;
  max-height: 60vh;
  background: #000;
  border-radius: 8px;
  object-fit: contain;
}

.camera-actions {
  display: flex;
  gap: 8px;
}

.camera-actions .btn {
  flex: 1;
}

.camera-error {
  font-size: 12px;
  color: var(--danger);
}

/* =========================================================
   PANTALLA DE PERFILES (login)
   ========================================================= */
#login-screen {
  max-width: 420px;
  margin: 60px auto;
  padding: 0 12px;
}

.login-card {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 30px 26px;
}

.login-title {
  font-family: 'Archivo Black', sans-serif;
  font-size: 19px;
  text-align: center;
  margin: 0 0 6px;
}

.login-sub {
  font-size: 11.5px;
  color: var(--muted);
  text-align: center;
  margin-bottom: 20px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 6px;
}

.auth-form input {
  width: 100%;
}

.auth-error {
  min-height: 14px;
  font-size: 11.5px;
  color: var(--danger);
  margin-top: -2px;
}

.auth-submit {
  width: 100%;
  margin-top: 4px;
}

.auth-switch {
  text-align: center;
  font-size: 11.5px;
  color: var(--muted);
  margin: 18px 0 0;
}

.auth-switch button {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 11.5px;
  color: var(--brand-dark);
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}

/* =========================================================
   FAVORITO Y SUPERMERCADOS ECONÓMICOS (chips)
   ========================================================= */
.fav-star-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0;
  color: var(--accent);
}

.chip.fav-market {
  box-shadow: 0 0 0 1.5px var(--accent) inset;
}

.chip .cheap-name {
  font-weight: 700;
}

/* =========================================================
   DASHBOARD
   ========================================================= */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.dash-stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
  background: var(--page-bg);
}

.dash-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 6px;
}

.dash-value {
  font-size: 15.5px;
  font-weight: 700;
  color: var(--brand-dark);
  word-break: break-word;
}

.dash-sub {
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 4px;
}

/* =========================================================
   MI LISTA DE LA COMPRA
   ========================================================= */
.shoplist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.shoplist-item .shoplist-text {
  flex: 1;
}

.shoplist-item.checked .shoplist-text {
  text-decoration: line-through;
  color: var(--muted);
}

.shoplist-item .shoplist-del {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}

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

@media (max-width:700px) {
  .addform {
    grid-template-columns: 1fr 1fr;
  }

  .header-inner {
    flex-direction: column;
    gap: 12px;
  }

  .compare-filters {
    flex-direction: column;
    align-items: stretch;
  }

  .compare-filters input,
  .compare-filters select {
    width: 100%;
  }
}
