:root {
  color-scheme: light;
  --bg: #eef3f7;
  --surface: rgba(255, 255, 255, 0.95);
  --surface-strong: #ffffff;
  --line: #d6dee6;
  --text: #1d2833;
  --muted: #5f6f82;
  --accent: #1c7c6f;
  --accent-strong: #156257;
  --danger: #a93939;
  --shadow: 0 18px 40px rgba(20, 37, 53, 0.10);
  --radius: 18px;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
.hidden { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at top right, rgba(28, 124, 111, 0.18), transparent 22rem),
    linear-gradient(180deg, #f7fafc 0%, var(--bg) 100%);
  color: var(--text);
}

/* ─── Layout ─────────────────────────────────────────────────────────────── */

.page-shell {
  display: grid;
  grid-template-columns: 22rem minmax(0, 1fr);
  gap: 1rem;
  padding: 1rem;
}

.sidebar,
.content {
  display: grid;
  gap: 1rem;
  align-content: start;
}

/* ─── Panel ──────────────────────────────────────────────────────────────── */

.panel {
  background: var(--surface);
  border: 1px solid rgba(214, 222, 230, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  /* Force GPU layer so Firefox paints children immediately */
  transform: translateZ(0);
  min-width: 0;
  overflow: hidden;
}

.summary-panel {
  position: sticky;
  top: 1rem;
  z-index: 1;
}

/* ─── Section head ───────────────────────────────────────────────────────── */

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

h1, h2, p { margin: 0; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.05rem; }
.muted { color: var(--muted); }

.beta-badge {
  display: inline-block;
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: rgba(28, 124, 111, 0.15);
  color: var(--accent-strong);
  border: 1px solid rgba(28, 124, 111, 0.3);
  border-radius: 999px;
  padding: 0.15rem 0.5rem;
  vertical-align: middle;
  position: relative;
  top: -0.2rem;
}

.auth-grid {
  display: grid;
  gap: 0.75rem;
  margin: 1rem 0 0.85rem;
}

.auth-actions {
  margin-bottom: 0.55rem;
}

.auth-helper {
  font-size: 0.8rem;
}

.auth-reset {
  margin-top: 0.75rem;
}

.auth-reset summary {
  cursor: pointer;
  color: var(--accent-strong);
  font-weight: 600;
}

.user-chip-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 1rem 0 0.75rem;
}

.user-email {
  font-weight: 600;
}

.role-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.25rem 0.6rem;
  background: rgba(28, 124, 111, 0.12);
  color: var(--accent-strong);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.version-label {
  font-size: 0.75rem;
  margin-top: 0.1rem !important;
  margin-bottom: 0.5rem !important;
}

/* ─── Form controls ──────────────────────────────────────────────────────── */

.field {
  display: grid;
  gap: 0.35rem;
  font-size: 0.92rem;
  min-width: 0;
}

.field.checkbox {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding-top: 1.3rem;
}

input, select, button { font: inherit; }

input[type="file"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="text"],
input[type="number"],
textarea,
select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-strong);
  padding: 0.75rem 0.85rem;
  color: var(--text);
}

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

