/* ================================================================
   CSS Custom Properties (Design Tokens)
   ================================================================ */
:root {
  --bg-body:        #0f1117;
  --bg-surface:     #1a1d27;
  --bg-surface-2:   #21253a;
  --bg-input:       #12151f;
  --bg-hover:       #252a40;
  --border:         #4a5480;
  --accent:         #4a67e8;
  --accent-hover:   #3d5ce0;
  --accent-text:    #7a95ff;
  --accent-soft:    rgba(74, 103, 232, 0.16);
  --text-primary:   #e8eaf6;
  --text-secondary: #8b93b8;
  --text-muted:     #828bb2;
  --success:        #3dd68c;
  --warning:        #fbbf24;
  --danger:         #f87171;
  --on-danger-text: #1a1714;
  --sidebar-width:  220px;
  --topbar-height:  54px;
  --radius:         8px;
  --radius-sm:      5px;
  --shadow:         0 2px 12px rgba(0,0,0,0.4);
  --font:           'Inter', system-ui, -apple-system, sans-serif;
}

/* ================================================================
   Reset
   ================================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { font-family: var(--font); background: var(--bg-body); color: var(--text-primary); line-height: 1.5; }
a { color: var(--accent-text); text-decoration: none; }
ul { list-style: none; }
button { cursor: pointer; font-family: inherit; }

/* Baseline text padding — components with their own layout needs override this via specificity */
h1, h2, h3, h4, h5, h6, p, span, label, li, td, th { padding: 5px; }

/* ================================================================
   App Layout
   ================================================================ */
.app-body {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ================================================================
   Sidebar
   ================================================================ */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100vh;
  overflow-y: auto;
  transition: width 0.2s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1rem 1rem;
  border-bottom: 1px solid var(--border);
  height: var(--topbar-height);
}

.sidebar-logo-icon { width: 28px; height: 28px; flex-shrink: 0; }

.sidebar-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.nav-list { padding: 0.35rem 0; flex: 1; }

.nav-section-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0.7rem 1rem 0.2rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.36rem 1rem;
  border-radius: var(--radius-sm);
  margin: 0 0.4rem;
  font-size: 0.88rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  user-select: none;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }

/* Sub-items nested under a parent nav entry */
.nav-sub-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.22rem 1rem 0.22rem 2.4rem;
  border-radius: var(--radius-sm);
  margin: 0 0.4rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  user-select: none;
}
.nav-sub-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-sub-item.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }

/* Role-based nav filtering (app.js applyRoleVisibility) sets [hidden] on
   items not shown to the current role — .nav-item/.nav-sub-item's own
   `display: flex` above would otherwise win over the UA stylesheet's
   [hidden]{display:none}, since author styles beat UA styles regardless
   of specificity. Same fix already applied to .modal-overlay[hidden] etc. */
.nav-item[hidden], .nav-sub-item[hidden] { display: none; }

.nav-icon { font-size: 1rem; width: 20px; text-align: center; }

/* ================================================================
   Main Area
   ================================================================ */
.main-area {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
}

/* ================================================================
   Top Bar
   ================================================================ */
