/* ===== Shared UI Components ===== */

/* ─── Page / section headers ─────────────────────────────────────────────────── */

.page-header { margin-bottom: 1.5rem; }

.page-header h2 {
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 0.6rem;
}

.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.section-header h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text-sub);
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.filter-row input[type="text"],
.filter-row select {
  padding: 0.38rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.875rem;
  background: var(--surface);
  color: var(--text);
}

.filter-row input[type="text"] { min-width: 220px; }

.filter-row label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-left: auto;
}

/* ─── Form row ───────────────────────────────────────────────────────────────── */

.form-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.75rem;
}

.form-row label {
  font-weight: 500;
  color: var(--text-sub);
  white-space: nowrap;
}

.form-row select {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.875rem;
  min-width: 240px;
  background: var(--surface);
  color: var(--text);
}

/* ─── Selected model / navigation header ─────────────────────────────────────── */

.selected-model-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.75rem;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border-mid);
  border-radius: 6px;
  box-shadow: 0 1px 4px var(--shadow-sm);
}

#selected-model-label,
#config-selected-type-label {
  font-weight: 500;
  color: var(--text);
  flex: 1;
}

/* System tab — override card grid to fit all 4 cards in one row */
#tab-system .prod-type-grid {
  grid-template-columns: repeat(4, 1fr);
  max-width: none;
}


/* ─── BOM module labels + hierarchy ──────────────────────────────────────────── */

.bom-module-label {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.bom-module-desc {
  font-size: 0.825rem;
  color: var(--text-faint);
  margin-top: 0.15rem;
}

.bom-hierarchy {
  display: flex;
  align-items: center;
  gap: 0;
}

.bom-hierarchy-branch {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  position: relative;
  padding-left: 1.1rem;
  margin-left: 0.5rem;
}

.bom-hierarchy-branch::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.55rem;
  bottom: 0.55rem;
  border-left: 2px solid var(--border-mid);
}

.bom-hierarchy-path {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  position: relative;
}

.bom-hierarchy-path::before {
  content: '';
  position: absolute;
  left: -1.1rem;
  top: 50%;
  width: 0.9rem;
  border-top: 2px solid var(--border-mid);
  transform: translateY(-1px);
}

.bom-hierarchy-dim::before {
  border-color: color-mix(in srgb, var(--border-mid) 50%, transparent);
}

.bom-hierarchy-step {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border-mid);
  border-radius: 4px;
  padding: 0.15rem 0.55rem;
  transition: color 0.2s, background 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.bom-hierarchy-step.current {
  color: var(--navy);
  border: 1.5px solid var(--navy);
  box-shadow: 0 0 6px color-mix(in srgb, var(--navy) 40%, transparent);
}

.bom-hierarchy-step.active {
  color: var(--surface);
  background: var(--navy);
  border-color: var(--navy);
  border-width: 1.5px;
  font-weight: 700;
  box-shadow: none;
}

.bom-hierarchy-arrow {
  font-size: 0.85rem;
  color: var(--text-faint);
}

/* ─── Buttons ────────────────────────────────────────────────────────────────── */

.btn-primary {
  background: var(--navy);
  color: #fff;
  border: none;
  padding: 0.5rem 1.25rem;
  border-radius: 4px;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--navy-hover); }

.btn-secondary {
  background: var(--surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 0.38rem 0.8rem;
  border-radius: 4px;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-secondary:hover { background: var(--surface-alt); }

.btn-danger {
  background: var(--surface);
  color: var(--danger);
  border: 1px solid var(--danger-border);
  padding: 0.38rem 0.8rem;
  border-radius: 4px;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-danger:hover { background: var(--danger-bg); }

/* .btn-edit and .btn-info are identical — single rule covers both */
.btn-edit,
.btn-info {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text-faint);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  transition: color 0.15s, background 0.15s;
}
.btn-edit:hover,
.btn-info:hover {
  color: var(--text);
  background: var(--btn-hover-bg);
}

.btn-delete {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--border);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  transition: color 0.15s, background 0.15s;
}
.btn-delete:hover { color: var(--danger); background: var(--danger-bg); }

.btn-success {
  background: #166534;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 0.3rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-success:hover { background: #15803d; }

.btn-sm {
  padding: 0.2rem 0.55rem;
  font-size: 0.7rem;
}

/* Icon-only action buttons (accept / reject) */
.btn-icon-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border: none;
  border-radius: 4px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
  margin-right: 0.2rem;
}
.btn-accept { background: rgba(34,197,94,0.12);  color: var(--success); }
.btn-reject { background: rgba(220,53,69,0.12);  color: var(--danger); }
.btn-accept:hover { background: rgba(34,197,94,0.25); }
.btn-reject:hover { background: rgba(220,53,69,0.25); }
.btn-export { background: rgba(99,102,241,0.1); color: var(--accent); }
.btn-export:hover { background: rgba(99,102,241,0.22); }

/* ─── Badges ─────────────────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge-active       { background: var(--success-bg); color: var(--success); }
.badge-inactive     { background: var(--danger-bg);  color: var(--danger); }
.badge-comprehensive { background: var(--badge-info-bg);    color: var(--badge-info-color); }
.badge-assembled    { background: var(--badge-purple-bg);   color: var(--badge-purple-color); }
.badge-flagged      { background: var(--warning-bg);        color: var(--warning); }

/* Generic status badge — shared base with quality-badge */
.status-badge,
.quality-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: 10px;
}

