  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
  :root {
    --bg: #f7f7f6; --bg2: #efefed; --bg3: #e5e5e2;
    --text: #1a1a18; --text2: #6b6b66; --text3: #9b9b94;
    --border: #e0e0db; --border2: #d0d0ca;
    --blue: #4361EE; --blue-bg: #EEF2FF;
    --green: #166534; --green-bg: #DCFCE7;
    --amber: #92400e; --amber-bg: #FEF3C7;
    --warn: #b45309;
    --radius: 8px; --radius-lg: 12px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  }
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
  body { font-family: var(--font); background: var(--bg); color: var(--text); }
  .app { display: flex; height: 100vh; }
  .sidebar { width: 204px; flex-shrink: 0; background: #fff; border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 1rem 0; }
  .sidebar-logo { padding: 0 1rem 1rem; font-size: 15px; font-weight: 600; border-bottom: 1px solid var(--border); margin-bottom: 0.5rem; }
  .sidebar-logo span { color: var(--text2); font-weight: 400; font-size: 12px; display: block; margin-top: 2px; }
  .nav-item { display: flex; align-items: center; gap: 8px; padding: 8px 1rem; font-size: 14px; color: var(--text2); cursor: pointer; transition: background 0.12s; }
  .nav-item:hover { background: var(--bg); color: var(--text); }
  .nav-item.active { background: var(--bg2); color: var(--text); font-weight: 500; }
  .nav-item.mt-auto { margin-top: auto; }
  .main { flex: 1; overflow-y: auto; padding: 1.5rem; }
  .page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
  .page-title { font-size: 20px; font-weight: 600; }
  .btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; font-size: 13px; font-weight: 500; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; color: var(--text); cursor: pointer; transition: background 0.12s; }
  .btn:hover { background: var(--bg); }
  .btn.primary { background: var(--text); color: #fff; border-color: var(--text); }
  .btn.primary:hover { opacity: 0.85; }
  .cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 12px; }
  .card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1rem 1.2rem; }
  .section-label { font-size: 11px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 8px; }
  .stats-bar { display: grid; grid-template-columns: repeat(4,1fr); gap: 12px; margin-bottom: 1.5rem; }
  .stat { background: var(--bg2); border-radius: var(--radius); padding: 0.875rem 1rem; }
  .stat-label { font-size: 12px; color: var(--text2); margin-bottom: 4px; }
  .stat-value { font-size: 22px; font-weight: 600; }
  .empty { text-align: center; padding: 3rem 1rem; color: var(--text2); font-size: 14px; }
  .icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border: 1px solid var(--border); border-radius: var(--radius); background: transparent; cursor: pointer; color: var(--text2); font-size: 14px; transition: background 0.12s; }
  .icon-btn:hover { background: var(--bg); color: var(--text); }
  .icon-btn.danger:hover { background: #FEE2E2; color: #991B1B; border-color: #FECACA; }
  .cost-breakdown { background: var(--bg); border-radius: var(--radius); padding: 10px 12px; margin-top: 8px; font-size: 13px; }
  .cost-breakdown .row { display: flex; justify-content: space-between; padding: 2px 0; color: var(--text2); }
  .cost-breakdown .subtotal { font-weight: 500; color: var(--text); border-top: 1px solid var(--border); padding-top: 5px; margin-top: 3px; }
  .cost-breakdown .total { font-weight: 600; color: var(--text); border-top: 2px solid var(--border2); padding-top: 6px; margin-top: 4px; }
  .cost-breakdown .section-divider { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text3); padding-top: 8px; margin-top: 4px; padding-bottom: 2px; }
  .pill { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; padding: 2px 7px; border-radius: 99px; background: var(--blue-bg); color: var(--blue); margin-left: 6px; vertical-align: middle; }
  .time-pill { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; padding: 2px 7px; border-radius: 99px; background: var(--amber-bg); color: var(--amber); margin-left: 4px; vertical-align: middle; }
  /* Modal */
  .modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 100; display: flex; align-items: center; justify-content: center; }
  .modal { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.5rem; width: 560px; max-width: calc(100vw - 2rem); max-height: 90vh; overflow-y: auto; }
  .modal-title { font-size: 17px; font-weight: 600; margin-bottom: 1.25rem; }
  .modal-section { font-size: 11px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 0.07em; margin: 1rem 0 8px; padding-top: 1rem; border-top: 1px solid var(--border); }
  .modal-section:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }
  .field { margin-bottom: 1rem; }
  .field label { display: block; font-size: 13px; color: var(--text2); margin-bottom: 4px; }
  .field input, .field select { width: 100%; padding: 7px 10px; font-size: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; color: var(--text); }
  .field input:focus, .field select:focus { outline: none; border-color: #aaa; }
  .field textarea { width: 100%; padding: 7px 10px; font-size: 14px; font-family: inherit; line-height: 1.5; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; color: var(--text); resize: vertical; }
  .field textarea:focus { outline: none; border-color: #aaa; }
  .field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .field-row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
  .modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--border); }
  .ing-row { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; background: var(--bg); border-radius: var(--radius); padding: 8px 10px; }
  .ing-row select, .ing-row input { flex: 1; padding: 5px 8px; font-size: 13px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; color: var(--text); min-width: 0; }
  .ing-row .unit-sel { flex: 0 0 82px; }
  .ing-row .remove-btn { width: 24px; height: 24px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 14px; border: none; background: none; border-radius: var(--radius); color: var(--text2); }
  .ing-row .remove-btn:hover { color: #991B1B; background: #FEE2E2; }
  .add-row-btn { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--text2); background: none; border: 1px dashed var(--border2); border-radius: var(--radius); padding: 6px 12px; cursor: pointer; width: 100%; justify-content: center; margin-top: 4px; }
  .add-row-btn:hover { background: var(--bg); color: var(--text); }
  .info-box { font-size: 12px; color: var(--text2); padding: 8px 12px; background: var(--bg); border-radius: var(--radius); margin-bottom: 1rem; line-height: 1.5; }
  .time-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .time-input-wrap { display: flex; gap: 6px; align-items: center; }
  .time-input-wrap input { width: 70px; padding: 7px 10px; font-size: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; color: var(--text); }
  .time-input-wrap select { padding: 7px 8px; font-size: 13px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; color: var(--text); }
  .time-input-wrap span { font-size: 13px; color: var(--text2); white-space: nowrap; }
  .labour-preview { font-size: 12px; color: var(--text2); margin-top: 6px; font-style: italic; }
  /* Settings */
  .settings-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.25rem; margin-bottom: 1.25rem; }
  .settings-card h2 { font-size: 14px; font-weight: 600; margin-bottom: 1rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--border); }
  .setting-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 10px 0; }
  .setting-row:not(:last-child) { border-bottom: 1px solid var(--border); }
  .setting-row select, .setting-row input[type=number] { padding: 7px 10px; font-size: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; color: var(--text); min-width: 180px; }
  .setting-right { display: flex; align-items: center; gap: 8px; }
  .setting-right span { font-size: 14px; color: var(--text2); }
  /* Converter */
  .conv-box { background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.25rem; margin-bottom: 1.5rem; }
  .conv-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
  .conv-row input { width: 100px; padding: 7px 10px; font-size: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; color: var(--text); }
  .conv-row select { padding: 7px 10px; font-size: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; color: var(--text); }
  .conv-arrow { font-size: 18px; color: var(--text2); }
  .conv-result { font-size: 20px; font-weight: 600; min-width: 150px; color: var(--text); }
  .conv-density { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 13px; color: var(--text2); }
  .conv-density input { width: 90px; padding: 5px 8px; font-size: 13px; border: 1px solid var(--border); border-radius: var(--radius); }
  .ref-table { width: 100%; border-collapse: collapse; font-size: 13px; }
  .ref-table th { text-align: left; font-size: 11px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 0.06em; padding: 6px 10px; border-bottom: 1px solid var(--border); }
  .ref-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); }
  .ref-table tr:last-child td { border-bottom: none; }
  .warn { font-size: 12px; color: var(--warn); margin-top: 6px; }
  .link { color: var(--blue); text-decoration: underline; cursor: pointer; font-size: 13px; }
  .density-section { background: var(--bg); border-radius: var(--radius); padding: 10px 12px; margin-top: -4px; margin-bottom: 1rem; }
  .density-section label { font-size: 12px; color: var(--text2); display: block; margin-bottom: 4px; }
  .density-section input { width: 130px; padding: 5px 8px; font-size: 13px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
  .hint { font-size: 11px; color: var(--text3); margin-top: 3px; font-style: italic; }
  .time-bar { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
  .time-chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text2); background: var(--bg2); border-radius: 99px; padding: 3px 10px; }
  /* Import: add unmatched ingredient to pantry */
  .import-add-block { background: var(--bg2); border-radius: var(--radius); padding: 8px; margin-bottom: 8px; }
  .add-imported-btn { display: flex; align-items: center; justify-content: center; gap: 6px; width: 100%; min-height: 44px; font-size: 13px; font-weight: 500; color: var(--blue); background: var(--blue-bg); border: 1px solid var(--blue); border-radius: var(--radius); cursor: pointer; transition: filter 0.12s; }
  .add-imported-btn:hover { filter: brightness(0.97); }
  .needs-price-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--amber); background: var(--amber-bg); border-radius: var(--radius); padding: 4px 9px; }
  .import-name-input { width: 100%; padding: 8px 10px; font-size: 13px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; color: var(--text); margin-bottom: 8px; }
  .import-name-input:focus { outline: none; border-color: #aaa; }
  /* Mobile sidebar drawer */
  .nav-toggle { display: none; position: fixed; top: 10px; left: 10px; z-index: 210; width: 40px; height: 40px; align-items: center; justify-content: center; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
  .nav-backdrop { display: none; }
  @media (max-width: 640px) {
    .nav-toggle { display: flex; }
    .sidebar { position: fixed; top: 0; left: 0; bottom: 0; transform: translateX(-100%); transition: transform 0.22s ease; z-index: 200; box-shadow: 2px 0 14px rgba(0,0,0,0.18); }
    .app.nav-open .sidebar { transform: translateX(0); }
    .sidebar-logo { padding-left: 3.5rem; }
    .nav-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 150; }
    .app.nav-open .nav-backdrop { display: block; }
    .main { padding-top: 3.5rem; }
  }
