/* ── Reset & base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Dark theme (default) */
:root {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --border:    #2c2f3e;
  --primary:   #4f8ef7;
  --primary-h: #3a7bf0;
  --danger:    #e05252;
  --success:   #3ecf8e;
  --warn:      #f0a843;
  --text:      #e2e5f0;
  --muted:     #7a7f9a;
  --radius:    8px;
  --shadow:    0 2px 8px rgba(0,0,0,0.4);
}

/* Light theme */
body.light {
  --bg:        #f0f2f8;
  --surface:   #ffffff;
  --border:    #d0d4e4;
  --primary:   #3a7bf0;
  --primary-h: #2a6be0;
  --danger:    #d93636;
  --success:   #27a870;
  --warn:      #d48a00;
  --text:      #1a1d2e;
  --muted:     #606680;
  --shadow:    0 2px 8px rgba(0,0,0,0.1);
}

/* ── Global themed scrollbars ────────────────────────────────────────────── */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
*::-webkit-scrollbar       { width: 7px; height: 7px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
*::-webkit-scrollbar-thumb:hover { background: var(--muted); }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 52px;
  display: flex;
  align-items: center;
}
.header-inner { display: flex; align-items: center; gap: 16px; width: 100%; }
.logo-link {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: inherit;
  flex-shrink: 0;
}
.logo-wordmark {
  display: flex;
  flex-direction: column;
  line-height: 1;
}
.logo-name {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text);
}
.logo-sub {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 2px;
}
.version { font-size: 11px; color: var(--muted); }

.version { margin-left: auto; }

/* ── Theme toggle button ─────────────────────────────────────────────── */
.theme-toggle-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 4px 8px;
  transition: border-color .15s, background .15s;
  flex-shrink: 0;
}
.theme-toggle-btn:hover { border-color: var(--primary); }

/* ── Unit btn (used in inline toggles) ───────────────────────────────── */
.unit-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  transition: background .15s, color .15s;
  letter-spacing: .4px;
}
.unit-btn:hover { color: var(--text); }
.unit-btn.active { background: var(--primary); color: #fff; }

/* ── Coil mode toggle ─────────────────────────────────────────────────────── */
.mode-toggle-row {
  display: flex;
  gap: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 4px;
}
.mode-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  padding: 7px 12px;
  transition: background .15s, color .15s;
}
.mode-btn input[type="radio"] { display: none; }
.mode-btn:hover { color: var(--text); }
.mode-btn.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

/* ── App body + sidebar ──────────────────────────────────────────────────── */
.app-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.sidebar {
  width: 56px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 12px 8px 8px;
  gap: 2px;
  position: fixed;
  top: 52px;
  left: 0;
  bottom: 0;
  z-index: 50;
  transition: width 0.2s ease;
}
.sidebar:hover {
  width: 216px;
  overflow-y: auto;
  box-shadow: 4px 0 24px rgba(0,0,0,.18);
}

.sidebar-group-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--muted);
  padding: 12px 10px 4px;
  opacity: 0;
  transition: opacity 0.15s ease;
  white-space: nowrap;
}
.sidebar:hover .sidebar-group-label { opacity: 1; }

.sidebar-section { display: flex; flex-direction: column; gap: 1px; }

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 0;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  text-decoration: none;
  transition: background .12s, color .12s, font-size .15s ease;
  white-space: nowrap;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  overflow: hidden;
}
.sidebar:hover .sidebar-item { font-size: 13px; justify-content: flex-start; }
.sidebar .sidebar-item { justify-content: center; }
.sidebar-item:hover  { background: rgba(79,142,247,.08); color: var(--text); }
.sidebar-item.active { background: rgba(79,142,247,.14); color: var(--primary); font-weight: 600; }

.si-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: .8;
}
.sidebar-item.active .si-icon { opacity: 1; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.sidebar-version {
  font-size: 11px;
  color: var(--muted);
  padding: 6px 10px;
  opacity: 0;
  transition: opacity 0.15s ease;
  white-space: nowrap;
}
.sidebar:hover .sidebar-version { opacity: .6; }

.sidebar .usage-bar {
  opacity: 0;
  transition: opacity 0.15s ease;
  white-space: nowrap;
}
.sidebar:hover .usage-bar { opacity: 1; }

.sidebar .pro-lock {
  opacity: 0;
  transition: opacity 0.15s ease;
}
.sidebar:hover .pro-lock { opacity: 1; }

/* ── Panes ──────────────────────────────────────────────────────────────── */
.pane {
  display: grid;
  grid-template-columns: 380px 1fr;
  flex: 1;
  min-height: 0;
  min-width: 0;
}
.pane.hidden { display: none !important; }

main { display: flex; flex-direction: column; flex: 1; min-height: 0; min-width: 0; margin-left: 56px; }

/* ── Home pane ──────────────────────────────────────────────────────────── */
.home-pane { display: flex; grid-template-columns: unset; overflow-y: auto; }
.home-inner { width: 100%; max-width: 960px; padding: 28px 32px; }

.home-stats-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.home-stat-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 18px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 100px;
}
.home-stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.home-stat-value { font-size: 22px; font-weight: 700; color: var(--text); }

