﻿:root {
  --bg: #f4eee6;
  --panel: #fffdf9;
  --panel-soft: #faf6f0;
  --text: #23201d;
  --muted: #8a837b;
  --line: #e7ddd0;
  --primary: #181514;
  --primary-hover: #312c28;
  --success: #0f8d62;
  --warn: #b87333;
  --danger: #be3b47;
  --shadow: 0 10px 30px rgba(25, 20, 16, 0.06);
  --radius: 12px;
  --radius-lg: 24px;
  --font: "SF Pro Display","SF Pro Text","PingFang SC","Microsoft YaHei","Helvetica Neue",sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: radial-gradient(circle at top left, rgba(255, 251, 245, 0.98), rgba(246, 239, 230, 0.98) 42%, rgba(239, 232, 221, 1) 100%);
  color: var(--text);
  min-height: 100vh;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.is-hidden { display: none !important; }

.boot-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at top left, rgba(255, 251, 245, 0.98), rgba(246, 239, 230, 0.98) 42%, rgba(239, 232, 221, 1) 100%);
  color: var(--muted);
  font-size: 14px;
  letter-spacing: 0.04em;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(420px, 100%);
  padding: 32px;
  border-radius: 24px;
  background: var(--panel);
  border: 1px solid rgba(231,221,208,0.9);
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }

.brand-mark {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--primary); color: #fff;
  font-size: 18px; font-weight: 700;
}

.brand-title { font-size: 16px; font-weight: 700; color: var(--text); }
.brand-subtitle { font-size: 12px; color: var(--muted); margin-top: 2px; }

.auth-switch {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 20px;
  padding: 4px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 40px;
}

.auth-tab {
  border: 0; background: transparent; border-radius: 40px;
  padding: 8px 16px; font-size: 14px; font-weight: 500;
  color: var(--muted); transition: all 0.15s;
}

.auth-tab.active {
  background: #fff; box-shadow: 0 1px 3px rgba(28,25,23,0.10);
  font-weight: 600; color: var(--text);
}

.auth-form { display: grid; gap: 14px; }
.auth-form label { display: grid; gap: 6px; }
.auth-form label span { font-size: 13px; font-weight: 500; color: var(--muted); }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 11px 14px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 100px; }
.confirm-field { transition: all 0.2s; }
.confirm-field.is-hidden { display: none; }

.auth-note { margin: 16px 0 0; font-size: 12px; color: var(--muted); text-align: center; }
.auth-note code { font-size: 12px; background: var(--panel-soft); padding: 2px 6px; border-radius: 6px; }

/* ─── App Shell ─── */
.app-shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: 10px 18px 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─── Top Nav ─── */
.top-nav {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: 8px 4px 14px;
  border-bottom: 0;
  flex-shrink: 0;
}

.top-nav-left { display: flex; align-items: center; gap: 10px; }
.top-nav-right { display: flex; align-items: center; gap: 14px; }

.nav-brand-mark {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: var(--primary); color: #fff;
  font-size: 14px; font-weight: 700;
}

.nav-brand-text { font-size: 14px; font-weight: 600; color: var(--text); }
.nav-brand-sub { font-size: 11px; color: var(--muted); }

.nav-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: 13px; color: var(--muted);
  transition: all 0.15s;
}

.nav-pill.active {
  color: var(--text);
  font-weight: 600;
  border-bottom: 2px solid var(--text);
  padding-bottom: 4px;
}

.nav-pill:hover { background: transparent; color: var(--text); }

.user-chip {
  padding: 4px 10px;
  border: 1px solid rgba(231,221,208,0.9);
  border-radius: 999px;
  background: rgba(255,253,249,0.9);
  font-size: 12px; color: var(--muted);
  white-space: nowrap;
}

.ghost-btn.small {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 999px;
}

/* ─── Main Layout ─── */
.main-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 30px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.main-layout.layout-single {
  grid-template-columns: 1fr;
}

