:root {
  --accent: #2383E2;
  --accent-soft: rgba(35, 131, 226, 0.14);
  --accent-hover: #1E72C7;
  --bg: #FFFFFF;
  --bg-elev: #FFFFFF;
  --bg-grouped: #FFFFFF;
  --bg-secondary-grouped: #FFFFFF;
  --bg-hover: rgba(55, 53, 47, 0.06);
  --bg-active: rgba(55, 53, 47, 0.12);
  --bg-sticky: rgba(55, 53, 47, 0.08);
  --bg-input: rgba(242, 241, 238, 0.6);
  --text: #37352F;
  --text-secondary: #787774;
  --text-tertiary: #9B9A97;
  --separator: rgba(55, 53, 47, 0.09);
  --separator-strong: rgba(55, 53, 47, 0.16);
  --danger: #E03E3E;
  --danger-soft: rgba(224, 62, 62, 0.1);
  --radius: 3px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --header-h: 44px;
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
  /* Legacy aliases */
  --tint: var(--accent);
  --tint-soft: var(--accent-soft);
  --warning: #D9730D;
  --success: #0F7B0F;
  --yellow: #C29343;
  --indigo: var(--accent);
  --gray: var(--text-tertiary);
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #529CCA;
    --accent-soft: rgba(82, 156, 202, 0.2);
    --accent-hover: #4789B5;
    --bg: #191919;
    --bg-elev: #2F2F2F;
    --bg-grouped: #191919;
    --bg-secondary-grouped: #191919;
    --bg-hover: rgba(255, 255, 255, 0.055);
    --bg-active: rgba(255, 255, 255, 0.09);
    --bg-sticky: rgba(255, 255, 255, 0.08);
    --bg-input: rgba(255, 255, 255, 0.055);
    --text: rgba(255, 255, 255, 0.81);
    --text-secondary: rgba(255, 255, 255, 0.6);
    --text-tertiary: rgba(255, 255, 255, 0.4);
    --separator: rgba(255, 255, 255, 0.094);
    --separator-strong: rgba(255, 255, 255, 0.13);
    --danger: #FF7369;
    --danger-soft: rgba(255, 115, 105, 0.15);
    --warning: #FFA344;
    --yellow: #DFAB01;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
html { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Helvetica Neue", system-ui, sans-serif;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: var(--bg);
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
#app { min-height: 100vh; padding-top: var(--safe-top); padding-bottom: var(--safe-bottom); background: var(--bg); }

/* Constrain app width on large screens */
@media (min-width: 820px) {
  body { background: rgba(55, 53, 47, 0.05); }
  #app {
    max-width: 800px;
    margin: 0 auto;
    background: var(--bg);
    box-shadow: 0 0 0 1px var(--separator);
  }
  .fab { right: max(16px, calc(50vw - 400px + 16px)); }
  .sheet-backdrop { justify-content: center; }
  .sheet { max-width: 800px; }
}
@media (prefers-color-scheme: dark) and (min-width: 820px) {
  body { background: #0F0F0F; }
}

input, textarea, select, button { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

*:focus { outline: none; }

/* Icons */
.icon {
  width: 16px;
  height: 16px;
  display: inline-block;
  vertical-align: -3px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.6;
}
.icon-lg { width: 20px; height: 20px; }
.icon-xl { width: 40px; height: 40px; }

/* Header */
.header {
  position: sticky;
  top: var(--safe-top);
  z-index: 30;
  background: var(--bg);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 8px;
  min-height: var(--header-h);
  border-bottom: 1px solid var(--separator);
}
.header .title {
  font-size: 14px;
  font-weight: 600;
  flex: 1;
  text-align: center;
  color: var(--text);
}
.header .back {
  color: var(--text-secondary);
  padding: 6px 8px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  gap: 2px;
  transition: background 120ms ease, color 120ms ease;
}
.header .back:hover { background: var(--bg-hover); color: var(--text); }
.header .icon-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  color: var(--text-secondary);
  transition: background 120ms ease, color 120ms ease;
}
.header .icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.header .icon-btn:active { background: var(--bg-active); }
.header .icon-btn.muted { color: var(--text-tertiary); }
.header .left, .header .right { display: flex; align-items: center; gap: 2px; }

/* Page */
.page { padding-bottom: 80px; }
.page-title-large {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  padding: 24px 16px 12px;
  color: var(--text);
}

/* Lists */
.list { background: var(--bg); margin: 8px 0; }
.list-grouped { background: var(--bg); }
.list-grouped .section { margin-top: 24px; }
.list-grouped .section:first-child { margin-top: 8px; }
.section-header {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  padding: 0 16px 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.section-footer {
  font-size: 12px;
  color: var(--text-secondary);
  padding: 8px 16px 0;
  line-height: 1.4;
}
.section-body {
  background: var(--bg);
  margin: 0 16px;
  overflow: hidden;
}
.section-header.collapsible { display: flex; align-items: center; cursor: pointer; user-select: none; }
.section-header .chevron-toggle { margin-left: auto; color: var(--text-tertiary); display: inline-flex; align-items: center; }
.section-header .chevron-toggle .icon { width: 14px; height: 14px; vertical-align: 0; }
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg);
  min-height: 36px;
  position: relative;
  transition: background 80ms ease;
  border-radius: var(--radius);
}
.row.tappable { cursor: pointer; }
.row.tappable:hover { background: var(--bg-hover); }
.row.tappable:active { background: var(--bg-active); }
.row .grow { flex: 1; min-width: 0; }
.row-title { font-size: 14px; font-weight: 500; color: var(--text); }
.row-subtitle { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.row-meta { display: flex; gap: 12px; font-size: 12px; color: var(--text-secondary); margin-top: 4px; align-items: center; }
.row-meta .icon { vertical-align: -2px; }
.row .accessory { color: var(--text-tertiary); }
.row .accessory .icon { width: 14px; height: 14px; }
.row-actions { display: inline-flex; gap: 4px; margin-left: auto; }

/* Buttons */
.btn {
  padding: 6px 12px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #FFF;
  font-weight: 500;
  font-size: 13px;
  border: 0;
  transition: background 120ms ease;
}
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--separator-strong);
}
.btn.secondary:hover { background: var(--bg-hover); }
.btn.text {
  color: var(--text);
  background: transparent;
  padding: 6px 8px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius);
  transition: background 120ms ease, color 120ms ease;
}
.btn.text:hover { background: var(--bg-hover); }
.btn.text.danger, .btn.danger { color: var(--danger); }
.btn.text.danger:hover { background: var(--danger-soft); }
.btn-block { display: block; width: calc(100% - 32px); margin: 12px 16px; text-align: center; }
.btn-bare {
  color: var(--text);
  padding: 8px 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius);
  transition: background 120ms ease, color 120ms ease;
  width: 100%;
  text-align: left;
}
.btn-bare:hover { background: var(--bg-hover); }
.btn-bare.danger-text { color: var(--danger); }
.btn-bare.danger-text:hover { background: var(--danger-soft); }
.btn-bare:disabled { color: var(--text-tertiary); cursor: not-allowed; }
.btn-bare:disabled:hover { background: transparent; }