.home-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 16px;
}
.home-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
}
#homeRecentCard { grid-column: 1 / 2; grid-row: 2 / 3; }
#homeTemplatesCard { grid-column: 2 / 3; grid-row: 2 / 3; }
.home-card:first-child { grid-column: 1 / -1; }

.home-card-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.home-card-link {
  font-size: 11px;
  color: var(--primary);
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}
.home-card-link:hover { text-decoration: underline; }
.home-empty { color: var(--muted); font-size: 12px; }

.home-recent-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 13px;
}
.home-recent-row:last-child { border-bottom: none; }
.home-recent-row:hover { color: var(--primary); }
.home-recent-type {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  min-width: 80px;
}
.home-recent-name { flex: 1; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.home-recent-when { font-size: 11px; color: var(--muted); white-space: nowrap; }

.home-quickstart-btns {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.home-qs-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  padding: 10px 16px;
  transition: border-color .15s, background .15s;
  flex: 1;
  min-width: 130px;
  justify-content: center;
}
.home-qs-btn:hover { border-color: var(--primary); color: var(--primary); background: rgba(79,142,247,.06); }
.home-qs-btn svg { width: 18px; height: 18px; flex-shrink: 0; }

.home-run-row, .home-tmpl-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  gap: 10px;
  font-size: 13px;
}
.home-run-row:last-child, .home-tmpl-row:last-child { border-bottom: none; }
.home-run-name  { font-weight: 500; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.home-run-meta  { color: var(--muted); font-size: 11px; white-space: nowrap; }
.home-run-eff   { color: var(--success); font-size: 11px; font-weight: 600; white-space: nowrap; }
.home-row-btn   { font-size: 11px; padding: 3px 10px; border: 1px solid var(--border); border-radius: 5px; background: transparent; color: var(--muted); cursor: pointer; white-space: nowrap; transition: border-color .12s, color .12s; }
.home-row-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ── Panels ─────────────────────────────────────────────────────────────── */
.panel {
  padding: 28px 24px;
  overflow-y: auto;
}
#input-panel,
#sheet-input-panel,
#inv-input-panel,
#ctl-input-panel {
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 20px;
}
#result-panel,
#sheet-result-panel,
#inv-results-panel,
#ctl-results-panel {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 20px;
}
/* results-panel class used by inventory, CTL, library, materials */
.results-panel {
  padding: 28px 24px;
  overflow-y: auto;
  background: var(--bg);
}
/* Widen CTL input column to prevent table horizontal scroll */
#ctl-pane { grid-template-columns: 430px 1fr; }

h2 {
  font-size: 15px;
  font-weight: 600;
}

/* Panel header row — h2 + collapse toggle */
.panel-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  margin-bottom: 4px;
}
.panel-toggle-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 8px;
  line-height: 1.6;
  flex-shrink: 0;
  transition: border-color .15s, color .15s;
}
.panel-toggle-btn:hover { border-color: var(--primary); color: var(--primary); }

/* Collapsed input panel */
.pane.input-collapsed { grid-template-columns: 40px 1fr !important; }
.pane.input-collapsed > .panel:first-child {
  padding: 10px 4px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.pane.input-collapsed > .panel:first-child .panel-hdr {
  border-bottom: none;
  padding-bottom: 0;
  justify-content: center;
}
.pane.input-collapsed > .panel:first-child .panel-hdr h2    { display: none; }
.pane.input-collapsed > .panel:first-child .panel-body      { display: none; }
.pane.input-collapsed > .panel:first-child .job-save-bar    { display: none; }
h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-top: 4px;
}

/* ── Form elements ───────────────────────────────────────────────────── */
.field-group { display: flex; flex-direction: column; gap: 6px; }
.field-group > label { font-size: 13px; color: var(--muted); font-weight: 500; }

.input-row { display: flex; align-items: center; gap: 8px; }
.input-row select { width: auto; flex-shrink: 0; font-size: 13px; padding: 7px 8px; }

.dim-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.dim-sep { color: var(--muted); font-size: 16px; font-weight: 300; }

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

input[type="number"],
input[type="text"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 7px 10px;
  font-size: 14px;
  transition: border-color .15s;
  width: 100%;
}
input[type="number"]:focus,
input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
}

select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 7px 10px;
  font-size: 14px;
  transition: border-color .15s;
  appearance: auto;
}
select:focus {
  outline: none;
  border-color: var(--primary);
}

.unit-hint { font-size: 12px; color: var(--muted); white-space: nowrap; }

.radio-row { display: flex; gap: 20px; }
.radio-row label {
  display: flex; align-items: center; gap: 6px;
  cursor: pointer; color: var(--text); font-size: 13px;
}

/* ── Input tables (coil slitting, flat sheet, CTL) ───────────────────── */
#widthsTable, #sheetPiecesTable, #ctlStripTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}
#widthsTable th, #sheetPiecesTable th, #ctlStripTable th {
  text-align: left;
  padding: 5px 6px;
  color: var(--muted);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
#widthsTable td, #sheetPiecesTable td, #ctlStripTable td {
  padding: 3px 4px;
  vertical-align: middle;
}

/* Compact inputs inside tables */
#widthsTable input,
#sheetPiecesTable input, #sheetPiecesTable select,
#ctlStripTable input {
  padding: 5px 7px;
  font-size: 13px;
  width: auto;
}