.history-sidebar {
  padding: 10px 6px 12px 0;
  border-right: 1px solid rgba(231,221,208,0.75);
  overflow: hidden;
}

.history-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  padding: 0 6px 0 0;
}

.history-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.history-header-top h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.history-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.new-conversation-btn {
  width: 100%;
  height: 42px;
  justify-content: center;
  border-radius: 14px;
  background: #111111;
  border: 1px solid #111111;
  color: #ffffff;
  box-shadow: 0 10px 24px rgba(17,17,17,0.10);
}

.new-conversation-btn:hover {
  background: #1b1b1b;
  border-color: #1b1b1b;
  color: #fff;
}

.icon-btn {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid rgba(231,221,208,0.9);
  background: rgba(255,255,255,0.72);
  color: var(--muted);
  flex-shrink: 0;
  transition: all 0.12s;
}

.icon-btn svg {
  width: 15px;
  height: 15px;
}

.icon-btn:hover {
  background: #fff;
  color: var(--danger);
  border-color: rgba(231,221,208,1);
}

.conversation-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-right: 0;
  overflow-y: auto;
  max-height: calc(100vh - 220px);
  scrollbar-width: none;
}

.conversation-list::-webkit-scrollbar { display: none; }

.history-empty {
  padding: 18px 12px;
  border: 1px dashed rgba(231,221,208,0.9);
  border-radius: 14px;
  background: rgba(255,255,255,0.55);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.conversation-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 72px;
  padding: 14px 14px 14px 18px;
  border-radius: 0;
  border: 0;
  background: transparent;
  overflow: hidden;
  transition: background 0.15s;
}

.conversation-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  border-radius: 0;
  background: transparent;
  transition: background 0.15s;
}

.conversation-item-btn {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  cursor: pointer;
  color: inherit;
  display: block;
  box-shadow: none;
}

.conversation-item:hover {
  background: rgba(255,255,255,0.16);
}

.conversation-item:hover::before {
  background: rgba(17,17,17,0.28);
}

.conversation-item.active {
  background: rgba(255,255,255,0.68);
}

.conversation-item.active::before {
  background: #111111;
}

.conversation-item-title {
  font-weight: 700;
  font-size: 14px;
  color: #1f1b17;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.35;
  letter-spacing: -0.01em;
}

.conversation-item-meta {
  font-size: 13px;
  color: #8f877f;
  margin-top: 5px;
  line-height: 1.35;
}

.conversation-item-del {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.conversation-item-del svg {
  width: 17px;
  height: 17px;
}

.conversation-item:hover .conversation-item-del,
.conversation-item.active .conversation-item-del {
  opacity: 1;
}

.conversation-item-del:hover {
  background: rgba(255,255,255,0.92);
  color: var(--danger);
}



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

.workspace-content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-bottom: 18px;
}


.conversation { display: flex; flex-direction: column; gap: 36px; }
.turn { display: flex; flex-direction: column; gap: 18px; }

.turn-prompt { align-self: flex-end; width: min(420px, 72%); text-align: right; padding: 4px 8px; }

.turn-prompt-text {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  max-width: 100%;
  padding: 8px 0;
  background: transparent;
  border-radius: 16px 4px 16px 16px;
  font-size: 15px; line-height: 1.7;
  color: var(--text);
}

.turn-meta {
  font-size: 11px; color: var(--muted);
  display: flex; gap: 8px; justify-content: flex-end;
  margin-bottom: 8px;
}

