/* Grocery Guard — senior-friendly, offline-first UI */

:root {
  --accent: #0d5c63;
  --accent-hover: #0a4a50;
  --accent-soft: #e3f3f4;
  --accent-mid: #148a94;
  --danger: #9b1c1c;
  --danger-soft: #fdecec;
  --warn: #8a5a00;
  --warn-soft: #fff4db;
  --ok: #1a6b4a;
  --ok-soft: #e6f4ed;
  --text: #1a2224;
  --text-muted: #4a5558;
  --border: #c4d0d2;
  --surface: #ffffff;
  --bg: #f2f6f7;
  --shadow: 0 2px 10px rgba(26, 34, 36, 0.08);
  --radius: 14px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --touch: 48px;
  --max: 720px;
  --space: 1rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 18px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
}

img {
  max-width: 100%;
}

/* Skip link */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: #fff;
  padding: 0.75rem 1rem;
  z-index: 1000;
  font-weight: 600;
}

.skip-link:focus {
  left: 0.5rem;
  top: 0.5rem;
}

/* Header */
.app-header {
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0.85rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-mark {
  font-size: 1.75rem;
  line-height: 1;
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--accent);
}

.tagline {
  margin: 0.1rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

/* Tabs */
.tab-nav {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0.5rem 0.75rem 0;
  display: flex;
  gap: 0.35rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-bottom: 2px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 40;
  width: 100%;
}

.tab {
  flex: 1 0 auto;
  min-height: var(--touch);
  min-width: 5.5rem;
  padding: 0.6rem 0.85rem;
  border: 2px solid transparent;
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  white-space: nowrap;
}

.tab:hover {
  color: var(--text);
  background: var(--surface);
}

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

.tab.active {
  background: var(--surface);
  color: var(--accent);
  border-color: var(--border);
  border-bottom-color: var(--surface);
  margin-bottom: -2px;
  box-shadow: 0 2px 0 var(--surface);
}

/* Main */
main {
  flex: 1;
  max-width: var(--max);
  width: 100%;
  margin: 0 auto;
  padding: 1.15rem 1rem 2.5rem;
}

.panel[hidden] {
  display: none !important;
}

.panel-title {
  margin: 0 0 0.25rem;
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text);
}

.panel-lead {
  margin: 0 0 1.15rem;
  color: var(--text-muted);
  font-size: 1rem;
}

.panel-head-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.panel-head-row .panel-lead {
  margin-bottom: 0;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: var(--touch);
  min-width: var(--touch);
  padding: 0.65rem 1.1rem;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  text-align: center;
  line-height: 1.2;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--accent);
  border-color: var(--accent);
}

.btn-secondary:hover {
  background: var(--accent-soft);
}

.btn-text {
  background: transparent;
  color: var(--accent);
  border-color: transparent;
  min-width: auto;
  padding-left: 0.5rem;
  padding-right: 0.5rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn-text:hover {
  color: var(--accent-hover);
  background: var(--accent-soft);
  text-decoration: none;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn-danger:hover {
  background: #7f1515;
  border-color: #7f1515;
}

.btn-danger-outline {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--danger);
}

.btn-danger-outline:hover {
  background: var(--danger-soft);
}

.btn-icon {
  min-height: var(--touch);
  min-width: var(--touch);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: var(--bg);
  color: var(--text);
}

.btn-icon:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.4rem;
  height: 1.4rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  margin-left: 0.25rem;
}

/* Cards & stats */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.card h3 {
  margin: 0 0 0.65rem;
  font-size: 1.15rem;
  color: var(--text);
}

.card-head h3 {
  margin-bottom: 0;
}

