/* ============================================================
     shadcn design tokens (neutral palette) — light is the default
     (:root), dark is applied via the .dark class on <html>.
     The theme toggle (light/dark/system) sets that class and
     persists the choice to localStorage.
     ============================================================ */
  :root {
    --background:        hsl(0 0% 100%);
    --foreground:        hsl(240 10% 3.9%);
    --card:              hsl(0 0% 100%);
    --card-foreground:   hsl(240 10% 3.9%);
    --popover:           hsl(0 0% 100%);
    --popover-foreground:hsl(240 10% 3.9%);
    --primary:           hsl(240 5.9% 10%);
    --primary-foreground:hsl(0 0% 98%);
    --secondary:         hsl(240 4.8% 95.9%);
    --secondary-foreground: hsl(240 5.9% 10%);
    --muted:             hsl(240 4.8% 95.9%);
    --muted-foreground:  hsl(240 3.8% 46.1%);
    --accent:            hsl(240 4.8% 95.9%);
    --accent-foreground: hsl(240 5.9% 10%);
    --destructive:       hsl(0 84.2% 60.2%);
    --destructive-foreground: hsl(0 0% 98%);
    --border:            hsl(240 5.9% 90%);
    --input:             hsl(240 5.9% 90%);
    --ring:              hsl(240 10% 3.9%);

    /* Semantic accents */
    --success:           hsl(142 71% 38%);
    --warning:           hsl(38 92% 45%);
    --info:              hsl(217 91% 55%);
    --price:             hsl(38 92% 42%);
    /* Brand accent used for kits/links/active states (cyan) */
    --brand:             hsl(189 94% 38%);
    --brand-strong:      hsl(189 94% 32%);

    --radius:            0.5rem;
  }

  .dark {
    --background:        hsl(240 10% 3.9%);
    --foreground:        hsl(0 0% 98%);
    --card:              hsl(240 10% 3.9%);
    --card-foreground:   hsl(0 0% 98%);
    --popover:           hsl(240 10% 3.9%);
    --popover-foreground:hsl(0 0% 98%);
    --primary:           hsl(0 0% 98%);
    --primary-foreground:hsl(240 5.9% 10%);
    --secondary:         hsl(240 3.7% 15.9%);
    --secondary-foreground: hsl(0 0% 98%);
    --muted:             hsl(240 3.7% 15.9%);
    --muted-foreground:  hsl(240 5% 64.9%);
    --accent:            hsl(240 3.7% 15.9%);
    --accent-foreground: hsl(0 0% 98%);
    --destructive:       hsl(0 62.8% 30.6%);
    --destructive-foreground: hsl(0 0% 98%);
    --border:            hsl(240 3.7% 15.9%);
    --input:             hsl(240 3.7% 15.9%);
    --ring:              hsl(240 4.9% 83.9%);

    --success:           hsl(142 70% 45%);
    --warning:           hsl(38 92% 50%);
    --info:              hsl(217 91% 60%);
    --price:             hsl(38 92% 50%);
    --brand:             hsl(189 94% 55%);
    --brand-strong:      hsl(189 94% 65%);
  }

  * { box-sizing: border-box; margin: 0; padding: 0; }

  html { font-size: 14px; }

  body {
    background: var(--background);
    color: var(--foreground);
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-feature-settings: "rlig" 1, "calt" 1;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    line-height: 1.5;
  }

  code, .mono {
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  }

  .container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem 1.5rem 4rem;
  }

  /* ============================================================
     Header
     ============================================================ */
  .header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.5rem;
    padding-bottom: 1.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
  }

  .header-title h1 {
    font-size: 1.875rem;
    line-height: 2.25rem;
    font-weight: 600;
    letter-spacing: -0.025em;
  }

  .header-title .subtitle {
    color: var(--muted-foreground);
    font-size: 0.875rem;
    margin-top: 0.25rem;
  }

  .header-title .subtitle code {
    color: var(--foreground);
    background: var(--muted);
    padding: 0.125rem 0.375rem;
    border-radius: calc(var(--radius) - 2px);
    font-size: 0.75rem;
  }

  .header-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.75rem;
  }

  /* Theme toggle — shadcn-style icon button + dropdown menu */
  .theme-menu { position: relative; }
  .theme-trigger {
    display: inline-flex; align-items: center; justify-content: center;
    width: 2.25rem; height: 2.25rem;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
    color: var(--foreground);
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.15s, border-color 0.15s;
  }
  .theme-trigger:hover { background: var(--accent); }
  .theme-trigger:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--ring); }
  .theme-trigger .icon, .theme-trigger-icon .icon { width: 1.05rem; height: 1.05rem; color: var(--foreground); }
  .theme-dropdown {
    position: absolute; right: 0; top: calc(100% + 0.375rem); z-index: 50;
    min-width: 9rem;
    background: var(--popover);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.25rem;
    box-shadow: 0 10px 30px rgb(0 0 0 / 0.18), 0 2px 6px rgb(0 0 0 / 0.12);
    display: none;
  }
  .theme-menu.open .theme-dropdown { display: block; }
  .theme-item {
    display: flex; align-items: center; gap: 0.5rem; width: 100%;
    background: transparent; border: none; color: var(--foreground);
    font-family: inherit; font-size: 0.8125rem; text-align: left;
    padding: 0.4rem 0.55rem; border-radius: calc(var(--radius) - 3px);
    cursor: pointer;
  }
  .theme-item:hover { background: var(--accent); }
  .theme-item > .icon:first-child { width: 0.95rem; height: 0.95rem; color: var(--muted-foreground); flex-shrink: 0; }
  .theme-item .ti-check { margin-left: auto; width: 0.9rem; height: 0.9rem; opacity: 0; color: var(--brand); }
  .theme-item.active .ti-check { opacity: 1; }
  .theme-item.active { color: var(--foreground); font-weight: 500; }
  .theme-item.active > .icon:first-child { color: var(--foreground); }

  /* Stat cards (compact, no decoration) */
  .stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
    gap: 0.75rem;
    width: 100%;
    max-width: 56rem;
  }

  .stat {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.875rem 1rem;
  }

  .stat-label {
    font-size: 0.75rem;
    color: var(--muted-foreground);
    font-weight: 500;
    margin-bottom: 0.25rem;
  }

  .stat-value {
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
  }

  /* ============================================================
     Tabs (shadcn-style: bg pill with active state)
     ============================================================ */
  .tabs {
    display: inline-flex;
    align-items: center;
    background: var(--muted);
    color: var(--muted-foreground);
    padding: 0.25rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    gap: 0.125rem;
  }

  .tab {
    background: transparent;
    border: none;
    color: inherit;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.375rem 0.875rem;
    border-radius: calc(var(--radius) - 2px);
    cursor: pointer;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
  }

  .tab:hover { color: var(--foreground); }
  .tab.active {
    background: var(--background);
    color: var(--foreground);
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  }

  .tab .count {
    font-size: 0.6875rem;
    font-variant-numeric: tabular-nums;
    background: var(--muted);
    padding: 0.0625rem 0.375rem;
    border-radius: 9999px;
    font-weight: 600;
  }
  .tab.active .count { background: var(--muted); color: var(--muted-foreground); }

  .tab-panel { display: none; }
  .tab-panel.active { display: block; }

  /* ============================================================
     Controls bar (search + dropdowns + view toggle)
     ============================================================ */
  .controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
  }

  .input,
  .select {
    background: transparent;
    border: 1px solid var(--input);
    color: var(--foreground);
    font-family: inherit;
    font-size: 0.875rem;
    height: 2.25rem;
    padding: 0 0.75rem;
    border-radius: calc(var(--radius) - 2px);
    transition: border-color 0.15s, box-shadow 0.15s;
  }

  .input::placeholder { color: var(--muted-foreground); }

  .input:focus,
  .select:focus {
    outline: none;
    border-color: var(--ring);
    box-shadow: 0 0 0 1px var(--ring);
  }

  .search {
    flex: 1;
    min-width: 16rem;
    position: relative;
  }

  .search .input {
    width: 100%;
    padding-left: 2.25rem;
    padding-right: 3.5rem;
  }

  .search-icon {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted-foreground);
    pointer-events: none;
  }

  .search-kbd {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    display: inline-flex;
    align-items: center;
    gap: 2px;
  }

  .kbd {
    background: var(--muted);
    color: var(--muted-foreground);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.6875rem;
    font-weight: 500;
    padding: 0.0625rem 0.375rem;
    border-radius: calc(var(--radius) - 4px);
    border: 1px solid var(--border);
    line-height: 1;
  }

  .select {
    appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    padding-right: 2rem;
    cursor: pointer;
  }

  /* Segmented view toggle (shadcn ToggleGroup) */
  .view-toggle {
    display: inline-flex;
    border: 1px solid var(--input);
    border-radius: calc(var(--radius) - 2px);
    overflow: hidden;
    height: 2.25rem;
  }

  .view-btn {
    background: transparent;
    border: none;
    color: var(--muted-foreground);
    width: 2.25rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    font-family: inherit;
  }
  .view-btn:hover { background: var(--accent); color: var(--accent-foreground); }
  .view-btn.active {
    background: var(--accent);
    color: var(--accent-foreground);
  }
  .view-btn + .view-btn { border-left: 1px solid var(--input); }

  /* Collapsible tag filter row */
  details.tag-filters {
    width: 100%;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 1.25rem;
  }
  details.tag-filters summary {
    cursor: pointer;
    padding: 0.625rem 0.875rem;
    font-size: 0.8125rem;
    color: var(--muted-foreground);
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }
  details.tag-filters summary::-webkit-details-marker { display: none; }
  details.tag-filters summary::before {
    content: "›";
    color: var(--muted-foreground);
    transition: transform 0.15s;
    display: inline-block;
    font-size: 1rem;
    line-height: 1;
  }
  details.tag-filters[open] summary::before { transform: rotate(90deg); }
  details.tag-filters summary strong { color: var(--foreground); font-weight: 500; }
  details.tag-filters .tag-list {
    padding: 0 0.875rem 0.875rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
  }

  /* ============================================================
     Badges (shadcn Badge component variants)
     ============================================================ */
  .badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.6875rem;
    font-weight: 500;
    line-height: 1.2;
    border: 1px solid transparent;
    white-space: nowrap;
  }

  .badge-default     { background: var(--primary); color: var(--primary-foreground); }
  .badge-secondary   { background: var(--secondary); color: var(--secondary-foreground); }
  .badge-outline     { border-color: var(--border); color: var(--foreground); }
  .badge-muted       { background: var(--muted); color: var(--muted-foreground); }
  .badge-success     { background: hsl(142 70% 45% / 0.15); color: var(--success); border-color: hsl(142 70% 45% / 0.3); }
  .badge-warning     { background: hsl(38 92% 50% / 0.15); color: var(--warning); border-color: hsl(38 92% 50% / 0.3); }
  .badge-destructive { background: hsl(0 62.8% 50% / 0.15); color: hsl(0 84% 70%); border-color: hsl(0 62.8% 50% / 0.3); }
  .badge-info        { background: hsl(217 91% 60% / 0.15); color: var(--info); border-color: hsl(217 91% 60% / 0.3); }

  .badge-toggle {
    cursor: pointer;
    background: transparent;
    color: var(--muted-foreground);
    border: 1px solid var(--border);
    font-family: inherit;
    transition: all 0.15s;
  }
  .badge-toggle:hover { background: var(--accent); color: var(--accent-foreground); }
  .badge-toggle.active {
    background: var(--primary);
    color: var(--primary-foreground);
    border-color: var(--primary);
  }
  .badge-toggle .count {
    font-variant-numeric: tabular-nums;
    opacity: 0.7;
    font-size: 0.625rem;
  }

  /* ============================================================
     Parts — grid view (Card)
     ============================================================ */
  .grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
    gap: 0.875rem;
  }

  .card {
    display: flex;
    flex-direction: column;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s, transform 0.15s;
    position: relative;
  }
  .card:hover {
    border-color: var(--ring);
    transform: translateY(-1px);
  }
  .card.out-of-stock { opacity: 0.6; }
  .card.out-of-stock:hover { opacity: 0.85; }

  .card-img-wrap {
    background: hsl(0 0% 98%);
    aspect-ratio: 1;
    overflow: hidden;
    position: relative;
  }

  .card-img-wrap img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 0.5rem;
    transition: transform 0.3s ease-out;
  }
  .card:hover .card-img-wrap img { transform: scale(1.04); }

  .stock-badge {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    backdrop-filter: blur(8px);
    background: hsl(240 10% 3.9% / 0.85);
    color: var(--success);
    border: 1px solid hsl(142 70% 45% / 0.3);
    font-size: 0.6875rem;
    font-weight: 600;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-variant-numeric: tabular-nums;
  }
  .stock-badge.low { color: var(--warning); border-color: hsl(38 92% 50% / 0.3); }
  .stock-badge.zero { color: hsl(0 84% 70%); border-color: hsl(0 62.8% 50% / 0.3); }
  .stock-badge .total { color: var(--muted-foreground); font-weight: 500; }

  /* Broken indicator — shown when a part has dead/burnt units. */
  .broken-badge {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    backdrop-filter: blur(8px);
    background: hsl(0 62.8% 30.6% / 0.9);
    color: hsl(0 0% 98%);
    border: 1px solid hsl(0 84% 60% / 0.5);
    font-size: 0.625rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    padding: 0.125rem 0.45rem;
    border-radius: 9999px;
    text-transform: uppercase;
  }
  .card.broken { border-color: hsl(0 62.8% 40% / 0.5); }
  .part-row-broken {
    color: hsl(0 84% 70%);
    font-size: 0.625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    margin-left: 0.4rem;
    border: 1px solid hsl(0 84% 60% / 0.4);
    border-radius: 9999px;
    padding: 0.05rem 0.4rem;
    white-space: nowrap;
  }

  .used-badge {
    position: absolute;
    bottom: 0.5rem;
    left: 0.5rem;
    backdrop-filter: blur(8px);
    background: hsl(240 10% 3.9% / 0.85);
    color: var(--info);
    border: 1px solid hsl(217 91% 60% / 0.3);
    font-size: 0.625rem;
    font-weight: 600;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.025em;
  }

  /* Kit / pack (container) styling — cyan accent, matches the CLI's ▸ marker. */
  .kit-badge {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    backdrop-filter: blur(8px);
    background: hsl(240 10% 3.9% / 0.85);
    color: var(--brand);
    border: 1px solid color-mix(in srgb, var(--brand) 35%, transparent);
    font-size: 0.625rem;
    font-weight: 700;
    padding: 0.125rem 0.45rem;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
  }
  .card.is-container { border-color: color-mix(in srgb, var(--brand) 30%, transparent); }
  .card.is-container:hover { border-color: color-mix(in srgb, var(--brand) 55%, transparent); }
  .part-row.is-container { border-left: 2px solid color-mix(in srgb, var(--brand) 50%, transparent); }
  .part-row.is-container .part-row-name { color: var(--brand); }
  /* Child value-rows — subtle inset so they read as "inside" a kit. */
  .card.is-child { border-style: dashed; border-color: var(--border); }
  .part-row.is-child { border-left: 2px solid var(--border); }
  .card-parent {
    font-size: 0.6875rem;
    color: var(--brand);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  /* Vendor SKU — the code printed on the physical packet (shelf-lookup key). */
  .card-sku {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.6875rem;
    color: var(--muted-foreground);
    letter-spacing: 0.02em;
  }
  .badge-sku {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    background: var(--muted);
    color: var(--muted-foreground);
    letter-spacing: 0.01em;
  }
  /* Order date — when the part was purchased. */
  .card-date {
    font-size: 0.6875rem;
    color: var(--muted-foreground);
    opacity: 0.85;
  }
  .badge-date {
    background: transparent;
    color: var(--muted-foreground);
    border: 1px solid var(--border);
  }

  .card-body {
    padding: 0.75rem 0.875rem 0.875rem;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    flex: 1;
  }

  .card-title {
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
  }

  .card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: auto;
    padding-top: 0.375rem;
  }

  .card-price {
    color: var(--price);
    font-size: 0.875rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
  }

  .card-source {
    font-size: 0.6875rem;
    color: var(--muted-foreground);
    font-weight: 500;
  }

  /* ============================================================
     Parts — list view (Table-ish rows)
     ============================================================ */
  .parts-list {
    display: flex;
    flex-direction: column;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
  }

  .part-row {
    display: grid;
    grid-template-columns: 2.75rem 1fr auto auto auto;
    align-items: center;
    gap: 0.875rem;
    padding: 0.625rem 0.875rem;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
  }
  .part-row:last-child { border-bottom: none; }
  .part-row:hover { background: var(--accent); }
  .part-row.out-of-stock { opacity: 0.55; }
  .part-row.out-of-stock:hover { opacity: 0.85; }

  .part-row-img {
    width: 2.75rem;
    height: 2.75rem;
    background: hsl(0 0% 98%);
    border-radius: calc(var(--radius) - 2px);
    overflow: hidden;
  }
  .part-row-img img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 0.25rem;
  }

  .part-row-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.1875rem;
  }

  .part-row-name {
    font-size: 0.8125rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .part-row-meta {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    flex-wrap: wrap;
    font-size: 0.6875rem;
    color: var(--muted-foreground);
  }

  .part-row-stock {
    font-size: 0.8125rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--success);
    min-width: 3.25rem;
    text-align: right;
  }
  .part-row-stock.low { color: var(--warning); }
  .part-row-stock.zero { color: hsl(0 84% 70%); }
  .part-row-stock .total { color: var(--muted-foreground); font-weight: 500; }

  .part-row-price {
    color: var(--price);
    font-size: 0.8125rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    min-width: 3.5rem;
    text-align: right;
  }

  .part-row-source {
    font-size: 0.6875rem;
    color: var(--muted-foreground);
    font-weight: 500;
    min-width: 5rem;
    text-align: right;
  }

  @media (max-width: 640px) {
    .part-row { grid-template-columns: 2.5rem 1fr auto; gap: 0.625rem; }
    .part-row-img { width: 2.5rem; height: 2.5rem; }
    .part-row-price, .part-row-source { display: none; }
  }

  /* ============================================================
     Projects panel
     ============================================================ */
  .projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(22rem, 1fr));
    gap: 1rem;
  }

  .project-card {
    display: block;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    transition: border-color 0.15s, transform 0.1s;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
  }
  .project-card:hover { border-color: var(--brand); }
  .project-card:active { transform: scale(0.995); }
  .project-card:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
  .project-card-cta {
    margin-top: 0.9rem; font-size: 0.8125rem; font-weight: 500;
    color: var(--brand); opacity: 0; transition: opacity 0.15s;
  }
  .project-card:hover .project-card-cta { opacity: 1; }

  /* ---- Project build guide (rendered on the project page) ---- */
  .pm-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
  .pm-title { font-size: 1.5rem; font-weight: 700; }
  .pm-slug { font-size: 0.8125rem; color: var(--muted-foreground); margin-top: 0.15rem; }
  .pm-desc { color: var(--foreground); margin-top: 0.75rem; }
  .pm-goal { color: var(--muted-foreground); margin-top: 0.35rem; font-size: 0.9rem; }
  .pm-section { font-size: 1.15rem; font-weight: 700; margin: 1.75rem 0 0.25rem; padding-top: 1.25rem; border-top: 1px solid var(--border); }
  .pm-section-hint { color: var(--muted-foreground); font-size: 0.8125rem; margin-bottom: 0.9rem; }
  .pm-parts { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.75rem; }

  /* Rendered markdown build guide */
  .pm-guide { line-height: 1.65; color: var(--foreground); font-size: 0.925rem; }
  .pm-guide h1 { font-size: 1.3rem; font-weight: 700; margin: 1.4rem 0 0.6rem; }
  .pm-guide h2 { font-size: 1.1rem; font-weight: 650; margin: 1.5rem 0 0.5rem; color: var(--brand); }
  .pm-guide h3 { font-size: 1rem; font-weight: 600; margin: 1.1rem 0 0.4rem; }
  .pm-guide p { margin: 0.6rem 0; }
  .pm-guide ul, .pm-guide ol { margin: 0.5rem 0 0.7rem 1.4rem; }
  .pm-guide li { margin: 0.3rem 0; }
  .pm-guide code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85em; background: var(--muted); padding: 0.1rem 0.35rem; border-radius: 4px; }
  .pm-guide a { color: var(--brand); text-decoration: underline; }
  .pm-guide hr { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }
  .pm-guide blockquote {
    margin: 0.9rem 0; padding: 0.6rem 1rem;
    border-left: 3px solid color-mix(in srgb, var(--brand) 50%, transparent);
    background: color-mix(in srgb, var(--brand) 6%, transparent); border-radius: 0 6px 6px 0;
    color: var(--foreground);
  }
  .pm-guide table { width: 100%; border-collapse: collapse; margin: 0.9rem 0; font-size: 0.875rem; }
  .pm-guide th, .pm-guide td { border: 1px solid var(--border); padding: 0.45rem 0.7rem; text-align: left; }
  .pm-guide th { background: var(--muted); font-weight: 600; }

  /* ---- Standalone project page (projects/<slug>/index.html) ---- */
  .project-page { max-width: 920px; }
  .page-topbar {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 1.5rem;
  }
  .back-link {
    color: var(--muted-foreground); text-decoration: none; font-size: 0.875rem;
    padding: 0.35rem 0.6rem; border-radius: calc(var(--radius) - 2px);
    transition: color 0.15s, background 0.15s;
  }
  .back-link:hover { color: var(--foreground); background: var(--muted); }
  .card-note { font-size: 0.6875rem; color: var(--muted-foreground); font-style: italic; }
  .muted { color: var(--muted-foreground); }
  .page-footer { margin-top: 2.5rem; padding-top: 1.25rem; border-top: 1px solid var(--border); }

  /* File & reference links (firmware / wiring / notes) */
  .file-links { display: flex; flex-wrap: wrap; gap: 0.5rem; }
  .file-link {
    display: inline-flex; align-items: center; gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--card); border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
    color: var(--foreground); text-decoration: none;
    font-size: 0.8125rem; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    transition: border-color 0.15s, background 0.15s;
  }
  .file-link:hover { border-color: var(--ring); background: var(--accent); }
  .file-link svg { width: 0.95rem; height: 0.95rem; color: var(--muted-foreground); flex-shrink: 0; }

  /* Inline icons (lucide-style) — inherit text color/size via currentColor. */
  .icon { width: 1em; height: 1em; display: inline-block; vertical-align: -0.125em; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .pm-section .icon { width: 1.1rem; height: 1.1rem; vertical-align: -0.15em; margin-right: 0.15rem; color: var(--muted-foreground); }

  .project-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
  }

  .project-name {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -0.01em;
  }

  .project-slug {
    color: var(--muted-foreground);
    font-size: 0.75rem;
    margin-top: 0.125rem;
  }

  .project-desc {
    color: var(--muted-foreground);
    font-size: 0.8125rem;
    line-height: 1.5;
    margin: 0.625rem 0 0.875rem;
  }

  .project-goal {
    background: var(--muted);
    border-left: 2px solid var(--foreground);
    padding: 0.5rem 0.75rem;
    border-radius: calc(var(--radius) - 2px);
    font-size: 0.75rem;
    color: var(--muted-foreground);
    margin-bottom: 0.875rem;
  }
  .project-goal strong { color: var(--foreground); font-weight: 500; }

  .project-parts-header {
    font-size: 0.6875rem;
    color: var(--muted-foreground);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
  }

  .project-parts-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
  }

  .alloc-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    background: var(--muted);
    border: 1px solid var(--border);
    border-radius: calc(var(--radius) - 2px);
    padding: 0.1875rem 0.5rem 0.1875rem 0.1875rem;
    font-size: 0.6875rem;
    color: var(--foreground);
    transition: background 0.15s;
  }
  .alloc-chip:hover { background: var(--accent); }

  .alloc-chip img {
    width: 1.25rem;
    height: 1.25rem;
    object-fit: contain;
    background: hsl(0 0% 98%);
    border-radius: calc(var(--radius) - 4px);
  }
  .alloc-chip.placeholder img { background: var(--background); }

  .alloc-qty {
    background: hsl(142 70% 45% / 0.15);
    color: var(--success);
    padding: 0.0625rem 0.3125rem;
    border-radius: calc(var(--radius) - 4px);
    font-weight: 600;
    font-size: 0.625rem;
  }
  .alloc-chip.reserved .alloc-qty { background: hsl(38 92% 50% / 0.15); color: var(--warning); }

  .project-empty {
    color: var(--muted-foreground);
    font-size: 0.75rem;
    font-style: italic;
  }

  /* ============================================================
     Allocations panel: groups of cards
     ============================================================ */
  .alloc-group {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem 1.25rem;
    margin-bottom: 1rem;
  }
  .alloc-group-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding-bottom: 0.75rem;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
  }
  .alloc-group-title {
    font-size: 0.9375rem;
    font-weight: 600;
  }
  .alloc-group-meta {
    font-size: 0.75rem;
    color: var(--muted-foreground);
    font-variant-numeric: tabular-nums;
  }

  /* ============================================================
     States
     ============================================================ */
  .loading,
  .empty-state {
    text-align: center;
    padding: 4rem 1.5rem;
    color: var(--muted-foreground);
    font-size: 0.875rem;
  }
  .empty-state { display: none; }
  .empty-state.visible { display: block; }
  .empty-state code {
    background: var(--muted);
    padding: 0.125rem 0.375rem;
    border-radius: calc(var(--radius) - 4px);
    font-size: 0.75rem;
    color: var(--foreground);
  }

  .error-banner {
    background: hsl(0 62.8% 50% / 0.1);
    border: 1px solid hsl(0 62.8% 50% / 0.3);
    color: hsl(0 84% 70%);
    padding: 1rem;
    border-radius: var(--radius);
    margin: 1rem 0;
    font-size: 0.875rem;
  }
  .error-banner code {
    background: hsl(0 0% 0% / 0.3);
    padding: 0.125rem 0.375rem;
    border-radius: calc(var(--radius) - 4px);
    font-size: 0.75rem;
  }

  /* ============================================================
     Responsive
     ============================================================ */
  @media (max-width: 640px) {
    .container { padding: 1rem 1rem 3rem; }
    .header-title h1 { font-size: 1.5rem; }
    .grid { grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); gap: 0.625rem; }
    .card-title { font-size: 0.75rem; }
    .projects-grid { grid-template-columns: 1fr; }
    .stats { grid-template-columns: repeat(2, 1fr); }
    .stat-value { font-size: 1rem; }

    /* Header stacks: title row (with theme button) on top, stats below full-width. */
    .header { flex-direction: column; gap: 1rem; }
    .header-right { flex-direction: column; align-items: stretch; width: 100%; gap: 1rem; }
    .stats { max-width: none; width: 100%; }
    /* Float the theme button to the top-right next to the title. */
    .header { position: relative; }
    .header-right .theme-menu { position: absolute; top: 0; right: 0; }
    .theme-dropdown { right: 0; }

    /* Tabs: let them scroll horizontally if cramped. */
    .tabs { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* Controls wrap; search takes the full row. */
    .controls { gap: 0.5rem; }
    .search { min-width: 100%; flex-basis: 100%; }

    /* Project page: parts grid + topbar. */
    .project-page { max-width: none; }
    .pm-parts { grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); }
    .pm-title { font-size: 1.25rem; }
    /* Long tables in the build guide scroll instead of overflowing. */
    .pm-guide table { display: block; overflow-x: auto; white-space: nowrap; }
  }

  @media (max-width: 380px) {
    .grid, .pm-parts { grid-template-columns: 1fr 1fr; }
    .stats { grid-template-columns: 1fr 1fr; }
  }
