:root{
    --bg: #F6EFDF;
    --surface: #EEE3C9;
    --surface-2: #E4D5AF;
    --ink: #201A13;
    --ink-soft: #7C6F5B;
    --accent: #6E2A34;
    --accent-dark: #4E1E26;
    --accent-light: #F1E1E0;
    --gold: #B07F26;
    --gold-light: #F6E7C4;
    --paprika: #A8452F;
    --paprika-light: #F3E1DB;
    --line: #E1D1AC;
    --white: #FFFBF3;
    --radius-s: 6px;
    --radius-m: 13px;
    --radius-l: 22px;
    --shadow: 0 14px 34px rgba(32,26,19,0.16);
    --scrim: linear-gradient(190deg, rgba(20,15,10,0) 42%, rgba(15,10,7,0.82) 100%);
  }

  * { box-sizing: border-box; }
  html, body { margin:0; padding:0; overflow-x: hidden; width: 100%; }
  body{
    background: var(--bg);
    color: var(--ink);
    font-family: 'Work Sans', sans-serif;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    overflow-x: hidden;
  }
  h1,h2,h3, .serif { font-family: 'Fraunces', serif; }

  button { font-family: inherit; cursor: pointer; }
  input, textarea, select { font-family: inherit; }

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

  @media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
  }

  #app {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    background: var(--bg);
    position: relative;
    padding-bottom: 150px;
  }

  /* ---------- Screens / tab bar ---------- */
  .screen { display: none; }
  .screen.active { display: block; }

  .tabbar {
    position: fixed;
    bottom: 0;
    left: 0; right: 0;
    z-index: 45;
    display: flex;
    max-width: 480px;
    margin: 0 auto;
    background: var(--white);
    border-top: 1px solid var(--line);
    box-shadow: 0 -6px 20px rgba(32,26,19,0.08);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tab-btn {
    flex: 1;
    background: none;
    border: none;
    padding: 10px 4px 9px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--ink-soft);
  }
  .tab-btn svg { width: 21px; height: 21px; }
  .tab-btn span { font-size: 11px; font-weight: 600; }
  .tab-btn.active { color: var(--accent); }

  /* ---------- Material rows ---------- */
  .mat-row {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    padding: 14px 14px;
    margin-bottom: 10px;
  }
  .mat-row-main { flex: 1; min-width: 0; }
  .mat-row-name { font-size: 15.5px; font-weight: 600; color: var(--ink); margin-bottom: 3px; }
  .mat-row-sub { font-size: 12.5px; color: var(--ink-soft); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
  .mat-row-cat {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    color: var(--accent-dark);
    background: var(--accent-light);
    padding: 2px 9px;
    border-radius: 999px;
  }
  .mat-row-rate { font-family: 'Fraunces', serif; font-weight: 600; font-size: 16px; color: var(--accent-dark); white-space: nowrap; }
  .mat-row-rate small { font-family: 'Work Sans', sans-serif; font-weight: 500; font-size: 11.5px; color: var(--ink-soft); }

  /* ---------- Costing ---------- */
  .cost-row {
    display: block;
    width: 100%;
    text-align: left;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    padding: 15px 16px;
    margin-bottom: 10px;
  }
  .cost-row-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
  .cost-row-title { font-family: 'Fraunces', serif; font-size: 17px; font-weight: 600; color: var(--ink); }
  .cost-row-sub { font-size: 12.5px; color: var(--ink-soft); margin-top: 3px; }
  .cost-row-figure { text-align: right; flex-shrink: 0; }
  .cost-row-figure b { font-family: 'Fraunces', serif; font-size: 18px; color: var(--accent-dark); display: block; }
  .cost-row-figure span { font-size: 11px; color: var(--ink-soft); }
  .cost-badge {
    display: inline-block;
    margin-top: 8px;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--paprika-light);
    color: var(--paprika);
  }
  .cost-option-list { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
  .cost-option-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13.5px;
    padding: 7px 10px;
    background: var(--surface);
    border-radius: 8px;
  }
  .cost-option-line span { color: var(--ink-soft); }
  .cost-option-line b { font-family: 'Fraunces', serif; color: var(--accent-dark); font-weight: 600; }

  .cost-section { margin-bottom: 26px; }
  .cost-section h3 { font-size: 15px; font-weight: 600; margin: 0 0 12px; color: var(--ink); }
  .cost-section .section-hint { font-size: 12.5px; color: var(--ink-soft); margin: -6px 0 14px; }
  .field-hint { font-size: 12.5px; color: var(--ink-soft); margin: -4px 0 9px; }

  .cost-line {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 0;
    border-bottom: 1px dashed var(--line);
  }
  .cost-line:last-child { border-bottom: none; }
  .cost-line-name { flex: 1; min-width: 0; }
  .cost-line-name b { display: block; font-size: 14.5px; color: var(--ink); font-weight: 600; }
  .cost-line-name span { font-size: 12px; color: var(--ink-soft); }
  .cost-line .mat-picker { max-width: 118px; flex-shrink: 0; }
  .cost-line-amt { width: 76px; text-align: right; flex-shrink: 0; font-size: 14px; font-weight: 600; color: var(--accent-dark); }
  .cost-line-amt.na { color: var(--paprika); font-weight: 500; font-size: 12px; }
  .cost-override {
    width: 100%;
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 6px;
    padding-left: 2px;
  }
  .cost-override input {
    width: 90px;
    border: 1px solid var(--line);
    background: var(--white);
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 13px;
    color: var(--ink);
  }
  .cost-override span { font-size: 12px; color: var(--ink-soft); }

  .cost-pack-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 9px;
  }
  .cost-pack-row input {
    border: 1px solid var(--line);
    background: var(--white);
    border-radius: 8px;
    padding: 9px 8px;
    font-size: 13px;
    color: var(--ink);
  }
  .cost-pack-row .mat-picker { flex: 1.4; min-width: 0; }
  .cost-pack-row .pack-qty { width: 56px; flex: none; text-align: center; padding: 9px 4px; }
  .cost-pack-row .pack-amt { width: 60px; flex: none; text-align: right; font-size: 13.5px; font-weight: 600; color: var(--accent-dark); }
  .cost-pack-row .pack-remove { flex: none; }

  /* ---- Searchable material picker (Costing: link ingredient/packing item to a material) ---- */
  .mat-picker { position: relative; }
  .mat-picker-btn {
    width: 100%;
    border: 1px solid var(--line);
    background: var(--white);
    border-radius: 8px;
    padding: 8px 24px 8px 8px;
    font-size: 13px;
    color: var(--ink);
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: relative;
  }
  .mat-picker-btn.placeholder { color: var(--ink-soft); }
  .mat-picker-btn::after {
    content: '';
    position: absolute;
    right: 8px; top: 50%;
    width: 7px; height: 7px;
    border-right: 1.6px solid var(--ink-soft);
    border-bottom: 1.6px solid var(--ink-soft);
    transform: translateY(-65%) rotate(45deg);
  }
  .mat-picker-panel {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    width: max(100%, 230px);
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    box-shadow: 0 10px 24px rgba(38,32,25,0.16);
    z-index: 40;
    overflow: hidden;
  }
  .mat-picker.open .mat-picker-panel { display: block; }
  .mat-picker-search {
    width: 100%;
    border: none;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
    padding: 10px 12px;
    font-size: 13.5px;
    color: var(--ink);
  }
  .mat-picker-list { max-height: 190px; overflow-y: auto; }
  .mat-picker-item {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 10px 12px;
    font-size: 13.5px;
    color: var(--ink);
    border-bottom: 1px solid var(--line);
    cursor: pointer;
  }
  .mat-picker-item:last-child { border-bottom: none; }
  .mat-picker-item:hover, .mat-picker-item:active { background: var(--surface); }
  .mat-picker-item.active { background: var(--accent-light); }
  .mat-picker-item .rate { color: var(--ink-soft); font-size: 12px; white-space: nowrap; flex-shrink: 0; }
  .mat-picker-item.mat-picker-clear { color: var(--ink-soft); font-style: italic; }
  .mat-picker-item.mat-picker-new { color: var(--accent-dark); font-weight: 600; gap: 6px; }
  .mat-picker-item.mat-picker-new svg { width: 13px; height: 13px; flex-shrink: 0; }
  .mat-picker-empty { padding: 10px 12px; font-size: 12.5px; color: var(--ink-soft); font-style: italic; }

  .pack-option-card {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    padding: 16px 14px;
    margin-bottom: 14px;
  }
  .po-header {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 14px;
  }
  .po-label {
    flex: 1.4;
    min-width: 0;
    border: 1px solid var(--line);
    background: var(--surface);
    border-radius: 8px;
    padding: 9px 10px;
    font-size: 14.5px;
    font-weight: 600;
    color: var(--ink);
    font-family: 'Fraunces', serif;
  }
  .po-units-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: none;
  }
  .po-units {
    width: 50px;
    border: 1px solid var(--line);
    background: var(--surface);
    border-radius: 8px;
    padding: 9px 6px;
    font-size: 13.5px;
    color: var(--ink);
    text-align: center;
  }
  .po-units-wrap span { font-size: 12px; color: var(--ink-soft); }
  .po-remove { flex: none; }
  .pack-option-card .add-row-btn { margin: 4px 0 2px; }
  .po-summary.cost-summary { padding: 13px 14px; }
  .po-summary .cost-summary-row { font-size: 13px; padding: 5px 0; }
  .po-summary .cost-summary-row.total { padding-top: 10px; }

  .cost-summary {
    background: var(--surface);
    border-radius: var(--radius-m);
    padding: 16px 16px;
    margin-top: 4px;
  }
  .cost-summary-row { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; font-size: 14px; color: var(--ink-soft); }
  .cost-summary-row b { color: var(--ink); font-weight: 500; }
  .cost-summary-row.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 14px; }
  .cost-summary-row.total span:first-child { font-weight: 600; color: var(--ink); }
  .cost-summary-row.total .cost-final { font-family: 'Fraunces', serif; font-size: 23px; font-weight: 700; color: var(--accent-dark); }

  .empty-material-hint {
    background: var(--gold-light);
    border-left: 3px solid var(--gold);
    border-radius: 0 var(--radius-m) var(--radius-m) 0;
    padding: 12px 14px;
    font-size: 13px;
    color: var(--ink);
    line-height: 1.5;
    margin-bottom: 16px;
  }

  /* ---------- Header ---------- */
  .header {
    padding: 32px 20px 18px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
  }
  .brand h1 {
    font-size: 34px;
    font-weight: 700;
    margin: 0;
    line-height: 1.05;
    letter-spacing: -0.02em;
    color: var(--ink);
  }
  .brand .rule {
    width: 46px;
    height: 3px;
    background: var(--gold);
    border-radius: 2px;
    margin: 10px 0 9px;
  }
  .brand p {
    margin: 0;
    font-size: 13.5px;
    font-style: italic;
    color: var(--ink-soft);
    font-family: 'Fraunces', serif;
  }
  .icon-btn {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ink);
    flex-shrink: 0;
    transition: background 0.15s ease;
  }
  .icon-btn:active { background: var(--surface-2); }
  .icon-btn svg { width: 18px; height: 18px; }
  .header-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
  }

  /* ---------- Search ---------- */
  .search-wrap {
    display: none;
    padding: 0 20px 14px;
  }
  .search-wrap.open {
    display: block;
    animation: searchIn 0.16s ease;
  }
  @keyframes searchIn {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
  }
  .search-input {
    width: 100%;
    border: 1px solid var(--line);
    background: var(--white);
    border-radius: var(--radius-m);
    padding: 14px 18px;
    font-size: 15.5px;
    color: var(--ink);
    display: block;
  }
  .search-input::placeholder { color: var(--ink-soft); }

  /* ---------- Category chips ---------- */
  .chips {
    display: flex;
    gap: 8px;
    padding: 4px 20px 18px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .chips::-webkit-scrollbar { display: none; }
  .chip {
    flex-shrink: 0;
    padding: 8px 17px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: var(--white);
    font-size: 13.5px;
    font-weight: 500;
    color: var(--ink-soft);
    white-space: nowrap;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  }
  .chip.active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--white);
    box-shadow: 0 6px 14px rgba(110,42,52,0.28);
  }

  /* ---------- Recipe collection ---------- */
  .list {
    padding: 6px 20px 0;
    display: flex;
    flex-direction: column;
    gap: 26px;
  }
  .section-label {
    font-size: 12.5px;
    color: var(--ink-soft);
    padding: 2px 0 10px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 4px;
  }
  .recipe-card {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
  }
  .card-media {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    border-radius: var(--radius-l);
    overflow: hidden;
    background: var(--accent-light);
    box-shadow: var(--shadow);
    transition: transform 0.15s ease;
  }
  .recipe-card:active .card-media { transform: scale(0.98); }
  .card-media img {
    width: 100%; height: 100%;
    object-fit: cover;
    display: block;
  }
  .card-placeholder {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
  }
  .card-placeholder svg { width: 46px; height: 46px; color: var(--accent); opacity: 0.55; }
  .card-scrim {
    position: absolute; inset: 0;
    background: var(--scrim);
    pointer-events: none;
  }
  .card-cat-badge {
    position: absolute;
    top: 14px; left: 14px;
    background: rgba(255,251,243,0.94);
    color: var(--accent-dark);
    font-size: 11.5px;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 999px;
  }
  .card-title-overlay {
    position: absolute;
    left: 18px; right: 18px; bottom: 16px;
    color: var(--white);
    font-family: 'Fraunces', serif;
    font-size: 22px;
    font-weight: 600;
    line-height: 1.2;
    text-shadow: 0 3px 12px rgba(0,0,0,0.3);
  }
  .card-meta-row {
    display: flex;
    gap: 18px;
    padding: 11px 3px 0;
    font-size: 12.5px;
    color: var(--ink-soft);
  }
  .card-meta-row span { display: flex; align-items: center; gap: 5px; }
  .card-meta-row svg { width: 13px; height: 13px; color: var(--gold); }

  /* ---------- Empty state ---------- */
  .empty {
    padding: 50px 30px 60px;
    text-align: center;
  }
  .empty-frame {
    width: 92px; height: 92px;
    margin: 0 auto 20px;
    border-radius: 50%;
    border: 1.5px dashed var(--gold);
    display: flex; align-items: center; justify-content: center;
  }
  .empty-frame svg { width: 38px; height: 38px; color: var(--gold); }
  .empty h3 { margin: 0 0 8px; font-size: 21px; font-weight: 600; }
  .empty p { color: var(--ink-soft); font-size: 14px; margin: 0 0 22px; }

  /* ---------- FAB ---------- */
  .fab {
    position: fixed;
    bottom: calc(76px + env(safe-area-inset-bottom));
    right: max(20px, calc((100vw - 480px)/2 + 20px));
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--white);
    border: none;
    box-shadow: 0 8px 22px rgba(78,30,38,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 40;
    transition: transform 0.12s ease;
  }
  .fab:active { transform: scale(0.94); }
  .fab svg { width: 24px; height: 24px; }

  /* ---------- Buttons ---------- */
  .btn {
    border: none;
    border-radius: var(--radius-m);
    padding: 13px 20px;
    font-size: 15px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
  }
  .btn-primary { background: var(--accent); color: var(--white); }
  .btn-primary:active { background: var(--accent-dark); }
  .btn-ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
  .btn-full { width: 100%; }
  .btn svg { width: 16px; height: 16px; }
  .btn[disabled] { opacity: 0.5; }

  /* ---------- Overlays (detail / form) ---------- */
  .overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    pointer-events: none;
    overflow: hidden;
  }
  .overlay-inner {
    width: 100%;
    max-width: 480px;
    height: 100%;
    margin: 0 auto;
    background: var(--bg);
    overflow-y: auto;
    overflow-x: hidden;
    transform: translateX(100%);
    transition: transform 0.24s cubic-bezier(.3,.1,.2,1);
  }
  .overlay.open { pointer-events: auto; }
  .overlay.open .overlay-inner { transform: translateX(0); }

  /* ---------- Detail view ---------- */
  .detail-hero {
    position: relative;
    width: 100%;
    height: 320px;
    background: var(--accent-light);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
  }
  .detail-hero img { width: 100%; height: 100%; object-fit: cover; }
  .detail-hero svg.placeholder-icon { width: 60px; height: 60px; color: var(--accent); }
  .hero-scrim {
    position: absolute; inset: 0;
    background: var(--scrim);
    pointer-events: none;
  }
  .hero-back {
    position: absolute;
    top: 18px;
    left: 18px;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(251,248,242,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    backdrop-filter: blur(2px);
    z-index: 2;
  }
  .hero-back svg { width: 18px; height: 18px; color: var(--ink); }
  .hero-text {
    position: absolute;
    left: 20px; right: 20px; bottom: 20px;
    z-index: 1;
  }
  .detail-tag {
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    color: var(--accent-dark);
    background: rgba(255,251,243,0.94);
    padding: 4px 12px;
    border-radius: 999px;
    margin-bottom: 12px;
  }
  .detail-title {
    font-size: 29px;
    font-weight: 600;
    margin: 0;
    line-height: 1.15;
    color: var(--white);
    text-shadow: 0 3px 14px rgba(0,0,0,0.32);
  }
  .detail-title.on-light { color: var(--ink); text-shadow: none; margin-bottom: 16px; }

  .detail-body { padding: 22px 20px 40px; }

  .stat-strip {
    display: flex;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    margin: 18px 0 26px;
  }
  .stat {
    flex: 1;
    text-align: center;
    padding: 15px 6px;
    border-right: 1px solid var(--line);
  }
  .stat:last-child { border-right: none; }
  .stat b { display: block; font-family: 'Fraunces', serif; font-size: 22px; font-weight: 600; color: var(--accent-dark); }
  .stat span { font-size: 11.5px; color: var(--ink-soft); }

  .detail-section { margin-bottom: 28px; }
  .detail-section h3 {
    font-size: 15px;
    font-weight: 600;
    margin: 0 0 14px;
    color: var(--ink);
  }

  .ing-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 9px 0;
    border-bottom: 1px dashed var(--line);
    font-size: 15px;
  }
  .ing-item:last-child { border-bottom: none; }
  .ing-check {
    width: 18px; height: 18px;
    border: 1.5px solid var(--accent);
    border-radius: 4px;
    flex-shrink: 0;
    margin-top: 2px;
    display: flex; align-items: center; justify-content: center;
    background: var(--white);
  }
  .ing-check svg { width: 12px; height: 12px; color: var(--white); display: none; }
  .ing-item.checked .ing-check { background: var(--accent); }
  .ing-item.checked .ing-check svg { display: block; }
  .ing-item.checked .ing-text { color: var(--ink-soft); text-decoration: line-through; }

  .step-item {
    display: flex;
    gap: 14px;
    padding: 0 0 20px;
    font-size: 15px;
    line-height: 1.55;
  }
  .step-num {
    flex-shrink: 0;
    width: 26px; height: 26px;
    border-radius: 50%;
    border: 1.5px solid var(--accent);
    color: var(--accent);
    font-family: 'Fraunces', serif;
    font-weight: 600;
    font-size: 13px;
    display: flex; align-items: center; justify-content: center;
  }
  .note-box {
    background: var(--gold-light);
    border-left: 3px solid var(--gold);
    border-radius: 0 var(--radius-m) var(--radius-m) 0;
    padding: 14px 16px;
    font-size: 14px;
    color: var(--ink);
    line-height: 1.5;
    font-style: italic;
  }

  .scale-box {
    background: var(--surface);
    border-radius: var(--radius-m);
    padding: 12px 14px;
    margin-bottom: 14px;
  }
  .scale-row {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 13.5px;
    color: var(--ink-soft);
  }
  .scale-row input {
    width: 62px;
    border: 1px solid var(--line);
    background: var(--white);
    border-radius: 8px;
    padding: 7px 6px;
    font-size: 14px;
    color: var(--ink);
    text-align: center;
  }
  .scale-reset {
    margin-left: auto;
    background: none; border: none;
    color: var(--accent);
    font-size: 12.5px;
    font-weight: 600;
  }
  .mismatch-banner {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    background: var(--paprika-light);
    color: var(--paprika);
    border-radius: var(--radius-m);
    padding: 12px 14px;
    font-size: 13px;
    line-height: 1.45;
    margin-bottom: 14px;
  }
  .mismatch-banner svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }

  .detail-actions {
    display: flex;
    gap: 8px;
    padding-top: 4px;
  }
  .detail-actions .btn { flex: 1; padding-left: 10px; padding-right: 10px; }
  .detail-actions .btn.icon-only { flex: 0 0 44px; padding-left: 0; padding-right: 0; }
  .action-danger { color: var(--paprika); }

  /* ---------- Form ---------- */
  .form-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 20px;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 5;
  }
  .form-header h2 { font-size: 19px; margin: 0; font-weight: 600; }
  .form-body { padding: 20px; }

  .field { margin-bottom: 20px; }
  .field label {
    display: block;
    font-size: 13px;
    color: var(--ink-soft);
    margin-bottom: 7px;
  }
  .field input[type=text], .field input[type=number], .field input[type=password], .field textarea, .field select {
    width: 100%;
    border: 1px solid var(--line);
    background: var(--white);
    border-radius: var(--radius-m);
    padding: 12px 13px;
    font-size: 15.5px;
    color: var(--ink);
  }
  .field input.title-input { font-family: 'Fraunces', serif; font-size: 19px; font-weight: 500; }
  .field textarea { resize: vertical; min-height: 46px; line-height: 1.4; }

  .field-row { display: flex; gap: 12px; }
  .field-row .field { flex: 1; }

  .input-suffix { position: relative; }
  .input-suffix input { padding-right: 46px !important; }
  .input-suffix span {
    position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
    font-size: 13px; color: var(--ink-soft); pointer-events: none;
  }

  .ing-row { align-items: center; }
  .ing-row .ing-qty {
    width: 62px !important; flex: none !important;
    text-align: center;
  }
  .ing-row .ing-unit {
    width: 68px !important; flex: none !important;
    padding: 12px 6px !important;
  }
  .ing-row .ing-name-wrap { flex: 1 !important; min-width: 0; position: relative; }
  .ing-row .ing-name { width: 100%; }

  .ing-suggest {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0; right: 0;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    box-shadow: 0 10px 24px rgba(38,32,25,0.14);
    max-height: 190px;
    overflow-y: auto;
    z-index: 30;
  }
  .ing-suggest.open { display: block; }
  .ing-suggest-item {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 10px 12px;
    font-size: 13.5px;
    color: var(--ink);
    border-bottom: 1px solid var(--line);
    cursor: pointer;
  }
  .ing-suggest-item:last-child { border-bottom: none; }
  .ing-suggest-item:active, .ing-suggest-item:hover { background: var(--surface); }
  .ing-suggest-item .rate { color: var(--ink-soft); font-size: 12px; white-space: nowrap; flex-shrink: 0; }

  .photo-drop {
    width: 100%;
    height: 160px;
    border-radius: var(--radius-m);
    border: 1.5px dashed var(--line);
    background: var(--surface);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--ink-soft);
    gap: 8px;
    overflow: hidden;
    position: relative;
  }
  .photo-drop img { position:absolute; inset:0; width:100%; height:100%; object-fit: cover; }
  .photo-drop .drop-label { font-size: 13.5px; z-index: 1; }
  .photo-drop svg { width: 26px; height: 26px; z-index: 1; }
  .photo-drop.has-img .drop-label, .photo-drop.has-img svg { display: none; }
  .photo-edit-badge {
    position: absolute;
    bottom: 10px; right: 10px;
    background: rgba(38,32,25,0.65);
    color: var(--white);
    font-size: 12px;
    padding: 5px 10px;
    border-radius: 999px;
    z-index: 2;
  }

  .dyn-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 9px;
  }
  .dyn-row input, .dyn-row textarea { flex: 1; }
  .dyn-remove {
    width: 32px; height: 32px;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: var(--white);
    color: var(--ink-soft);
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
  }
  .dyn-remove svg { width: 14px; height: 14px; }
  .step-row { align-items: flex-start; }
  .step-row .step-num-input {
    width: 26px; height: 26px; border-radius: 50%;
    background: var(--accent-light); color: var(--accent);
    font-family: 'Fraunces', serif; font-weight: 600; font-size: 12.5px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; margin-top: 6px;
  }

  .add-row-btn {
    background: none; border: none;
    color: var(--accent);
    font-size: 14px; font-weight: 600;
    display: flex; align-items: center; gap: 6px;
    padding: 6px 0;
  }
  .add-row-btn svg { width: 15px; height: 15px; }

  .form-footer {
    position: sticky;
    bottom: 0;
    padding: 16px 20px calc(16px + env(safe-area-inset-bottom));
    background: var(--bg);
    border-top: 1px solid var(--line);
    display: flex;
    gap: 10px;
  }

  /* ---------- Toast ---------- */
  .toast {
    position: fixed;
    bottom: calc(74px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--ink);
    color: var(--white);
    padding: 12px 20px;
    border-radius: 999px;
    font-size: 13.5px;
    z-index: 90;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;
    max-width: 90%;
    text-align: center;
  }
  .toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

  /* ---------- Confirm sheet ---------- */
  .sheet-backdrop {
    position: fixed; inset: 0;
    background: rgba(38,32,25,0.4);
    z-index: 210;
    display: none;
    align-items: flex-end;
    justify-content: center;
  }
  .sheet-backdrop.open { display: flex; }
  .sheet {
    background: var(--bg);
    width: 100%;
    max-width: 480px;
    border-radius: 18px 18px 0 0;
    padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  }
  .sheet h3 { margin: 0 0 8px; font-size: 18px; }
  .sheet p { margin: 0 0 20px; color: var(--ink-soft); font-size: 14px; }
  .sheet-actions { display: flex; gap: 10px; }
  .sheet-actions .btn { flex: 1; }

  .loading-wrap {
    padding: 80px 20px;
    text-align: center;
    color: var(--ink-soft);
    font-size: 14px;
  }

  /* ---------- Fingerprint lock screen ---------- */
  .lock-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: var(--bg);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
  }
  .lock-overlay.open { display: flex; }
  .lock-card {
    width: 100%;
    max-width: 360px;
    text-align: center;
  }
  .lock-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 18px;
    border-radius: 50%;
    background: var(--accent-light);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .lock-icon svg { width: 30px; height: 30px; }
  .lock-card h2 {
    margin: 0 0 10px;
    font-size: 24px;
    color: var(--ink);
  }
  .lock-sub {
    margin: 0 0 20px;
    font-size: 14px;
    color: var(--ink-soft);
    line-height: 1.5;
  }
  .lock-card .btn { width: 100%; margin-bottom: 10px; }
  .lock-error {
    margin: 10px 0 0;
    font-size: 13px;
    color: var(--paprika);
    min-height: 1em;
  }

  /* ---------- Device management list ---------- */
  .device-list { padding: 4px 20px 30px; }
  .device-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 0;
    border-bottom: 1px solid var(--line);
  }
  .device-row:last-child { border-bottom: none; }
  .device-row-icon {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--surface);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }
  .device-row-icon svg { width: 18px; height: 18px; }
  .device-row-main { flex: 1; min-width: 0; }
  .device-row-main .d-label { font-weight: 600; font-size: 14.5px; color: var(--ink); }
  .device-row-main .d-sub { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }
  .device-row-remove {
    background: none;
    border: none;
    color: var(--paprika);
    font-size: 13px;
    padding: 6px 10px;
    flex-shrink: 0;
  }
  .device-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--ink-soft);
    font-size: 14px;
  }
  .device-add-row { padding: 10px 20px 0; }

  /* ---------- Recipe PDFs ---------- */
  .pdf-row {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    padding: 14px 14px;
    margin-bottom: 10px;
  }
  .pdf-row-icon {
    width: 38px; height: 38px;
    border-radius: 10px;
    background: var(--accent-light);
    color: var(--accent-dark);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
  }
  .pdf-row-icon svg { width: 19px; height: 19px; }
  .pdf-row-main { flex: 1; min-width: 0; cursor: pointer; }
  .pdf-row-name { font-size: 15.5px; font-weight: 600; color: var(--ink); margin-bottom: 3px; }
  .pdf-row-sub { font-size: 12.5px; color: var(--ink-soft); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
  .pdf-row-actions { display: flex; gap: 6px; flex-shrink: 0; }
  .pdf-row-actions .icon-btn { width: 34px; height: 34px; }
  .pdf-row-actions .icon-btn svg { width: 15px; height: 15px; }
  .pdf-row-actions .dyn-remove { width: 34px; height: 34px; }

  .pdf-drop {
    width: 100%;
    min-height: 90px;
    border-radius: var(--radius-m);
    border: 1.5px dashed var(--line);
    background: var(--surface);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--ink-soft);
    gap: 8px;
    padding: 18px 12px;
    text-align: center;
  }
  .pdf-drop.has-file { color: var(--accent-dark); border-style: solid; border-color: var(--accent); background: var(--accent-light); }
  .pdf-drop svg { width: 26px; height: 26px; }
  .pdf-drop .drop-label { font-size: 13.5px; }

  /* ---------- Login screen: scrolls on short phones; account panel ---------- */
  .lock-overlay { overflow-y: auto; align-items: flex-start; }
  .lock-card { margin: auto; }
  .lock-card form { margin: 0; }
  .account-body { padding: 4px 20px 40px; }
  .account-h { margin: 22px 0 12px; font-size: 16px; color: var(--ink); }
  .account-reset {
    background: none; border: 0; padding: 6px 4px; cursor: pointer;
    font: inherit; font-size: 13px; color: var(--accent);
  }


  /* ---------- Kitchen groups ---------- */
  .kitchen-bar {
    position: sticky; top: 0; z-index: 20;
    background: var(--paper, #fbf6ee);
    border-bottom: 1px solid rgba(0,0,0,0.08);
    padding: 8px 16px;
  }
  .kitchen-bar-row { display: flex; align-items: center; gap: 10px; }
  .kitchen-bar-row label { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-soft); }
  .kitchen-bar-row select {
    flex: 1; min-width: 0; font: inherit; font-size: 15px; font-weight: 600;
    padding: 7px 10px; border-radius: 10px;
    border: 1px solid rgba(0,0,0,0.15); background: #fff; color: var(--ink);
  }
  .kitchen-bar-note { font-size: 12.5px; line-height: 1.4; color: var(--ink-soft); margin-top: 6px; }
  .kitchen-readonly-note {
    background: rgba(107,39,51,0.08); color: var(--ink);
    border-radius: 10px; padding: 10px 12px; margin-bottom: 14px;
    font-size: 13.5px; line-height: 1.45;
  }
  #accountToggle { position: relative; }
  #accountToggle.has-dot::after {
    content: ''; position: absolute; top: 6px; right: 6px;
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--paprika, #c0392b); border: 2px solid #fff;
  }
  .device-row .account-reset + .account-reset { margin-left: 6px; }