.turn-result { padding: 4px 8px; width: min(560px, 78%); align-self: flex-start; }
.turn-ai-meta { display: flex; align-items: center; gap: 14px; margin: 0 0 14px; font-size: 12px; color: var(--muted); }
.turn-error-message {
  max-width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(220, 38, 38, 0.18);
  border-radius: 12px;
  background: rgba(254, 242, 242, 0.9);
  color: #991b1b;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.turn-reference-text { margin-top: 8px; font-size: 12px; color: var(--muted); }
.turn-reference-list { display: flex; gap: 10px; justify-content: flex-end; margin-top: 10px; }
.turn-reference-item { display: grid; justify-items: end; gap: 6px; }
.turn-reference-title { font-size: 12px; color: var(--muted); }
.turn-reference-thumb { width: 96px; height: 72px; border: 1px solid var(--line); border-radius: 10px; background-size: cover; background-position: center; background-color: var(--panel-soft); }

.image-grid { columns: 1; gap: 12px; }
.image-grid > * { break-inside: avoid; margin-bottom: 12px; }

.image-card {
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid rgba(231,229,228,0.5);
  background: var(--panel-soft);
  transition: border-color 0.15s;
}

.image-card:hover { border-color: var(--line); }

.image-card-img {
  display: block; width: 100%; height: auto;
  cursor: zoom-in; transition: brightness 0.2s;
}

.image-card-img:hover { filter: brightness(0.92); }

.image-card-footer {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 10px 12px;
}

.image-card-label { font-size: 12px; color: var(--muted); }

/* ─── Status Badges ─── */
.status-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 12px; border-radius: 40px;
  font-size: 12px; font-weight: 500;
}

.status-loading,
.status-pending { background: #f0f9ff; color: #0069a4; }
.status-queued { background: #fffbeb; color: #b75000; }
.status-done,
.status-running,
.status-succeeded { background: #ecfdf5; color: #009767; }
.status-failed,
.status-canceled { background: #fff1f2; color: #c20039; }

/* ─── Input Area (fixed at bottom) ─── */
.input-area {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  padding: 0 4px 18px;
  position: sticky;
  bottom: 0;
  z-index: 5;
  background: linear-gradient(to top, rgba(244,238,230,0.98), rgba(244,238,230,0.72) 65%, transparent);
}

.input-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(980px, 100%);
}

.input-box {
  position: relative;
  border-radius: 30px;
  border: 1px solid rgba(231,221,208,0.95);
  background: var(--panel);
  box-shadow: 0 18px 72px -48px rgba(15,23,42,0.34);
  overflow: visible;
}

.ref-preview {
  position: relative;
  z-index: 3;
  margin: 0;
  pointer-events: auto;
}

.ref-preview.is-hidden {
  display: none;
}

.ref-preview-thumb {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 60px;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 8px 22px -18px rgba(15,23,42,0.35);
  overflow: visible;
}

.ref-preview-thumb img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  display: block;
  border-radius: 12px;
  border: 1px solid rgba(231,221,208,0.95);
  background: #fff;
}

.ref-preview-close {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 18px;
  height: 18px;
  border: 1px solid rgba(231,221,208,0.95);
  border-radius: 999px;
  background: #fff;
  color: #7b746b;
  font-size: 14px;
  line-height: 16px;
  text-align: center;
  padding: 0;
  box-shadow: 0 4px 10px rgba(15,23,42,0.12);
}

.send-btn svg { width: 16px; height: 16px; }
.send-btn:hover { background: var(--primary-hover); }
.send-btn:disabled { background: #d6d3d1; color: #fafaf9; cursor: not-allowed; opacity: 1; }

.input-toolbar {
  border-top: 1px solid rgba(231,221,208,0.75);
  background: rgba(255,253,249,0.85);
  padding: 12px 16px;
}

.input-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(231,221,208,0.95);
  background: linear-gradient(180deg, #fffdf9, #f8f1e8);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}

.tool-btn:hover {
  background: #fff;
  border-color: #d6cabb;
  box-shadow: 0 8px 18px -16px rgba(15,23,42,0.25);
}

.tool-btn svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.tool-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
}

.send-btn {
  margin-left: auto;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: #fff;
  transition: all 0.15s;
}

/* ─── Empty State ─── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 260px; text-align: center;
}

.empty-state h2 {
  font-family: "Palatino Linotype","Book Antiqua","Times New Roman",serif;
  font-size: 28px; font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--text);
  margin: 0 0 8px;
}

.empty-state p {
  font-family: "Palatino Linotype","Book Antiqua","Times New Roman",serif;
  font-size: 14px; color: var(--muted); font-style: italic;
  max-width: 360px; margin: 0;
}

/* ─── Panels (Library, Logs, Admin) ─── */
.page-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.page-panel h2 { font-size: 15px; font-weight: 600; margin: 0 0 4px; }
.page-panel .panel-desc { font-size: 12px; color: var(--muted); margin: 0 0 16px; }

.asset-grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }

.asset-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--panel-soft);
}

