/* MeshForge workspace — dark, utilitarian, tool-shaped. */

:root {
  --bg:        #0f1116;
  --bg-panel:  #14161d;
  --bg-inset:  #1a1d26;
  --bg-raised: #21252f;
  --line:      #262a35;
  --line-hi:   #343a49;

  --text:      #e6e9f0;
  --text-dim:  #98a0b2;
  --text-mute: #6a7285;

  --accent:      #ff8a3d;
  --accent-hi:   #ffa163;
  --accent-wash: rgba(255, 138, 61, 0.13);

  --danger:      #ff6259;
  --danger-wash: rgba(255, 98, 89, 0.12);

  /* Job status palette — one hue per lifecycle stage. */
  --s-queued:     #7c8598;
  --s-generating: #56a8ff;
  --s-prepping:   #a68bff;
  --s-ready:      #35cf87;
  --s-printing:   #ff8a3d;
  --s-done:       #2f9f74;
  --s-error:      #ff6259;

  --radius:    6px;
  --radius-lg: 9px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --rail: 336px;
}

* { box-sizing: border-box; }

/* The UI toggles panes with the `hidden` attribute, and several of them carry
   an explicit `display` — which would otherwise win over the UA's [hidden]. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.num, .mono { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12px; }

::selection { background: var(--accent-wash); }

/* ── Top bar ─────────────────────────────────────────────────────────────── */

.topbar {
  flex: 0 0 auto;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-panel);
}

.brand { display: flex; align-items: baseline; gap: 9px; }
.brand-mark { width: 19px; height: 19px; color: var(--accent); align-self: center; }
.brand-name { font-weight: 620; letter-spacing: -0.01em; }
.brand-sub {
  color: var(--text-mute);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.topbar-right { display: flex; align-items: center; gap: 10px; }

.poll-indicator {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-mute);
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 100px;
}
.poll-indicator.is-hot { color: var(--accent); border-color: rgba(255, 138, 61, 0.35); }

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

.layout {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
}

.rail {
  border-right: 1px solid var(--line);
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.panel { padding: 14px; border-bottom: 1px solid var(--line); }
.panel-grow { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; border-bottom: 0; }

.panel-title {
  margin: 0 0 12px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-mute);
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-count {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-dim);
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 100px;
  padding: 1px 6px;
  letter-spacing: 0;
}

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

.form { display: flex; flex-direction: column; gap: 12px; }

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  padding: 2px;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.seg-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 13px;
  padding: 6px 0;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.is-active { background: var(--bg-raised); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-hi); }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-row { display: grid; grid-template-columns: 1fr 118px; gap: 10px; }
.field-narrow { min-width: 0; }

.field-label {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-mute);
}

.input, .select, .textarea {
  width: 100%;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  padding: 7px 9px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.textarea { resize: vertical; min-height: 76px; line-height: 1.45; }

.input:focus, .select:focus, .textarea:focus {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-wash);
}

.select {
  appearance: none;
  padding-right: 26px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5 6 8l3-3.5' fill='none' stroke='%2398a0b2' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 12px;
  cursor: pointer;
}
.select option:disabled { color: var(--text-mute); }

.input-suffix { position: relative; }
.input-suffix .suffix {
  position: absolute;
  right: 9px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: var(--text-mute);
  pointer-events: none;
}
.input-suffix .input { padding-right: 30px; }
.input[type="number"] { -moz-appearance: textfield; }
.input[type="number"]::-webkit-outer-spin-button,
.input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ── Dropzone ────────────────────────────────────────────────────────────── */

.dropzone {
  display: block;
  border: 1px dashed var(--line-hi);
  border-radius: var(--radius);
  background: var(--bg-inset);
  padding: 16px 12px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.dropzone:hover { border-color: var(--text-mute); }
.dropzone.is-dragover {
  border-color: var(--accent);
  background: var(--accent-wash);
}
.dropzone.has-file { padding: 10px; border-style: solid; cursor: default; }

.dropzone-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--text-dim);
  pointer-events: none;
}
.dropzone-icon { width: 22px; height: 22px; color: var(--text-mute); margin-bottom: 2px; }
.dropzone-label { font-size: 13px; }
.dropzone-hint { font-size: 11.5px; color: var(--text-mute); }