/* Pills */
.pill-row {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  background: var(--bg);
  overflow-x: auto;
  scrollbar-width: none;
}
.filter-bar {
  display: flex;
  align-items: stretch;
  background: var(--bg);
  border-bottom: 1px solid var(--separator);
}
.filter-bar .pill-row { flex: 1; min-width: 0; }
.inline-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-left: 1px solid var(--separator);
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}
.pill-row::-webkit-scrollbar { display: none; }
.pill {
  padding: 4px 10px;
  border-radius: var(--radius);
  background: var(--bg-hover);
  border: 0;
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  flex: 0 0 auto;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  transition: background 120ms ease, color 120ms ease;
}
.pill:hover { background: var(--bg-active); }
.pill .icon { width: 14px; height: 14px; vertical-align: 0; }
.pill.active { background: var(--accent-soft); color: var(--accent); }
.pill.ghost { background: transparent; color: var(--text-secondary); }
.pill.ghost:hover { background: var(--bg-hover); color: var(--text); }
.pill.ghost.active { background: var(--bg-hover); color: var(--text); }

/* Forms */
.form { padding: 0; }
.form-section { margin-top: 24px; }
.form-section:first-child { margin-top: 8px; }
.form-section .section-header { padding-bottom: 4px; }
.field {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--separator);
  min-height: 40px;
  font-size: 14px;
}
.field:last-child { border-bottom: 0; }
.field label { color: var(--text-secondary); flex: 0 0 100px; font-weight: 400; }
.field .input {
  flex: 1;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  outline: none;
  text-align: right;
  color: var(--text);
  font-size: 14px;
  padding: 4px 8px;
  transition: background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}