/* Coil slitting column widths */
#widthsTable td:nth-child(1) input { width: 80px; }  /* Width  */
#widthsTable td:nth-child(2) input { width: 52px; }  /* Qty    */
#widthsTable td:nth-child(3) input { width: 110px; } /* Item # */

/* Flat sheet column widths */
#sheetPiecesTable td:nth-child(1) input { width: 88px; }  /* Item # */
#sheetPiecesTable td:nth-child(2) input { width: 60px; }  /* W      */
#sheetPiecesTable td:nth-child(3) input { width: 60px; }  /* L      */
#sheetPiecesTable td:nth-child(4) select { width: 100px; } /* Shape  */
#sheetPiecesTable td:nth-child(5) input { width: 48px; }  /* Qty    */

/* CTL column widths */
#ctlStripTable td:nth-child(1) input { width: 88px; }  /* Item # */
#ctlStripTable td:nth-child(2) input { width: 65px; }  /* Width  */
#ctlStripTable td:nth-child(3) input { width: 65px; }  /* Length */
#ctlStripTable td:nth-child(4) input { width: 52px; }  /* Qty    */

/* select element styling inside tables */
#sheetPiecesTable select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 5px 6px;
  font-size: 13px;
  appearance: auto;
}
#sheetPiecesTable select:focus { outline: none; border-color: var(--primary); }

/* Allow table containers to scroll horizontally if needed */
.field-group .table-wrap { overflow-x: auto; }

.btn-remove {
  background: none; border: none;
  color: var(--danger); cursor: pointer;
  font-size: 16px; padding: 0 4px; line-height: 1;
  opacity: .7; transition: opacity .15s;
}
.btn-remove:hover { opacity: 1; }

/* ── Buttons ────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--primary); border: none;
  border-radius: var(--radius); color: #fff;
  cursor: pointer; font-size: 14px; font-weight: 600;
  padding: 9px 24px; transition: background .15s;
}
.btn-primary:hover { background: var(--primary-h); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

.btn-secondary {
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: var(--radius); color: var(--muted);
  cursor: pointer; font-size: 13px; padding: 6px 14px;
  transition: border-color .15s, color .15s;
}
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }
label.btn-secondary { cursor: pointer; display: inline-block; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--muted);
  cursor: pointer; font-size: 14px; padding: 9px 18px;
  transition: border-color .15s, color .15s;
}
.btn-ghost:hover { border-color: var(--text); color: var(--text); }

.action-row { display: flex; gap: 10px; align-items: center; }
.sheet-row-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ── Error ───────────────────────────────────────────────────────────── */
.error-box {
  background: #2a1515; border: 1px solid var(--danger);
  border-radius: var(--radius); color: var(--danger);
  padding: 10px 14px; font-size: 13px;
}
.hidden { display: none !important; }

/* ── Placeholder ─────────────────────────────────────────────────────── */
.placeholder {
  flex: 1; display: flex;
  align-items: center; justify-content: center;
  color: var(--muted); font-size: 15px;
  text-align: center; padding: 60px 20px;
}

/* ── KPI cards ───────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.kpi-label {
  font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px;
}
.kpi-value { font-size: 22px; font-weight: 700; color: var(--primary); }
.kpi-solver { font-size: 14px; }

/* ── Result tables ───────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.result-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.result-table th {
  text-align: left; padding: 8px 12px;
  color: var(--muted); font-weight: 500;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.result-table td {
  padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle;
}
.result-table tr:last-child td { border-bottom: none; }
.result-table tr:hover td { background: rgba(79,142,247,.05); }

.extra-positive { color: var(--warn); }
.extra-zero     { color: var(--success); }

/* ── Auto-calculated qty ─────────────────────────────────────────────── */
input.auto-qty {
  opacity: 0.65;
  cursor: not-allowed;
  background: var(--surface);
  color: var(--muted);
}

/* ── Weight unit toggle (inline with input) ──────────────────────────── */
.weight-unit-toggle {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
}

/* ── Coil visual bar ─────────────────────────────────────────────────── */
.vis-bar {
  display: flex; height: 18px;
  border-radius: 4px; overflow: hidden;
  min-width: 120px; background: var(--border);
}
.vis-segment {
  height: 100%; display: flex;
  align-items: center; justify-content: center;
  font-size: 10px; font-weight: 600; color: #fff;
  overflow: hidden; white-space: nowrap;
  cursor: default; transition: opacity .15s;
}
.vis-segment:hover { opacity: .85; }
.vis-trim {
  background: repeating-linear-gradient(
    45deg, #3a3d4e, #3a3d4e 4px, #2c2f3e 4px, #2c2f3e 8px
  );
}

