/* ═══════════════════════════════════════════════════════════
   BOM Manager — Styles
   Two-tier: BOM (structure) + Single-Source (parts master)
   Features: inline edit, sort, filter, column show/hide, reorder
   ═══════════════════════════════════════════════════════════ */

/* ── Self-hosted Fonts (Source Sans Pro) ── */
@font-face {
  font-family: 'Source Sans Pro';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/source-sans-pro-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Source Sans Pro';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('fonts/source-sans-pro-600.woff2') format('woff2');
}
@font-face {
  font-family: 'Source Sans Pro';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/source-sans-pro-700.woff2') format('woff2');
}

/* ── CSS Variables (Light — warm grays, primary #000) ── */
:root {
  --bg:           #f5f3f0;
  --bg-card:      #ffffff;
  --bg-hover:     #f0ede8;
  --bg-active:    #e8e4dd;
  --bg-input:     #ffffff;
  --border:       #d4cfc7;
  --border-light: #e8e4dd;
  --text:         #000000;
  --text-sec:     #5c5650;
  --text-muted:   #9a9088;
  --accent:       #000000;
  --accent-hover: #333333;
  --accent-bg:    #f0ede8;
  --danger:       #dc2626;
  --danger-bg:    #fee2e2;
  --success:      #16a34a;
  --success-bg:   #dcfce7;
  --warning:      #ca8a04;
  --warning-bg:   #fef9c3;
  --shadow:       0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg:    0 10px 15px rgba(0,0,0,.08), 0 4px 6px rgba(0,0,0,.04);
  --radius:       8px;
  --radius-sm:    5px;
  --header-h:     52px;
  --tabs-h:       40px;
  --font:         'Source Sans Pro', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --log-green:    #22c55e;
  --log-yellow:   #eab308;
  --log-red:      #ef4444;
  --log-gray:     #9a9088;
  --pos-bg:       #fcfbf9;
  --row-alt:      #f8f6f3;
  --row-alt-soft: #faf9f7;
  --stat-bg:      #f0ede8;
  --bom-group-main-bg: #f6f3f0;
  --bom-group-main-hover-bg: #ede9e4;
  --bom-group-sub-bg:  #f5f3f1;
  --bom-group-sub-hover-bg: #ede9e4;
  --project-name-color: #000;
  --modal-overlay-bg: rgba(0,0,0,.35);
  --btn-hover-bg: var(--bg-hover);
  --btn-active-bg: var(--bg-active);
  --danger-text: #b91c1c;
  --pos-highlight-bg: var(--danger-bg);
  --merge-highlight-pulse-bg: #f0ede8;
}

/* Dark theme — GitHub Dark */
[data-theme="dark"] {
  --bg:           #0d1117;
  --bg-card:      #161b22;
  --bg-hover:     #1c2128;
  --bg-active:    #272d36;
  --bg-input:     #0d1117;
  --border:       #30363d;
  --border-light: #21262d;
  --text:         #e6edf3;
  --text-sec:     #a8b2bd;
  --text-muted:   #848d97;
  --accent:       #58a6ff;
  --accent-hover: #79c0ff;
  --accent-bg:    rgba(56,139,253,.15);
  --danger:       #f85149;
  --danger-bg:    rgba(248,81,73,.15);
  --success:      #3fb950;
  --success-bg:   rgba(63,185,80,.15);
  --warning:      #d29922;
  --warning-bg:   rgba(210,153,34,.15);
  --shadow:       0 1px 4px rgba(0,0,0,.45);
  --shadow-lg:    0 10px 18px rgba(0,0,0,.50);
  --pos-bg:       var(--bg-card);
  --row-alt:      #1c2128;
  --row-alt-soft: #161b22;
  --stat-bg:      #1c2128;
  --bom-group-main-bg: #242b35;
  --bom-group-main-hover-bg: #2d3540;
  --bom-group-sub-bg:  #1e2530;
  --bom-group-sub-hover-bg: #262e3a;
  --project-name-color: #c9d1d9;
  --modal-overlay-bg: rgba(0,0,0,.70);
  --btn-hover-bg: #1c2128;
  --btn-active-bg: #272d36;
  --danger-text: #f85149;
  --pos-highlight-bg: rgba(248,81,73,.2);
  --merge-highlight-pulse-bg: rgba(56,139,253,.2);
  --log-green:    #3fb950;
  --log-yellow:   #d29922;
  --log-red:      #f85149;
  --log-gray:     #6e7681;
}

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 17px; }
body {
  font-family: var(--font);
  background: linear-gradient(180deg, #ffffff 0%, #ffffff 70%, var(--bg) 100%);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
}
[data-theme="dark"] body {
  background: linear-gradient(180deg, #161b22 0%, #161b22 70%, var(--bg) 100%);
  background-attachment: fixed;
}
body.modal-open {
  overflow: hidden;
}
input, select, textarea, button { font-family: inherit; font-size: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
hr { border: none; border-top: 1px solid var(--border-light); margin: 16px 0; }

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.app-main {
  flex: 1 0 0;
  position: relative;
}

/* ═══════ HEADER ═══════ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
  z-index: 100;
}
/* Floating overlay on scroll-up */
#app.header-floating .app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
}
#app.header-floating .view-tabs-bar {
  position: fixed;
  top: var(--header-h);
  left: 0;
  right: 0;
  z-index: 31;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.brand-name {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.header-project-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.header-project-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-sec);
}
.header-project-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  color: var(--accent);
}
.header-project-name {
  color: var(--project-name-color);
  font-weight: 700;
  font-size: .9375rem;
  margin-right: 2px;
  white-space: nowrap;
  cursor: text;
}