.field .input.left { text-align: left; }
.field .input:hover { background: var(--bg-hover); }
.field .input:focus {
  background: var(--bg);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
  text-align: left;
}
.field .input::placeholder { color: var(--text-tertiary); }
.field-stack { display: block; padding: 10px 12px; background: var(--bg); border-bottom: 1px solid var(--separator); }
.field-stack label {
  display: block;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  padding-bottom: 4px;
}
.field-stack .input, .field-stack textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid transparent;
  border-radius: var(--radius);
  outline: none;
  color: var(--text);
  font-size: 14px;
  resize: vertical;
  min-height: 32px;
  padding: 6px 10px;
  font-family: inherit;
  transition: background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}
.field-stack .input:focus, .field-stack textarea:focus {
  background: var(--bg);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.field-stack textarea { min-height: 80px; line-height: 1.45; }

/* Two stacked fields side by side when wide, stacked when narrow (no media query). */
.field-pair { display: flex; flex-wrap: wrap; align-items: flex-start; }
.field-pair > * { flex: 1 1 200px; min-width: 0; }

/* Subcategory chips (item editor) */
.chip-field { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 4px 3px 8px; font-size: 13px;
  background: var(--bg-input); border: 1px solid var(--separator-strong);
}
.chip-name { outline: none; cursor: text; min-width: 1ch; }
.chip-name:focus { box-shadow: inset 0 -1px 0 var(--accent); }
.chip-x { font-size: 11px; line-height: 1; color: var(--text-tertiary); padding: 2px 4px; }
.chip-x:hover { color: var(--text); }
.chip-input {
  flex: 1; min-width: 110px;
  background: var(--bg-input); border: 1px solid transparent; border-radius: var(--radius);
  outline: none; color: var(--text); font-size: 14px; padding: 6px 10px;
}
.chip-input:focus { background: var(--bg); border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.chip-input::placeholder { color: var(--text-tertiary); }

/* Item editor: one row per category — selector + its subcategories on one line. */
.cat-edit-row { padding: 10px 0; border-top: 1px solid var(--separator); }
.cat-edit-row:first-child { border-top: none; padding-top: 0; }
.cat-edit-line { display: flex; align-items: center; gap: 8px; }
.cat-edit-line .chip-field { flex: 1; min-width: 0; }
.cat-edit-select {
  flex: 0 0 auto; max-width: 45%;
  background: var(--bg-input); border: 1px solid var(--separator-strong);
  color: var(--text); font-size: 14px; font-weight: 600; font-family: inherit;
  padding: 6px 8px; cursor: pointer;
}

/* Item editor top row: photo + legacy on one line. */
.edit-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 10px 12px; }
.edit-top-photo { display: flex; align-items: center; gap: 8px; }
.edit-top-legacy { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text-secondary); cursor: pointer; }
.photo-box {
  width: 56px; height: 56px; flex: 0 0 56px;
  border: 1px solid var(--separator-strong);
  object-fit: cover; background: var(--bg-input);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-tertiary); cursor: pointer;
}

.toggle {
  position: relative;
  width: 28px;
  height: 16px;
  background: var(--separator-strong);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  flex: 0 0 28px;
  transition: background 120ms ease;
}
.toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  background: #FFF;
  border-radius: 50%;
  transition: transform 120ms ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.toggle.on { background: var(--accent); }
.toggle.on::after { transform: translateX(12px); }

.stepper {
  display: inline-flex;
  align-items: center;
  background: var(--bg-hover);
  border-radius: var(--radius);
  overflow: hidden;
}
.stepper button {
  padding: 4px 10px;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  min-width: 28px;
  transition: background 120ms ease;
}
.stepper button:hover { background: var(--bg-active); }
.stepper button:disabled { color: var(--text-tertiary); }
.stepper .qty {
  padding: 0 8px;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: var(--text);
  min-width: 24px;
  text-align: center;
  font-size: 13px;
}
.stepper .sep { width: 1px; height: 16px; background: var(--separator); }

