:root {
  color-scheme: dark;

  /* Graphite canvas, tinted a hair toward indigo so neutrals feel intentional */
  --bg: oklch(0.155 0.008 285);
  --surface: oklch(0.194 0.008 285);
  --surface-raised: oklch(0.224 0.009 285);
  --sidebar: oklch(0.134 0.009 285);
  --well: oklch(0.118 0.008 285);

  --text: oklch(0.95 0.006 285);
  --text-secondary: oklch(0.75 0.01 285);
  --text-muted: oklch(0.605 0.012 285);

  --border: oklch(0.305 0.01 285);
  --border-subtle: oklch(0.252 0.009 285);

  /* Single restrained accent, reserved for primary action / selection / focus */
  --accent: oklch(0.62 0.17 274);
  --accent-hover: oklch(0.675 0.17 274);
  --accent-active: oklch(0.565 0.16 274);
  --accent-soft: oklch(0.62 0.17 274 / 0.15);
  --on-accent: oklch(0.99 0.01 274);

  --danger: oklch(0.66 0.19 25);
  --danger-border: oklch(0.5 0.13 25);
  --success: oklch(0.74 0.15 155);
  --warning: oklch(0.8 0.13 80);

  --radius-sm: 7px;
  --radius-md: 11px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 2px oklch(0.05 0.01 285 / 0.4);
  --shadow-md: 0 4px 16px oklch(0.05 0.01 285 / 0.45);
  --shadow-lg: 0 20px 50px -12px oklch(0.03 0.01 285 / 0.7);

  --ring: 0 0 0 3px oklch(0.62 0.17 274 / 0.35);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SFMono-Regular", Menlo, monospace;
  --sidebar-width: 248px;
  --content-max: 960px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, textarea { font: inherit; color: inherit; }

.hidden { display: none !important; }

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

/* Restrained, on-theme scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: var(--border);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: 999px;
}
*::-webkit-scrollbar-thumb:hover { background: oklch(0.4 0.012 285); background-clip: content-box; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(60% 50% at 50% -5%, oklch(0.62 0.17 274 / 0.12), transparent 70%),
    var(--bg);
}

.login-panel {
  width: min(430px, 100%);
  padding: 2.25rem;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.login-brand h1 {
  margin: 1rem 0 0.4rem;
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.login-brand p {
  margin: 0;
  color: var(--text-secondary);
  max-width: 42ch;
  line-height: 1.55;
}

.login-form { margin-top: 1.75rem; }

.login-form label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.login-form .btn { margin-top: 1rem; }

/* ---------- Brand mark ---------- */
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  color: var(--on-accent);
  background: linear-gradient(160deg, var(--accent-hover), var(--accent-active));
  box-shadow: 0 2px 8px oklch(0.62 0.17 274 / 0.4), inset 0 1px 0 oklch(1 0 0 / 0.2);
}
.brand-mark svg { width: 22px; height: 22px; }

/* ---------- Shell ---------- */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid var(--border-subtle);
  padding: 1.125rem 0.875rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.25rem 0.5rem 1.125rem;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 0.875rem;
}

.brand-text { line-height: 1.2; }
.brand-text strong { display: block; font-size: 0.95rem; font-weight: 600; letter-spacing: -0.01em; }
.brand-text span { color: var(--text-muted); font-size: 0.8rem; }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 450;
  text-align: left;
  cursor: pointer;
  transition: background 160ms var(--ease), color 160ms var(--ease);
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--text-muted);
  transition: color 160ms var(--ease);
}

.nav-item:hover { background: oklch(0.2 0.01 285); color: var(--text); }
.nav-item:hover .nav-icon { color: var(--text-secondary); }

.nav-item:focus-visible { outline: none; box-shadow: var(--ring); }

.nav-item.active {
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 550;
}
.nav-item.active .nav-icon { color: var(--accent); }

.sidebar-footer {
  margin-top: auto;
  padding-top: 0.875rem;
  border-top: 1px solid var(--border-subtle);
}

.server-status {
  display: flex;
  gap: 0.625rem;
  align-items: flex-start;
  padding: 0.75rem;
  margin-bottom: 0.625rem;
  background: oklch(0.175 0.008 285);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}
.server-status-text { min-width: 0; }

