/* Pantry Minder — senior-friendly, offline-first UI */

:root {
  --accent: #1a6b4a;
  --accent-hover: #14553a;
  --accent-soft: #e6f4ed;
  --accent-mid: #2d8a62;
  --danger: #a32020;
  --danger-soft: #fdecec;
  --warn: #8a5a00;
  --warn-soft: #fff4db;
  --ok: #1a6b4a;
  --ok-soft: #e6f4ed;
  --text: #1a1f1c;
  --text-muted: #4a554e;
  --border: #c5d0c9;
  --surface: #ffffff;
  --bg: #f3f6f4;
  --shadow: 0 2px 10px rgba(26, 31, 28, 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;
}

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;
}

/* When header is sticky, tabs stick below it roughly — fine for SPA */
.app-header + .tab-nav {
  top: auto;
  position: sticky;
  top: 0;
}

.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;
}

.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);
  box-shadow: inset 0 -3px 0 var(--accent);
}

/* Main */
#main {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}

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

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

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

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  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-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

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

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

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

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

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

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

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

.btn-danger:hover:not(:disabled) {
  background: #861a1a;
}

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

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

.btn-text.danger-text {
  color: var(--danger);
}

.btn-text.danger-text:hover:not(:disabled) {
  background: var(--danger-soft);
}

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

.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;
}

/* Cards */
.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.75rem;
}

.card h3 {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
}

.card-head h3 {
  margin: 0;
}

.sample-card {
  border-style: dashed;
  border-width: 2px;
  border-color: var(--accent-mid);
  background: var(--accent-soft);
}

/* Stats */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 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 {
  background: var(--danger-soft);
  border-color: #e8b4b4;
}

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

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

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

.stat-value {
  margin: 0;
  font-size: 1.85rem;
  font-weight: 750;
  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: 2.5rem;
  padding: 0.25rem 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;
  border-radius: 4px;
}

/* Location pills */
.location-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.15rem;
}

.location-pill {
  flex: 1 1 auto;
  min-width: 6.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.55rem 0.9rem;
  font-size: 0.95rem;
  color: var(--text-muted);
  text-align: center;
}

.location-pill strong {
  color: var(--text);
  margin-left: 0.2rem;
}

.loc-icon {
  margin-right: 0.2rem;
}

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

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

.req {
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--danger);
}

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

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

@media (max-width: 420px) {
  .field-row {
    grid-template-columns: 1fr;
  }
}

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

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

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

input[type="checkbox"] {
  width: 1.35rem;
  height: 1.35rem;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.checkbox-field {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
}

.checkbox-field label {
  margin: 0;
  font-weight: 500;
  line-height: 1.4;
}

.form-error {
  margin: 0.5rem 0 0;
  padding: 0.65rem 0.85rem;
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-weight: 600;
}

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

@media (min-width: 520px) {
  .filters .filter-row {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

.result-count {
  margin: 0 0 0.65rem;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.95rem;
}

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

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 5px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow);
}

.item-card.status-expired {
  border-left-color: var(--danger);
  background: #fffafa;
}

.item-card.status-soon {
  border-left-color: var(--warn);
  background: #fffdf7;
}

.item-card.status-fresh {
  border-left-color: var(--ok);
}

.item-card.status-none {
  border-left-color: #8a9690;
}

.item-top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.4rem 0.75rem;
  align-items: flex-start;
}

.item-name {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

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

.item-notes {
  margin: 0.4rem 0 0;
  font-size: 0.95rem;
  color: var(--text);
}

.status-pill {
  display: inline-block;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill.expired {
  background: var(--danger-soft);
  color: var(--danger);
}

.status-pill.soon {
  background: var(--warn-soft);
  color: var(--warn);
}

.status-pill.fresh {
  background: var(--ok-soft);
  color: var(--ok);
}

.status-pill.none {
  background: #e8ecea;
  color: var(--text-muted);
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.item-actions .btn {
  min-height: var(--touch);
  padding: 0.5rem 0.9rem;
  font-size: 0.95rem;
}

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

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

.tip-list li:last-child {
  margin-bottom: 0;
}

.tip-cards {
  display: grid;
  gap: 0.75rem;
}

.tip-card h3 {
  color: var(--accent);
  margin-bottom: 0.4rem;
}

.tip-card p {
  margin: 0;
  color: var(--text);
}

.savings-summary {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.55;
}

/* Meals */
.meals-grid {
  display: grid;
  gap: 0.85rem;
}

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

.meal-card h3 {
  margin: 0 0 0.35rem;
  font-size: 1.2rem;
  color: var(--accent);
}

.meal-meta {
  margin: 0 0 0.65rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.meal-card p {
  margin: 0 0 0.65rem;
}

.meal-card ul {
  margin: 0;
  padding-left: 1.2rem;
}

.meal-card li {
  margin-bottom: 0.3rem;
}

.meal-match {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.3rem 0.7rem;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 700;
}

.meal-missing {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 0.5rem;
}

/* Empty / status */
.empty-msg {
  margin: 1rem 0;
  padding: 1.25rem;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
}

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

/* 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(0, 0, 0, 0.18);
  color: var(--text);
  background: var(--surface);
}

dialog::backdrop {
  background: rgba(26, 31, 28, 0.55);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 0.85rem 0.5rem 1.15rem;
  border-bottom: 1px solid var(--border);
}

.dialog-header h2 {
  margin: 0;
  font-size: 1.25rem;
}

.dialog-body {
  padding: 1rem 1.15rem;
  max-height: min(70vh, 520px);
  overflow-y: auto;
}

.dialog-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1.15rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

/* Footer */
.app-footer {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1.5rem 1rem 2.5rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.95rem;
  border-top: 1px solid var(--border);
}

.app-footer p {
  margin: 0 0 0.75rem;
}

.footer-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem 0.5rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  max-width: min(90vw, 420px);
  padding: 0.9rem 1.2rem;
  background: var(--text);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 600;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  text-align: center;
}

.toast[hidden] {
  display: none;
}

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