:root {
  color-scheme: light dark;
  --bg: #ffffff;
  --panel: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #e0e0e4;
  --field: #d2d2d7;
  --subtle: #f5f5f7;
  --accent: #345b45;
  --button: #1d1d1f;
  --on-button: #ffffff;
  --danger: #b3261e;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .4; cursor: not-allowed; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--accent); 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; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin-top: 0; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 216px minmax(0,1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 32px 16px 24px; border-right: 1px solid var(--line); background: var(--bg); }
.brand { display: block; padding: 0 12px; color: var(--text); text-decoration: none; font-size: 20px; font-weight: 700; letter-spacing: -.5px; }
.brand-dot, .mobile-brand span { color: var(--accent); }
.nav-list { display: grid; gap: 4px; margin-top: 40px; }
.nav-item { min-height: 44px; width: 100%; padding: 8px 12px; border: 0; border-radius: 8px; background: none; color: var(--muted); text-align: left; display: flex; gap: 8px; align-items: center; }
.nav-item:hover { color: var(--text); }
.nav-item.active { color: var(--text); font-weight: 600; background: var(--subtle); }
.nav-count { margin-left: auto; color: var(--muted); font-size: 13px; font-weight: 400; }
.sidebar-bottom { margin-top: auto; padding: 0 12px; }
.sidebar-foot { color: var(--muted); font-size: 13px; }
.main-shell { min-width: 0; display: flex; flex-direction: column; }
.topbar, .mobile-brand { display: none; }
main { flex: 1; width: 100%; max-width: 960px; padding: 0 64px 96px; }
.view { display: none; }
.view.active { display: block; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 24px; min-height: 44px; padding: 48px 0 0; margin-bottom: 32px; box-sizing: content-box; }
h1 { margin: 0; font-size: 34px; line-height: 1.15; letter-spacing: -.6px; font-weight: 700; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.section-heading h2 { margin: 0; font-size: 22px; line-height: 1.25; font-weight: 700; letter-spacing: -.3px; }
.section-heading h2 span { margin-left: 4px; color: var(--muted); font-size: 15px; font-weight: 400; letter-spacing: 0; }

.primary-button, .secondary-button, .topbar-add { min-height: 44px; padding: 0 16px; border-radius: 8px; font-weight: 600; white-space: nowrap; }
.primary-button { border: 1px solid var(--button); background: var(--button); color: var(--on-button); }
.primary-button:hover:not(:disabled) { opacity: .85; }
.secondary-button, .topbar-add { border: 1px solid var(--field); background: var(--panel); color: var(--text); }
.secondary-button:hover, .topbar-add:hover { background: var(--subtle); }
.subtle-button { min-height: 44px; padding: 0 8px; border: 0; background: none; color: var(--muted); font-weight: 600; white-space: nowrap; }
.subtle-button:hover { color: var(--text); }

.search-box input, .ingredient-entry input, .naming-panel textarea, .form-field input, .form-field select, .form-field textarea { width: 100%; border: 1px solid var(--field); border-radius: 8px; background: var(--panel); color: var(--text); font-size: 16px; }
input::placeholder, textarea::placeholder { color: var(--muted); }
.search-box input, .ingredient-entry input, .form-field input, .form-field select { min-height: 44px; padding: 0 12px; }
.search-box input { appearance: none; }

.library-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 24px; }
.search-box { display: block; width: min(320px,100%); }
.filter-pills { display: flex; gap: 4px; }
.filter-pill { min-height: 44px; padding: 0 12px; border: 0; border-radius: 8px; background: none; color: var(--muted); white-space: nowrap; }
.filter-pill:hover { color: var(--text); }
.filter-pill.active { background: var(--subtle); color: var(--text); font-weight: 600; }

.recipe-grid { border-top: 1px solid var(--line); }
.recipe-grid:empty { display: none; }
.recipe-row { display: grid; grid-template-columns: minmax(0,5fr) minmax(0,8fr) 88px; grid-template-areas: "name ingredients type"; gap: 4px 24px; align-items: baseline; width: 100%; min-height: 56px; padding: 16px 0; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--text); text-align: left; }
.row-name { grid-area: name; font-size: 17px; line-height: 1.3; font-weight: 600; letter-spacing: -.2px; }
.row-ingredients { grid-area: ingredients; overflow: hidden; color: var(--muted); white-space: nowrap; text-overflow: ellipsis; }
.row-type { grid-area: type; color: var(--muted); font-size: 13px; text-align: right; white-space: nowrap; }
.recipe-row:hover .row-ingredients { color: var(--text); }

