/* Mercado — mobile-first, light/dark, one-hand friendly. Tokens can later be
   aligned to the Personal Hub's design tokens. */
:root {
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-2: #eef0f2;
  --text: #1a1d21;
  --muted: #616a75;
  --border: #dde1e6;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --danger: #b42318;
  --alta: #b42318;
  --media: #b25b00;
  --baja: #3f6212;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 12px rgba(16, 24, 40, 0.08);
  --radius: 14px;
  --tap: 48px;
}
[data-theme="dark"] {
  --bg: #0e1116;
  --surface: #171b21;
  --surface-2: #21262e;
  --text: #e7ebef;
  --muted: #9aa4b0;
  --border: #2b323b;
  --primary: #2dd4bf;
  --primary-ink: #04211d;
  --danger: #f97066;
  --alta: #f97066;
  --media: #fdb022;
  --baja: #a6e267;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1116; --surface: #171b21; --surface-2: #21262e; --text: #e7ebef;
    --muted: #9aa4b0; --border: #2b323b; --primary: #2dd4bf; --primary-ink: #04211d;
    --danger: #f97066; --alta: #f97066; --media: #fdb022; --baja: #a6e267;
  }
}

* { box-sizing: border-box; }
/* The [hidden] attribute must always win over class-level display rules
   (toast, editor archive button, recurrence field, view toggles). */
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 0.5rem; }
.muted { color: var(--muted); font-size: 0.9rem; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0);
}

.app-header {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.5rem; padding: 0.75rem 1rem;
  padding-top: max(0.75rem, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.app-header__title { display: flex; align-items: center; gap: 0.5rem; }
.app-header__logo { font-size: 1.4rem; }
.app-header__actions { display: flex; align-items: center; gap: 0.4rem; }

.app-main { max-width: 640px; margin: 0 auto; padding: 1rem; padding-bottom: 4rem; }

.btn {
  min-height: var(--tap); padding: 0 1rem; border-radius: 10px; border: 1px solid transparent;
  font-size: 0.95rem; font-weight: 600; cursor: pointer; background: var(--surface-2);
  color: var(--text); display: inline-flex; align-items: center; justify-content: center;
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--primary); color: var(--primary-ink); }
.btn--ghost { background: transparent; border-color: var(--border); }
.btn--icon { min-width: var(--tap); padding: 0; font-size: 1.2rem; background: transparent; }
.btn--danger-ghost { background: transparent; color: var(--danger); border-color: var(--border); }
.btn[aria-pressed="true"] { background: var(--primary); color: var(--primary-ink); }

.quick-add { display: flex; gap: 0.5rem; margin-bottom: 0.6rem; }
.quick-add__input {
  flex: 1; min-height: var(--tap); padding: 0 0.9rem; font-size: 1rem;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
}
.ai-add { width: 100%; margin-bottom: 0.8rem; font-size: 0.9rem; }
.quick-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 1rem; }
.chip {
  min-height: 40px; padding: 0 0.8rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 0.85rem; cursor: pointer;
}

.dashboard { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; margin-bottom: 1.2rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem 0.5rem; text-align: center; }
.tile__num { font-size: 1.4rem; font-weight: 700; }
.tile__label { font-size: 0.7rem; color: var(--muted); }
.tile--wide { grid-column: span 4; text-align: left; }
@media (max-width: 400px) { .dashboard { grid-template-columns: repeat(2, 1fr); } .tile--wide { grid-column: span 2; } }

.filters { display: flex; gap: 0.5rem; margin-bottom: 0.8rem; }
.filters__search { flex: 1; min-height: 44px; padding: 0 0.8rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); }
.filters__select, #editor-category, #editor-status, #editor-priority, #set-market-day {
  min-height: 44px; padding: 0 0.5rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text);
}

.section { margin-bottom: 1.4rem; }
.section__head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.section__head h2 { margin: 0; }
.section__count { color: var(--muted); font-size: 0.85rem; }

.card {
  display: flex; align-items: center; gap: 0.75rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0.7rem 0.8rem;
  margin-bottom: 0.5rem; box-shadow: var(--shadow);
}
.card--urgent { border-left: 4px solid var(--alta); }
.card__body { flex: 1; min-width: 0; }
.card__name { font-weight: 600; display: flex; align-items: center; gap: 0.4rem; }
.card__meta { font-size: 0.8rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.15rem; }
.badge { font-size: 0.72rem; padding: 0.1rem 0.45rem; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; }
.badge--alta { color: var(--alta); border-color: var(--alta); }
.badge--media { color: var(--media); border-color: var(--media); }
.badge--baja { color: var(--baja); border-color: var(--baja); }
.card__actions { display: flex; gap: 0.35rem; }
.iconbtn {
  min-width: 40px; min-height: 40px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); cursor: pointer; font-size: 1rem;
}
.iconbtn--go { background: var(--primary); color: var(--primary-ink); border-color: transparent; }