.card-lead {
  margin: -0.35rem 0 0.85rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.sample-card {
  border-color: var(--accent);
  background: linear-gradient(180deg, var(--accent-soft) 0%, var(--surface) 48%);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}

@media (min-width: 560px) {
  .stat-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 0.85rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.stat-card.stat-danger {
  border-color: #e3a0a0;
  background: var(--danger-soft);
}

.stat-card.stat-warn {
  border-color: #e6c97a;
  background: var(--warn-soft);
}

.stat-card.stat-ok {
  border-color: #9dceb5;
  background: var(--ok-soft);
}

.stat-label {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.stat-value {
  margin: 0;
  font-size: 1.85rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text);
}

.stat-danger .stat-value {
  color: var(--danger);
}

.stat-warn .stat-value {
  color: var(--warn);
}

.stat-ok .stat-value {
  color: var(--ok);
}

.stat-link {
  margin-top: 0.35rem;
  align-self: flex-start;
  min-height: 40px;
  padding: 0.35rem 0;
  border: none;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.stat-link:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* Chips */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 2rem;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.9rem;
  border: 1px solid #a8d0d4;
}

/* Aisle summary */
.aisle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.55rem;
}

.aisle-pill {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-height: var(--touch);
}

.aisle-pill strong {
  font-size: 1.15rem;
  color: var(--accent);
}

.aisle-pill span {
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Forms */
.field {
  margin-bottom: 0.9rem;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.65rem;
}

@media (min-width: 480px) {
  .field-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .field-row.three,
  .filters .field-row {
    grid-template-columns: repeat(3, 1fr);
  }
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--text);
}

.optional {
  font-weight: 500;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.req {
  color: var(--danger);
}

input[type="text"],
input[type="search"],
input[type="number"],
textarea,
select {
  width: 100%;
  min-height: var(--touch);
  padding: 0.65rem 0.8rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  color: var(--text);
  background: var(--surface);
}

textarea {
  min-height: 5.5rem;
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 92, 99, 0.22);
}

.field-hint {
  margin: 0.35rem 0 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.field-error {
  margin: 0.35rem 0 0;
  color: var(--danger);
  font-weight: 600;
  font-size: 0.9rem;
}

.filters.card-like,
.card-like {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  margin-bottom: 0.85rem;
}

.list-actions {
  margin-bottom: 0.75rem;
}

/* Check grid for diet */
fieldset {
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem 1rem;
  margin: 0 0 1rem;
}

legend {
  font-weight: 700;
  padding: 0 0.35rem;
  color: var(--text);
}

.fieldset-hint {
  margin: 0 0 0.75rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.check-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.4rem;
}

@media (min-width: 480px) {
  .check-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.check-item {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  min-height: var(--touch);
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  cursor: pointer;
}

.check-item:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.check-item:focus-within {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.check-item input {
  width: 1.25rem;
  height: 1.25rem;
  min-height: 0;
  margin-top: 0.15rem;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.check-item .check-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.check-item .check-title {
  font-weight: 600;
  color: var(--text);
}

.check-item .check-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
}

/* Item lists */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 0.95rem;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.65rem 0.75rem;
  align-items: start;
  box-shadow: var(--shadow);
}

.item-card.caution {
  border-color: #d4a04a;
  background: #fffdf6;
}

.item-card.bought {
  opacity: 0.72;
}

.item-card.bought .item-name {
  text-decoration: line-through;
  color: var(--text-muted);
}

.item-check {
  width: 1.4rem;
  height: 1.4rem;
  min-height: 0;
  margin-top: 0.2rem;
  accent-color: var(--accent);
  cursor: pointer;
}

.item-body {
  min-width: 0;
}

.item-name {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  word-break: break-word;
}

.item-meta {
  margin: 0.2rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.item-flags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.4rem;
}

.flag-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  min-height: 1.7rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
}

.flag-pill.caution {
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid #e0c06a;
}

.flag-pill.safe {
  background: var(--ok-soft);
  color: var(--ok);
  border: 1px solid #9dceb5;
}

.flag-pill.info {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid #a8d0d4;
}

.item-actions {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.item-actions .btn {
  min-height: 44px;
  padding: 0.4rem 0.7rem;
  font-size: 0.9rem;
}

.item-alt {
  grid-column: 2 / -1;
  margin: 0;
  padding: 0.55rem 0.7rem;
  background: var(--ok-soft);
  border-left: 4px solid var(--ok);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.92rem;
  color: var(--text);
}

.item-alt strong {
  color: var(--ok);
}

/* Aisle groups on list */
.aisle-groups {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.aisle-group h3 {
  margin: 0 0 0.55rem;
  font-size: 1.1rem;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.aisle-count {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Alternatives */
.alts-groups {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1rem;
}

.alt-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.95rem 1rem;
  box-shadow: var(--shadow);
}

.alt-card h4 {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
}

.alt-reason {
  margin: 0 0 0.55rem;
  color: var(--warn);
  font-weight: 600;
  font-size: 0.92rem;
}

.alt-suggestion {
  margin: 0;
  padding: 0.55rem 0.7rem;
  background: var(--ok-soft);
  border-radius: var(--radius-sm);
  color: var(--text);
}

.alt-suggestion strong {
  color: var(--ok);
}

.alt-actions {
  margin-top: 0.65rem;
}

.guide-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.guide-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.25rem;
  padding: 0.65rem 0.75rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

@media (min-width: 520px) {
  .guide-row {
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 0.65rem;
  }
}

.guide-from {
  font-weight: 600;
  color: var(--text);
}

.guide-arrow {
  color: var(--accent);
  font-weight: 700;
  text-align: center;
}

.guide-to {
  color: var(--ok);
  font-weight: 600;
}

/* Tips */
.tip-list {
  margin: 0;
  padding-left: 1.25rem;
}

.tip-list li {
  margin-bottom: 0.45rem;
}

.tip-list.plain {
  list-style: disc;
}

.empty-msg {
  margin: 0.5rem 0 0;
  padding: 1rem;
  text-align: center;
  color: var(--text-muted);
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
}

.status-msg {
  margin: 0.65rem 0 0;
  font-weight: 600;
  color: var(--accent);
  min-height: 1.4rem;
}

/* Live safety preview in form */
.live-safety {
  margin: 0 0 1rem;
  padding: 0.75rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
}

.live-safety.caution {
  background: var(--warn-soft);
  border: 1px solid #e0c06a;
  color: var(--warn);
}

.live-safety.safe {
  background: var(--ok-soft);
  border: 1px solid #9dceb5;
  color: var(--ok);
}

.live-safety strong {
  display: block;
  margin-bottom: 0.2rem;
}

/* Dialogs */
dialog {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  max-width: min(520px, calc(100vw - 1.5rem));
  width: 100%;
  box-shadow: 0 12px 40px rgba(26, 34, 36, 0.2);
  color: var(--text);
  background: var(--surface);
}

dialog::backdrop {
  background: rgba(20, 30, 32, 0.55);
}

dialog form,
dialog > .dialog-head,
#safety-dialog,
#confirm-dialog {
  /* structure handled below */
}

#item-dialog form,
#safety-dialog,
#confirm-dialog {
  padding: 1.1rem 1.15rem 1.2rem;
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.dialog-head h2 {
  margin: 0;
  font-size: 1.3rem;
  color: var(--text);
}

.dialog-lead {
  margin: -0.35rem 0 0.85rem;
  color: var(--text-muted);
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* Footer */
.app-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 1rem;
  text-align: center;
}

.app-footer p {
  margin: 0;
  max-width: var(--max);
  margin-inline: auto;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  z-index: 200;
  max-width: min(480px, calc(100vw - 2rem));
  padding: 0.85rem 1.15rem;
  background: var(--text);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  text-align: center;
}

.toast[hidden] {
  display: none;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