.empty-state, .suggestion-empty { padding: 32px 0; }
.empty-state h3, .suggestion-empty h3 { margin: 0 0 4px; font-size: 17px; font-weight: 600; }
.empty-state p, .suggestion-empty p { max-width: 480px; margin: 0 0 16px; color: var(--muted); }

.pantry, .naming-panel { max-width: 640px; }
.field-label, .section-kicker { display: block; margin-bottom: 8px; color: var(--muted); font-size: 13px; }
.quick-label { margin-top: 24px; }
.field-hint { color: var(--muted); font-size: 13px; line-height: 1.5; }
.ingredient-entry { display: flex; gap: 8px; }
.ingredient-entry input { min-width: 0; flex: 1; }
.ingredient-entry button { flex: none; }
.selected-chips, .quick-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.selected-chips { margin-top: 16px; }
.selected-chips:empty { display: none; }
.selected-chip, .quick-chip { min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: none; color: var(--text); }
.selected-chip { border-color: var(--subtle); background: var(--subtle); font-weight: 600; }
.selected-chip span { margin-left: 8px; color: var(--muted); font-weight: 400; }
.quick-chip { color: var(--muted); }
.quick-chip:hover { border-color: var(--field); color: var(--text); }
.selected-chip:hover { border-color: var(--field); }