.status-dot {
  width: 8px;
  height: 8px;
  margin-top: 0.32rem;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.status-dot.ready { background: var(--success); box-shadow: 0 0 0 3px oklch(0.74 0.15 155 / 0.18); }
.status-dot.loading { background: var(--warning); box-shadow: 0 0 0 3px oklch(0.8 0.13 80 / 0.18); animation: pulse 1.4s var(--ease) infinite; }
.status-dot.error { background: var(--danger); box-shadow: 0 0 0 3px oklch(0.66 0.19 25 / 0.18); }

@keyframes pulse { 50% { opacity: 0.4; } }

.status-line { font-size: 0.8125rem; font-weight: 500; }
.status-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Workspace ---------- */
.workspace { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  padding: 1.5rem 2.25rem 1.125rem;
  border-bottom: 1px solid var(--border-subtle);
  background: linear-gradient(var(--bg), oklch(0.165 0.008 285));
}

.eyebrow {
  margin: 0;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 500;
}

.topbar h2 {
  margin: 0.3rem 0 0;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.025em;
}

.content {
  padding: 1.75rem 2.25rem 3rem;
  width: 100%;
  max-width: var(--content-max);
}

.panel { display: none; animation: fade-in 260ms var(--ease); }
.panel.active { display: block; }

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

.panel-header { margin-bottom: 1.25rem; }
.panel-desc { margin: 0; color: var(--text-secondary); max-width: 60ch; }

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.panel-section { margin-bottom: 1.25rem; }
.panel-section.narrow { max-width: 580px; }

/* ---------- Fields ---------- */
.field-label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.field label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}

input, textarea {
  width: 100%;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  color: var(--text);
  transition: border-color 150ms var(--ease), box-shadow 150ms var(--ease), background 150ms var(--ease);
}
input[type="number"] { font-variant-numeric: tabular-nums; }
input::placeholder, textarea::placeholder { color: var(--text-muted); }

input:hover, textarea:hover { border-color: oklch(0.38 0.012 285); }
input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
  background: var(--surface);
}

.prompt-block { margin-bottom: 1rem; }
.prompt-input { min-height: 128px; resize: vertical; line-height: 1.55; }

.prompt-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.4rem;
}
.prompt-label-row .field-label { margin-bottom: 0; }
.prompt-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4rem;
}
.prompt-generate,
.prompt-enhance { display: inline-flex; align-items: center; gap: 0.4rem; }
.prompt-generate .btn-icon-sm,
.prompt-enhance .btn-icon-sm { width: 1rem; height: 1rem; }
.prompt-generate.is-busy,
.prompt-enhance.is-busy { opacity: 0.7; pointer-events: none; }
.prompt-context-field { margin-bottom: 0.85rem; }
.prompt-context-input { min-height: 4.5rem; }

.input-row { display: flex; gap: 0.625rem; }
.input-row input { flex: 1; }

/* ---------- Generate controls ---------- */
.controls {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.controls-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem 1.5rem;
}

.params-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.75rem;
  width: 100%;
}

.btn-generate {
  flex-shrink: 0;
  height: 2.6rem;
  padding-inline: 1.4rem;
}

.controls-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  width: 100%;
  padding-top: 0.15rem;
  border-top: 1px solid var(--border-subtle);
}

.controls-actions .gen-option {
  margin-right: 0.25rem;
}

.controls-actions .btn-generate {
  margin-left: auto;
}

@media (max-width: 900px) {
  .controls-actions .btn-generate {
    margin-left: 0;
    width: 100%;
  }
}

.gen-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.gen-option input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
  cursor: pointer;
}
.gen-option input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.generate-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) min(18rem, 32vw);
  gap: 1.25rem;
  align-items: start;
}
.generate-main { min-width: 0; }
.jobs-pane {
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 7rem);
  overflow: auto;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.jobs-pane-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.jobs-pane-title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
}
.jobs-pane-summary {
  margin: 0.25rem 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.jobs-pane-actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}