/* ═══════ BUTTONS ═══════ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s, box-shadow .15s;
  white-space: nowrap;
  color: var(--text);
  background: transparent;
}
.btn:hover { background: var(--btn-hover-bg); }
.btn:active { background: var(--btn-active-bg); }
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 2px 8px rgba(37,99,235,.2); }
.btn-outline {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}
.btn-outline:hover { background: var(--accent-bg); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost {
  background: transparent;
  color: var(--text-sec);
}
.btn-ghost:hover { background: var(--btn-hover-bg); color: var(--text); }
.btn-ghost.active {
  background: var(--accent-bg);
  color: var(--accent);
}
.btn-icon {
  padding: 6px;
  border-radius: var(--radius-sm);
  justify-content: center;
  align-items: center;
  gap: 0;
}
.btn-sm { padding: 4px 10px; font-size: .8125rem; }
.btn-xs { padding: 2px 8px; font-size: .75rem; }

/* ═══════ VIEW TABS BAR ═══════ */
.view-tabs-bar {
  display: flex;
  align-items: center;
  height: var(--tabs-h);
  padding: 0 12px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-light);
  gap: 2px;
  flex-shrink: 0;
  overflow-x: hidden;
  z-index: 31;
}
.view-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.view-tabs::-webkit-scrollbar { display: none; }
.view-tab {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  font-size: .8125rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: transparent;
  color: var(--text-sec);
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
  position: relative;
}
.view-tab:hover { background: var(--bg-hover); color: var(--text); }
.view-tab.active {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
  border-radius: var(--radius-sm);
  border-bottom: none;
}


.btn-add-tab {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-size: .75rem;
  font-weight: 500;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.btn-add-tab:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-bg);
}
.btn-add-tab-inline {
  padding: 4px 10px;
  font-size: .75rem;
  border-style: dashed;
}
.tab-icon-btn {
  width: 30px;
  height: 30px;
  padding: 0;
  justify-content: center;
  margin-left: 2px;
}

.switch-project-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
}
.switch-project-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
  padding: 8px 10px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  text-align: left;
}
.switch-project-item:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}
.switch-project-item.active {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 700;
}

/* ═══════ MAIN ═══════ */
.view {
  display: none;
  flex-direction: column;
}
.view.active {
  display: flex;
}
#view-ss.active {
  /* page-level scroll like BOM — no height constraint */
  display: flex;
}

/* ═══════ BOM HEADER BAR ═══════ */
.bom-header-bar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 5px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
  flex-wrap: wrap;
  position: sticky;
  top: var(--bom-header-bar-top, 0px);
  z-index: 30;
}
.bom-header-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.bom-header-field label {
  font-size: .625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text);
}
.bom-header-field-inline {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.bom-header-field-inline label {
  white-space: nowrap;
  margin-bottom: 0;
}
.bom-header-field input {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: .8125rem;
  width: 120px;
}
.bom-header-field input[type="number"] { width: 80px; }
.bom-header-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-bg);
}
.bom-header-summary {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: auto;
}
.bom-stat {
  font-size: .75rem;
  color: var(--text-sec);
  white-space: nowrap;
}
.bom-stat-cost {
  font-weight: 700;
  color: var(--text);
  background: var(--stat-bg);
  padding: 6px 16px;
  border-radius: var(--radius-sm);
  font-size: .90625rem;
}

/* ═══════ TOOLBAR ═══════ */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 16px;
  flex-shrink: 0;
  gap: 12px;
}
#view-bom > .toolbar {
  position: sticky;
  top: var(--bom-toolbar-top, 0px);
  z-index: 29;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-light);
}
#view-ss > .toolbar {
  position: sticky;
  top: var(--ss-toolbar-top, 0px);
  z-index: 29;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-light);
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}
.toolbar-icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  justify-content: center;
}
.toolbar-icon-btn:hover {
  background: var(--bg-active);
  color: var(--accent);
  box-shadow: 0 0 0 1px var(--border);
}
.toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border-light);
  margin: 0 4px;
  flex-shrink: 0;
}
.bom-status-filter-btn.active {
  background: var(--accent-bg);
  box-shadow: 0 0 0 1.5px var(--accent);
}
.bom-log-filter-btn.active,
.ss-log-filter-btn.active {
  background: var(--accent-bg);
  box-shadow: 0 0 0 1.5px var(--accent);
}

/* ═══════ FILTER PILLS BAR ═══════ */
.filter-pills-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-light);
  flex-wrap: wrap;
  min-height: 34px;
  position: sticky;
  z-index: 28;
}
#view-bom .filter-pills-bar {
  top: var(--bom-pills-top, 0px);
}
#view-ss .filter-pills-bar {
  top: var(--ss-pills-top, 0px);
}
.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px 3px 10px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 16px;
  font-size: .6875rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: default;
  line-height: 1.1;
}
.filter-pill .pill-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  font-size: 11px;
  cursor: pointer;
  opacity: .7;
  transition: opacity .15s, background .15s;
}
.filter-pill .pill-remove:hover {
  opacity: 1;
  background: var(--accent);
  color: #fff;
}
.filter-pills-count {
  display: inline-flex;
  align-items: center;
  font-size: .6875rem;
  font-weight: 400;
  color: var(--text-muted);
  white-space: nowrap;
  margin-left: auto;
  padding: 3px 0;
}
.filter-pills-reset {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border: 1px solid var(--danger);
  border-radius: 16px;
  font-size: .6875rem;
  font-weight: 500;
  color: var(--danger);
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
}
.filter-pills-reset:hover {
  background: rgba(220,38,38,.1);
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-wrap .search-icon {
  position: absolute;
  left: 8px;
  color: var(--text-muted);
  pointer-events: none;
}
.search-wrap input {
  padding: 5px 28px 5px 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  width: 220px;
  font-size: .78125rem;
}
.search-wrap input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-bg);
}
.search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0 2px;
  font-size: 0;
  line-height: 1;
  display: none;
}
.search-clear:hover { color: var(--text); }
.search-wrap input:not(:placeholder-shown) ~ .search-clear { display: block; }

/* ═══════ DROPDOWN / COLUMN MENU ═══════ */
.dropdown-wrap {
  position: relative;
}
.col-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 220px;
  max-height: 360px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  padding: 6px 0;
}
.col-menu.open { display: block; }
.col-menu-item {
  display: grid;
  grid-template-columns: 16px 1fr;
  align-items: center;
  column-gap: 8px;
  padding: 6px 14px;
  font-size: .78125rem;
  cursor: pointer;
  transition: background .1s;
  user-select: none;
}
.col-menu-item:hover { background: var(--bg-hover); }
.col-menu-item input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
  margin: 0;
  place-self: center;
}
.col-menu-item.disabled {
  opacity: .4;
  pointer-events: none;
}

/* ═══════ CUSTOM CHECKBOXES ═══════ */
input[type="checkbox"].custom-cb {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-radius: 3px;
  background: var(--bg-input);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: background .15s, border-color .15s;
}
input[type="checkbox"].custom-cb:checked {
  background: var(--accent);
  border-color: var(--accent);
}
input[type="checkbox"].custom-cb:checked::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 0px;
  width: 6px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