.suggestions-heading { margin-top: 48px; margin-bottom: 8px; }
.suggestion-tools { display: flex; align-items: center; gap: 8px; }
.ai-status { margin: 0 0 16px; color: var(--muted); }
.suggestions-list { border-top: 1px solid var(--line); }
.suggestion-card { display: flex; align-items: center; gap: 24px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.suggestion-info { flex: 1; min-width: 0; }
.suggestion-tag { color: var(--muted); font-size: 13px; }
.suggestion-info h3 { margin: 4px 0; font-size: 17px; line-height: 1.3; font-weight: 600; letter-spacing: -.2px; }
.suggestion-info p { margin: 0; color: var(--muted); }
.suggestion-action { display: flex; gap: 8px; }

.naming-panel textarea { display: block; min-height: 216px; padding: 12px; resize: vertical; line-height: 1.6; }
.naming-actions { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 16px; }
.save-status { color: var(--muted); font-size: 13px; }

dialog { width: min(560px,calc(100% - 32px)); max-height: 90vh; max-height: min(90dvh,848px); padding: 0; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); box-shadow: 0 8px 32px #0000001f; }
dialog[open], #recipe-form { display: flex; flex-direction: column; min-height: 0; }
dialog::backdrop { background: #00000052; }
.dialog-head { display: flex; flex: none; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 24px 12px 16px 24px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; font-size: 22px; line-height: 1.25; font-weight: 700; letter-spacing: -.3px; }
.dialog-head .section-kicker { margin-bottom: 4px; }
.icon-button { flex: none; width: 44px; height: 44px; margin-top: -8px; border: 0; border-radius: 8px; background: none; color: var(--muted); font-size: 24px; line-height: 1; }
.icon-button:hover { color: var(--text); }
.dialog-body { flex: 1; min-height: 0; overflow: auto; padding: 24px; }
.form-field { display: block; margin-bottom: 16px; font-size: 13px; font-weight: 600; }
.form-field input, .form-field select, .form-field textarea { display: block; margin-top: 8px; font-weight: 400; }
.form-field textarea { padding: 12px; line-height: 1.5; resize: vertical; }
.form-field .field-hint { margin-left: 4px; font-weight: 400; }
.form-assist { margin: 0; color: var(--muted); font-size: 13px; }
.form-error { margin-top: 12px; color: var(--danger); font-size: 13px; }
.dialog-actions { display: flex; flex: none; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 12px; padding: 16px 24px calc(16px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.dialog-action-right { display: flex; gap: 8px; margin-left: auto; }
.dialog-actions > .primary-button { margin-left: auto; }
.danger-link { min-height: 44px; padding: 0; border: 0; background: none; color: var(--danger); }
.danger-link.armed { font-weight: 600; }
.detail-body h3 { margin: 0 0 8px; color: var(--muted); font-size: 13px; font-weight: 400; }
.detail-body ul { margin: 0 0 24px; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.detail-body li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.detail-body > p { margin: 0 0 24px; white-space: pre-line; }
.detail-body > p:last-child { margin-bottom: 0; }
.detail-body .recipe-steps { margin: 0; padding: 0 0 0 24px; list-style: decimal; border: 0; }
.recipe-steps li { padding: 0 0 8px 4px; border: 0; }
.recipe-steps li::marker { color: var(--muted); }
.original-entry { margin-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.original-entry summary { min-height: 44px; padding: 12px 0; cursor: pointer; }
.original-entry p { margin: 8px 0; white-space: pre-line; }

.toast { position: fixed; bottom: 24px; left: 50%; z-index: 10; max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 8px; transform: translate(-50%,16px); background: var(--text); color: var(--bg); font-size: 13px; opacity: 0; pointer-events: none; transition: .2s; }
.toast.show { transform: translate(-50%,0); opacity: 1; }

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; top: auto; bottom: 0; left: 0; right: 0; z-index: 5; height: auto; padding: 0 max(8px,env(safe-area-inset-right)) env(safe-area-inset-bottom) max(8px,env(safe-area-inset-left)); border-right: 0; border-top: 1px solid var(--line); }
  .brand, .sidebar-bottom, .nav-count, #main-add { display: none; }
  .nav-list { grid-template-columns: repeat(3,1fr); gap: 0; margin: 0; }
  .nav-item { min-height: 56px; justify-content: center; padding: 8px 4px; border-radius: 0; font-size: 13px; text-align: center; line-height: 1.2; }
  .nav-item.active { background: none; box-shadow: inset 0 2px var(--text); }
  .topbar { display: flex; align-items: center; justify-content: space-between; min-height: 60px; padding: env(safe-area-inset-top) max(16px,env(safe-area-inset-right)) 0 max(16px,env(safe-area-inset-left)); }
  .mobile-brand { display: block; font-size: 20px; font-weight: 700; letter-spacing: -.5px; }
  .topbar-add { border-color: var(--line); }
  main { padding: 0 max(16px,env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left)); }
  .page-head { padding-top: 16px; margin-bottom: 24px; }
  .library-toolbar { flex-direction: column; align-items: stretch; gap: 8px; }
  .search-box { width: 100%; }
  .recipe-row { grid-template-columns: minmax(0,1fr) auto; grid-template-areas: "name type" "ingredients ingredients"; column-gap: 16px; }
  .suggestions-heading { flex-wrap: wrap; }
  .suggestions-heading h2 { flex: 1; }
  .suggestion-tools { flex: 1 0 100%; flex-direction: row-reverse; }
  .suggestion-tools .primary-button { flex: 1; }
  .suggestion-card { flex-direction: column; align-items: stretch; gap: 12px; }
  .toast { bottom: calc(72px + env(safe-area-inset-bottom)); width: max-content; }
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111112; --panel: #1c1c1e; --text: #f5f5f7; --muted: #a1a1a6; --line: #2c2c2e; --field: #48484a; --subtle: #2c2c2e; --accent: #8fbf9a; --button: #f5f5f7; --on-button: #1d1d1f; --danger: #ff8a80; }
  .search-box input, .ingredient-entry input, .naming-panel textarea, .secondary-button, .topbar-add { background: transparent; }
  dialog .form-field input, dialog .form-field select, dialog .form-field textarea, dialog .secondary-button { background: transparent; }
  dialog { box-shadow: 0 8px 32px #00000080; }
  dialog::backdrop { background: #00000099; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