.dropzone-filled { display: flex; align-items: center; gap: 10px; }
.file-preview {
  width: 46px; height: 46px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--bg-raised);
  flex: 0 0 auto;
}
.file-meta { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
.file-name {
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-size { font-size: 11px; color: var(--text-mute); font-variant-numeric: tabular-nums; }

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

.btn {
  appearance: none;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: var(--bg-raised);
  border: 1px solid var(--line-hi);
  border-radius: var(--radius);
  padding: 7px 12px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s, opacity 0.12s;
}
.btn:hover:not(:disabled) { background: #272c37; border-color: #3f4757; }
.btn:focus-visible { outline: 0; box-shadow: 0 0 0 3px var(--accent-wash); border-color: var(--accent); }
.btn:disabled { opacity: 0.42; cursor: not-allowed; }

.btn-block { display: block; width: 100%; }
.btn-sm { font-size: 12px; padding: 4px 9px; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #21140a;
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hi); border-color: var(--accent-hi); }

.btn-ghost { background: transparent; border-color: var(--line-hi); color: var(--text-dim); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-raised); color: var(--text); }

.btn-danger-ghost { background: transparent; border-color: var(--line-hi); color: var(--danger); }
.btn-danger-ghost:hover:not(:disabled) { background: var(--danger-wash); border-color: var(--danger); }

.form-error {
  margin: 0;
  font-size: 12.5px;
  color: var(--danger);
  background: var(--danger-wash);
  border: 1px solid rgba(255, 98, 89, 0.3);
  border-radius: var(--radius);
  padding: 7px 9px;
}

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

.job-list {
  list-style: none;
  margin: 0 -6px;
  padding: 0 6px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.job {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 3px 8px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 8px 9px;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: background 0.12s, border-color 0.12s;
}
.job:hover { background: var(--bg-inset); }
.job.is-selected { background: var(--bg-inset); border-color: var(--line-hi); }
.job:focus-visible { outline: 0; border-color: var(--accent); }

.job-label {
  grid-column: 1;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.job-label.is-untitled { color: var(--text-mute); font-style: italic; }
.job .chip { grid-column: 2; grid-row: 1; align-self: start; }
.job-sub {
  grid-column: 1 / -1;
  font-size: 11px;
  color: var(--text-mute);
  display: flex;
  gap: 6px;
  font-variant-numeric: tabular-nums;
}
.job-sub .dot { color: var(--line-hi); }

/* ── Status chips ────────────────────────────────────────────────────────── */

.chip {
  --chip: var(--s-queued);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--chip);
  border: 1px solid color-mix(in srgb, var(--chip) 35%, transparent);
  background: color-mix(in srgb, var(--chip) 12%, transparent);
  border-radius: 100px;
  padding: 2px 8px 2px 6px;
  white-space: nowrap;
}
.chip::before {
  content: "";
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}
.chip.is-live::before { animation: pulse 1.4s ease-in-out infinite; }

.chip[data-status="queued"]     { --chip: var(--s-queued); }
.chip[data-status="generating"] { --chip: var(--s-generating); }
.chip[data-status="prepping"]   { --chip: var(--s-prepping); }
.chip[data-status="ready"]      { --chip: var(--s-ready); }
.chip[data-status="printing"]   { --chip: var(--s-printing); }
.chip[data-status="done"]       { --chip: var(--s-done); }
.chip[data-status="error"]      { --chip: var(--s-error); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.25; }
}

.empty-note {
  margin: 6px 0 0;
  font-size: 12.5px;
  color: var(--text-mute);
}

/* ── Workspace ───────────────────────────────────────────────────────────── */

.workspace { min-width: 0; min-height: 0; display: flex; flex-direction: column; }

.placeholder {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-mute);
}
.placeholder-icon { width: 46px; height: 46px; opacity: 0.5; }
.placeholder p { margin: 0; font-size: 13.5px; }

.detail { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

.detail-head {
  flex: 0 0 auto;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
}
.detail-head-main { display: flex; align-items: center; gap: 10px; min-width: 0; }
.detail-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.detail-title.is-untitled { color: var(--text-dim); font-style: italic; font-weight: 500; }

.detail-meta {
  display: flex;
  gap: 22px;
  margin: 0;
  flex: 0 0 auto;
}
.detail-meta div { display: flex; flex-direction: column; gap: 1px; }
.detail-meta dt {
  font-size: 10px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-mute);
}
.detail-meta dd { margin: 0; font-size: 12.5px; color: var(--text-dim); }

.detail-body {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 296px;
}

/* ── Viewer ──────────────────────────────────────────────────────────────── */

.viewer-wrap { position: relative; min-width: 0; background: #111319; }
.viewer { position: absolute; inset: 0; }
.viewer canvas { display: block; width: 100%; height: 100%; }

.viewer-reframe { position: absolute; top: 12px; right: 12px; backdrop-filter: blur(6px); }

.viewer-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(17, 19, 25, 0.86);
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  padding: 20px;
}