/* ── Sheet layout grid ───────────────────────────────────────────────── */
.sheet-layouts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin-top: 4px;
}
.sheet-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.sheet-card-title {
  font-size: 12px; font-weight: 600;
  color: var(--muted); text-transform: uppercase;
  letter-spacing: .5px; margin-bottom: 8px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.sheet-card-title span { color: var(--text); font-size: 11px; font-weight: 400; }
.sheet-card-label { display: flex; align-items: center; gap: 6px; color: var(--text); }

.repeat-badge {
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
  letter-spacing: .3px;
}

.repeat-note {
  font-size: 12px;
  color: var(--primary);
  margin-bottom: 8px;
  font-weight: 500;
}

.sheet-svg-wrap {
  width: 100%;
  border-radius: 4px;
  overflow: hidden;
  background: #1e2030;
  border: 1px solid var(--border);
}
.sheet-svg-wrap svg { display: block; width: 100%; height: auto; }

/* SVG pieces */
.svg-piece { cursor: default; }
.svg-piece rect { stroke: #0f1117; stroke-width: 1.5; }
.svg-piece text {
  fill: #fff; font-family: 'Segoe UI', sans-serif;
  font-weight: 600; pointer-events: none;
  dominant-baseline: middle; text-anchor: middle;
}

/* Sheet legend */
.sheet-legend {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 10px;
}
.legend-item {
  display: flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--muted);
}
.legend-swatch {
  width: 12px; height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
}

.hint { font-size: 12px; color: var(--muted); margin-top: -12px; }

/* ── Slit head visual bar ─────────────────────────────────────────────────── */
.sh-vis-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.sh-vis-bar {
  display: flex;
  height: 36px;
  border-radius: 4px;
  overflow: hidden;
  width: 100%;
}
.sh-seg {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  overflow: hidden;
  white-space: nowrap;
  cursor: default;
  transition: opacity .15s;
}
.sh-seg:hover { opacity: .85; }
.sh-edge {
  background: repeating-linear-gradient(
    45deg, #3a3d4e, #3a3d4e 3px, #2c2f3e 3px, #2c2f3e 6px
  );
}
.sh-vis-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.sh-trim-note {
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
}

/* ── Spinner ─────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .6s linear infinite;
  vertical-align: middle; margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Tooltip ─────────────────────────────────────────────────────────── */
.tooltip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--border); color: var(--muted);
  font-size: 10px; font-weight: 700; cursor: help; margin-left: 4px;
}

/* ── Inventory Planner ────────────────────────────────────────────────── */

/* Upload zone */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 18px 14px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
  background: var(--bg);
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--primary);
  background: rgba(79,142,247,.05);
}
.upload-zone.has-file {
  border-color: var(--success);
  background: rgba(62,207,142,.04);
}
.upload-icon { font-size: 22px; margin-bottom: 6px; }
.upload-label { font-size: 13px; color: var(--muted); }
.upload-link {
  color: var(--primary); cursor: pointer; text-decoration: underline;
  text-underline-offset: 2px;
}
.upload-hint { font-size: 11px; color: var(--muted); margin-top: 4px; font-family: monospace; }
.upload-filename {
  margin-top: 8px; font-size: 12px; color: var(--success); font-weight: 600;
}
.hint-small { font-size: 11px; color: var(--muted); font-weight: 400; }

/* File summary chips */
.inv-file-summary {
  display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap;
}
.inv-file-chip {
  font-size: 12px; color: var(--muted); background: var(--border);
  border-radius: 12px; padding: 3px 10px;
}

/* Filter row */
.inv-filter-row {
  display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap;
}
.inv-filter-btn {
  padding: 4px 12px; border-radius: 16px;
  border: 1px solid var(--border);
  background: transparent; color: var(--muted);
  font-size: 12px; cursor: pointer; transition: all .15s;
}
.inv-filter-btn:hover { border-color: var(--primary); color: var(--text); }
.inv-filter-btn.active {
  background: var(--primary); border-color: var(--primary);
  color: #fff; font-weight: 600;
}

/* Status badges */
.status-badge {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 700; letter-spacing: .3px; white-space: nowrap;
}
.status-ok         { background: rgba(62,207,142,.15); color: var(--success); }
.status-short      { background: rgba(224,82,82,.15);  color: var(--danger); }
.status-build_ahead { background: rgba(240,168,67,.15);  color: var(--warn); }

/* Inventory table row coloring */
.inv-status-table tr.row-short td    { background: rgba(224,82,82,.04); }
.inv-status-table tr.row-build_ahead td { background: rgba(240,168,67,.03); }

/* Slitting plan cards */
.inv-plan-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
  overflow: hidden;
}
.inv-plan-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap;
}
.inv-plan-title { font-size: 15px; font-weight: 700; }
.inv-plan-meta  { font-size: 12px; color: var(--muted); margin-top: 2px; }
.inv-plan-status-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 7px; }
.inv-plan-badge {
  display: inline-block; padding: 2px 9px; border-radius: 10px;
  font-size: 11px; font-weight: 700; letter-spacing: .3px; white-space: nowrap;
}
.badge-short { background: rgba(224,82,82,.15);  color: var(--danger); }
.badge-build { background: rgba(240,168,67,.15);  color: var(--warn); }
.badge-ok    { background: rgba(62,207,142,.15);  color: var(--success); }
.inv-plan-eff   { margin-left: auto; font-size: 13px; font-weight: 600; color: var(--success); white-space: nowrap; }
.inv-plan-body  { padding: 16px 18px; }

/* Sort bar above slitting plans */
.inv-sort-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 0 4px;
}
.inv-sort-label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.inv-sort-btn {
  padding: 4px 12px; border-radius: 16px;
  border: 1px solid var(--border);
  background: transparent; color: var(--muted);
  font-size: 12px; cursor: pointer; transition: all .15s;
}
.inv-sort-btn:hover { border-color: var(--primary); color: var(--text); }
.inv-sort-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }

/* Master coil selection checklist */
/* Coil search input */
.inv-coil-search-row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 6px;
}
.inv-coil-search-input {
  flex: 1; font-size: 13px; padding: 5px 10px;
}
.inv-coil-search-msg {
  font-size: 11px; white-space: nowrap; min-width: 0;
  transition: color .15s;
}
.inv-coil-search-msg.ok    { color: var(--success); }
.inv-coil-search-msg.error { color: var(--danger); }

.inv-coil-checklist {
  max-height: 180px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px 8px; background: var(--bg);
  display: flex; flex-direction: column; gap: 2px;
  /* themed scrollbar */
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.inv-coil-checklist::-webkit-scrollbar       { width: 6px; }
.inv-coil-checklist::-webkit-scrollbar-track { background: transparent; }
.inv-coil-checklist::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.inv-coil-checklist::-webkit-scrollbar-thumb:hover { background: var(--muted); }
.inv-coil-check {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 6px; border-radius: 4px; cursor: pointer;
  font-size: 13px;
}
.inv-coil-check:hover { background: rgba(79,142,247,.08); }
.inv-coil-check input[type="checkbox"] { accent-color: var(--primary); width: 14px; height: 14px; cursor: pointer; }
.inv-coil-check-id { font-weight: 600; flex: 1; }
.inv-sel-actions { display: flex; gap: 4px; }

/* Lot list */
.inv-lot-list {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px;
}
.inv-lot-chip {
  background: rgba(79,142,247,.12);
  border: 1px solid rgba(79,142,247,.3);
  border-radius: 6px; padding: 4px 10px;
  font-size: 12px; font-weight: 600; color: var(--primary);
}
.inv-lot-chip span { color: var(--muted); font-weight: 400; }

/* Warnings */
.inv-warnings {
  background: rgba(240,168,67,.1);
  border: 1px solid rgba(240,168,67,.3);
  border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 16px;
}
.inv-warnings p { font-size: 13px; color: var(--warn); margin-bottom: 4px; }
.inv-warnings p:last-child { margin-bottom: 0; }

/* Needed indicator */
.needed-positive { color: var(--danger); font-weight: 700; }
.needed-zero     { color: var(--muted); }

/* ── Piece cards (flat sheet) ─────────────────────────────────────────── */
.pieces-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 48px;
}
.pieces-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 12px 0 4px;
  text-align: center;
}
.pieces-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.piece-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  transition: border-color .15s;
}
.piece-card:hover { border-color: var(--primary); }
.piece-card-thumb {
  width: 52px;
  height: 44px;
  flex-shrink: 0;
  background: #1a1d27;
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.piece-card-thumb svg { max-width: 100%; max-height: 100%; display: block; }
.piece-card-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.piece-card-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.piece-card-dims {
  font-size: 12px;
  color: var(--muted);
  font-family: monospace;
}
.piece-card-badge {
  font-size: 10px;
  font-weight: 600;
  color: var(--primary);
  background: rgba(79,142,247,.12);
  border-radius: 3px;
  padding: 1px 5px;
  display: inline-block;
  letter-spacing: .3px;
  text-transform: uppercase;
  align-self: flex-start;
}
.piece-card-qty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}
.piece-card-qty label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.piece-qty-input {
  width: 52px !important;
  padding: 4px 6px !important;
  font-size: 13px !important;
  text-align: center;
}
.piece-card-remove {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 6px;
  border-radius: 4px;
  transition: color .15s, background .15s;
  flex-shrink: 0;
}
.piece-card-remove:hover { color: var(--danger); background: rgba(224,82,82,.12); }

/* ── Basic shape dialog ───────────────────────────────────────────────── */
.shape-dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.shape-dialog-overlay.hidden { display: none !important; }
.shape-dialog-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 340px;
  max-width: 95vw;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.shape-dialog-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}
.shape-dialog-actions {
  display: flex;
  gap: 10px;
}

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .pane { grid-template-columns: 1fr !important; }
  #input-panel, #sheet-input-panel, #inv-input-panel,
  #ctl-input-panel, #library-input-panel {
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .dim-row { flex-wrap: wrap; }
}