.asset-preview { aspect-ratio: 16/10; background: linear-gradient(135deg, #d6d3d1, #f5f5f4); }
.asset-meta { padding: 10px; }
.asset-actions { display: flex; gap: 8px; margin-top: 8px; }

.list, .log-list, .stack-list { display: grid; gap: 8px; }

.task-item, .log-item, .stack-item {
  display: flex; justify-content: space-between;
  gap: 12px; padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-soft);
}

.log-item {
  align-items: center;
}

.log-item .stack-meta {
  margin-top: 4px;
}

.log-item .task-meta {
  margin-top: 6px;
}

.log-item .status-badge {
  flex-shrink: 0;
}

.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.admin-box {
  background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}

.admin-box h3 { font-size: 14px; font-weight: 600; margin: 0 0 12px; }
.admin-settings-box { margin-top: 16px; }

.settings-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.settings-form label { display: grid; gap: 6px; font-size: 13px; font-weight: 500; }
.masked-key-input {
  -webkit-text-security: disc;
  text-security: disc;
}

.toggle-row { display: flex !important; align-items: center; gap: 8px; grid-column: span 2; }
.toggle-row input { width: 18px; height: 18px; margin: 0; }

.primary-btn {
  padding: 9px 18px; border-radius: 40px; border: 0;
  background: var(--primary); color: #fff;
  font-size: 14px; font-weight: 500;
  transition: background 0.15s;
}

.primary-btn:hover { background: var(--primary-hover); }
.primary-btn.full { width: 100%; }

.ghost-btn {
  padding: 7px 14px; border-radius: 40px;
  border: 1px solid var(--line);
  background: var(--panel-soft); color: var(--text);
  font-size: 13px; transition: all 0.12s;
}

.ghost-btn:hover { border-color: #d6d3d1; background: #fff; }
.ghost-btn.small { padding: 5px 10px; font-size: 12px; }

.admin-action {
  padding: 5px 10px; font-size: 12px;
  border-radius: 40px; border: 1px solid var(--line);
  background: var(--panel-soft);
}

.admin-action:hover { border-color: #d6d3d1; }

.stack-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
}
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }

.toast {
  position: fixed; right: 20px; bottom: 20px;
  z-index: 40;
  min-width: 200px; max-width: 360px;
  padding: 12px 20px;
  border-radius: 16px;
  background: var(--primary); color: #fff;
  font-size: 13px;
  box-shadow: 0 12px 24px rgba(15,23,42,0.25);
  transition: all 0.2s;
}

.toast-success { background: var(--primary); }
.toast-error { background: var(--danger); }
.toast.is-hidden { opacity: 0; pointer-events: none; transform: translateY(10px); }

code { padding: 2px 6px; border-radius: 6px; background: var(--panel-soft); font-size: 12px; }

.hide-scrollbar { -ms-overflow-style: none; scrollbar-width: thin; }
.hide-scrollbar::-webkit-scrollbar { width: 4px; }
.hide-scrollbar::-webkit-scrollbar-thumb { background: rgba(120,113,108,0.45); border-radius: 40px; }
.hide-scrollbar::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 900px) {
  .main-layout { grid-template-columns: 1fr; }
  .history-sidebar { display: none; }
  .image-grid { columns: 1; }
  .admin-grid { grid-template-columns: 1fr; }
  .asset-grid-2 { grid-template-columns: 1fr; }
  .settings-form { grid-template-columns: 1fr; }
  .toggle-row { grid-column: auto; }
}