input[type="checkbox"].custom-cb:hover {
  border-color: var(--accent);
}
input[type="checkbox"].custom-cb:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-bg);
}

/* ═══════ SHARED TABLE STYLES (BOM + SS) ═══════ */

/* Table header containers */
.bom-tree-header, .ss-table-header {
  display: grid;
  align-items: center;
  padding: 0 16px 0 2px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-light);
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--text-muted);
  flex-shrink: 0;
  min-width: max-content;
  position: sticky;
}

/* Table header cells */
.bt-col, .sc {
  padding: 0 4px;
  cursor: default;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bt-col.sortable, .sc.sortable { cursor: pointer; }
.bt-col.sortable:hover, .sc.sortable:hover { color: var(--accent); }
.bt-col.sorted, .sc.sorted { color: var(--accent); }
.bt-col[draggable="true"], .sc[draggable="true"] { cursor: grab; }
.bt-col[draggable="true"]:active, .sc[draggable="true"]:active { cursor: grabbing; }
.bt-col.drag-over, .sc.drag-over { border-left: 2px solid var(--accent); }

/* Sort indicators */
.sort-arrow {
  display: inline-flex;
  align-items: center;
  font-size: .75rem;
  width: 12px;
  justify-content: center;
}
.sort-arrow.active { color: var(--accent); font-weight: 700; }

/* Filter rows */
.bom-filter-row, .ss-filter-row {
  display: grid;
  align-items: center;
  padding: 0 16px 0 2px;
  height: 38px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
  min-width: max-content;
  position: sticky;
}
.bom-filter-row input, .ss-filter-row input {
  width: 100%;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg-input);
  color: var(--text);
  font-size: .75rem;
}
.bom-filter-row input:focus, .ss-filter-row input:focus { outline: none; border-color: var(--accent); }

/* Group headers (assemblies / SS categories) */
.asm-row, .ss-group-header {
  display: flex;
  align-items: center;
  padding: 0 16px 0 2px;
  height: 40px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background .15s;
  min-width: max-content;
  background: var(--bom-group-main-bg);
  gap: 8px;
  user-select: none;
  font-weight: 700;
}
.asm-row:not(.asm-sub):hover, .ss-group-header:hover { background: var(--bom-group-main-hover-bg); }

/* Group toggle arrow */
.asm-toggle, .ss-group-toggle {
  display: flex;
  align-items: center;
  color: var(--text-sec);
  transition: color .15s;
}
.asm-row:hover .asm-toggle, .ss-group-header:hover .ss-group-toggle { color: var(--accent); }

/* Group name */
.asm-name, .ss-group-name {
  font-weight: 700;
  font-size: .875rem;
  color: var(--text);
  margin-right: 25px;
}

/* Group count badge */
.asm-badge, .ss-group-count {
  font-size: .6875rem;
  font-weight: 400;
  color: var(--text-sec);
  margin-right: 0;
}

/* Group action buttons */
.asm-actions, .ss-group-actions {
  margin-left: auto;
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity .15s;
}
.asm-row:hover .asm-actions, .ss-group-header:hover .ss-group-actions { opacity: 1; }

/* Data rows */
.pos-row, .ss-row {
  display: grid;
  align-items: center;
  padding: 0 16px 0 2px;
  height: 36px;
  border-bottom: 1px solid var(--border-light);
  transition: background .1s;
  font-size: 14px;
  min-width: max-content;
  background: var(--bg-card);
}
.pos-row:hover, .ss-row:hover { background: var(--accent-bg); }
.pos-row.inactive, .ss-row.inactive { color: var(--text-muted); filter: saturate(.3); }
.pos-row.inactive .pos-cell, .ss-row.inactive .ss-cell { opacity: .45; }
.pos-row.inactive .pos-active, .ss-row.inactive .ss-active { opacity: 1; }

/* Table cells */
.pos-cell, .ss-cell {
  padding: 0 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Cell: name */
.pos-name, .ss-cell-name { font-weight: 500; color: var(--text); }
/* Cell: type */
.pos-type, .ss-cell-type { color: var(--text-sec); font-size: 12px; }
/* Cell: manufacturer */
.pos-mfr, .ss-cell-mfr { font-size: .75rem; }
.pos-mfr a, .ss-cell-mfr a { font-size: inherit; color: var(--accent); }
/* Cell: quantity / numeric */
.pos-qty, .ss-cell-qty { text-align: right; font-variant-numeric: tabular-nums; }
/* Cell: price */
.pos-price, .ss-cell-price { text-align: right; font-variant-numeric: tabular-nums; }
/* Cell: log status */
.pos-logstatus, .ss-cell-status { display: flex; align-items: center; justify-content: center; }
/* Cell: row actions */
.pos-actions, .ss-cell-actions {
  display: flex;
  justify-content: flex-start;
  gap: 2px;
  opacity: 0;
  transition: opacity .15s;
}
.pos-row:hover .pos-actions, .ss-row:hover .ss-cell-actions { opacity: 1; }

/* Editable cells */
.pos-cell.editable, .ss-cell.editable { cursor: text; }
.ss-cell.editing, .pos-cell.editing { overflow: visible; padding: 2px; }

/* Drag & drop (rows) */
.pos-row[draggable="true"], .ss-row[draggable="true"] { cursor: grab; position: relative; }
.pos-row[draggable="true"]:active, .ss-row[draggable="true"]:active { cursor: grabbing; }
.pos-row.bom-pos-dragging, .ss-row.ss-dragging { opacity: .4; }
.asm-row.bom-drop-target, .ss-group-header.ss-drop-target {
  background: var(--accent-bg) !important;
  box-shadow: inset 0 0 0 2px var(--accent);
}

/* Drag grip icon */
.pos-toggle, .ss-toggle { display: flex; align-items: center; justify-content: center; }
.pos-drag-grip { color: var(--text-muted); opacity: .4; transition: opacity .15s; cursor: grab; }
.pos-row:hover .pos-drag-grip, .ss-row:hover .pos-drag-grip { opacity: .8; }
.pos-drag-grip:active { cursor: grabbing; }

/* Fixed checkbox column (active toggle) */
.bt-active, .sc-active {
  display: flex;
  align-items: center;
  justify-content: center;
}
.pos-active, .ss-active {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  overflow: visible;
  position: relative;
  z-index: 2;
}

/* Log status badges (group headers) */
.ss-group-log-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 4px;
  margin-right: 25px;
}
.ss-log-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  font-size: .625rem;
  font-weight: 700;
  padding: 0 5px;
  line-height: 1;
}
.ss-log-badge.red    { background: var(--danger-bg); color: var(--log-red); }
.ss-log-badge.yellow { background: var(--warning-bg); color: var(--log-yellow); }
.ss-log-badge.green  { background: var(--success-bg); color: var(--log-green); }
.ss-log-badge.gray   { background: var(--bg-active); color: var(--text-muted); }