/* ── Cost calculation UI ───────────────────────────────────────────────── */
.cost-toggle-row {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* ── CSV template link & preview panel ───────────────────────────────── */
.template-link {
  font-size: 11px;
  font-weight: 500;
  color: var(--primary);
  text-decoration: none;
  margin-left: 8px;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(79,142,247,0.08);
  transition: background .12s;
}
.template-link:hover { background: rgba(79,142,247,0.18); }

.csv-preview {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 12px;
}
.csv-preview.hidden { display: none; }
.csv-preview-details summary {
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  user-select: none;
  list-style: none;
}
.csv-preview-details summary::-webkit-details-marker { display: none; }
.csv-preview-details summary::before {
  content: '▸';
  display: inline-block;
  width: 12px;
  color: var(--muted);
  transition: transform .15s;
}
.csv-preview-details[open] summary::before { transform: rotate(90deg); }
.csv-mapping {
  padding: 0 12px 8px;
  border-top: 1px solid var(--border);
}
.csv-mapping-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 4px 12px;
}
.csv-mapping-list li {
  font-size: 11px;
  color: var(--muted);
}
.csv-mapping-list li strong {
  color: var(--text);
  font-weight: 600;
}
.csv-mapping-list li code {
  background: rgba(79,142,247,0.12);
  color: var(--primary);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 10px;
}
.csv-mapping-list li.missing strong { color: var(--warn, #c47a00); }
.csv-preview-table-wrap {
  max-height: 180px;
  overflow: auto;
  border-top: 1px solid var(--border);
}
.csv-preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}
.csv-preview-table th,
.csv-preview-table td {
  padding: 4px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.csv-preview-table th {
  background: var(--bg);
  font-weight: 600;
  color: var(--muted);
  position: sticky;
  top: 0;
}
.csv-preview-more {
  padding: 6px 12px;
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.toggle-label input[type="checkbox"] {
  width: 15px; height: 15px;
  accent-color: var(--primary);
  cursor: pointer;
}
.cost-section {
  margin-top: 10px;
  padding: 10px 12px;
  background: rgba(79,142,247,0.07);
  border: 1px solid rgba(79,142,247,0.2);
  border-radius: var(--radius);
}
.cost-section .field-group { margin-bottom: 8px; }
.cost-section .field-group:last-child { margin-bottom: 0; }
.mat-select {
  width: 100%;
  font-size: 12px;
}
.cost-summary-section {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 2px solid var(--primary);
}
.cost-summary-section h3 {
  color: var(--primary);
  margin-bottom: 8px;
}
.cost-kpi-grid {
  grid-template-columns: repeat(5, 1fr) !important;
}
.cost-kpi .kpi-value {
  font-size: 15px;
  color: var(--success);
}
.cost-kpi:nth-child(3) .kpi-value { color: var(--danger); }
.cost-kpi:last-child   .kpi-value { color: var(--warn); }

/* ── Materials pane ────────────────────────────────────────────────────── */
#materials-pane {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 0;
  height: 100%;
}
#materials-input-panel  { border-right: 1px solid var(--border); }
#materials-results-panel { padding: 24px; overflow-y: auto; }
.lib-type-chip.custom {
  background: rgba(240,168,67,0.15);
  color: var(--warn);
}

/* ── Settings pane ─────────────────────────────────────────────────────── */
#settings-pane {
  grid-template-columns: 480px 1fr;
}
#settings-input-panel { border-right: 1px solid var(--border); }
.settings-right-panel { padding: 32px; overflow-y: auto; }

.settings-section { margin-bottom: 28px; }
.settings-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--muted);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.settings-option-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.settings-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  cursor: pointer;
  text-align: left;
  transition: border-color .15s, background .15s;
  color: var(--text);
  width: 100%;
}
.settings-option:hover { border-color: var(--primary); }
.settings-option.active {
  border-color: var(--primary);
  background: rgba(79,142,247,0.08);
}
.settings-option-label {
  font-size: 13px;
  font-weight: 600;
}
.settings-option-desc {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.settings-save-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.settings-saved-msg {
  font-size: 12px;
  color: var(--success);
  font-weight: 600;
}

.settings-info-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 420px;
}
.settings-info-box h3 {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--text);
}
.settings-info-box p, .settings-info-box li {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.7;
}
.settings-info-box ul {
  padding-left: 18px;
  margin: 8px 0;
}
.settings-info-box li { margin-bottom: 6px; }
.settings-info-box strong { color: var(--text); }

/* ── Job save bar (above each optimizer's panel-body) ──────────────────── */
.job-save-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(79,142,247,0.04);
}
.job-name-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  padding: 5px 10px;
  min-width: 0;
}
.job-name-input:focus { outline: none; border-color: var(--primary); }
.btn-save-job {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  white-space: nowrap;
  transition: border-color .15s, color .15s;
}
.btn-save-job:hover { border-color: var(--primary); color: var(--primary); }

/* ── Jobs pane ─────────────────────────────────────────────────────────── */
#jobs-pane { grid-template-columns: 320px 1fr; }
.jobs-sidebar { border-right: 1px solid var(--border); }

.jobs-filter-row {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.jobs-filter-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 12px;
  transition: all .15s;
}
.jobs-filter-btn:hover  { border-color: var(--primary); color: var(--primary); }
.jobs-filter-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.job-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.job-card:hover       { border-color: var(--primary); }
.job-card-active      { border-color: var(--primary); background: rgba(79,142,247,0.08); }
.job-card-name        { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.job-card-meta        { display: flex; align-items: center; gap: 8px; }
.job-card-date        { font-size: 11px; color: var(--muted); }

.jobs-detail-pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 12px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.7;
}