select.picker {
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 14px;
  text-align: right;
  font-family: inherit;
  cursor: pointer;
  padding: 4px 0;
}

/* Tags / badges */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: var(--radius);
  background: var(--bg-hover);
  color: var(--text-secondary);
  vertical-align: middle;
  margin-left: 6px;
}
.badge.tint { background: var(--accent-soft); color: var(--accent); }
.badge.warning { background: rgba(217, 115, 13, 0.15); color: var(--warning); }

.icon-warn { color: var(--warning); display: inline-flex; align-items: center; }
.icon-lock { color: var(--text-tertiary); margin-right: 4px; display: inline-flex; align-items: center; }

/* Empty state */
.empty {
  text-align: center;
  padding: 56px 24px;
  color: var(--text-secondary);
}
.empty h2 {
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 6px;
}
.empty p { font-size: 13px; margin: 4px 0 16px; line-height: 1.4; }
.empty-icon { margin: 0 auto 16px; display: block; opacity: 0.4; color: var(--text-tertiary); }
.empty-icon .icon { display: block; margin: 0 auto; }
.empty > .icon, .empty > .icon-xl { display: block; margin: 0 auto 16px; opacity: 0.4; color: var(--text-tertiary); }

/* FAB */
.fab {
  position: fixed;
  right: 16px;
  bottom: calc(16px + var(--safe-bottom));
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--accent);
  color: #FFF;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(35, 131, 226, 0.35), 0 2px 4px rgba(35, 131, 226, 0.2);
  z-index: 20;
  border: 0;
  transition: background 120ms ease, transform 120ms ease;
}
.fab:hover { background: var(--accent-hover); }
.fab:active { transform: scale(0.96); }
.fab .icon { width: 22px; height: 22px; vertical-align: 0; }

/* Centered blue add pill (library) */
.add-pill {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(16px + var(--safe-bottom));
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 18px; border-radius: 999px;
  background: var(--accent); color: #FFF; font-size: 14px; font-weight: 500;
  box-shadow: 0 4px 12px rgba(35, 131, 226, 0.35), 0 2px 4px rgba(35, 131, 226, 0.2);
  z-index: 20; border: 0;
  transition: background 120ms ease, transform 120ms ease;
}
.add-pill:hover { background: var(--accent-hover); }
.add-pill:active { transform: translateX(-50%) scale(0.96); }
.add-pill .icon { width: 18px; height: 18px; vertical-align: 0; }

/* Search bar */
.search-bar {
  display: flex; gap: 8px; align-items: center;
  padding: 8px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--separator);
}
.search-input-wrap {
  flex: 1;
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-input);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 6px 10px;
  transition: background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}
.search-input-wrap:focus-within {
  background: var(--bg);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.search-input-wrap input {
  flex: 1; background: transparent; border: 0; outline: none; color: var(--text); font-size: 14px;
}
.search-input-wrap input::placeholder { color: var(--text-tertiary); }
.search-input-wrap .magnify {
  color: var(--text-tertiary);
  display: inline-flex;
  align-items: center;
}

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 15, 15, 0.4);
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--bg-elev);
  border-radius: var(--radius-md);
  width: min(400px, 100%);
  padding: 20px;
  box-shadow: rgba(15, 15, 15, 0.1) 0 0 0 1px, rgba(15, 15, 15, 0.2) 0 5px 10px, rgba(15, 15, 15, 0.4) 0 15px 40px;
}
.modal-title {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 6px;
  text-align: left;
  color: var(--text);
}
.modal-body { margin: 12px 0; font-size: 14px; color: var(--text-secondary); text-align: left; line-height: 1.4; }
.modal-body input, .modal-body textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 14px;
  color: var(--text);
  outline: none;
  margin-top: 8px;
  font-family: inherit;
  transition: background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}