/* ═══════ BOM TREE (specific) ═══════ */
.bom-tree-header {
  height: 32px;
  top: var(--bom-tree-header-top, 0px);
  z-index: 8;
}

.bt-indent  { width: 0; }
.bt-toggle  { width: 28px; }

.bom-tree-wrap {
  position: relative;
  min-width: 0;
}
.bom-tree-body {
  padding-bottom: 40px;
  min-width: max-content;
}

/* BOM Filter Row */
.bom-filter-row {
  top: var(--bom-filter-row-top, 0px);
  z-index: 7;
}

/* Assembly row (BOM-specific) */
.asm-row {
  border-left: 3.5px solid var(--text-sec);
}
.asm-row.asm-sub {
  background: #fffcfa;
  border-left-color: var(--border);
}
.asm-row.asm-sub:hover { background: var(--bg-hover); }
.bom-tree-body > .asm-row:not(.asm-sub) {
  position: sticky;
  top: var(--bom-asm-top, 0px);
  z-index: 6;
  box-shadow: 0 1px 0 var(--border-light);
}

.asm-indent { flex-shrink: 0; }
.asm-toggle, .ss-group-toggle {
  width: 28px;
  flex-shrink: 0;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  transition: color .15s, transform .15s;
}
.asm-toggle svg, .ss-group-toggle svg { transition: transform .2s ease; }
.asm-inline-add {
  display: flex;
  gap: 6px;
  margin-right: auto;
  opacity: 0;
  transition: opacity .15s;
}
.asm-row:hover .asm-inline-add { opacity: 1; }
.asm-add-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-sec);
  cursor: pointer;
  font-size: .6875rem;
  font-weight: 600;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}
.asm-add-btn:hover {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: var(--accent);
}
.asm-add-btn svg { flex-shrink: 0; }
.asm-cost {
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-sec);
  margin-right: 25px;
}

.asm-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-sec);
  cursor: pointer;
  font-size: .8125rem;
}
.asm-action-btn:hover { background: var(--bg-card); color: var(--accent); box-shadow: 0 0 0 1px var(--border-light); }
.asm-action-btn.danger:hover { color: var(--danger); background: var(--danger-bg); }

/* Position row (BOM-specific additions) */
.pos-row:nth-child(even of .pos-row) { background: var(--bg-card); }
.pos-row:nth-child(even of .pos-row):hover { background: var(--accent-bg); }

.pos-active { text-align: center; }
.pos-active input[type="checkbox"] { cursor: pointer; }
.pos-source { color: var(--text-sec); font-size: .75rem; }
.pos-source-link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  font-weight: 500;
}
.pos-source-link:hover { text-decoration: underline; }
.pos-unit { color: var(--text-sec); }
.pos-status { text-align: center; }

/* Mapping status badges */
.status-dot {
  display: inline-block;
  width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  border-radius: 50%;
  font-size: .625rem;
}
.status-dot.mapped { background: var(--success-bg); color: var(--success); }
.status-dot.unmapped { background: var(--bg-active); color: var(--text-muted); }
.status-dot.conflict { background: var(--warning-bg); color: var(--warning); }
.status-dot.no-source { background: var(--danger-bg); color: var(--danger); }

/* ═══════ SINGLE-SOURCE VIEW ═══════ */
.ss-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
  position: sticky;
  top: var(--ss-header-bar-top, 0px);
  z-index: 30;
}
.ss-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}
.ss-list-name {
  font-size: .9375rem;
  font-weight: 700;
}
.ss-series-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  background: var(--accent-bg);
  color: var(--accent);
  font-size: .6875rem;
  font-weight: 600;
  border-radius: 12px;
}
.ss-header-stats {
  display: flex;
  align-items: center;
  gap: 14px;
}
.ss-stat {
  font-size: .75rem;
  color: var(--text-sec);
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.ss-stat-green::before,
.ss-stat-yellow::before,
.ss-stat-red::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.ss-stat-green::before  { background: var(--log-green); }
.ss-stat-yellow::before { background: var(--log-yellow); }
.ss-stat-red::before    { background: var(--log-red); }
.ss-stat-cost {
  font-weight: 700;
  color: var(--text);
  background: var(--stat-bg);
  padding: 6px 16px;
  border-radius: var(--radius-sm);
  font-size: .90625rem;
}

/* SS Table */
.ss-table-wrap {
  position: relative;
  min-width: 0;
}

/* SS min-width floor */
.ss-table-header, .ss-row, .ss-filter-row, .ss-group-header {
  min-width: 1400px;
}
.ss-table-header {
  height: 32px;
  top: var(--ss-table-header-top, 0px);
  z-index: 5;
}

/* SS header cells (unique overrides) */
.sc-active { text-align: center; justify-content: center; }
/* SS Filter Row */
.ss-filter-row {
  top: var(--ss-filter-row-top, 0px);
  z-index: 4;
}

/* SS category border — match BOM assemblies */
.ss-group-header {
  border-left: 3.5px solid var(--text-sec);
  box-shadow: 0 1px 0 var(--border-light);
  z-index: 1;
  height: 36px;
}

/* SS sticky group headers — direct DOM, like BOM assemblies */
.ss-table-body > .ss-group-header {
  position: sticky;
  top: var(--ss-group-top, 0px);
  z-index: 6;
  box-shadow: 0 1px 0 var(--border-light);
}

.sc-qtydev, .sc-qtyseries, .sc-toorder, .sc-delivery, .sc-stock,
.sc-uprice, .sc-tprice { justify-content: flex-end; }
.sc-logstatus { justify-content: center; }

.ss-table-body {
  padding-bottom: 0;
}

.ss-row-even { background: var(--bg-card); }
.ss-row-even:hover { background: var(--accent-bg); }

/* Dynamic tooltip */
.ui-tooltip {
  position: fixed;
  z-index: 4000;
  max-width: 280px;
  padding: 6px 9px;
  border-radius: 8px;
  background: #111;
  color: #fff;
  font-size: .75rem;
  line-height: 1.3;
  box-shadow: 0 6px 22px rgba(0,0,0,.28);
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .12s ease, transform .12s ease;
}
.ui-tooltip.show {
  opacity: 1;
  transform: translateY(0);
}

.ss-cell-num { font-family: 'Menlo', 'Consolas', monospace; font-size: 12px; color: var(--text-sec); }
.ss-cell-total { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.ss-cell-comment { color: var(--text-sec); font-size: .78125rem; }
.ss-cell-center { text-align: center; }
.ss-cell-center[data-field="unit"] { font-size: 12px; color: var(--text-sec); }

/* ═══════ INLINE EDITING ═══════ */
.inline-edit {
  width: 100%;
  padding: 2px 6px;
  border: 1px solid var(--accent);
  border-radius: 3px;
  background: var(--bg-input);
  color: var(--text);
  font-size: .8125rem;
  font-family: inherit;
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-bg);
}
.inline-edit:focus {
  border-color: var(--accent);
}

/* Traffic-light dots */
.log-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid transparent;
}
.log-dot.green  { background: var(--log-green); border-color: #16a34a; }
.log-dot.yellow { background: var(--log-yellow); border-color: #ca8a04; }
.log-dot.red    { background: var(--log-red); border-color: #dc2626; }
.log-dot.gray   { background: var(--log-gray); border-color: #6b7280; }

/* ═══════ EMPTY STATE ═══════ */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: .875rem;
  gap: 12px;
}
.empty-state svg { opacity: .5; }

/* ═══════ LOADING OVERLAY ═══════ */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,.45);
  pointer-events: all;
  backdrop-filter: blur(1px);
}
[data-theme="dark"] .loading-overlay { background: rgba(0,0,0,.35); }
.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════ MODALS ═══════ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--modal-overlay-bg);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open {
  display: flex;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 480px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
  animation: modalIn .15s ease;
}
.modal-lg { width: 640px; }