/* ── Light mode overrides ────────────────────────────────────────────── */
body.light .logo-img { filter: invert(1) hue-rotate(180deg); }
body.light header,
body.light nav.tab-bar       { background: var(--surface); }
body.light .tab-bar          { border-bottom-color: var(--border); }
body.light input,
body.light select,
body.light textarea          { background: var(--bg); color: var(--text); border-color: var(--border); }
body.light .result-table th  { background: var(--bg); }
body.light .result-table tr:hover td { background: rgba(0,0,0,0.03); }
body.light .kpi-card         { background: var(--bg); }
body.light .piece-card       { background: var(--bg); }
body.light .inv-lot-chip     { background: var(--bg); }
body.light .shape-dialog-box { background: var(--surface); }
body.light .upload-zone      { background: var(--bg); }
body.light .settings-option  { background: var(--bg); }
body.light .settings-option.active { background: rgba(58,123,240,0.08); }
body.light .job-card         { background: var(--bg); }
body.light .job-card-active  { background: rgba(58,123,240,0.08); }
body.light .jobs-detail-pre  { background: var(--bg); }
body.light .toast            { background: #333; color: #fff; }
body.light .sidebar:hover    { box-shadow: 4px 0 24px rgba(0,0,0,.08); }

/* ── History pane ────────────────────────────────────────────────────── */
#history-pane { grid-template-columns: 320px 1fr; }
#history-sidebar-panel { border-right: 1px solid var(--border); }

.hist-filter-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 12px;
  transition: all .15s;
}
.hist-filter-btn:hover  { border-color: var(--primary); color: var(--primary); }
.hist-filter-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.hist-kpi-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.hist-kpi-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 90px;
}
.hist-kpi-label { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.hist-kpi-value { font-size: 15px; font-weight: 700; color: var(--text); }

body.light .hist-kpi-chip { background: var(--bg); }

/* ── Inventory export rows ───────────────────────────────────────────────── */
.inv-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 18px 0 8px;
}
.inv-export-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.inv-export-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .4px;
}

/* ── Header right / account chip ────────────────────────────────────────── */
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.account-chip {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px 4px 10px;
  cursor: pointer;
  user-select: none;
  font-size: 12px;
}
.account-chip:hover { border-color: var(--primary); }
.account-chip-info { display: flex; align-items: center; gap: 7px; }
.account-email { color: var(--text); font-size: 12px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-badge { border-radius: 10px; padding: 1px 7px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }
.badge-pro  { background: rgba(79,142,247,.2); color: #4f8ef7; }
.badge-free { background: rgba(107,107,136,.15); color: var(--muted); }

/* ── Pro lock badge (inline next to Pro-only buttons/labels) ─────────── */
.pro-lock {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 9px;
  font-weight: 800;
  background: linear-gradient(135deg, rgba(255,180,0,.18), rgba(255,140,0,.12));
  color: #e6a000;
  border: 1px solid rgba(255,180,0,.35);
  border-radius: 4px;
  padding: 1px 5px;
  letter-spacing: .4px;
  vertical-align: middle;
  margin-left: 5px;
  pointer-events: none;
  white-space: nowrap;
}
.pro-lock::before { content: "★ "; font-size: 8px; }

/* Sidebar nav item with Pro lock */
.sidebar-item .pro-lock { margin-left: auto; }

.account-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0,0,0,.3);
  min-width: 170px;
  z-index: 200;
  overflow: hidden;
}
.account-menu.open { display: block; }
.account-menu-item {
  display: block;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.account-menu-item:hover { background: rgba(79,142,247,.08); }
.account-menu-signout { color: var(--error) !important; }
.account-menu-danger { color: var(--danger) !important; }

/* ── Usage bar ───────────────────────────────────────────────────────────── */
.usage-bar {
  margin: 8px 10px 4px;
  padding: 10px 12px;
  background: rgba(107,107,136,.1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.usage-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
}
.usage-track {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 8px;
}
.usage-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 2px;
  transition: width .4s;
}
.usage-upgrade-btn {
  width: 100%;
  padding: 6px;
  background: none;
  border: 1px solid var(--primary);
  border-radius: 6px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.usage-upgrade-btn:hover { background: rgba(79,142,247,.12); }

/* ── Upgrade modal ───────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 12px 40px rgba(0,0,0,.4);
}
.modal-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--text);
}
.modal-body {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 16px;
  line-height: 1.5;
}
.modal-features {
  list-style: none;
  margin-bottom: 22px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.modal-features li {
  font-size: 13px;
  color: var(--text);
}
.btn-primary-full {
  display: block;
  width: 100%;
  padding: 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 10px;
  transition: background .15s;
}
.btn-primary-full:hover { background: #3a7de8; }
.btn-primary-full:disabled { opacity: .55; cursor: not-allowed; }
.btn-ghost-modal {
  display: block;
  width: 100%;
  padding: 10px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  transition: border-color .15s;
}
.btn-ghost-modal:hover { border-color: var(--text); color: var(--text); }

/* ── Team / Org management (Settings pane) ─────────────────────────────── */
.team-section { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--border); }
.team-org-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.team-org-name { font-size: 16px; font-weight: 700; color: var(--text); }
.team-org-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.team-org-badge.pro  { background: rgba(79,142,247,.15); color: var(--primary); }
.team-org-badge.free { background: rgba(122,127,154,.15); color: var(--muted); }
.team-invite-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.team-invite-row input {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}
.team-invite-row input:focus { outline: none; border-color: var(--primary); }
.team-invite-link-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(79,142,247,.07);
  border: 1px solid rgba(79,142,247,.2);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin-bottom: 16px;
  font-size: 12px;
  word-break: break-all;
}
.team-invite-link-box code { flex: 1; color: var(--primary); }
.team-members-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 16px;
}
.team-members-table th {
  text-align: left;
  padding: 5px 8px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.team-members-table td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.team-members-table tr:last-child td { border-bottom: none; }
.team-role-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 99px;
  text-transform: uppercase;
}
.team-role-badge.owner  { background: rgba(240,168,67,.15); color: var(--warn); }
.team-role-badge.admin  { background: rgba(79,142,247,.15); color: var(--primary); }
.team-role-badge.member { background: rgba(122,127,154,.12); color: var(--muted); }
.team-action-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.btn-danger-sm {
  padding: 6px 14px;
  background: none;
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  transition: background .15s;
}
.btn-danger-sm:hover { background: rgba(224,82,82,.1); }
.btn-sm {
  padding: 6px 14px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  transition: background .15s;
}
.btn-sm:hover { background: rgba(255,255,255,.06); }
.team-pending-section { margin-bottom: 14px; }
.team-pending-section h4 { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing:.04em; margin-bottom: 6px; }
.team-pending-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.team-pending-item:last-child { border-bottom: none; }