.jobs-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.jobs-item {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--well);
  cursor: pointer;
  transition: border-color 160ms var(--ease), box-shadow 160ms var(--ease);
}
.jobs-item:hover { border-color: var(--border); }
.jobs-item.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px color-mix(in oklch, var(--accent) 35%, transparent);
}
.jobs-item.is-running {
  border-color: color-mix(in oklch, var(--accent) 55%, var(--border-subtle));
}
.jobs-item.is-paused { opacity: 0.92; }
.jobs-item.is-done { opacity: 0.85; }
.jobs-item.is-error {
  border-color: color-mix(in oklch, var(--danger) 45%, var(--border-subtle));
}
.jobs-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.jobs-item-prompt {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--text-secondary);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.jobs-item-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.jobs-item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.jobs-status {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  white-space: nowrap;
}
.jobs-status.running { color: var(--accent); }
.jobs-status.paused { color: var(--text-secondary); }
.jobs-status.done { color: var(--success); }
.jobs-status.error { color: var(--danger); }
.jobs-empty {
  margin: 0;
  padding: 1rem 0.5rem;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-muted);
}
@media (max-width: 1100px) {
  .generate-layout { grid-template-columns: 1fr; }
  .jobs-pane { position: static; max-height: none; }
}

.settings-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  max-width: 620px;
  margin-bottom: 1.125rem;
}

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

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 550;
  font-size: 0.875rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 150ms var(--ease), border-color 150ms var(--ease),
    box-shadow 150ms var(--ease), transform 120ms var(--ease), opacity 150ms var(--ease);
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-icon { width: 16px; height: 16px; }

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 1px 2px oklch(0.05 0.01 285 / 0.4), inset 0 1px 0 oklch(1 0 0 / 0.12);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:active:not(:disabled) { background: var(--accent-active); }

.btn-secondary {
  background: var(--surface-raised);
  border-color: var(--border);
  color: var(--text);
}
.btn-secondary:hover:not(:disabled) { border-color: oklch(0.4 0.012 285); background: oklch(0.26 0.01 285); }

.btn-ghost {
  background: transparent;
  border-color: var(--border-subtle);
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) { background: oklch(0.2 0.01 285); color: var(--text); }

.btn-danger {
  background: transparent;
  border-color: var(--danger-border);
  color: var(--danger);
}
.btn-danger:hover:not(:disabled) { background: oklch(0.66 0.19 25 / 0.14); }

.btn-block { width: 100%; }
.btn-sm { padding: 0.4rem 0.7rem; font-size: 0.8rem; }

/* ---------- Feedback ---------- */
.feedback {
  min-height: 1.25rem;
  margin: 0.875rem 0 0;
  font-size: 0.875rem;
  color: var(--text-secondary);
}
.feedback.ok { color: var(--success); }
.feedback.error { color: var(--danger); }

.gen-progress {
  margin-top: 0.75rem;
  max-width: 42rem;
}
.gen-progress.hidden { display: none; }
.gen-progress-track {
  height: 0.45rem;
  border-radius: 999px;
  background: var(--well);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
}
.gen-progress-bar {
  height: 100%;
  width: 0%;
  min-width: 0;
  border-radius: inherit;
  background: var(--accent);
  transition: width 240ms var(--ease);
}
.gen-progress-track.indeterminate .gen-progress-bar {
  width: 35%;
  animation: gen-progress-indeterminate 1.1s ease-in-out infinite;
}
@keyframes gen-progress-indeterminate {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}
@media (prefers-reduced-motion: reduce) {
  .gen-progress-track.indeterminate .gen-progress-bar { animation: none; width: 35%; }
}
.gen-progress-label {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  flex: 1;
  min-width: 0;
}
.gen-progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.45rem;
}
.gen-progress-hint {
  margin: 0.25rem 0 0;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* ---------- Gallery ---------- */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.125rem;
  margin-top: 1.5rem;
}

.gallery-item {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: border-color 180ms var(--ease), box-shadow 180ms var(--ease), transform 180ms var(--ease);
}
.gallery-item:hover {
  border-color: var(--border);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.gallery-item img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  background: var(--well);
}