.modal-body input:focus, .modal-body textarea:focus {
  background: var(--bg);
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.modal-actions {
  display: flex; gap: 8px; margin-top: 16px; justify-content: flex-end;
}

/* Sheet */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 15, 15, 0.4);
  z-index: 100;
  display: flex; align-items: flex-end;
}
.sheet {
  background: var(--bg);
  width: 100%;
  height: 92vh;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  display: flex; flex-direction: column;
  padding-bottom: var(--safe-bottom);
  animation: slide-up 0.2s ease-out;
  box-shadow: rgba(15, 15, 15, 0.1) 0 0 0 1px;
}
@keyframes slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.sheet > .header { position: relative; top: 0; border-radius: var(--radius-md) var(--radius-md) 0 0; }
.sheet-body { flex: 1; overflow-y: auto; background: var(--bg); }
.sheet-body.list-grouped { background: var(--bg); }

.full-screen {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 50;
  display: flex; flex-direction: column;
  padding-top: var(--safe-top);
}
.full-screen > .header { position: sticky; top: 0; }
.full-screen-body { flex: 1; overflow-y: auto; }
@media (min-width: 820px) {
  .full-screen {
    left: calc(50% - 400px);
    right: calc(50% - 400px);
    box-shadow: 0 0 0 1px var(--separator);
  }
}

/* Toast */
.toast {
  position: fixed;
  top: calc(20px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 200;
  pointer-events: none;
  box-shadow: rgba(15, 15, 15, 0.2) 0 4px 12px;
}

/* Kit row */
.kit-row { display: flex; flex-direction: column; gap: 4px; width: 100%; }
.kit-row .title-line { display: flex; align-items: center; gap: 6px; font-weight: 500; font-size: 14px; }
.kit-row .star { color: var(--yellow); display: inline-flex; align-items: center; }
.kit-row .star .icon { width: 14px; height: 14px; vertical-align: 0; }
.kit-row .meta-line { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-secondary); }
.kit-row.archived .title-line { color: var(--text-secondary); }

/* Pack rows */
.pack-cat-header {
  display: flex; align-items: center;
  padding: 16px 16px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  background: var(--bg);
  cursor: pointer;
  user-select: none;
  position: sticky;
  top: 0;
  z-index: 5;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.pack-cat-header .chevron-toggle {
  margin-left: auto;
  color: var(--text-tertiary);
  display: inline-flex;
  align-items: center;
}
.pack-cat-header .chevron-toggle .icon { width: 14px; height: 14px; vertical-align: 0; }
/* Collapsed group header reads like a primary row: item-size, near the left edge. */
.brand-header {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 6px;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: background 120ms ease;
  border-radius: var(--radius);
  margin: 0;
}
/* Expanded: the header recedes — smaller and more inset, just above its items. */
.brand-header:not(.collapsed) {
  color: var(--text-secondary);

}
.brand-header:hover { background: var(--bg-hover); }
.brand-header .chev {
  transition: transform 150ms ease;
  display: inline-flex;
  align-items: center;
  color: var(--text-tertiary);
}
.brand-header .chev .icon { width: 14px; height: 14px; vertical-align: 0; }
.brand-header:not(.collapsed) .chev { transform: rotate(90deg); }

.pack-row { padding-left: 16px; }
.pack-row.indented { padding-left: 36px; }
.pack-row.indented-2 { padding-left: 56px; }

/* Subcategory headers — a brand-header variant, one indent deeper (and deeper
   again when nested inside a brand group). */
.subcat-header {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 12px;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: background 120ms ease;
  margin: 0;
}
.subcat-header.nested { padding-left: 24px; }
/* Expanded: smaller and more inset, just above its items. */
.subcat-header:not(.collapsed) {
  color: var(--text-secondary);
}
.subcat-header.nested:not(.collapsed) { padding-left: 44px; }
.subcat-header:hover { background: var(--bg-hover); }
.subcat-header .chev {
  transition: transform 150ms ease;
  display: inline-flex; align-items: center;
  color: var(--text-tertiary);
}
.subcat-header .chev .icon { width: 14px; height: 14px; vertical-align: 0; }
.subcat-header:not(.collapsed) .chev { transform: rotate(90deg); }

/* Kit detail */
.cat-sub-row {
  padding: 16px 16px 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  background: var(--bg);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.kit-group-header {
  padding: 20px 16px 8px;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex; align-items: center;
}
.kit-group-header .name {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.kit-group-header .name.subtle { font-weight: 400; color: var(--text-secondary); }
.kit-group-header .right { margin-left: auto; display: flex; gap: 4px; }
.kit-group-divider { height: 1px; background: var(--separator); margin: 16px 0; }

/* Quantity column */
.qty-col {
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--text-secondary);
  font-size: 13px;
}
.qty-col.muted { opacity: 0; }

/* Notes inline */
.note {
  font-size: 12px;
  color: var(--text-secondary);
}
.note-locked {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 4px;
}
.note-locked .icon { width: 12px; height: 12px; vertical-align: 0; }
.kit-only-tag {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: var(--radius);
  background: var(--bg-hover);
  color: var(--text-secondary);
  margin-left: 6px;
}

/* Overflow menu */
.row-menu-btn {
  color: var(--text-tertiary);
  padding: 4px 6px;
  background: transparent;
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius);
  transition: background 120ms ease, color 120ms ease;
}
.row-menu-btn:hover { background: var(--bg-hover); color: var(--text); }
.context-menu-backdrop {
  position: fixed; inset: 0;
  background: transparent;
  z-index: 150;
}
.context-menu {
  position: fixed;
  background: var(--bg-elev);
  border-radius: var(--radius-md);
  box-shadow: rgba(15, 15, 15, 0.1) 0 0 0 1px, rgba(15, 15, 15, 0.1) 0 3px 6px, rgba(15, 15, 15, 0.2) 0 9px 24px;
  min-width: 220px;
  padding: 6px;
  z-index: 151;
  overflow: hidden;
}
.context-menu .item {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
  border-radius: var(--radius);
  transition: background 120ms ease;
}
.context-menu .item:hover { background: var(--bg-hover); }
.context-menu .item:active { background: var(--bg-active); }
.context-menu .item.danger { color: var(--danger); }
.context-menu .item.danger:hover { background: var(--danger-soft); }
.context-menu .item.disabled { color: var(--text-tertiary); pointer-events: none; }
.context-menu .sep { height: 1px; background: var(--separator); margin: 4px 0; }

/* Export preview */
.export-preview {
  background: var(--bg-input);
  padding: 16px;
  margin: 0 0;
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
  flex: 1;
  overflow-y: auto;
  color: var(--text);
}
.export-preview.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; }
.print-frame {
  flex: 1;
  width: 100%;
  height: 100%;
  min-height: 70vh;
  border: none;
  background: #fff;
}