/* ── Invite page ────────────────────────────────────────────────────────── */
.invite-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 20px;
}
.invite-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px 32px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow);
}
.invite-box h1 { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.invite-box .invite-sub { color: var(--muted); font-size: 14px; margin-bottom: 24px; }
.invite-tabs { display: flex; gap: 0; margin-bottom: 20px; }
.invite-tab {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  background: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.invite-tab:first-child { border-radius: var(--radius) 0 0 var(--radius); border-right: none; }
.invite-tab:last-child  { border-radius: 0 var(--radius) var(--radius) 0; }
.invite-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.invite-field { margin-bottom: 14px; }
.invite-field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 600; }
.invite-field input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.invite-field input:focus { outline: none; border-color: var(--primary); }
.invite-error { color: var(--danger); font-size: 13px; margin-bottom: 10px; }
.invite-success { color: var(--success); font-size: 14px; text-align: center; margin-top: 16px; }

/* ── Custom Dialog (replaces browser confirm/alert) ──────────────────────── */
.dialog-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.dialog-overlay.open { display: flex; }

.dialog-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px 24px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 24px 64px rgba(0,0,0,.55);
  text-align: center;
  animation: dialog-pop .15s ease;
}
@keyframes dialog-pop {
  from { opacity: 0; transform: scale(.94) translateY(10px); }
  to   { opacity: 1; transform: none; }
}

.dialog-icon  { font-size: 38px; margin-bottom: 14px; line-height: 1; }
.dialog-title {
  font-size: 17px; font-weight: 700;
  color: var(--text); margin-bottom: 8px;
}
.dialog-msg {
  font-size: 14px; color: var(--muted);
  line-height: 1.6; margin-bottom: 26px;
}
.dialog-btns {
  display: flex; gap: 10px;
}
.dialog-btns .btn-ghost { flex: 1; }
.dialog-ok {
  flex: 1;
  padding: 10px 16px;
  border: none; border-radius: var(--radius);
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  background: var(--primary); color: #fff;
  transition: opacity .15s;
}
.dialog-ok.danger { background: var(--error, #e05555); }
.dialog-ok:hover  { opacity: .88; }

/* ── Help / support floating widget ─────────────────────────────────────── */
#helpFabBtn {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 900;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--primary, #4f8ef7);
  color: #fff;
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
  transition: transform .15s, box-shadow .15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
#helpFabBtn:hover  { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,.5); }
#helpFabBtn.open   { transform: rotate(45deg); }

.help-panel {
  display: none;
  position: fixed;
  bottom: 92px;
  right: 28px;
  width: 360px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 140px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,.45);
  z-index: 899;
  flex-direction: column;
  overflow: hidden;
  animation: helpFadeIn .18s ease-out;
}
.help-panel.open { display: flex; }

@keyframes helpFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.help-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.help-panel-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}
.help-close {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  padding: 0 4px;
}
.help-close:hover { color: var(--text); }

.help-search-wrap { padding: 12px 14px 6px; }
.help-search-wrap input {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.help-search-wrap input:focus { border-color: var(--primary); }

.help-results {
  flex: 1;
  overflow-y: auto;
  padding: 4px 6px 10px;
}
.help-results .help-empty {
  padding: 22px 16px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}
.help-results .help-section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 10px 12px 4px;
}
.help-item {
  border-radius: 8px;
  margin: 2px 6px;
  overflow: hidden;
}
.help-item:hover { background: var(--bg); }
.help-item-q {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  padding: 9px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  line-height: 1.4;
}
.help-item-q .help-chev {
  color: var(--muted);
  transition: transform .15s;
  flex-shrink: 0;
}
.help-item.open .help-item-q .help-chev { transform: rotate(180deg); }
.help-item-a {
  display: none;
  padding: 0 12px 11px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.55;
}
.help-item.open .help-item-a { display: block; }
.help-item-a p   { margin: 0 0 6px; }
.help-item-a ul  { margin: 4px 0 6px 18px; padding: 0; }
.help-item-a li  { margin-bottom: 3px; }

.help-footer {
  border-top: 1px solid var(--border);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
  background: var(--bg);
}
.help-contact-btn {
  padding: 7px 14px;
  font-size: 13px;
  border-radius: 8px;
  text-decoration: none;
  display: inline-block;
}