.gallery-meta { padding: 0.8rem 0.85rem 0.35rem; }
.gallery-prompt {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.prompt-negative-input { margin-top: 0.35rem; }
.gallery-negative-prompt {
  margin: 0.35rem 0 0;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--text-muted);
  -webkit-line-clamp: 2;
}
.params-hint { margin: 0 0 0.35rem; }
.control-section { margin-bottom: 0; min-width: 0; }
.chip-row { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.35rem; }
.chip {
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: var(--surface-raised);
  color: var(--text-secondary);
  font-size: 0.78rem;
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--text-primary); }
.preset-row { flex: 1 1 280px; max-width: 420px; }
.preset-select {
  width: 100%;
  margin-top: 0.35rem;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  color: var(--text);
}
.history-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-bottom: 0.85rem;
}
.history-toolbar input[type="search"] {
  flex: 1 1 180px;
  min-width: 0;
}
.history-filter-check {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}
.history-view-toggle {
  display: inline-flex;
  gap: 0.35rem;
  margin-left: auto;
}
.history-view-toggle .btn.is-active {
  background: var(--accent-muted);
  border-color: color-mix(in oklch, var(--accent) 35%, var(--border-subtle));
  color: var(--accent);
}
.history-generations-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}
.history-generation {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
}
.history-generation-header {
  padding: 0.85rem 0.95rem 0.65rem;
  border-bottom: 1px solid var(--border-subtle);
}
.history-generation-prompt {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.45;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.history-generation-prompt.is-empty {
  color: var(--text-muted);
  font-style: italic;
}
.history-generation-meta {
  margin-top: 0.45rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.history-generation-negative {
  margin: 0.45rem 0 0;
  font-size: 0.75rem;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.history-generation-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.75rem 0.95rem;
  background: var(--well);
}
.history-generation-thumb {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  background: var(--surface);
}
.history-generation-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.history-generation-thumb-more {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface);
}
.history-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1rem;
}
.history-pagination.hidden { display: none; }
.history-pagination-label {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.history-generation-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.65rem 0.95rem 0.85rem;
}
.history-generation-details {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 0.85rem;
  padding: 0 0.95rem 0.95rem;
}
.history-generation-details .gallery-item img {
  aspect-ratio: auto;
  max-height: 280px;
  object-fit: contain;
  background: var(--well);
}
.gallery-history-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.55rem;
}
.preset-list {
  display: grid;
  gap: 0.35rem;
  margin: 0.5rem 0 0.75rem;
  max-height: 16rem;
  overflow-y: auto;
}
.preset-list-item {
  font-size: 0.78rem;
  color: var(--text-secondary);
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}
.preset-editor {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}
.preset-editor input { flex: 1 1 160px; min-width: 0; }
.gallery-details {
  margin-top: 0.35rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.gallery-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.85rem;
  border-top: 1px solid var(--border-subtle);
}
.gallery-actions a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.8125rem;
  font-weight: 500;
  transition: color 150ms var(--ease);
}
.gallery-actions a:hover { color: var(--accent); }

.batch-actions { margin-top: 1rem; }

/* Skeleton loading tiles */
.skeleton-item {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  aspect-ratio: 4 / 5;
  background: linear-gradient(100deg, var(--surface) 30%, var(--surface-raised) 50%, var(--surface) 70%);
  background-size: 220% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { from { background-position: 180% 0; } to { background-position: -80% 0; } }
@media (prefers-reduced-motion: reduce) {
  .skeleton-item, .status-dot.loading { animation: none; }
  .panel { animation: none; }
}

.settings-telegram {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-subtle);
}

.field-hint {
  margin: 0.5rem 0 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
  max-width: 60ch;
  line-height: 1.5;
}

.history-gallery {
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

.history-gallery .gallery-item img {
  aspect-ratio: auto;
  max-height: 340px;
  object-fit: contain;
  background: var(--well);
}

.history-gallery .gallery-prompt-block {
  padding: 0.75rem 0.85rem 0.55rem;
  border-top: 1px solid var(--border-subtle);
}

.history-gallery .gallery-prompt-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

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

.history-gallery .gallery-copy-btn {
  flex-shrink: 0;
}

.history-gallery .gallery-prompt-wrap {
  display: block;
  overflow: visible;
  -webkit-line-clamp: unset;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.history-gallery .gallery-prompt-empty {
  color: var(--text-muted);
  font-style: italic;
}

.history-gallery .gallery-details {
  margin-top: 0.5rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--border-subtle);
}

/* ---------- Empty state ---------- */
.empty-state {
  grid-column: 1 / -1;
  padding: 3.25rem 1.5rem;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  color: var(--text-muted);
}
.empty-icon { color: var(--text-muted); opacity: 0.7; margin-bottom: 0.75rem; }
.empty-icon svg { width: 40px; height: 40px; }
.empty-state p { margin: 0; font-weight: 550; color: var(--text-secondary); }
.empty-state span { display: block; margin-top: 0.35rem; font-size: 0.875rem; }

/* ---------- Models table ---------- */
.model-table {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.model-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  align-items: center;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--border-subtle);
  transition: background 150ms var(--ease);
}
.model-row:last-child { border-bottom: none; }
.model-row:hover { background: oklch(0.21 0.008 285); }
.model-row.active { background: var(--accent-soft); }