@media (max-width: 640px) {
  .app-shell { padding: 6px 10px; }
  .top-nav { flex-wrap: wrap; }
  .input-box { border-radius: 20px; }
  .input-textarea { padding: 14px 16px; min-height: 60px; font-size: 14px; border-radius: 20px 20px 0 0; }
  .input-toolbar { padding: 8px 16px 12px; flex-wrap: wrap; }
}

/* ─── Lightbox ─── */
.lightbox-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
}

.lightbox-overlay.is-hidden { display: none; }

.lightbox-backdrop {
  position: absolute; inset: 0;
  background: rgba(28,25,23,0.8);
  backdrop-filter: blur(4px);
}

.lightbox-panel {
  position: relative; z-index: 1;
  display: flex; flex-direction: column;
  width: min(90vw, 960px);
  max-height: 90vh;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.35);
  overflow: hidden;
}

.lightbox-top {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.lightbox-title {
  font-size: 14px; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.lightbox-top-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.lightbox-counter { font-size: 12px; color: var(--muted); }

.lightbox-body {
  display: flex; align-items: center; justify-content: center;
  flex: 1; min-height: 300px;
  background: #f5f5f4;
  position: relative;
}

.lightbox-image-wrap {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 16px; overflow: hidden;
}

.lightbox-placeholder {
  width: 100%; max-width: 600px;
  aspect-ratio: 16/10;
  border-radius: 8px;
  background: linear-gradient(135deg, #d6d3d1, #f5f5f4);
}

.lightbox-nav-btn {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: 50%;
  background: rgba(255,255,255,0.9);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  transition: all 0.15s;
  z-index: 2;
}

.lightbox-nav-btn:hover { background: #fff; box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
.lightbox-prev { left: 16px; }
.lightbox-next { right: 16px; }
.lightbox-nav-btn.is-hidden { display: none; }

@media (max-width: 640px) {
  .lightbox-panel { width: 100vw; max-height: 100vh; border-radius: 0; }
  .lightbox-body { min-height: 200px; }
  .lightbox-prev { left: 8px; }
  .lightbox-next { right: 8px; }
}

/* ─── Toolbar Controls ─── */
.tool-input-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 40px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 13px;
  color: var(--muted);
}

.tool-input-group span {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.tool-number-input {
  width: 40px;
  height: 28px;
  border: 0;
  padding: 0 4px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: transparent;
  outline: none;
  border-radius: 0;
}

.tool-number-input::-webkit-inner-spin-button {
  opacity: 1;
}

.tool-select {
  height: 28px;
  border: 0;
  padding: 0 4px 0 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: transparent;
  outline: none;
  cursor: pointer;
  border-radius: 0;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='none' stroke='%2379716b' stroke-width='2' width='12' height='12'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 2px center;
  padding-right: 16px;
}

.input-box {
  position: relative;
  border-radius: 30px;
  border: 1px solid rgba(231,221,208,0.95);
  background: var(--panel);
  box-shadow: 0 18px 72px -48px rgba(15,23,42,0.34);
  overflow: visible;
}

.input-textarea {
  width: 100%;
  min-height: 180px;
  border: 0;
  border-radius: 28px 28px 0 0;
  padding: 22px 22px 10px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: transparent;
  resize: none;
  outline: none;
}

.ref-preview {
  position: relative;
  z-index: 3;
  margin: 0;
  pointer-events: auto;
}

.ref-preview.is-hidden {
  display: none;
}

.ref-preview-thumb {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 60px;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 8px 22px -18px rgba(15,23,42,0.35);
  overflow: visible;
}

.ref-preview-thumb img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  display: block;
  border-radius: 12px;
  border: 1px solid rgba(231,221,208,0.95);
  background: #fff;
}

.ref-preview-close {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 18px;
  height: 18px;
  border: 1px solid rgba(231,221,208,0.95);
  border-radius: 999px;
  background: #fff;
  color: #7b746b;
  font-size: 14px;
  line-height: 16px;
  text-align: center;
  padding: 0;
  box-shadow: 0 4px 10px rgba(15,23,42,0.12);
}

.input-textarea {
  width: 100%;
  min-height: 180px;
  border: 0;
  border-radius: 28px 28px 0 0;
  padding: 22px 22px 10px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: transparent;
  resize: none;
  outline: none;
}

.input-textarea.edit-mode {
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(255,249,240,0.95));
}

/* ─── History Item (updated) ─── */
.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 10px 0;
  border-radius: 10px;
  border-left: 3px solid transparent;
  position: relative;
  background: transparent;
  transition: all 0.12s;
}

.history-item:hover {
  background: rgba(0,0,0,0.03);
  border-left-color: var(--line);
}

.history-item.active {
  border-left-color: var(--primary);
  background: rgba(41,37,36,0.04);
}

.history-item-btn {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  color: inherit;
  display: block;
}

.history-item-title {
  font-weight: 500;
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item.active .history-item-title {
  font-weight: 600;
}

.history-item-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
}

.history-item .task-status {
  flex-shrink: 0;
}

.history-item-del {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  opacity: 0;
  transition: all 0.12s;
  cursor: pointer;
}

.history-item:hover .history-item-del {
  opacity: 1;
}

.history-item-del:hover {
  background: #fee2e2;
  color: var(--danger);
}

/* ─── Sidebar polish ─── */
.history-sidebar {
  padding: 10px 8px 12px 0;
  border-right: 1px solid rgba(231,221,208,0.75);
  overflow: hidden;
}

.history-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  padding: 0 6px 0 0;
}