.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--line-hi);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ── Sidecar ─────────────────────────────────────────────────────────────── */

.sidecar {
  border-left: 1px solid var(--line);
  background: var(--bg-panel);
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 12px;
}
.card-title {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-mute);
}
.card-error { border-color: rgba(255, 98, 89, 0.35); background: var(--danger-wash); }
.card-error .card-title { color: var(--danger); }

.error-text {
  margin: 0;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.5;
  color: #ffb4ae;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
  overflow-y: auto;
}

.report { width: 100%; border-collapse: collapse; }
.report th {
  text-align: left;
  font-weight: 400;
  color: var(--text-mute);
  font-size: 12.5px;
  padding: 4px 0;
}
.report td {
  text-align: right;
  font-size: 12.5px;
  padding: 4px 0;
  font-variant-numeric: tabular-nums;
}
.report tr + tr th, .report tr + tr td { border-top: 1px solid var(--line); }

.flag-yes { color: var(--s-ready); font-weight: 600; }
.flag-no  { color: var(--danger); font-weight: 600; }

.actions { display: flex; flex-direction: column; gap: 7px; }

.print-state {
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 1.45;
  border-radius: var(--radius);
  padding: 7px 9px;
  border: 1px solid var(--line-hi);
  background: var(--bg-raised);
  color: var(--text-dim);
}
.print-state.is-dry { border-color: rgba(86, 168, 255, 0.35); color: #a9cffb; background: rgba(86, 168, 255, 0.1); }
.print-state.is-live { border-color: rgba(255, 138, 61, 0.45); color: var(--accent-hi); background: var(--accent-wash); }

/* ── Overlays & modals ───────────────────────────────────────────────────── */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 9, 13, 0.72);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}

.modal {
  width: 100%;
  max-width: 420px;
  background: var(--bg-panel);
  border: 1px solid var(--line-hi);
  border-radius: 10px;
  padding: 18px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-title { margin: 0; font-size: 15px; font-weight: 620; }
.modal-body { margin: 0; font-size: 13px; line-height: 1.55; color: var(--text-dim); }
.modal-body code {
  font-family: var(--mono);
  font-size: 11.5px;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 4px;
}
.modal-body p { margin: 0 0 8px; }
.modal-body p:last-child { margin-bottom: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.callout {
  border-radius: var(--radius);
  padding: 9px 10px;
  font-size: 12.5px;
  line-height: 1.5;
  border: 1px solid var(--line-hi);
  background: var(--bg-inset);
  color: var(--text-dim);
}
.callout strong { color: var(--text); }
.callout.is-dry { border-color: rgba(86, 168, 255, 0.35); background: rgba(86, 168, 255, 0.1); }
.callout.is-dry strong { color: #a9cffb; }
.callout.is-live { border-color: rgba(255, 138, 61, 0.45); background: var(--accent-wash); }
.callout.is-live strong { color: var(--accent-hi); }
.callout.is-danger { border-color: rgba(255, 98, 89, 0.35); background: var(--danger-wash); }
.callout.is-danger strong { color: #ffb4ae; }

/* ── Toasts ──────────────────────────────────────────────────────────────── */

.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 60;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  max-width: min(380px, calc(100vw - 32px));
}

.toast {
  background: var(--bg-raised);
  border: 1px solid var(--line-hi);
  border-left: 3px solid var(--text-mute);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4);
  animation: toast-in 0.16s ease-out;
  word-break: break-word;
}
.toast.is-error { border-left-color: var(--danger); }
.toast.is-ok { border-left-color: var(--s-ready); }
.toast.is-info { border-left-color: var(--s-generating); }
.toast-title { display: block; font-weight: 600; margin-bottom: 2px; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ── Narrow viewports ────────────────────────────────────────────────────── */

@media (max-width: 1080px) {
  .detail-body { grid-template-columns: minmax(0, 1fr) 250px; }
  .detail-meta { gap: 16px; }
}

@media (max-width: 900px) {
  body { overflow: auto; }
  .layout { grid-template-columns: 1fr; }
  .rail { border-right: 0; border-bottom: 1px solid var(--line); }
  .detail-body { grid-template-columns: 1fr; }
  .viewer-wrap { height: 60vh; }
  .sidecar { border-left: 0; border-top: 1px solid var(--line); }
  .detail-head { flex-direction: column; gap: 12px; }
}