.badge-muted   { color: var(--text-muted); }
.badge-warning { background: rgba(245,158,11,0.12); color: var(--warning); }
.badge-success { background: rgba(34,197,94,0.12);  color: var(--success); }
.badge-danger  { background: rgba(220,53,69,0.12);  color: var(--danger); }
[data-theme="dark"] .badge-warning { background: rgba(251,191,36,0.15); }
[data-theme="dark"] .badge-success { background: rgba(74,222,128,0.15); }
[data-theme="dark"] .badge-danger  { background: rgba(248,113,113,0.15); }

.quality-badge.open     { background: rgba(220,53,69,0.12); color: var(--danger); }
.quality-badge.resolved { color: var(--text-muted); }
[data-theme="dark"] .quality-badge.open { background: rgba(248,113,113,0.15); }

/* ─── Row highlight + table loading ──────────────────────────────────────────── */

tr.row-highlight td {
  background: var(--row-selected) !important;
  border-right-color: transparent !important;
}

.table-wrap-loading { position: relative; }
.table-wrap-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--surface);
  opacity: 0.7;
  z-index: 2;
}
.table-wrap-loading-label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  z-index: 3;
  pointer-events: none;
}

/* ─── Data table ─────────────────────────────────────────────────────────────── */

.table-scroll {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 1px 4px var(--shadow-md);
}

.data-table thead {
  background: var(--navbar-bg);
  color: #fff;
}

.data-table th {
  text-align: center;
  padding: 0.65rem 0.9rem;
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.data-table td {
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-sub);
  text-align: center;
  font-size: 0.875rem;
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--row-hover); cursor: pointer; }

.data-table tbody tr.row-highlight td {
  background: var(--row-selected);
  outline: 2px solid var(--navy);
  outline-offset: -2px;
  transition: background 2s ease, outline-color 2s ease;
}

/* Sortable column headers */
.th-sort { cursor: pointer; user-select: none; white-space: nowrap; }
.th-sort::after {
  content: '';
  display: inline-block;
  width: 0.8em;
  margin-left: 0.3em;
  opacity: 0.3;
}
.th-sort.th-sort-active::after { opacity: 1; }
.th-sort.th-sort-active[data-dir="asc"]::after  { content: '↑'; }
.th-sort.th-sort-active[data-dir="desc"]::after { content: '↓'; }

/* Section separator between stacked tables */
.section-sep {
  margin: 1.75rem 0 0;
  border: none;
  border-top: 1px solid var(--border-light);
  padding-top: 1.75rem;
}

/* Column helpers */
.col-action { width: 2.5rem; text-align: center; }
thead .col-action { background: #000; }
.col-date   { white-space: nowrap; color: var(--text-faint); font-size: 0.8rem; }
.col-truncate {
  max-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
}

/* ─── Status / empty states ──────────────────────────────────────────────────── */

.status-text {
  color: var(--text-faint);
  font-size: 0.875rem;
  margin-bottom: 0.75rem;
  min-height: 1.2em;
}

.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-faint);
  background: var(--surface);
  border-radius: 6px;
  box-shadow: 0 1px 4px var(--shadow-md);
}

/* ─── Loading overlay ────────────────────────────────────────────────────────── */

#loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
#loading-overlay.hidden { display: none; }

.loading-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2rem 2.5rem;
  text-align: center;
  min-width: 240px;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto 1rem;
}

.spinner-sm {
  display: inline-block;
  width: 11px;
  height: 11px;
  border: 2px solid var(--border);
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 0.4rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

@keyframes row-highlight-fade {
  0%   { background-color: rgba(232,168,56,0.35); }
  100% { background-color: transparent; }
}
.row-highlight { animation: row-highlight-fade 2.5s ease-out forwards; }

#loading-message {
  font-weight: 600;
  font-size: 0.95rem;
  margin: 0 0 0.25rem;
}
.loading-sub {
  font-size: 0.78rem;
  color: var(--text-faint);
  margin: 0;
}

/* ─── Modal ──────────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal {
  background: var(--surface);
  border-radius: 8px;
  width: 520px;
  max-width: 95vw;
  box-shadow: 0 8px 32px var(--shadow-lg);
}
.modal-sm { width: 340px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--border-light);
}
.modal-header h3 { font-size: 1rem; font-weight: 600; color: var(--text); }

.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text-faint);
  line-height: 1;
}
.modal-close:hover { color: var(--text-sub); }

.modal-body {
  padding: 1.25rem;
  max-height: 62vh;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem 1rem;
  border-top: 1px solid var(--border-light);
}
.modal-footer-right { display: flex; gap: 0.75rem; }

/* ─── Form fields ────────────────────────────────────────────────────────────── */