.new-conversation-btn {
  flex: 1;
  min-width: 0;
  height: 42px;
  justify-content: center;
  border-radius: 14px;
  background: #111111;
  border: 1px solid #111111;
  color: #ffffff;
  box-shadow: 0 10px 24px rgba(17,17,17,0.10);
}

.new-conversation-btn:hover {
  background: #1b1b1b;
  border-color: #1b1b1b;
  color: #fff;
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  border: 1px solid rgba(231,221,208,0.9);
  background: rgba(255,255,255,0.72);
  color: var(--muted);
  flex-shrink: 0;
  transition: all 0.12s;
}

.icon-btn svg {
  width: 15px;
  height: 15px;
}

.icon-btn:hover {
  background: #fff;
  color: var(--danger);
  border-color: rgba(231,221,208,1);
}

.conversation-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-right: 0;
  overflow-y: auto;
  max-height: calc(100vh - 220px);
  scrollbar-width: none;
}

.conversation-list::-webkit-scrollbar { display: none; }

.history-empty {
  padding: 18px 12px;
  border: 1px dashed rgba(231,221,208,0.9);
  border-radius: 14px;
  background: rgba(255,255,255,0.55);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.conversation-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 72px;
  padding: 14px 14px 14px 18px;
  border-radius: 0;
  border: 0;
  background: transparent;
  overflow: hidden;
  transition: background 0.15s;
}

.conversation-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  border-radius: 0;
  background: transparent;
  transition: background 0.15s;
}

.conversation-item-btn {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  cursor: pointer;
  color: inherit;
  display: block;
  box-shadow: none;
}

.conversation-item:hover {
  background: rgba(255,255,255,0.16);
}

.conversation-item:hover::before {
  background: rgba(17,17,17,0.28);
}

.conversation-item.active {
  background: rgba(255,255,255,0.68);
}

.conversation-item.active::before {
  background: #111111;
}

.conversation-item-title {
  font-weight: 700;
  font-size: 14px;
  color: #1f1b17;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.35;
  letter-spacing: -0.01em;
}

.conversation-item-meta {
  font-size: 13px;
  color: #8f877f;
  margin-top: 5px;
  line-height: 1.35;
}