/* Segmented */
.segmented {
  display: flex;
  background: var(--bg-hover);
  border-radius: var(--radius);
  padding: 2px;
  margin: 12px 16px;
}
.segmented button {
  flex: 1;
  padding: 6px 8px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  border-radius: calc(var(--radius) - 1px);
  transition: background 120ms ease, color 120ms ease;
}
.segmented button:hover { color: var(--text); }
.segmented button.active {
  background: var(--bg);
  color: var(--text);
  box-shadow: rgba(15, 15, 15, 0.04) 0 1px 2px, rgba(15, 15, 15, 0.06) 0 1px 1px;
}

.check {
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  min-width: 16px;
}

/* Drag-and-drop reorder handle */
.drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 4px;
  color: var(--text-tertiary);
  cursor: grab;
  touch-action: none;
  user-select: none;
  border-radius: var(--radius);
  transition: background 120ms ease, color 120ms ease;
}
.drag-handle:hover { background: var(--bg-hover); color: var(--text-secondary); }
.drag-handle:active { cursor: grabbing; }
.row.dragging {
  opacity: 0.4;
  background: var(--bg-hover);
}
/* Reorder view: a subcategory group is a container (header + its item rows);
   loose items sit beside groups in one freely-mixed order. */
.reorder-group { border: 1px solid var(--separator); margin: 4px 0; }
.reorder-group.dragging { opacity: 0.4; }
.reorder-group-head {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--separator);
  background: var(--bg-input);
  cursor: pointer;
  user-select: none;
}
.reorder-group.collapsed > .reorder-group-head { border-bottom: none; }
.reorder-group.collapsed > .row { display: none; }   /* kept in DOM to preserve order */
.reorder-group-name { font-size: 14px; font-weight: 600; color: var(--text); }
.reorder-group-count { margin-left: auto; font-size: 12px; color: var(--text-tertiary); }
.reorder-group-head .chevron-toggle { display: inline-flex; color: var(--text-tertiary); }

