/* Family Recipe Vault — senior-friendly heirloom cookbook
   Base ≥18px, 48px targets, WCAG AA, one accent (deep warm brick) */

:root {
  --bg: #faf6f1;
  --bg-card: #ffffff;
  --bg-soft: #f3ebe3;
  --text: #2a1f1a;
  --text-muted: #5e4f46;
  --border: #dccfc3;
  --accent: #8b3a2b;
  --accent-dark: #6b2c21;
  --accent-soft: #f3e0db;
  --ok: #2d6a4f;
  --ok-soft: #d8f3e4;
  --danger: #9b2226;
  --danger-soft: #fde8e8;
  --shadow: 0 2px 14px rgba(42, 31, 26, 0.08);
  --radius: 14px;
  --radius-sm: 10px;
  --space: 1rem;
  --space-lg: 1.5rem;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --focus: 3px solid var(--accent);
  --touch: 48px;
  --max: 920px;
}

*,
*::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);
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

img,
svg {
  max-width: 100%;
  height: auto;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: var(--focus);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 1000;
  background: var(--accent);
  color: #fff;
  padding: 0.75rem 1rem;
  font-weight: 600;
  text-decoration: none;
  border-radius: 0 0 var(--radius-sm) 0;
}

.skip-link:focus {
  left: 0;
}

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

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

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

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

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

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

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

/* Keep header + tabs usable; tabs sit below header flow naturally via document order.
   Sticky tab bar under header when scrolled. */
.app-header + .tab-nav {
  top: 0;
}

.tab {
  flex: 1 0 auto;
  min-height: var(--touch);
  min-width: 4.5rem;
  padding: 0.6rem 0.85rem;
  border: none;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

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

.tab.active,
.tab[aria-selected="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--accent-soft);
}

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

.panel {
  display: none;
}

.panel.active {
  display: block;
}

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

.panel-lead {
  margin: 0 0 var(--space-lg);
  color: var(--text-muted);
  max-width: 40rem;
}

.panel-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space);
  flex-wrap: wrap;
  margin-bottom: 0.35rem;
}

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

/* 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.15rem;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  font-weight: 600;
  text-decoration: none;
  line-height: 1.2;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

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

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

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

.btn-secondary {
  background: var(--bg-card);
  color: var(--accent-dark);
  border-color: var(--accent);
}

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

.btn-text {
  background: transparent;
  color: var(--accent);
  border-color: transparent;
  min-width: auto;
}

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

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

.btn-danger:hover:not(:disabled) {
  background: #7a1a1d;
}

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

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

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

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

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

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

.btn-row.wrap {
  flex-wrap: wrap;
}

.file-btn {
  position: relative;
  overflow: hidden;
  cursor: pointer;
}

.file-btn input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  font-size: 0;
}

/* Cards & stats */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-lg);
  margin-bottom: var(--space);
  box-shadow: var(--shadow);
}

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

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

.card-note {
  margin: 0 0 var(--space);
  color: var(--text-muted);
  font-size: 0.95rem;
}

.sample-card {
  border-color: #c9b29a;
  background: linear-gradient(180deg, #fffdf9 0%, #faf6f1 100%);
}

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

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

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-height: 7.5rem;
}

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

.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: 700;
  color: var(--accent-dark);
  line-height: 1.15;
}

.stat-link {
  margin-top: auto;
  align-self: flex-start;
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  min-height: 44px;
  padding: 0.35rem 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.stat-link:hover {
  color: var(--accent-dark);
}

/* Quick actions */
.quick-actions {
  display: grid;
  gap: 0.75rem;
}

@media (min-width: 640px) {
  .quick-actions {
    grid-template-columns: repeat(3, 1fr);
  }
}

.action-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  gap: 0.25rem;
  min-height: var(--touch);
  padding: 1rem;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s, background 0.15s;
}

.action-tile:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.action-icon {
  font-size: 1.5rem;
  line-height: 1;
  margin-bottom: 0.25rem;
}

.action-title {
  font-weight: 700;
  color: var(--text);
}

.action-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Fields */
.field {
  margin-bottom: 1rem;
}

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

.field-check {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-height: var(--touch);
}

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

.field-check label {
  margin: 0;
  font-weight: 600;
}

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

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

input[type="file"] {
  padding: 0.5rem;
  line-height: 1.4;
}