.conversation-item-del {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.conversation-item-del svg {
  width: 17px;
  height: 17px;
}

.conversation-item:hover .conversation-item-del,
.conversation-item.active .conversation-item-del {
  opacity: 1;
}

.conversation-item-del:hover {
  background: rgba(255,255,255,0.92);
  color: var(--danger);
}


@media (max-width: 900px) {
  .main-layout { grid-template-columns: 1fr; }
  .history-sidebar { display: none; }
  .image-grid { columns: 1; }
  .admin-grid { grid-template-columns: 1fr; }
  .asset-grid-2 { grid-template-columns: 1fr; }
  .settings-form { grid-template-columns: 1fr; }
  .toggle-row { grid-column: auto; }
}

@media (max-width: 640px) {
  .app-shell { padding: 6px 10px; }
  .top-nav { flex-wrap: wrap; }
  .input-box { border-radius: 20px; }
  .input-textarea { padding: 14px 16px; min-height: 60px; font-size: 14px; border-radius: 20px 20px 0 0; }
  .input-toolbar { padding: 8px 16px 12px; flex-wrap: wrap; }
}

/* ─── 图像设置面板 ─── */
.input-container {
  position: relative;
}

.image-settings-panel {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 0;
  width: min(560px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 24px 48px -24px rgba(15, 23, 42, 0.28);
  padding: 18px 20px 20px;
  z-index: 40;
}

.settings-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
}

.settings-section {
  margin-bottom: 14px;
}

.settings-section:last-child {
  margin-bottom: 0;
}

.settings-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

.settings-label-note {
  margin-left: 6px;
  font-size: 11px;
  color: var(--muted);
  opacity: 0.85;
}

.settings-model-row {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
  font-size: 13px;
  color: var(--text);
}

.settings-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.settings-opt {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.settings-opt:hover {
  background: #fff;
  border-color: #d6cabb;
}

.settings-opt.active {
  background: #fff;
  border-color: var(--primary);
  font-weight: 600;
  box-shadow: 0 8px 18px -16px rgba(15, 23, 42, 0.35);
}

.ratio-glyph {
  display: inline-block;
  border: 1.5px solid currentColor;
  border-radius: 3px;
  opacity: 0.7;
}

.ratio-square { width: 11px; height: 11px; }
.ratio-landscape { width: 14px; height: 9px; }
.ratio-portrait { width: 9px; height: 14px; }

.settings-hint {
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.5;
  color: #a3542f;
  background: rgba(163, 84, 47, 0.08);
  border-radius: 10px;
  padding: 8px 12px;
}

.points-chip {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

/* ─── 沉浸式全屏灯箱(覆盖上方旧样式):图片撑满视口,控件悬浮 ─── */
.lightbox-backdrop {
  background: rgba(12, 10, 9, 0.92);
  backdrop-filter: blur(6px);
}

.lightbox-panel {
  width: 100vw;
  height: 100vh;
  max-height: 100vh;
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  /* 空白处的点击穿透到 backdrop,点哪都能关闭;可交互控件单独恢复 pointer-events */
  pointer-events: none;
}

.lightbox-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  border-bottom: 0;
  padding: 14px 20px 28px;
  background: linear-gradient(rgba(12, 10, 9, 0.6), rgba(12, 10, 9, 0));
  pointer-events: auto;
}

.lightbox-title { color: #fff; }
.lightbox-counter { color: rgba(255, 255, 255, 0.75); }

.lightbox-top .ghost-btn {
  border-color: rgba(255, 255, 255, 0.35);
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.lightbox-top .ghost-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.55);
}

.lightbox-body {
  background: transparent;
  min-height: 0;
  height: 100%;
}

.lightbox-image-wrap {
  padding: 0;
  width: 100%;
  height: 100%;
}

.lightbox-placeholder {
  width: 100%;
  height: 100%;
  max-width: none;
  aspect-ratio: auto;
  border-radius: 0;
  pointer-events: none;
}

.lightbox-nav-btn {
  pointer-events: auto;
  width: 48px;
  height: 48px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  backdrop-filter: blur(4px);
  box-shadow: none;
}

.lightbox-nav-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ─── 生成中占位:骨架微光 + 转圈 + 计时 ─── */
.turn-generating {
  margin-top: 10px;
}

.gen-skeleton {
  position: relative;
  width: min(360px, 100%);
  max-height: 300px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: linear-gradient(160deg, #f7f1e8, #eee4d5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  overflow: hidden;
}

/* 安静的呼吸光晕，替代扫光 */
.gen-skeleton::before {
  content: "";
  position: absolute;
  inset: -30%;
  background: radial-gradient(circle at 50% 45%, rgba(255, 253, 247, 0.95), rgba(255, 253, 247, 0) 55%);
  animation: gen-breathe 3.2s ease-in-out infinite;
  pointer-events: none;
}

.gen-skeleton > * {
  position: relative;
}

@keyframes gen-breathe {
  0%, 100% { opacity: 0.3; transform: scale(0.96); }
  50% { opacity: 0.85; transform: scale(1.05); }
}

.gen-spinner {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid rgba(24, 21, 20, 0.12);
  border-top-color: var(--primary);
  animation: gen-spin 0.9s linear infinite;
}

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

.gen-status {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.gen-status-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.gen-status-text::after {
  content: "";
  display: inline-block;
  width: 1.2em;
  text-align: left;
  animation: gen-dots 1.5s steps(4, end) infinite;
}

@keyframes gen-dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75% { content: "..."; }
}

.gen-timer {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.gen-hint {
  font-size: 12px;
  color: var(--muted);
  opacity: 0.85;
}

/* ─── 图片管理页统计瓷片 ─── */
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.panel-head h2 {
  margin-bottom: 4px;
}

.panel-head .panel-desc {
  margin: 0;
}

.stat-tiles {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

.stat-tile {
  min-width: 88px;
  padding: 10px 16px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-shadow: 0 10px 24px -22px rgba(15, 23, 42, 0.35);
}

.stat-tile-label {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.stat-tile-value {
  font-size: 21px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
}

/* ─── 管理后台:紧凑列表与任务缩略图 ─── */
.admin-box .stack-list {
  max-height: 340px;
  overflow-y: auto;
}

.admin-task-item {
  justify-content: flex-start;
  align-items: center;
  gap: 12px;
}

.admin-task-thumb {
  width: 46px;
  height: 46px;
  flex-shrink: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background-color: var(--panel-soft);
  background-size: cover;
  background-position: center;
  cursor: zoom-in;
  transition: box-shadow 0.15s ease;
}

.admin-task-thumb:not(.is-empty):hover {
  box-shadow: 0 6px 16px -10px rgba(15, 23, 42, 0.4);
}

.admin-task-thumb.is-empty {
  cursor: default;
  border-style: dashed;
}

.admin-task-info {
  min-width: 0;
}

.admin-task-info .stack-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── 修复:长提示词把 1fr 网格列撑爆导致页面横向溢出 ───
   1fr 的最小宽度是内容宽度,配合 nowrap 标题会让列宽失控;
   minmax(0, 1fr) 强制列可收缩,省略号才能生效。 */
.admin-grid {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

@media (max-width: 900px) {
  .admin-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

.admin-task-item {
  min-width: 0;
}

.admin-task-info {
  flex: 1;
  min-width: 0;
}

.admin-task-info .stack-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── 模型渠道管理 ─── */
.model-config-list {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.model-config-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
}

.model-config-item.is-active {
  border-color: var(--primary);
  background: #fff;
}

.model-config-info {
  flex: 1;
  min-width: 0;
}

.model-config-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.model-config-badge {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  flex-shrink: 0;
}

.model-config-meta {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-config-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.model-config-activate {
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

.model-config-toolbar {
  margin-bottom: 10px;
}

.model-config-form {
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

.model-config-form-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ─── 失败任务重试按钮 ─── */
.turn-retry-btn {
  margin-top: 8px;
}