@keyframes modalIn {
  from { opacity: 0; transform: translateY(-10px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-light);
}
.modal-header h3 { font-size: .9375rem; font-weight: 700; }
.modal-close {
  border: none;
  background: none;
  font-size: 1.375rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--bg-hover); color: var(--text); }

.modal-body { padding: 20px; flex: 1; overflow-y: auto; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border-light);
}

/* ═══════ FORMS ═══════ */
.form-group {
  margin-bottom: 14px;
}
.form-group label {
  display: block;
  font-size: .75rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.form-group .required { color: var(--danger); }
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: .8125rem;
  transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-bg);
}
.form-group textarea { resize: vertical; }
.form-group input[readonly] {
  background: var(--bg-hover);
  color: var(--text-sec);
}

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

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}
.form-grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0 16px;
}
.form-section-title {
  font-size: .6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-muted);
  margin: 20px 0 10px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border-light);
}
.form-section-title:first-child { margin-top: 0; }

/* Manufacturer grid */
.mfr-grid { display: flex; flex-direction: column; gap: 8px; }
.mfr-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.mfr-radio { flex-shrink: 0; cursor: pointer; accent-color: var(--accent); }
.mfr-name { flex: 1; }
.mfr-link { flex: 1.3; }
.mfr-price { width: 80px; flex-shrink: 0; text-align: right; }\n.mfr-currency { width: 52px; flex-shrink: 0; }
.mfr-row input[type="text"],
.mfr-row input[type="url"] {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: .78125rem;
}
.mfr-row select {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: .78125rem;
}
.mfr-row input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-bg);
}
.mfr-row select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-bg);
}
.mfr-add-btn {
  width: 24px;
  height: 24px;
  border: 1px solid var(--border);
  color: var(--text-sec);
  background: var(--bg-card);
}

.switch-project-item.create {
  border-style: dashed;
  color: var(--text-sec);
}

/* ═══════ PART SEARCH (in Position modal) ═══════ */
.part-search-wrap {
  position: relative;
}
.part-search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 200px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 50;
}
.part-result {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: .78125rem;
  transition: background .1s;
}
.part-result:hover { background: var(--bg-hover); }
.part-result-name { font-weight: 600; }
.part-result-list {
  font-size: .6875rem;
  color: var(--accent);
  background: var(--accent-bg);
  padding: 1px 6px;
  border-radius: 8px;
}
.part-result-num {
  font-size: .6875rem;
  color: var(--text-muted);
  font-family: 'Menlo', monospace;
}
.part-result-none {
  padding: 12px;
  text-align: center;
  color: var(--text-muted);
  font-size: .75rem;
}

/* Mapping info */
.mapping-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  padding: 6px 10px;
  background: var(--success-bg);
  border-radius: var(--radius-sm);
  font-size: .75rem;
}
.mapping-badge {
  font-weight: 700;
  font-size: .6875rem;
}
.mapping-badge.mapped { color: var(--success); }
.mapping-detail { color: var(--text-sec); }

/* ═══════ CHANGELOG ═══════ */
.changelog-list { display: flex; flex-direction: column; gap: 2px; }
.changelog-entry {
  display: grid;
  grid-template-columns: 130px 70px 1fr;
  gap: 8px;
  padding: 6px 8px;
  font-size: .75rem;
  border-radius: var(--radius-sm);
}
.changelog-entry:nth-child(odd) { background: var(--bg-hover); }
.cl-time { color: var(--text-muted); font-family: 'Menlo', monospace; font-size: .6875rem; }
.cl-action {
  font-weight: 600;
  font-size: .6875rem;
  text-transform: uppercase;
}
.cl-action.add    { color: var(--success); }
.cl-action.edit   { color: var(--accent); }
.cl-action.delete { color: var(--danger); }
.cl-action.map    { color: var(--warning); }
.cl-detail { color: var(--text-sec); }
.cl-detail b { color: var(--text); font-weight: 600; }

.changelog-empty {
  text-align: center;
  padding: 30px;
  color: var(--text-muted);
}