.top-bar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0 1.2rem;
  height: var(--topbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.top-bar-title {
  font-size: 1rem;
  font-weight: 600;
  flex: 1;
  color: var(--text-primary);
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.user-badge {
  font-size: 0.82rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

/* ================================================================
   Content Area
   ================================================================ */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

/* ================================================================
   Status Banner (bottom, always visible — help link + trial-mode status)
   ================================================================ */
.status-banner {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1rem;
  flex-shrink: 0;
  padding: 0.35rem 1.2rem;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.status-banner-link {
  color: var(--text-secondary);
  text-decoration: none;
}
.status-banner-link:hover { color: var(--accent-text); text-decoration: underline; }

.status-banner-text { color: red; font-weight: 700; }

/* ================================================================
   Buttons
   ================================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  margin: 0.15rem 0.2rem;
  padding: 0.55rem 1.15rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
/* Author styles beat the UA [hidden]{display:none} rule regardless of
   specificity — same gotcha as .nav-item[hidden]/.modal-overlay[hidden]
   above. #impersonateBtn toggles visibility via the hidden attribute (see
   app.js's syncImpersonateBtn), so without this it stays visible no matter
   what app.js sets .hidden to. */
.btn[hidden] { display: none; }

.btn-primary { background: var(--accent); color: var(--tag-selected-text, #fff); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-ghost { background: transparent; color: var(--text-secondary); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }

.btn-secondary { background: transparent; color: var(--accent-text); border-color: var(--accent); }
.btn-secondary:hover:not(:disabled) { background: var(--accent-soft); }

.btn-danger { background: var(--danger); color: var(--on-danger-text, #1a1714); border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { opacity: 0.85; }

.btn-sm { padding: 0.42rem 0.9rem; font-size: 0.8rem; }
.btn-xs { padding: 0.32rem 0.7rem; font-size: 0.75rem; }

/* ================================================================
   Section Header
   ================================================================ */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.2rem;
  flex-wrap: wrap;
  gap: 0.8rem;
}

.section-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

.section-header-actions { display: flex; gap: 0.5rem; align-items: center; }

/* ================================================================
   Cards / Surface
   ================================================================ */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  margin-bottom: 1rem;
}

.card-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.2rem;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* ================================================================
   Table
   ================================================================ */
.table-wrap {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  background: var(--bg-surface-2);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.65rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
thead th.col-actions { text-align: right; width: 1%; }

thead th.sortable-col {
  cursor: pointer;
  user-select: none;
  transition: color 0.12s;
}
thead th.sortable-col:hover { color: var(--text-primary); }
thead th.sortable-col::after {
  content: '\2195';
  display: inline-block;
  margin-left: 0.35rem;
  opacity: 0.35;
}
thead th.sortable-col.sort-asc::after  { content: '\2191'; opacity: 1; color: var(--accent-text); }
thead th.sortable-col.sort-desc::after { content: '\2193'; opacity: 1; color: var(--accent-text); }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }

tbody td {
  padding: 0.65rem 1rem;
  color: var(--text-primary);
  vertical-align: middle;
}
tbody td:has(.table-actions), tbody td.col-actions { text-align: right; width: 1%; white-space: nowrap; }

.table-actions { display: flex; justify-content: flex-end; gap: 0.4rem; }
.table-actions .btn { padding: 0.32rem 0.5rem; font-size: 0.85rem; }

.grid-edit-input {
  width: 100%;
  padding: 0.4rem 0.6rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-family: inherit;
}
.grid-edit-input:focus { outline: none; border-color: var(--accent); }
.grid-edit-checkbox { width: 1.1rem; height: 1.1rem; }
.editable-grid .multiselect-tags:empty { margin-bottom: 0; }

.editable-grid table { font-size: 0.8rem; }
.editable-grid tbody td {
  max-width: 300px;
  overflow-wrap: break-word;
}
/* Headers default to nowrap (see thead th above), sized to fit the longest
   one on a single line — a header like "Subscriber Readonly" then eats far
   more column width than the data underneath it actually needs. Letting
   headers wrap frees that width up for the data columns instead. */
.editable-grid thead th { white-space: normal; }

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ================================================================
   Badge / Status chips
   ================================================================ */
.badge {
  display: inline-block;
  margin: 0.1rem 0.15rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.badge-success { background: rgba(61,214,140,.15); color: var(--success); }
.badge-warning { background: rgba(251,191,36,.15); color: var(--warning); }
.badge-danger  { background: rgba(248,113,113,.15); color: var(--danger); }
.badge-info    { background: var(--accent-soft); color: var(--accent-text); }
.badge-neutral { background: rgba(139,147,184,.12); color: var(--text-secondary); }

/* ================================================================
   Modal
   ================================================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}
.modal.modal-wide { max-width: 760px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border);
}

.modal-title { font-size: 1rem; font-weight: 600; }

.modal-close {
  background: none; border: none; font-size: 1.4rem;
  color: var(--text-secondary); line-height: 1;
}
.modal-close:hover { color: var(--text-primary); }

.modal-body {
  padding: 1.2rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  padding: 0.9rem 1.2rem;
  border-top: 1px solid var(--border);
}

/* ================================================================
   Form Elements
   ================================================================ */
.form-row { margin-bottom: 1rem; }

.form-row label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

/* Mandatory-field marker — mandatory-ness comes from the backend's live
   entity scheme (GET /rest/varia/schemeItems), see reqMark() in dom.js. */
.required-mark {
  color: var(--danger);
  font-weight: 700;
  margin-left: 0.15rem;
}

.form-row input,
.form-row select,
.form-row textarea {
  width: 100%;
  padding: 0.55rem 0.8rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
}

.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.form-row select option { background: var(--bg-surface); }

.form-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 1.2rem;
  row-gap: 0;
}

/* ================================================================
   Solver section specifics
   ================================================================ */
.solver-controls {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1.2rem;
}

.data-export-controls {
  display: flex;
  gap: 0.8rem;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-bottom: 1.2rem;
}

/* Created/Actions stay narrow so the Note column takes the rest of the row. */
#dataExportListContainer .table-wrap th:first-child,
#dataExportListContainer .table-wrap td:first-child {
  width: 1%;
  white-space: nowrap;
}

/* Notes can span multiple lines; preserve the line breaks the user typed. */
.data-export-note {
  white-space: pre-wrap;
}

.solver-status-row {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.2rem;
}

.solver-stat {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 1.2rem;
}

/* ================================================================
   Orders — Status chips & filter bar
   ================================================================ */
.status-chips {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.status-chip {
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.status-chip:hover { background: var(--bg-hover); color: var(--text-primary); }
.status-chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

/* expand toggle button */
.order-expand-btn {
  font-size: 0.7rem;
  padding: 0.2rem 0.45rem;
  opacity: 0.6;
  transition: opacity 0.15s, transform 0.15s;
}
.order-expand-btn:hover { opacity: 1; }

/* ================================================================
   Orders — Inline detail panel
   ================================================================ */
.order-detail-row td {
  padding: 0 !important;
  border-bottom: 1px solid var(--border) !important;
  background: var(--bg-body) !important;
}

.order-detail-panel {
  padding: 0.8rem 1.2rem 1rem;
}

.detail-tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.9rem;
}

.detail-tab {
  padding: 0.5rem 1rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: -1px;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  transition: color 0.15s, border-color 0.15s;
}
.detail-tab:hover { color: var(--text-primary); }
.detail-tab.active {
  color: var(--accent-text);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.detail-tab-badge {
  display: inline-block;
  padding: 0.1rem 0.42rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 0.7rem;
  font-weight: 700;
}

.detail-tab-body {
  min-height: 60px;
}

/* Nested table inside detail panel — slightly compact */
.order-detail-panel .table-wrap { border: 1px solid var(--border); border-radius: var(--radius-sm); }
.order-detail-panel table th  { font-size: 0.7rem; padding: 0.85rem 1rem; }
.order-detail-panel table td  { padding: 0.85rem 1rem; font-size: 0.82rem; }
.order-detail-panel table td:first-child,
.order-detail-panel table th:first-child { text-align: left; }

.cell-text { display: inline-block; padding: 0 0.15rem; }

.detail-tab-toolbar { display: flex; justify-content: flex-end; margin-bottom: 0.7rem; }

/* Order sub-tables (Cap. Bundles / Dependencies / Assignations) — thin column dividers */
.order-subtable th, .order-subtable td { border-right: 1px solid var(--border); }
.order-subtable th:last-child, .order-subtable td:last-child { border-right: none; }

/* Cap. Bundles — center Min–Max/Preserve/Control Resource */
.cap-bundle-table th:nth-child(3), .cap-bundle-table td:nth-child(3),
.cap-bundle-table th:nth-child(4), .cap-bundle-table td:nth-child(4),
.cap-bundle-table th:nth-child(5), .cap-bundle-table td:nth-child(5) { text-align: center; }

/* Assignations — fit columns to their data, center date/constraint columns */
.assignation-table th:nth-child(2), .assignation-table td:nth-child(2) { width: 80px; text-align: center; }
.assignation-table th:nth-child(3), .assignation-table td:nth-child(3),
.assignation-table th:nth-child(4), .assignation-table td:nth-child(4) { width: 105px; text-align: center; }
.assignation-table th:nth-child(5), .assignation-table td:nth-child(5) { width: 110px; text-align: center; }
.assignation-table th:nth-child(6), .assignation-table td:nth-child(6) { text-align: left; }

/* Dependencies — same width/centering rule as Assignations for Status/Start/End */
.deps-table th:nth-child(2), .deps-table td:nth-child(2) { width: 110px; text-align: center; }
.deps-table th:nth-child(3), .deps-table td:nth-child(3),
.deps-table th:nth-child(4), .deps-table td:nth-child(4) { width: 105px; text-align: center; }

/* ================================================================
   Loading spinner
   ================================================================ */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Small inline variant used inside a button label (Validate/Solve while a
   request is in flight) — the default .spinner is sized for a standalone
   loading state, too big to sit next to button text. */
.spinner-btn { width: 12px; height: 12px; border-width: 2px; margin-right: 0.35rem; }

.loading-row td {
  text-align: center;
  padding: 2rem;
  color: var(--text-secondary);
}

/* Indeterminate progress bar — shown above the Running Tasks table while at
   least one solver task is in progress; there's no numeric percentage to
   report, so a sliding stripe communicates "still working" instead. */
.solver-progress-bar {
  position: relative;
  height: 4px;
  border-radius: 999px;
  background: var(--bg-surface-2);
  overflow: hidden;
  margin-bottom: 0.9rem;
}
.solver-progress-bar::after {
  content: '';
  position: absolute;
  top: 0; left: -35%;
  height: 100%;
  width: 35%;
  border-radius: 999px;
  background: var(--accent);
  animation: solver-progress-slide 1.3s ease-in-out infinite;
}
@keyframes solver-progress-slide {
  0%   { left: -35%; }
  100% { left: 100%; }
}

.badge-running { animation: badge-pulse 1.6s ease-in-out infinite; }
@keyframes badge-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74,103,232,0.45); }
  50%      { box-shadow: 0 0 0 4px rgba(74,103,232,0); }
}

/* ================================================================
   Toast Notifications
   ================================================================ */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 2000;
}

.toast {
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 0.7rem 1rem;
  font-size: 0.85rem;
  color: var(--text-primary);
  box-shadow: var(--shadow);
  animation: slideIn 0.2s ease;
  max-width: 320px;
}
.toast.toast-success { border-left-color: var(--success); }
.toast.toast-error   { border-left-color: var(--danger); }
.toast.toast-warning { border-left-color: var(--warning); }

@keyframes slideIn {
  from { transform: translateX(120%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ================================================================
   Misc utilities
   ================================================================ */
.text-muted { color: var(--text-muted); }
.text-sm    { font-size: 0.82rem; }
.mt-1       { margin-top: 0.5rem; }
.mt-2       { margin-top: 1rem; }
.flex       { display: flex; }
.gap-1      { gap: 0.5rem; }
.items-center { align-items: center; }

.section-refresh-btn {
  font-size: 1rem;
  color: var(--text-muted);
  padding: 0.2rem 0.4rem;
  transition: color 0.15s, transform 0.4s;
}
.section-refresh-btn:hover { color: var(--text-primary); }
.section-refresh-btn:active { transform: rotate(360deg); }

.section-header-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

/* ================================================================
   Theme picker
   ================================================================ */
.theme-panel {
  position: fixed;
  top: calc(var(--topbar-height) + 6px);
  right: 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  min-width: 170px;
  z-index: 900;
  box-shadow: 0 4px 24px rgba(0,0,0,.6);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.theme-swatch {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.75rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, color 0.12s;
}
.theme-swatch:hover { background: var(--bg-hover); color: var(--text-primary); }
.theme-swatch.active { border-color: var(--accent); background: var(--accent-soft); color: var(--text-primary); font-weight: 600; }

.theme-dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ================================================================
   Tags — display chips for capabilities / types
   ================================================================ */
.tag {
  display: inline-flex;
  align-items: center;
  margin: 0.1rem 0.15rem;
  padding: 0.1rem 0.48rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  border: 1px solid transparent;
  white-space: nowrap;
  line-height: 1.45;
}

/* capability tag — blue accent */
.tag-cap {
  background: rgba(74,103,232,.16);
  color: var(--accent-text);
  border-color: rgba(74,103,232,.28);
}

/* capability-type tag — green */
.tag-type {
  background: rgba(61,214,140,.1);
  color: var(--success);
  border-color: rgba(61,214,140,.2);
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

/* ================================================================
   Multiselect — autocomplete-driven multi-select (tags + search)
   ================================================================ */
.multiselect { position: relative; }

.multiselect-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.5rem;
}
.multiselect-tags:empty { margin-bottom: 0; }

.multiselect-tag {
  background: var(--accent-soft);
  color: var(--accent-text);
  border-color: rgba(74,103,232,.28);
}

.multiselect-tag-remove {
  cursor: pointer;
  margin-left: 0.2rem;
  opacity: 0.7;
}
.multiselect-tag-remove:hover { opacity: 1; }

.multiselect-input {
  width: 100%;
  padding: 0.4rem 0.6rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-family: inherit;
}
.multiselect-input:focus { outline: none; border-color: var(--accent); }

/* Opt-in layout (see multiselectHtml's `inline` option): tag(s) sit right
   before the input on the same line instead of their own row above it. */
.multiselect-inline {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.3rem;
}
.multiselect-inline .multiselect-tags { margin-bottom: 0; }
.multiselect-inline .multiselect-input { flex: 1; width: auto; min-width: 80px; }

/* Default layout (see multiselectHtml's `border` option, on unless passed
   false): tags+input grouped into one curved-border box instead of the
   input drawing its own separate border — purely a skin on top of whichever
   stacking (.multiselect-inline or the legacy vertical default) is active,
   so it doesn't disturb that arrangement. */
.multiselect-bordered {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  padding: 0.3rem 0.5rem;
}
.multiselect-bordered:focus-within { border-color: var(--accent); }
.multiselect-bordered .multiselect-input {
  border: none;
  background: transparent;
  padding: 0.15rem 0.2rem;
}
.multiselect-bordered .multiselect-input:focus { outline: none; }

/* position: fixed + coordinates set by JS (positionDropdown) from the input's
   bounding rect — this lets the dropdown escape any scrollable/clipping
   ancestor (e.g. .modal-body's overflow-y: auto) instead of being hidden by it. */
.multiselect-dropdown {
  position: fixed;
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-height: 320px;
  overflow-y: auto;
  z-index: 1100;
  box-shadow: var(--shadow);
}
.multiselect-dropdown[hidden] { display: none; }

.multiselect-option {
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-primary);
}
.multiselect-option:hover { background: var(--bg-hover); }
.multiselect-option.active {
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 600;
}

.multiselect-empty {
  padding: 0.3rem 0.6rem;
  color: var(--text-muted);
  font-size: 0.78rem;
}

/* ================================================================
   Solver Report — Gantt chart (By Resource / By Order tabs)
   ================================================================ */
.report-panel { padding-top: 0.2rem; }

/* One CSS Grid spans the whole chart (label column + timeline column, N rows) —
   NOT one grid per row — so every row's column tracks are guaranteed to line up,
   and the sticky header/label cells below stick against a single shared scrollport. */
.gantt-grid {
  display: grid;
  grid-template-columns: 170px 1fr;
  column-gap: 0.8rem;
  /* stretch (not start): the sticky label/axis/spacer cells have no explicit
     height, so they must fill the full row band for their opaque background to
     cover it completely — otherwise bars/ticks scrolling underneath show through
     wherever the cell's own content is shorter than its row. */
  align-items: stretch;
}

/* Card owns the border/padding; .gantt-wrap (the actual scroll container) stays
   unpadded. Padding on a *scrolling* ancestor creates a gap the sticky header/
   label cells don't cover (sticky only sticks to the padding edge, not the
   border edge), and scrolled bars/ticks can slide into that gap and show through
   above/left of them. Keeping the breathing room on this non-scrolling outer
   card instead removes that gap entirely. */
.gantt-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-surface);
  padding: 0.9rem 1.1rem 1.1rem;
}

.gantt-wrap {
  overflow: auto;
  max-height: 65vh;
}

/* Top row (corner spacer + axis) — pinned to the top of .gantt-wrap so the
   month/week axis stays put while rows scroll vertically underneath it, but the
   axis itself is NOT left-pinned, so it still scrolls horizontally in sync with
   the bars beneath it. */
.gantt-header-cell {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--bg-surface);
  padding-bottom: 0.5rem;
}

/* Width is set inline in JS (days-in-domain * px-per-day) so a long solve window
   renders at readable week granularity and simply overflows .gantt-wrap's
   horizontal scrollbar, rather than compressing every tick to fit the viewport. */
.gantt-axis-months {
  position: relative;
  height: 1.15rem;
  border-bottom: 1px solid var(--border);
}

.gantt-axis-month {
  position: absolute;
  top: 0;
  height: 100%;
  border-left: 1px solid var(--border);
  padding-left: 0.35rem;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gantt-axis-month:first-child { border-left: none; }

.gantt-axis-weeks {
  position: relative;
  height: 1.2rem;
  border-bottom: 1px solid var(--border);
}

.gantt-tick {
  position: absolute;
  top: 0;
  border-left: 1px solid var(--border);
  padding-left: 0.3rem;
  font-size: 0.68rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Left column (corner spacer + every row's label) — pinned to the left of
   .gantt-wrap so resource/order identity stays put while the timeline scrolls
   horizontally, but each label is NOT top-pinned, so it still scrolls vertically
   in sync with its own row. The corner spacer is pinned on BOTH axes at once
   (it's a .gantt-header-cell too) and layers above everything else. */
.gantt-axis-label-spacer,
.gantt-row-label {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--bg-surface);
}
.gantt-axis-label-spacer { z-index: 4; }

.gantt-row-label { padding: 0.3rem 0.15rem; }

/* Resource/order identity, styled like the .tag chips used elsewhere (order codes,
   capability tags) but allowed to wrap to multiple lines instead of truncating —
   a long resource/order name should stay fully readable in the fixed left column. */
.gantt-row-tag {
  display: inline-block;
  max-width: 100%;
  white-space: normal;
  word-break: break-word;
  line-height: 1.3;
  margin: 0;
  border-radius: var(--radius-sm);
}

/* Width/height are set inline in JS — width from the domain's day-span (see
   .gantt-axis-months/.gantt-axis-weeks above), height from lane-count * lane
   height (see assignLanes): segments whose timeframes overlap are assigned
   separate lanes so they never visually collide. */
.gantt-track {
  position: relative;
  margin: 0.3rem 0;
}

.gantt-bar {
  position: absolute;
  border-radius: 4px;
  min-width: 5px;
  color: #fff;
  font-size: 0.7rem;
  line-height: 1.25;
  padding: 0.2rem 0.4rem;
  cursor: default;
  outline-offset: 2px;
  transition: filter 0.1s;
  /* Wrap the caption up to 2 lines, clamp with an ellipsis rather than hard-cropping —
     the full label is still always available via the title attr and tooltip. */
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  word-break: break-word;
}
.gantt-bar:hover, .gantt-bar:focus-visible { filter: brightness(1.12); }

/* Shared tooltip element (positioned via JS from the hovered bar's bounding rect) —
   fixed so it can't be clipped by .gantt-wrap's overflow-x: auto. */
.gantt-tooltip {
  position: fixed;
  z-index: 1200;
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 0.5rem 0.7rem;
  max-width: 320px;
  font-size: 0.78rem;
}
.gantt-tooltip[hidden] { display: none; }
.gantt-tooltip-title { font-weight: 600; color: var(--text-primary); margin-bottom: 0.2rem; }
.gantt-tooltip-row   { color: var(--text-secondary); }