/* Misc */
.danger-text { color: var(--danger); }
.muted { color: var(--text-secondary); }
.center { text-align: center; }
.spacer { flex: 1; }
.hidden { display: none !important; }

/* ---------- Collaboration: shared-kit indicator ---------- */
.shared-line {
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
  margin-top: 2px;
}
.kit-role-banner {
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
  padding: 4px 16px 8px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 4px;
}
.kit-role-banner .icon { width: 12px; height: 12px; }
.kit-row .share-mark {
  color: var(--text-secondary);
  display: inline-flex; align-items: center;
  margin-right: 4px;
}
.kit-row .share-mark .icon { width: 14px; height: 14px; vertical-align: 0; }
input[readonly], textarea[readonly] {
  background: var(--bg-hover);
  color: var(--text-secondary);
  cursor: default;
}

/* ---------- Sync status icon (always in header.right) ---------- */
.sync-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  padding: 4px;
  margin-left: 4px;
  cursor: pointer;
  border-radius: 999px;
  color: var(--text);
}
.sync-status .icon { width: 20px; height: 20px; transition: color 160ms ease; }
.sync-status.is-out     .icon { color: #c0392b; }
.sync-status.is-offline .icon { color: #d28a00; }
.sync-status.is-online  .icon { color: #22a36b; }
.sync-status.is-syncing .icon { color: #22a36b; animation: sync-pulse 1s ease-in-out infinite; }
.sync-status.flash-ok   { animation: sync-flash-ok .6s ease-out; }
.sync-status.flash-err  { animation: sync-flash-err .6s ease-out; }

@keyframes sync-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .5; transform: scale(.88); }
}
@keyframes sync-flash-ok {
  0%   { box-shadow: 0 0 0 0 rgba(34, 163, 107, .55); }
  100% { box-shadow: 0 0 0 14px rgba(34, 163, 107, 0); }
}
@keyframes sync-flash-err {
  0%   { box-shadow: 0 0 0 0 rgba(192, 57, 43, .55); }
  100% { box-shadow: 0 0 0 14px rgba(192, 57, 43, 0); }
}

/* ---------- Auth / login overlay ---------- */
.auth-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .35);
  display: flex; align-items: center; justify-content: center;
  z-index: 185;
}
/* Opaque, non-dismissible login gate that fully covers the app. */
.auth-overlay.login-gate { background: var(--bg); z-index: 200; }
.auth-card {
  background: var(--bg);
  border: 1px solid var(--border);
  width: min(360px, calc(100vw - 32px));
  padding: 20px;
  display: flex; flex-direction: column; gap: 12px;
}
.auth-title {
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-secondary);
}
.auth-email { font-size: 15px; font-weight: 500; }
.auth-meta  { font-size: 12px; color: var(--text-secondary); }
.auth-error { font-size: 12px; color: var(--danger); min-height: 14px; }
.auth-row {
  display: flex; justify-content: flex-end; gap: 8px; align-items: center;
  flex-wrap: wrap; margin-top: 4px;
}
.auth-row .danger { color: var(--danger); margin-right: auto; }
.auth-card .input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  font: inherit;
}

/* ---- Library-item photos ---- */
.row-thumb {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  object-fit: cover;
  border: 1px solid var(--separator-strong);
  /* margin-right: 12px; */
  cursor: zoom-in;
  background: var(--bg-input);
}

.photo-row { align-items: flex-start; gap: 16px; }
.edit-photo {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border: 1px solid var(--separator-strong);
  cursor: zoom-in;
  background: var(--bg-input);
}
.photo-actions { display: flex; flex-direction: column; gap: 4px; }

/* ---- Full-size image lightbox ---- */
.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(24px + var(--safe-top));
  padding-bottom: calc(24px + var(--safe-bottom));
}
.lightbox-content {
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  cursor: zoom-out;
}
.lightbox-spinner,
.lightbox-msg { color: rgba(255, 255, 255, 0.7); font-size: 14px; }
.lightbox-close {
  position: absolute;
  top: calc(8px + var(--safe-top));
  right: 12px;
  width: 40px;
  height: 40px;
  font-size: 22px;
  line-height: 1;
  color: #fff;
}