/* ═══════ SETTINGS ═══════ */
.settings-units {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.unit-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  background: var(--bg-hover);
  border-radius: 12px;
  font-size: .75rem;
  font-weight: 500;
}
.unit-tag .remove-unit {
  cursor: pointer;
  color: var(--text-muted);
  font-size: .875rem;
  line-height: 1;
}
.unit-tag .remove-unit:hover { color: var(--danger); }
.settings-add-row {
  display: flex;
  gap: 6px;
}
.settings-add-row input {
  flex: 1;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: .78125rem;
}
.settings-add-row input:focus {
  outline: none;
  border-color: var(--accent);
}

/* Manufacturer management list */
.mfr-mgmt-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
  max-height: 300px;
  overflow-y: auto;
}
.mfr-mgmt-item {
  display: grid;
  grid-template-columns: 1fr 1fr 28px 28px;
  gap: 6px;
  align-items: center;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  background: var(--bg-hover);
  font-size: .75rem;
}
.mfr-mgmt-item:hover {
  background: var(--bg-active);
}
.mfr-mgmt-item input {
  padding: 3px 6px;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: var(--text);
  font-size: .75rem;
}
.mfr-mgmt-item input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-input);
}
.mfr-mgmt-item input::placeholder {
  color: var(--text-muted);
  font-style: italic;
}
.mfr-mgmt-item .mfr-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 50%;
  cursor: pointer;
  font-size: .875rem;
  transition: all .15s;
}
.mfr-mgmt-item .mfr-remove:hover {
  background: rgba(220,38,38,.1);
  color: var(--danger);
}
.mfr-mgmt-add {
  display: flex;
  gap: 6px;
}
.mfr-mgmt-add input {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: .78125rem;
}
.mfr-mgmt-add input:focus {
  outline: none;
  border-color: var(--accent);
}
.mfr-mgmt-header {
  display: grid;
  grid-template-columns: 1fr 1fr 28px 28px;
  gap: 6px;
  padding: 0 6px 4px;
  font-size: .625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--text-muted);
}

/* ═══════ TOAST ═══════ */
.toast-wrap {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 10px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: .8125rem;
  color: var(--text);
  pointer-events: auto;
  animation: toastIn .25s ease;
  max-width: 360px;
}
.toast.success { border-left: 4px solid var(--success); }
.toast.error   { border-left: 4px solid var(--danger); }
.toast.info    { border-left: 4px solid var(--accent); }
.toast.warning { border-left: 4px solid var(--warning); }
.toast.fade-out { animation: toastOut .3s ease forwards; }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: none; }
}
@keyframes toastOut {
  to { opacity: 0; transform: translateX(40px); }
}

/* ═══════ COLUMN RESIZE HANDLE ═══════ */
.col-resize-handle {
  position: absolute;
  top: 0;
  right: -2px;
  width: 5px;
  height: 100%;
  cursor: col-resize;
  z-index: 10;
  user-select: none;
}
.col-resize-handle:hover,
.col-resize-handle.active {
  background: var(--accent);
  opacity: .4;
}
.bt-col, .sc { position: relative; }

/* Undo/Redo disabled */
.btn[disabled], .btn:disabled {
  opacity: .3;
  pointer-events: none;
  cursor: default;
}