button {
  border: 0;
  border-radius: 999px;
  padding: 0.8rem 1.2rem;
  background: var(--accent);
  color: white;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease;
  white-space: nowrap;
}
button:hover { background: var(--accent-strong); transform: translateY(-1px); }
button:disabled { background: #a8b6c4; cursor: not-allowed; transform: none; }
button.secondary { background: #dfe8ef; color: var(--text); }
button.secondary:hover { background: #ccd8e2; }
button.danger { background: var(--danger); }
button.danger:hover { background: #8a2c2c; }
button.danger-secondary { background: #fde8e8; color: var(--danger); }
button.danger-secondary:hover { background: #f8cccc; }

/* ─── Action + badge rows ────────────────────────────────────────────────── */

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.badge-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  background: #dfe8ef;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.72rem;
}
.status-badge.previewing,
.status-badge.building   { background: #fff0c7; }
.status-badge.preview_ready,
.status-badge.build_ready { background: #d8f4e7; }
.status-badge.error      { background: #ffd8d8; color: var(--danger); }
.status-badge.cancelled  { background: #ede8ff; color: #5b3ea8; }
.status-badge.queued     { background: #fff6e0; color: #8a6000; }

/* ─── Spinner ────────────────────────────────────────────────────────────── */

.spinner {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
.spinner.hidden { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.smart-suggestions-loading {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0.75rem 0;
  color: var(--muted);
}

.smart-suggestions-mode-field {
  min-width: 12rem;
  max-width: 14rem;
}

.smart-suggestions-applied {
  margin-top: 0.8rem;
  border: 1px solid rgba(28, 124, 111, 0.2);
  border-radius: 14px;
  padding: 0.8rem 0.9rem;
  background: rgba(236, 251, 247, 0.92);
}

.smart-suggestions-applied strong {
  display: block;
  margin-bottom: 0.3rem;
}

.smart-suggestions-applied ul {
  margin: 0;
  padding-left: 1.1rem;
  display: grid;
  gap: 0.3rem;
}

.smart-suggestions-applied p {
  margin-top: 0.45rem;
  color: var(--muted);
}

.smart-suggestions-loading .spinner {
  display: inline-block;
}

.smart-suggestions-content {
  display: grid;
  gap: 1rem;
  margin: 1rem 0;
}

.smart-suggestions-title {
  margin: 0 0 0.55rem;
  font-size: 0.86rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.smart-suggestions-list,
.smart-suggestions-settings {
  display: grid;
  gap: 0.7rem;
}

.smart-suggestion-card,
.smart-setting-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.85rem;
  background: rgba(255, 255, 255, 0.84);
}

.smart-suggestion-card.warning {
  border-color: rgba(169, 57, 57, 0.26);
  background: rgba(255, 241, 241, 0.92);
}

.smart-suggestion-card.ok {
  border-color: rgba(28, 124, 111, 0.22);
  background: rgba(236, 251, 247, 0.92);
}

.smart-suggestion-top,
.smart-setting-top {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: baseline;
}

.smart-suggestion-label,
.smart-setting-label {
  font-weight: 600;
}

.smart-suggestion-confidence {
  font-size: 0.84rem;
  color: var(--muted);
}

.smart-confidence-bar {
  height: 0.42rem;
  margin-top: 0.6rem;
  border-radius: 999px;
  background: rgba(29, 40, 51, 0.08);
  overflow: hidden;
}

.smart-confidence-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #f3b14b 0%, #d76b55 100%);
}

.smart-suggestion-card.ok .smart-confidence-fill {
  background: linear-gradient(90deg, #68bea4 0%, #1c7c6f 100%);
}

.smart-setting-value {
  color: var(--accent-strong);
  font-weight: 600;
}

.smart-suggestions-notes {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--muted);
  display: grid;
  gap: 0.35rem;
}

/* ─── Stats chips ────────────────────────────────────────────────────────── */

.stats-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
  min-height: 1.5rem;
}

.admin-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.admin-toolbar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.admin-stat {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.85rem;
  background: rgba(255, 255, 255, 0.82);
}

.admin-stat strong {
  display: block;
  font-size: 1.2rem;
  margin-top: 0.2rem;
}

.admin-split {
  grid-template-columns: 0.95fr 1.4fr;
}

.admin-list {
  display: grid;
  gap: 0.6rem;
}

.admin-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.86);
}

.admin-item strong,
.admin-item span {
  display: block;
}

.admin-item span {
  color: var(--muted);
  font-size: 0.84rem;
  margin-top: 0.15rem;
}

.admin-item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.7rem;
}

.admin-item-actions button {
  padding: 0.45rem 0.8rem;
  font-size: 0.82rem;
}
.stat-chip {
  background: rgba(28, 124, 111, 0.10);
  color: var(--accent-strong);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
}

/* ─── Job list ───────────────────────────────────────────────────────────── */

.job-list { display: grid; gap: 0.75rem; }

.job-card {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.85rem;
  background: rgba(248, 250, 252, 0.95);
  cursor: pointer;
  color: var(--text);
  text-align: left;
}
.job-card.active  { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(28, 124, 111, 0.12); }
.job-card:hover   { background: #ffffff; }
.job-card h3      { margin: 0 0 0.25rem; font-size: 0.98rem; }
.job-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.82rem;
}

/* ─── Settings layout (form + sticky SVG preview) ───────────────────────── */

.settings-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  align-items: start;
}

@media (min-width: 960px) {
  .settings-layout {
    grid-template-columns: 1fr 17rem;
  }
}

.settings-form-col {
  min-width: 0;
}

.settings-preview-col {
  position: sticky;
  top: 5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.settings-svg-preview {
  border-radius: 14px;
  overflow: hidden;
  background-color: #e8eef2;
  background-image: repeating-conic-gradient(#cdd6de 0% 25%, #e8eef2 0% 50%);
  background-size: 20px 20px;
  border: 1px solid var(--line);
  min-height: 12rem;
  display: flex;
  position: relative;
  align-items: center;
  justify-content: center;
}

.settings-preview-placeholder {
  padding: 1.5rem 1rem;
  text-align: center;
  font-size: 0.82rem;
  line-height: 1.55;
}

.settings-preview-img {
  display: block;
  width: 100%;
  object-fit: contain;
  max-height: clamp(14rem, 40vh, 32rem);
}

.settings-preview-note {
  font-size: 0.76rem;
  text-align: center;
  line-height: 1.4;
}

.settings-quick-preview {
  font-size: 0.82rem;
  padding: 0.5rem 0.9rem;
  white-space: nowrap;
}

.settings-dirty-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.72rem;
  font-weight: 600;
  color: #8a6000;
  background: #fff6e0;
  border: 1px solid #f0d080;
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  animation: dirty-pulse 2s ease-in-out infinite;
}
@keyframes dirty-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.6; }
}

/* ─── Settings top bar (Mode + Clicker Size) ─────────────────────────────── */

.settings-top-bar {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.75rem 0 0.75rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 0.75rem;
}

.settings-top-mode {
  flex: 0 0 auto;
  min-width: 10rem;
}

.settings-top-size {
  flex: 1 1 auto;
  min-width: 14rem;
}

/* ─── Settings ───────────────────────────────────────────────────────────── */

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.9rem 1rem;
  min-width: 0;
}

.settings-section {
  border: none;
  border-top: 1px solid var(--line);
  margin-top: 0.75rem;
  padding-top: 0.75rem;
}

.settings-section-toggle {
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
  list-style: none;
  margin-bottom: 0.75rem;
  user-select: none;
}
.settings-section-toggle::-webkit-details-marker { display: none; }
.settings-section-toggle::before { content: "▶ "; font-size: 0.7rem; }
details[open] .settings-section-toggle::before { content: "▼ "; }
.settings-section-toggle:hover { color: var(--text); }

/* ─── Clicker Size presets ────────────────────────────────────────────────── */

.clicker-size-field {
  grid-column: span 1;
}

.size-preset-row {
  display: flex;
  gap: 0.4rem;
}

.size-preset-btn {
  flex: 1;
  padding: 0.5rem 0.6rem;
  font-size: 0.82rem;
  border-radius: 10px;
  background: #dfe8ef;
  color: var(--text);
  border: 1.5px solid transparent;
  transition: background 130ms, border-color 130ms, transform 130ms;
}
.size-preset-btn:hover { background: #ccd8e2; transform: translateY(-1px); }
.size-preset-btn.active {
  background: rgba(28, 124, 111, 0.13);
  border-color: var(--accent);
  color: var(--accent-strong);
}

.size-mm-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.size-mm-row input { flex: 1; }
.size-mm-unit {
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
}

/* ─── Segmented mode buttons ─────────────────────────────────────────────── */

.seg-btn-group {
  display: flex;
  border-radius: 12px;
  overflow: hidden;
  border: 1.5px solid var(--line);
  background: var(--surface-strong);
  gap: 0;
}

.seg-btn {
  flex: 1;
  border-radius: 0;
  padding: 0.6rem 0.7rem;
  font-size: 0.85rem;
  background: transparent;
  color: var(--muted);
  border: 0;
  border-right: 1px solid var(--line);
  transition: background 130ms, color 130ms;
}
.seg-btn:last-child { border-right: 0; }
.seg-btn:hover { background: rgba(28, 124, 111, 0.06); color: var(--text); transform: none; }
.seg-btn.active {
  background: rgba(28, 124, 111, 0.13);
  color: var(--accent-strong);
  font-weight: 600;
}

/* ─── Input with inline unit label ───────────────────────────────────────── */

.input-with-unit {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.input-with-unit input { flex: 1; }
.field-unit {
  font-size: 0.82rem;
  color: var(--muted);
  white-space: nowrap;
}

/* ─── Switch Placement ───────────────────────────────────────────────────── */

.switch-placement-body {
  display: grid;
  grid-template-columns: 18rem 1fr;
  gap: 1.25rem;
  align-items: start;
}

.switch-controls {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.switch-hint {
  font-size: 0.82rem;
  line-height: 1.45;
  margin-top: 0.25rem;
}

.switch-action-row {
  display: flex;
  gap: 0.5rem;
}
.switch-action-row button {
  font-size: 0.82rem;
  padding: 0.5rem 0.9rem;
}

.switch-notes {
  font-size: 0.8rem;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  border-top: 1px solid var(--line);
  padding-top: 0.75rem;
  margin-top: 0.1rem;
}

.switch-preview-wrap {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: #0f1c24;
  border: 1px solid #16303a;
  min-height: 12rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.switch-layout-empty {
  padding: 2rem;
  text-align: center;
  font-size: 0.88rem;
}

.switch-layout-svg {
  width: 100%;
  height: 22rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.switch-layout-svg svg {
  width: 100%;
  height: 100%;
}

.switch-layout-svg.hidden { display: none; }

@media (max-width: 860px) {
  .switch-placement-body {
    grid-template-columns: 1fr;
  }
}

/* ─── Color & Region Insights ────────────────────────────────────────────── */

/* Side-by-side layout when a spotlight is open */
.insights-body {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  align-items: start;
}
.insights-body.spotlight-open {
  grid-template-columns: minmax(11rem, 1fr) minmax(14rem, 1.5fr);
}
.insights-body.spotlight-open .region-spotlight {
  position: sticky;
  top: 5rem; /* clear the summary sticky panel */
}

.insights-click-hint {
  font-size: 0.78rem;
  white-space: nowrap;
}

.spotlight-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.55rem;
}
.spotlight-label {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.spotlight-close-btn {
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  flex-shrink: 0;
}

.color-breakdown {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.color-row,
.region-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.6rem;
  border-radius: 10px;
  transition: background 120ms;
}
.color-row.clickable,
.region-row.clickable { cursor: pointer; }
.color-row.clickable:hover,
.region-row.clickable:hover { background: rgba(28, 124, 111, 0.07); }
.color-row.active,
.region-row.active { background: rgba(28, 124, 111, 0.13); }

.color-swatch {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  border: 1px solid rgba(0,0,0,0.12);
  flex-shrink: 0;
}
.color-swatch.small {
  width: 13px;
  height: 13px;
  border-radius: 4px;
}

.color-hex {
  font-family: "SFMono-Regular", "Menlo", monospace;
  font-size: 0.82rem;
  color: var(--muted);
  width: 5.5rem;
  flex-shrink: 0;
}

.color-bar-wrap {
  flex: 1;
  height: 7px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.color-bar {
  height: 100%;
  border-radius: 999px;
  opacity: 0.75;
  transition: width 300ms ease;
}

.color-pct {
  font-size: 0.82rem;
  color: var(--muted);
  width: 3rem;
  text-align: right;
  flex-shrink: 0;
}

.region-table-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem 0.2rem;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-top: 1px solid var(--line);
  margin-top: 0.5rem;
}
.region-table-header span:first-child { flex: 1; }
.region-table-header span:nth-child(2) { width: 13px; }
.region-table-header span:last-child { width: 3rem; text-align: right; }

.region-id-label {
  font-family: "SFMono-Regular", "Menlo", monospace;
  font-size: 0.78rem;
  color: var(--muted);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.region-spotlight { margin-top: 0; }
.spotlight-img {
  display: block;
  width: 100%;
  height: clamp(16rem, 45vh, 36rem);
  object-fit: contain;
  object-position: center;
  border-radius: 14px;
  background-color: #e8eef2;
  background-image: repeating-conic-gradient(#cdd6de 0% 25%, #e8eef2 0% 50%);
  background-size: 20px 20px;
  border: 1px solid var(--line);
}

/* ─── Preview grid ───────────────────────────────────────────────────────── */

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: 1rem;
}

/* Featured layout: source is large on the left, others stack on the right */
.preview-grid.preview-grid-featured {
  grid-template-columns: 1.75fr 1fr;
  align-items: start;
}
.preview-grid.preview-grid-featured .preview-card.preview-source {
  grid-row: 1 / span 2;
}
.preview-grid.preview-grid-featured .preview-card.preview-source img {
  height: clamp(20rem, 55vh, 46rem);
}
.preview-grid.preview-grid-featured .preview-card:not(.preview-source) img {
  height: 14rem;
}

.preview-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  background: white;
}
.preview-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.88rem;
  font-weight: 600;
}
.preview-card-open-btn {
  font-size: 0.75rem;
  padding: 0.25rem 0.55rem;
  border-radius: 8px;
  background: rgba(28,124,111,0.1);
  color: var(--accent-strong);
  border: none;
  cursor: pointer;
  transition: background 120ms;
}
.preview-card-open-btn:hover {
  background: rgba(28,124,111,0.2);
  transform: none;
}
.preview-card img {
  display: block;
  width: 100%;
  height: 18rem;
  object-fit: contain;
  object-position: center;
  background-color: #e8eef2;
  background-image: repeating-conic-gradient(#cdd6de 0% 25%, #e8eef2 0% 50%);
  background-size: 20px 20px;
}

/* ─── Trace-preview loading bar ──────────────────────────────────────────── */

.trace-preview-bar-wrap {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: rgba(0,0,0,0.08);
  border-radius: 0 0 14px 14px;
  overflow: hidden;
  opacity: 0;
  transition: opacity 200ms;
}
.trace-preview-bar-wrap.visible {
  opacity: 1;
}
.trace-preview-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
  transition: width 600ms ease-out;
}
.trace-preview-bar.indeterminate {
  width: 40%;
  animation: trace-bar-slide 1.2s ease-in-out infinite alternate;
}
@keyframes trace-bar-slide {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}

/* ─── Split panel ────────────────────────────────────────────────────────── */

.split-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

/* ─── Drop zone ──────────────────────────────────────────────────────────── */

.drop-zone {
  position: relative;
  border: 2px dashed var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  transition: border-color 150ms, background 150ms;
  margin-bottom: 0.5rem;
  overflow: hidden;
}
.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--accent-strong);
  background: rgba(28, 124, 111, 0.06);
}
.drop-zone.drag-over { border-style: solid; }

.drop-zone-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 1.1rem 1rem;
  pointer-events: none;
}
.drop-zone-icon {
  font-size: 1.5rem;
  line-height: 1;
  color: var(--accent-strong);
  opacity: 0.7;
}
.drop-zone-text {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}
.drop-zone-sub {
  font-size: 0.75rem;
  color: var(--muted);
}

/* Hide the real file input but keep it accessible */
.drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  font-size: 0; /* prevent any flash */
}

.upload-filename {
  font-size: 0.78rem;
  text-align: center;
  margin: 0 0 0.4rem;
  word-break: break-all;
}

/* ─── Downloads ──────────────────────────────────────────────────────────── */

.download-list { display: flex; flex-wrap: wrap; gap: 0.65rem; }

.download-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  text-decoration: none;
  color: var(--accent-strong);
  font-weight: 600;
  font-size: 0.88rem;
  padding: 0.55rem 1rem 0.55rem 0.75rem;
  border-radius: 10px;
  background: rgba(28, 124, 111, 0.08);
  border: 1px solid rgba(28, 124, 111, 0.2);
  transition: background 120ms, border-color 120ms;
}
.download-btn:hover {
  background: rgba(28, 124, 111, 0.15);
  border-color: rgba(28, 124, 111, 0.4);
}
.dl-icon { font-size: 1rem; }
.dl-label { }
.dl-ext {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  background: rgba(28, 124, 111, 0.12);
  color: var(--accent-strong);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

.build-log-head {
  align-items: center;
}

.build-log-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.ml-tools-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

.ml-tools-toolbar button {
  white-space: nowrap;
}

.case-review-form {
  display: grid;
  gap: 0.9rem;
}

.case-review-issues {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.55rem 0.8rem;
}

.case-review-issue {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.9rem;
}

.case-review-issue input {
  width: auto;
  margin: 0;
}

/* ─── Live log badge ─────────────────────────────────────────────────────── */

.live-badge {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #c0392b;
  animation: live-pulse 1.4s ease-in-out infinite;
}
@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.35; }
}

/* ─── Upload thumbnail ───────────────────────────────────────────────────── */

.upload-thumb-wrap {
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  margin-bottom: 0.5rem;
  text-align: center;
}
.upload-thumb {
  display: block;
  width: 100%;
  max-height: 140px;
  object-fit: contain;
  padding: 0.4rem;
}

/* ─── Error banner ───────────────────────────────────────────────────────── */

.error-banner {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  background: #fff0f0;
  border: 1px solid #f5c6c6;
  border-radius: 12px;
  padding: 0.85rem 1rem;
  color: #b91c1c;
  font-size: 0.88rem;
  line-height: 1.5;
  margin-bottom: 0.5rem;
}
.error-banner-icon {
  font-size: 1rem;
  flex-shrink: 0;
  margin-top: 0.1rem;
}
.error-banner span:nth-child(2) { flex: 1; word-break: break-word; }
.error-banner-close {
  background: none;
  border: none;
  color: #b91c1c;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0 0.2rem;
  opacity: 0.6;
  flex-shrink: 0;
  line-height: 1;
}
.error-banner-close:hover { opacity: 1; }

/* ─── Warnings ───────────────────────────────────────────────────────────── */

.warning-list { display: grid; gap: 0.65rem; }

.warning-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem;
  background: rgba(255, 255, 255, 0.88);
}
.warning-item.info    { border-color: #c9dbf2; }
.warning-item.warning { border-color: #eed292; }
.warning-item.error   { border-color: #efb2b2; }
.warning-item p       { margin: 0.2rem 0 0; font-size: 0.88rem; color: var(--muted); }

/* ─── Log ────────────────────────────────────────────────────────────────── */

.log-output {
  margin: 0;
  min-height: 12rem;
  max-height: 22rem;
  overflow: auto;
  border-radius: 14px;
  border: 1px solid #16303a;
  background: #0f1c24;
  color: #d8efe9;
  padding: 1rem;
  font-family: "SFMono-Regular", "Menlo", monospace;
  font-size: 0.82rem;
  line-height: 1.45;
}

/* ─── Toast notifications ────────────────────────────────────────────────── */

#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column-reverse;
  gap: 0.6rem;
  z-index: 100;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.75rem 1rem;
  box-shadow: 0 8px 24px rgba(20,37,53,0.14);
  font-size: 0.88rem;
  min-width: 14rem;
  max-width: 22rem;
  pointer-events: auto;
  animation: toast-in 220ms ease forwards;
}
.toast.toast-out {
  animation: toast-out 200ms ease forwards;
}
.toast.toast-success { border-color: rgba(28,124,111,0.35); }
.toast.toast-error   { border-color: rgba(169,57,57,0.35); background: #fff8f8; }
.toast.toast-info    { border-color: rgba(60,120,200,0.3); }
.toast-icon { font-size: 1rem; flex-shrink: 0; }
.toast-text { flex: 1; line-height: 1.4; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(8px); }
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 1100px) {
  .page-shell {
    grid-template-columns: 1fr;
  }
  .summary-panel {
    position: static;
  }
  .split-panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .insights-body.spotlight-open {
    grid-template-columns: 1fr;
  }
  .insights-body.spotlight-open .region-spotlight {
    position: static;
  }
  .preview-grid.preview-grid-featured {
    grid-template-columns: 1fr;
  }
  .preview-grid.preview-grid-featured .preview-card.preview-source {
    grid-row: auto;
  }
  .preview-grid.preview-grid-featured .preview-card.preview-source img,
  .preview-grid.preview-grid-featured .preview-card:not(.preview-source) img {
    height: 18rem;
  }
}

@media (max-width: 600px) {
  .preview-grid {
    grid-template-columns: 1fr;
  }
  .action-row {
    flex-direction: column;
  }
  .action-row button {
    width: 100%;
  }
  #toast-container {
    bottom: 0.75rem;
    right: 0.75rem;
    left: 0.75rem;
  }
  .toast {
    max-width: 100%;
  }
}