.empty { color: var(--muted); font-size: 0.9rem; padding: 0.5rem 0; }

/* Shopping mode */
.shopping__progress { font-weight: 700; font-size: 1.1rem; margin-bottom: 1rem; text-align: center; }
.shop-group__title { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 1rem 0 0.4rem; }
.shop-item {
  display: flex; align-items: center; gap: 0.75rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0.9rem; margin-bottom: 0.5rem;
}
.shop-item--done { opacity: 0.5; }
.shop-item__check { min-width: var(--tap); min-height: var(--tap); border-radius: 12px; border: 2px solid var(--primary); background: transparent; font-size: 1.3rem; cursor: pointer; }
.shop-item--done .shop-item__check { background: var(--primary); color: var(--primary-ink); }
.shop-item__name { flex: 1; font-weight: 600; }

/* Dialogs */
.editor { width: min(560px, 92vw); border: none; border-radius: 18px; padding: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.editor::backdrop { background: rgba(0,0,0,0.45); }
.editor__form { display: flex; flex-direction: column; gap: 0.7rem; padding: 1.2rem; }
.editor__form label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; color: var(--muted); }
.editor__form input, .editor__form textarea, .editor__form select {
  min-height: 44px; padding: 0.4rem 0.6rem; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text); font-size: 1rem;
}
.editor__form textarea { min-height: 60px; }
.editor__row { display: flex; gap: 0.6rem; }
.editor__row label { flex: 1; }
.editor__check { flex-direction: row !important; align-items: center; gap: 0.5rem !important; color: var(--text) !important; }
.editor__check input { min-height: auto; width: 20px; height: 20px; }
.editor__actions { display: flex; justify-content: space-between; align-items: center; margin-top: 0.5rem; gap: 0.5rem; }
.editor__actions-right { display: flex; gap: 0.5rem; }
.tg-section { border: 1px solid var(--border); border-radius: 12px; padding: 0.7rem; display: flex; flex-direction: column; gap: 0.5rem; }
.tg-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.tg-actions .btn { flex: 1; min-width: 130px; text-decoration: none; }
.tg-help { font-size: 0.78rem; margin: 0; }
.insights__head { display: flex; align-items: center; justify-content: space-between; }
.insights { max-height: 70vh; overflow: auto; }
.ins-h { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 1rem 0 0.4rem; }
.ins-row { display: grid; grid-template-columns: 5.5rem 1fr auto; align-items: center; gap: 0.5rem; margin-bottom: 0.35rem; font-size: 0.85rem; }
.ins-row__l { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ins-row__v { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.ins-bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.ins-bar__fill { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.ins-line { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; padding: 0.35rem 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.ins-line span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.onboarding__list { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; max-height: 55vh; overflow: auto; }
.onboarding__item { display: flex; align-items: center; gap: 0.4rem; padding: 0.4rem; border: 1px solid var(--border); border-radius: 10px; font-size: 0.9rem; }

.toast {
  position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 0.7rem 1rem; border-radius: 10px; z-index: 50;
  max-width: 90vw; box-shadow: var(--shadow); display: flex; gap: 0.8rem; align-items: center;
}
.toast__undo { color: var(--primary); background: transparent; border: none; font-weight: 700; cursor: pointer; }
.is-busy { opacity: 0.6; pointer-events: none; }

/* Desktop: widen the container and lay the three shopping sections side by side.
   Mobile-first stays the default; this only enhances wide screens. */
@media (min-width: 780px) {
  .app-main { max-width: 1120px; padding: 1.5rem; }
  .sections { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.2rem; align-items: start; }
  .shopping__groups, #shopping-groups { columns: 2; column-gap: 1.2rem; }
  .shop-item { break-inside: avoid; }
  .card:hover { border-color: var(--primary); }
  .chip:hover, .iconbtn:hover { border-color: var(--primary); }
}
@media (min-width: 780px) and (max-width: 1080px) {
  .sections { grid-template-columns: repeat(3, 1fr); }
}