/* ═══════ UTILITIES ═══════ */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.fw-bold { font-weight: 700; }
.mono { font-family: 'Menlo', 'Consolas', monospace; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ═══════ PHASE 29 — NEW FEATURES ═══════ */

/* Unmapped / no-source position — red text + pill (no background) */
.pos-row.pos-unmapped .pos-name {
  color: var(--danger);
  font-weight: 600;
}
.pos-row.pos-unmapped .pos-cell {
  color: var(--danger-text, #b91c1c);
}
.pos-row.pos-unmapped .pos-active,
.pos-row.pos-unmapped .pos-toggle,
.pos-row.pos-unmapped .pos-actions { color: inherit; }

/* Unmapped count badge in assembly headers */
.asm-unmapped-badge {
  font-size: .7rem;
  font-weight: 600;
  color: #fff;
  background: var(--danger);
  border-radius: 8px;
  padding: 1px 8px;
  margin-left: 4px;
  white-space: nowrap;
  line-height: 1.4;
}

/* Inline "Bauteil anlegen" button inside unmapped position name cell */
.pos-create-inline-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 8px;
  padding: 1px 8px;
  font-size: .65rem;
  font-weight: 600;
  color: #fff;
  background: var(--danger);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  vertical-align: middle;
  transition: background .15s;
}
.pos-create-inline-btn:hover { background: #b91c1c; }
.pos-create-inline-btn svg { flex-shrink: 0; }

/* Navigation highlight (cycle through unmapped/conflicts) — reddish */
.pos-row.pos-highlight {
  background: var(--pos-highlight-bg) !important;
  box-shadow: inset 3px 0 0 var(--danger);
  animation: pos-highlight-pulse .8s ease-in-out 2;
}
@keyframes pos-highlight-pulse {
  0%, 100% { box-shadow: inset 3px 0 0 var(--danger); }
  50% { box-shadow: inset 5px 0 0 var(--danger); }
}

/* Merge / duplicate highlight — accent pulse */
.pos-row.pos-merge-highlight {
  background: var(--accent-bg) !important;
  box-shadow: inset 3px 0 0 var(--accent);
  animation: pos-merge-pulse 1s ease-in-out 3;
}
@keyframes pos-merge-pulse {
  0%, 100% { box-shadow: inset 3px 0 0 var(--accent); }
  50% { box-shadow: inset 5px 0 0 var(--accent); background: var(--merge-highlight-pulse-bg); }
}

/* Insert highlight — brief green flash on newly inserted rows */
.pos-row.bom-inserted, .asm-row.bom-inserted {
  animation: bom-insert-flash 1.2s ease-out;
}
@keyframes bom-insert-flash {
  0%   { background: color-mix(in srgb, var(--accent) 28%, var(--bg-card)); }
  100% { background: var(--bg-card); }
}

/* Assembly active checkbox */
.asm-active {
  width: 30px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.asm-row.asm-inactive { color: var(--text-muted); filter: saturate(.3); }
.asm-row.asm-inactive .asm-name { text-decoration: line-through; opacity: .5; }
.asm-row.asm-inactive .asm-toggle,
.asm-row.asm-inactive .asm-count { opacity: .45; }

/* Inactive row checkboxes gray */
.pos-row.inactive .custom-cb,
.asm-row.asm-inactive .custom-cb {
  border-color: var(--text-muted) !important;
  opacity: .5;
}
.pos-row.inactive .custom-cb:checked,
.asm-row.asm-inactive .custom-cb:checked {
  background: var(--text-muted) !important;
  border-color: var(--text-muted) !important;
}

/* Clickable stat badges (unmapped / conflict) */
.bom-stat-clickable {
  cursor: pointer;
  color: var(--danger) !important;
  font-weight: 600;
  transition: background .15s;
  border-radius: 3px;
  padding: 1px 4px;
}
.bom-stat-clickable:hover {
  background: var(--danger-bg);
}
.nav-close-btn {
  cursor: pointer;
  margin-left: 4px;
  color: var(--text-muted);
  font-size: .875rem;
  font-weight: 400;
  line-height: 1;
}
.nav-close-btn:hover { color: var(--danger); }

/* SS row highlight (jump from BOM → SS) */
.ss-row.ss-row-highlight {
  background: var(--accent-bg) !important;
  box-shadow: inset 3px 0 0 var(--accent);
}

/* SS-specific drag/drop (shared base in shared section) */
.ss-row.ss-row-grouped .ss-cell-name { padding-left: 16px; }
.ss-drop-zone-ungrouped {
  min-height: 36px;
  margin: 0;
  display: flex;
  align-items: center;
  transition: background .15s;
  border-top: 1px dashed var(--border-light);
  border-bottom: 1px dashed var(--border-light);
}
.ss-drop-zone-ungrouped.ss-drop-target {
  background: var(--accent-bg);
  min-height: 56px;
}

/* SS add-row at bottom */
.ss-add-row-bottom,
.ss-row.ss-add-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  color: var(--text-muted);
  font-size: .78125rem;
  cursor: pointer;
  transition: background .15s, color .15s;
  border-top: 1px dashed var(--border-light);
}
.ss-row.ss-add-row {
  justify-content: flex-start;
  padding: 4px 16px 4px 11px;
  border-top: none;
  border-bottom: 1px dashed var(--border-light);
}
.ss-add-row-bottom:hover {
  background: var(--accent-bg);
  color: var(--accent);
}
.ss-add-row-bottom svg { color: inherit; }

/* ═══════ SS LOCK ICON ═══════ */
.ss-lock {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  opacity: .45;
  transition: opacity .15s, color .15s;
}
.ss-lock:hover { opacity: 1; color: var(--accent); }
.ss-row-locked .ss-lock { opacity: .8; color: var(--warning); }
.ss-row-locked .ss-lock:hover { color: var(--danger); }
.ss-lock-hdr {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: .7rem;
}

/* Duplicate indicator icon */
.ss-dup {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
}
.ss-has-dupe .ss-dup {
  cursor: pointer;
  color: var(--warning);
  opacity: .75;
  transition: opacity .15s, color .15s;
}
.ss-has-dupe .ss-dup:hover {
  opacity: 1;
  color: var(--danger);
}
.ss-dup-hdr {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Inline manufacturer dropdown in SS */
.ss-inline-select {
  position: absolute;
  z-index: 200;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  min-width: 160px;
  max-height: 200px;
  overflow-y: auto;
  padding: 4px 0;
}
.ss-inline-select .ss-inline-opt {
  padding: 5px 10px;
  font-size: .75rem;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.ss-inline-select .ss-inline-opt:hover {
  background: var(--accent-bg);
  color: var(--accent);
}

/* BOM create-part icon for unmapped positions */
.pos-create-part-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--accent);
  border-radius: var(--radius-sm);
  padding: 0;
  transition: opacity .15s;
}
.pos-create-part-btn:hover { opacity: 1; }

/* ═══════ SCROLLBAR REFINEMENT ═══════ */
.ss-table-wrap::-webkit-scrollbar,
.bom-tree-wrap::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
.ss-table-wrap::-webkit-scrollbar-thumb,
.bom-tree-wrap::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
.ss-table-wrap::-webkit-scrollbar-thumb:hover,
.bom-tree-wrap::-webkit-scrollbar-thumb:hover {
  background: var(--text-sec);
}

/* ═══════ RESPONSIVE ═══════ */
@media (max-width: 900px) {
  .bom-header-bar { flex-direction: column; align-items: flex-start; gap: 8px; }
  .bom-header-summary { margin-left: 0; }
  .ss-header-bar { flex-direction: column; align-items: flex-start; gap: 8px; }
}

/* ═══════ MANUFACTURER DROPDOWN + LINK BUTTON ═══════ */
.pos-mfr-split, .ss-mfr-split {
  display: flex;
  align-items: center;
  gap: 6px;
}
.mfr-inline-select {
  flex: 1;
  min-width: 0;
  padding: 2px 4px;
  border: 1px solid var(--border-light);
  border-radius: 3px;
  background: var(--bg-input);
  color: var(--text);
  font-size: .75rem;
  cursor: pointer;
  outline: none;
  max-width: 100%;
}
.mfr-inline-select:focus { border-color: var(--accent); }
.mfr-link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: stretch;
  padding: 0 5px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: transparent;
  color: var(--text-muted);
  font-size: .6875rem;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
  cursor: pointer;
  gap: 3px;
  box-sizing: border-box;
}
.mfr-link-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--text-muted);
}

/* (Bauteil-anlegen button now uses asm-action-btn class) */

/* ═══════ BOM INLINE AUTOCOMPLETE ═══════ */
.bom-ac-wrapper { position: relative; width: 100%; }
.bom-ac-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 220px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  font-size: .8125rem;
}
.bom-ac-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  cursor: pointer;
  transition: background .1s;
}
.bom-ac-item:hover, .bom-ac-item.bom-ac-active {
  background: var(--accent-bg);
}
.bom-ac-name { font-weight: 600; color: var(--text); }
.bom-ac-list { font-size: .6875rem; color: var(--text-muted); }

/* Dark mode: all links white */
[data-theme="dark"] a { color: var(--text); }
[data-theme="dark"] .pos-source-link { color: var(--text); }
[data-theme="dark"] .mfr-link-btn { color: var(--text-muted); border-color: var(--border); }
[data-theme="dark"] .mfr-link-btn:hover { color: var(--text); border-color: var(--text-sec); }