textarea {
  min-height: 7rem;
  resize: vertical;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-row {
  display: grid;
  gap: 0.75rem;
}

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

.filters {
  display: grid;
  gap: 0.75rem;
  margin-bottom: var(--space);
  padding: var(--space);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

@media (min-width: 640px) {
  .filters {
    grid-template-columns: 1.4fr 1fr 1fr auto;
    align-items: end;
  }

  .cookbook-filters {
    grid-template-columns: 1fr auto;
  }
}

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

/* Recipe lists & cards */
.recipe-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.recipe-card {
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  text-align: left;
  width: 100%;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.recipe-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 16px rgba(139, 58, 43, 0.12);
}

.recipe-list.compact .recipe-card {
  padding: 0.85rem;
}

.recipe-thumb {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.recipe-thumb.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: var(--text-muted);
}

.recipe-body {
  flex: 1;
  min-width: 0;
}

.recipe-body h3,
.recipe-body .recipe-name {
  margin: 0 0 0.2rem;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

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

.recipe-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.45rem;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--bg-soft);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.badge.sample {
  background: #fff4d6;
  color: #6b4f00;
  border-color: #e6d18a;
}

.badge.favorite {
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-color: #d4a89c;
}

.badge.photo {
  background: var(--ok-soft);
  color: var(--ok);
  border-color: #a8d5c0;
}

.recipe-actions {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex-shrink: 0;
}

.recipe-actions .btn {
  min-width: var(--touch);
  padding: 0.45rem 0.65rem;
}

.empty-msg {
  margin: 0.5rem 0 0;
  color: var(--text-muted);
  font-style: italic;
}

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

.status-msg.error {
  color: var(--danger);
}

/* Capture */
.capture-grid {
  display: grid;
  gap: var(--space);
}

@media (min-width: 800px) {
  .capture-grid {
    grid-template-columns: 1fr 1.15fr;
    align-items: start;
  }
}

.photo-stage {
  min-height: 200px;
  background: var(--bg-soft);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: var(--space);
}

.photo-stage.has-photo {
  border-style: solid;
  border-color: var(--border);
}

.photo-stage img {
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  display: block;
}

.photo-placeholder {
  margin: 0;
  color: var(--text-muted);
  font-weight: 600;
  padding: 2rem;
  text-align: center;
}

.inline-photo {
  margin-top: 0.65rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
}

.inline-photo img {
  max-width: 100%;
  max-height: 160px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* Cookbook */
.cookbook-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.cookbook-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.cookbook-section-head {
  background: var(--accent-soft);
  border-bottom: 1px solid var(--border);
  padding: 0.9rem 1.15rem;
}

.cookbook-section-head h3 {
  margin: 0;
  font-size: 1.15rem;
  color: var(--accent-dark);
}

.cookbook-section-head p {
  margin: 0.2rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.cookbook-recipe {
  padding: 1.15rem;
  border-bottom: 1px solid var(--border);
}

.cookbook-recipe:last-child {
  border-bottom: none;
}

.cookbook-recipe h4 {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
}

.cookbook-recipe .meta-line {
  margin: 0 0 0.65rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.cookbook-recipe .story {
  margin: 0 0 0.75rem;
  padding: 0.75rem 0.9rem;
  background: var(--bg-soft);
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-style: italic;
  color: var(--text);
}

.cookbook-recipe .col-list {
  margin: 0 0 0.75rem;
  padding-left: 1.25rem;
}

.cookbook-recipe .col-list li {
  margin-bottom: 0.25rem;
}

.cookbook-recipe .view-btn {
  margin-top: 0.35rem;
}

/* Breakdown lists (insights) */
.breakdown-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.breakdown-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
}

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

.breakdown-label {
  font-weight: 600;
  min-width: 0;
}

.breakdown-bar-wrap {
  grid-column: 1 / -1;
  height: 10px;
  background: var(--bg-soft);
  border-radius: 999px;
  overflow: hidden;
}

.breakdown-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  min-width: 4px;
}

.breakdown-count {
  font-weight: 700;
  color: var(--accent-dark);
  font-variant-numeric: tabular-nums;
}

/* Detail view */
.detail-layout {
  display: grid;
  gap: var(--space);
}

@media (min-width: 640px) {
  .detail-layout.has-photo {
    grid-template-columns: 200px 1fr;
  }
}

.detail-photo {
  width: 100%;
  max-height: 280px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-soft);
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0 0 0.75rem;
}

.detail-story {
  margin: 0 0 1rem;
  padding: 0.85rem 1rem;
  background: var(--bg-soft);
  border-left: 4px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-style: italic;
}

.detail-section {
  margin-bottom: 1rem;
}

.detail-section h3 {
  margin: 0 0 0.45rem;
  font-size: 1rem;
  color: var(--accent-dark);
}

.detail-section ol,
.detail-section ul {
  margin: 0;
  padding-left: 1.3rem;
}

.detail-section li {
  margin-bottom: 0.4rem;
}

/* Modals */
.modal {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  max-width: min(560px, calc(100vw - 1.5rem));
  width: 100%;
  box-shadow: 0 12px 40px rgba(42, 31, 26, 0.2);
  color: var(--text);
  background: var(--bg-card);
}

.modal.modal-wide {
  max-width: min(680px, calc(100vw - 1.5rem));
}

.modal.modal-sm {
  max-width: min(420px, calc(100vw - 1.5rem));
}

.modal::backdrop {
  background: rgba(42, 31, 26, 0.45);
}

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

.modal-head h2 {
  margin: 0;
  font-size: 1.2rem;
}

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

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.85rem 1.15rem 1.15rem;
  border-top: 1px solid var(--border);
}

.modal-status {
  padding: 0 1.15rem 1rem;
  margin: 0;
}

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

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

.app-footer p {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-muted);
}

/* Print — heirloom cookbook */
@media print {
  .skip-link,
  .app-header,
  .tab-nav,
  .app-footer,
  .filters,
  .panel-head-row .btn,
  #btn-print-cookbook,
  .view-btn,
  .toast,
  dialog {
    display: none !important;
  }

  body {
    background: #fff;
    color: #000;
  }

  #main {
    max-width: none;
    padding: 0;
  }

  .panel {
    display: none !important;
  }

  #panel-cookbook.panel.active,
  #panel-cookbook.panel:not([hidden]) {
    display: block !important;
  }

  .panel-title {
    font-size: 1.6rem;
    margin-bottom: 0.25rem;
  }

  .panel-lead {
    margin-bottom: 1rem;
  }

  .cookbook-section {
    box-shadow: none;
    break-inside: avoid;
    page-break-inside: avoid;
    margin-bottom: 1rem;
  }

  .cookbook-recipe {
    break-inside: avoid;
  }

  .stat-grid,
  .card.sample-card {
    display: none;
  }
}

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