.form-section-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  margin: 1rem 0 0.4rem;
}

.form-section-title,
.info-section-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text);
  padding: 0.75rem 0 0.3rem;
  border-bottom: 2px solid var(--navy);
  margin-bottom: 0.75rem;
}
.info-section-title { padding: 0.6rem 0 0.2rem; margin-bottom: 0.2rem; }

.form-field { margin-bottom: 0.9rem; }

.form-field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-field input[type="text"],
.form-field input[type="number"] {
  width: 100%;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.875rem;
  background: var(--surface);
  color: var(--text);
}
.form-field input:focus { outline: none; border-color: var(--navy); }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
}

.form-checks {
  display: flex;
  gap: 1.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-light);
  margin-top: 0.5rem;
}
.form-checks label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  cursor: pointer;
}

/* ─── Info grid ──────────────────────────────────────────────────────────────── */

.info-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.info-row {
  display: flex;
  justify-content: space-between;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border-light);
}

.info-label { font-weight: 600; color: var(--text-muted); }
.info-value { color: var(--text-sub); }

.info-block {
  font-size: 0.8rem;
  color: var(--text-sub);
  line-height: 1.5;
  padding: 0.4rem 0;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ─── Login card ─────────────────────────────────────────────────────────────── */

.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
}

.login-card {
  background: var(--surface);
  border-radius: 10px;
  width: 340px;
  max-width: 95vw;
  padding: 2rem;
  box-shadow: 0 8px 32px var(--shadow-lg);
  text-align: center;
}
.login-card .form-field label { text-align: left; }

.login-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.875rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s;
  text-align: left;
}
.login-input:focus {
  outline: none;
  border-color: var(--navbar-bg);
  box-shadow: 0 0 0 2px rgba(26,26,46,0.12);
}

.login-error {
  font-size: 0.825rem;
  color: var(--danger);
  min-height: 1.2em;
  margin-bottom: 0.5rem;
  text-align: center;
}

/* ─── Account tab ────────────────────────────────────────────────────────────── */

.account-layout {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  max-width: 760px;
  margin-top: 1.25rem;
}

.account-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem 1.75rem;
  flex: 1;
  min-width: 280px;
  box-shadow: 0 1px 4px var(--shadow-sm);
}

.account-card-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1.1rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border-light);
}

.account-info-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border-light);
}
.account-info-row:last-child { border-bottom: none; }

.account-info-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  width: 70px;
  flex-shrink: 0;
}
.account-info-value {
  font-size: 0.875rem;
  color: var(--text);
  font-weight: 500;
}

.account-field { margin-bottom: 0.9rem; }
.account-field-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}
.account-field-input {
  width: 100%;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.875rem;
  background: var(--bg);
  color: var(--text);
  box-sizing: border-box;
}
.account-field-input:focus { outline: none; border-color: var(--navy); }

.account-pw-error   { font-size: 0.82rem; color: var(--danger);  min-height: 1.1rem; }
.account-pw-success { font-size: 0.82rem; color: #27ae60; min-height: 1.1rem; }

/* ─── Quote tab ──────────────────────────────────────────────────────────────── */

.quote-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: flex-end;
  padding: 0.75rem 0 1.25rem;
}

.quote-control-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.quote-part-search-group {
  flex: 1;
  min-width: 220px;
}

.quote-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.quote-select {
  min-width: 180px;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.875rem;
}
.quote-select:disabled { opacity: 0.5; cursor: not-allowed; }

.quote-search-wrap { position: relative; }

.quote-input {
  width: 100%;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.875rem;
  box-sizing: border-box;
}
.quote-input:disabled { opacity: 0.5; cursor: not-allowed; }

.quote-dropdown {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 100;
  list-style: none;
  margin: 0;
  padding: 0;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}
.quote-dropdown li {
  padding: 0.45rem 0.7rem;
  font-size: 0.875rem;
  cursor: pointer;
  color: var(--text);
}
.quote-dropdown li:hover { background: var(--row-hover); }
.quote-dropdown-empty { color: var(--text-muted); cursor: default !important; }
.quote-dropdown-empty:hover { background: transparent !important; }

.quote-parts-cell { line-height: 1.6; white-space: normal; }
.quote-qty-cell   { text-align: center; }

.quote-qty {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.quote-qty-btn {
  width: 1.5rem;
  height: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.quote-qty-btn:hover { background: var(--row-hover); }

.quote-qty-val {
  min-width: 1.4rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.quote-summary-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 1.75rem 0 0.6rem;
  color: var(--text);
}

.quote-summary-total td {
  border-top: 2px solid var(--border-mid);
  background: var(--surface-alt);
}

.quote-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 0 0.5rem;
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
}