/* Dark mode: checkboxes black/white */
[data-theme="dark"] input[type="checkbox"].custom-cb {
  border-color: var(--text-sec);
  background: transparent;
}
[data-theme="dark"] input[type="checkbox"].custom-cb:checked {
  background: var(--text);
  border-color: var(--text);
}
[data-theme="dark"] input[type="checkbox"].custom-cb:checked::after {
  border-color: var(--bg);
}
[data-theme="dark"] input[type="checkbox"].custom-cb:hover {
  border-color: var(--text);
}
[data-theme="dark"] input[type="checkbox"].custom-cb:focus-visible {
  box-shadow: 0 0 0 2px rgba(201,209,217,.2);
}

/* Dark mode: asm-action-btn no blue outlines */
[data-theme="dark"] .asm-action-btn:focus-visible {
  box-shadow: 0 0 0 2px rgba(201,209,217,.2);
  outline: none;
}
[data-theme="dark"] .asm-row.asm-sub {
  background: var(--bom-group-sub-bg);
}
[data-theme="dark"] .asm-row.asm-sub:hover {
  background: var(--bom-group-sub-hover-bg);
}

/* Dark mode: primary button accent — darker text on light blue */
[data-theme="dark"] .primary-btn {
  background: #388bfd;
  border-color: #388bfd;
  color: #fff;
}
[data-theme="dark"] .primary-btn:hover {
  background: #2d7ef0;
  border-color: #2d7ef0;
}

/* ═══════ INLINE ADD ROW (inside expanded assembly) ═══════ */
.pos-add-row {
  display: flex !important;
  grid-template-columns: none !important;
  background: var(--bg-card) !important;
  border-bottom: 1px dashed var(--border-light);
  height: 34px;
}
.pos-add-row-content {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}
.inline-add-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: .6875rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}
.inline-add-btn:hover {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: var(--accent);
}
.inline-add-btn svg { flex-shrink: 0; }

/* ═══════ UNGROUPED BOM SECTION ═══════ */
.bom-ungrouped-section {
  margin-top: 4px;
  border-top: 2px solid var(--border);
}
.bom-ungrouped-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  height: 36px;
  background: var(--bg-hover);
  font-size: .78125rem;
  font-weight: 700;
  color: var(--text-sec);
  border-bottom: 1px solid var(--border-light);
}
.bom-ungrouped-header .asm-badge {
  font-weight: 400;
}

/* ═══════ BOM MULTI-SELECT ═══════ */
.pos-row.bom-selected {
  background: color-mix(in srgb, var(--accent) 14%, var(--bg-card)) !important;
  box-shadow: inset 3px 0 0 var(--accent);
  outline: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  outline-offset: -1px;
  border-radius: 3px;
}
.pos-row.bom-selected:hover {
  background: color-mix(in srgb, var(--accent) 20%, var(--bg-card)) !important;
}

/* ═══════ BOM CONTEXT MENU ═══════ */
.bom-ctx-menu {
  position: fixed;
  z-index: 9999;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,.14);
  min-width: 180px;
  padding: 4px 0;
  font-size: .8125rem;
}
.bom-ctx-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  cursor: pointer;
  color: var(--text);
  transition: background .12s, color .12s;
}
.bom-ctx-item:hover {
  background: var(--accent-bg);
  color: var(--accent);
}
.bom-ctx-disabled {
  opacity: .4;
  cursor: default;
  pointer-events: none;
}
.bom-ctx-divider {
  height: 1px;
  background: var(--border-light);
  margin: 3px 0;
}
.bom-ctx-hint {
  padding: 3px 14px 4px;
  font-size: .6875rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}

/* ═══════ SS MULTI-SELECT ═══════ */
.ss-row.ss-selected {
  background: var(--accent-bg) !important;
  box-shadow: inset 3px 0 0 var(--accent);
}
.ss-row.ss-selected:hover {
  background: var(--accent-bg) !important;
}

/* ═══════ CSV IMPORT MODAL ═══════ */
.modal-import-wide {
  width: min(720px, 95vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-import-wide .modal-body {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.import-info {
  font-size: var(--font-sm);
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 500;
}

.import-mapping-hint {
  font-size: var(--font-sm);
  color: var(--text-muted);
  margin: 0 0 12px;
  line-height: 1.4;
}

.import-mapping-table-wrap {
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
}

.import-mapping-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-sm);
}
.import-mapping-table th {
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 1;
  padding: 6px 10px;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.import-mapping-table td {
  padding: 5px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.import-mapping-table tr:last-child td {
  border-bottom: none;
}
.import-col-name {
  font-weight: 600;
  white-space: nowrap;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.import-col-preview {
  color: var(--text-muted);
  font-size: 0.85em;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.import-field-select {
  width: 100%;
  padding: 4px 6px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: var(--font-sm);
  cursor: pointer;
}
.import-field-select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-bg);
}

.import-preview-section {
  margin-top: 8px;
}
.import-summary {
  font-size: var(--font-sm);
  font-weight: 500;
  margin: 0 0 8px;
}
.text-danger {
  color: var(--danger);
}
.text-muted {
  color: var(--text-muted);
}

.import-preview-table-wrap {
  max-height: 180px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.import-preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8em;
}
.import-preview-table th {
  background: var(--bg-card);
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 4px 8px;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.import-preview-table td {
  padding: 3px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.import-preview-table tr:nth-child(even) {
  background: color-mix(in srgb, var(--accent) 4%, var(--bg));
}

.import-template-btns {
  display: flex;
  gap: 8px;
}
.btn-sm {
  padding: 4px 12px;
  font-size: var(--font-sm);
}

.cb-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: var(--font-sm);
}

.import-cb-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: var(--font-sm);
  font-weight: 500;
  margin-bottom: 0;
}
.import-cb-label .custom-cb {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  padding: 0;
  border: 2px solid var(--border);
  border-radius: 3px;
}

.import-undo-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 12px;
  background: color-mix(in srgb, var(--accent) 10%, var(--bg));
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  font-size: var(--font-sm);
}
.import-undo-bar .undo-hint-text {
  flex: 1;
}
.import-undo-bar .btn-undo-import {
  flex-shrink: 0;
  padding: 4px 12px;
  font-size: var(--font-sm);
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
}
.import-undo-bar .btn-undo-import:hover {
  opacity: 0.85;
}

.form-hint {
  margin: 4px 0 0;
  font-size: 0.8em;
  color: var(--text-muted);
  line-height: 1.4;
}