.model-id { font-weight: 600; font-size: 0.9rem; display: flex; align-items: center; }
.model-name { margin-top: 0.2rem; color: var(--text-secondary); font-size: 0.8125rem; }
.model-meta { margin-top: 0.25rem; color: var(--text-muted); font-size: 0.72rem; font-variant-numeric: tabular-nums; }

.model-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: flex-end; }

.badge {
  display: inline-flex;
  align-items: center;
  margin-left: 0.5rem;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--accent);
  color: var(--on-accent);
}

.badge-muted {
  background: oklch(0.32 0.01 285);
  color: var(--text-secondary);
}

/* ---------- Civitai explorer ---------- */
.explore-toolbar {
  display: grid;
  gap: 0.875rem;
  margin-bottom: 1rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.explore-search {
  display: flex;
  gap: 0.625rem;
}

.explore-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.875rem 1.25rem;
  align-items: end;
}

.explore-filter {
  min-width: 180px;
}

.explore-filter span {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}

.explore-filter select {
  width: 100%;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem;
}

.explore-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.explore-toggle input {
  width: auto;
  accent-color: var(--accent);
}

.explore-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.explore-row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) auto;
  gap: 1rem;
  align-items: start;
  padding: 0.9rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  transition: border-color 160ms var(--ease), background 160ms var(--ease);
}

.explore-row:hover {
  border-color: var(--border);
  background: oklch(0.21 0.008 285);
}

.explore-row.installed {
  background: oklch(0.2 0.01 285);
}

.explore-thumb {
  width: 72px;
  height: 72px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--well);
  border: 1px solid var(--border-subtle);
}

.explore-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.explore-thumb-empty {
  display: grid;
  place-items: center;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.explore-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  font-size: 0.95rem;
}

.explore-version {
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-weight: 500;
}

.explore-meta {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.explore-desc {
  margin: 0.45rem 0 0;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.explore-actions {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  align-items: stretch;
}

.explore-more {
  margin-top: 1rem;
}

.explore-manual {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-subtle);
}

.explore-manual summary {
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 550;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

.explore-manual[open] summary {
  margin-bottom: 1rem;
}

/* ---------- Status list ---------- */
.status-list {
  margin: 0;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.status-row {
  display: grid;
  grid-template-columns: 170px 1fr;
  gap: 1rem;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--border-subtle);
}
.status-row:last-child { border-bottom: none; }
.status-row dt { margin: 0; font-size: 0.8125rem; font-weight: 500; color: var(--text-muted); }
.status-row dd { margin: 0; font-size: 0.875rem; word-break: break-word; font-variant-numeric: tabular-nums; }

/* ---------- Log ---------- */
.log {
  margin-top: 1rem;
  padding: 0.9rem;
  background: var(--well);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 0.75rem;
  line-height: 1.5;
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  color: var(--text-secondary);
}

/* ---------- Responsive ---------- */
@media (max-width: 880px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 0.75rem;
  }
  .sidebar-nav {
    flex: initial;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
  }
  .nav-item { width: auto; }
  .sidebar-footer { display: none; }
  .topbar { padding: 1.25rem 1.25rem 1rem; }
  .content { padding: 1.25rem 1.25rem 2.5rem; }
  .params-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .explore-row { grid-template-columns: 64px minmax(0, 1fr); }
  .explore-actions {
    grid-column: 1 / -1;
    flex-direction: row;
    justify-content: flex-end;
  }
  .status-row { grid-template-columns: 1fr; gap: 0.25rem; }
}

@media (max-width: 460px) {
  .params-grid, .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
