/* Hallmark · macrostructure: Workbench · tone: technical · anchor hue: cool-blue */

@import url("tokens.css");

html[data-theme="dark"] { color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }

html, body {
  overflow: hidden;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
}

html:fullscreen,
html:-webkit-full-screen {
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  max-height: none !important;
  margin: 0 !important;
  overflow: hidden !important;
  background: var(--color-ink);
  writing-mode: horizontal-tb;
}

html:fullscreen body,
html:-webkit-full-screen body,
html.is-fs body {
  display: grid !important;
  grid-template-rows: auto auto minmax(0, 1fr) !important;
  width: 100%;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  writing-mode: horizontal-tb;
}

body {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-width: 0;
  background: var(--color-ink);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--text-ui);
  line-height: 1.4;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

h1, h2, h3, .brand {
  font-family: var(--font-display);
  font-style: normal;
  font-weight: 700;
  overflow-wrap: anywhere;
  min-width: 0;
}

.skip {
  position: absolute;
  left: -999px;
  top: 0;
}

.skip:focus {
  left: var(--space-3);
  top: var(--space-3);
  z-index: 40;
  padding: var(--space-2) var(--space-3);
  background: var(--color-accent);
  color: var(--color-on-accent);
}

.menubar {
  display: flex;
  align-items: center;
  position: relative;
  z-index: 20;
  min-height: var(--menu-h);
  height: var(--menu-h);
  padding: 0 var(--space-2);
  overflow: visible;
  background: var(--color-ink);
  border-bottom: var(--rule) solid var(--color-line);
}

.menubar-left {
  display: flex;
  align-items: stretch;
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

.menubar-left > * {
  pointer-events: auto;
}

.menubar-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 1;
  max-width: 48%;
  padding: 0 var(--space-3);
  overflow: hidden;
  transform: translate(calc(-50% - 50px), -50%);
}

.menu {
  position: relative;
  height: 100%;
}

.menu > button {
  height: 100%;
  padding: 0 var(--space-3);
  border: 0;
  background: transparent;
  color: var(--color-text);
  white-space: nowrap;
  cursor: pointer;
}

.menu > button:hover,
.menu.open > button {
  background: var(--color-surface);
}

.menu-panel {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 30;
  min-width: 268px;
  padding: var(--space-1) 0;
  background: var(--color-surface);
  border: var(--rule) solid var(--color-line);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

.menu.open > .menu-panel,
.menu-panel:focus-within {
  display: block;
}

.menu-panel button,
.menu-panel a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-6);
  width: 100%;
  padding: 7px var(--space-4);
  border: 0;
  background: transparent;
  color: var(--color-text);
  text-align: left;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.menu-panel button:hover,
.menu-panel a:hover {
  background: var(--color-surface-hi);
}

.menu-panel button:disabled {
  color: var(--color-mute);
  cursor: default;
}

.menu-panel .kbd {
  flex: none;
  color: var(--color-mute);
  font-size: var(--text-small);
  font-family: var(--font-mono);
  white-space: nowrap;
}

.menu-sep {
  height: var(--rule);
  margin: var(--space-1) 0;
  background: var(--color-line);
}

.brand {
  flex: none;
  margin: 0;
  font-size: 1.375rem;
  line-height: 1;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

#title {
  width: 360px;
  max-width: 100%;
  min-width: 0;
  height: 26px;
  padding: 0 var(--space-2);
  background: var(--color-field);
  border: var(--rule) solid var(--color-line);
  color: var(--color-accent);
  font-weight: 700;
  text-align: center;
}

.file-bar {
  display: flex;
  flex-wrap: nowrap;
  flex: 1 1 0;
  justify-content: flex-end;
  align-items: center;
  gap: var(--space-1);
  z-index: 2;
  min-width: 0;
  height: 100%;
  overflow: hidden;
  pointer-events: none;
}

.file-bar > * {
  pointer-events: auto;
}

.toolbar {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  align-items: center;
  gap: var(--space-3);
  height: var(--toolbar-h);
  padding: 0 var(--space-3);
  border-bottom: var(--rule) solid var(--color-line);
}

.tools, .cables {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  min-width: 0;
}

.hint {
  min-width: 0;
  overflow: hidden;
  color: var(--color-text-dim);
  font-size: var(--text-small);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cable-lab {
  padding: 0 var(--space-2) 0 var(--space-3);
  color: var(--color-text-dim);
  font-size: var(--text-small);
}

.cable-sep {
  flex: none;
  width: 1px;
  height: 16px;
  margin: 0 var(--space-2);
  background: var(--color-line);
}

.swatch {
  width: 20px;
  height: 20px;
  margin-left: var(--space-2);
  border: var(--rule) solid rgba(0, 0, 0, 0.35);
  border-radius: 50%;
  cursor: pointer;
}

.workbench {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  min-height: 0;
  height: 100%;
  overflow: hidden;
  position: relative;
}

.workbench.has-ai-split {
  --ai-float-w: max(320px, min(var(--ai-panel-w, 42vw), calc(100% - var(--rail-w))));
  grid-template-columns: var(--rail-w) minmax(280px, 1fr) 6px minmax(320px, var(--ai-panel-w, 1fr));
}

.workbench.has-ai-split.ai-split-maximized {
  grid-template-columns: 0 0 0 minmax(0, 1fr);
}

.workbench.has-ai-split.ai-split-maximized .rail,
.workbench.has-ai-split.ai-split-maximized .canvas-host,
.workbench.has-ai-split.ai-split-maximized .ai-split-resizer {
  display: none !important;
}

.workbench.has-ai-split.ai-split-collapsed {
  grid-template-columns: var(--rail-w) minmax(0, 1fr) 0 0;
}

.workbench.has-ai-split.ai-split-collapsed .ai-split-resizer {
  display: none !important;
}

.workbench.has-ai-split.ai-split-collapsed .ai-split-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: var(--ai-float-w);
  min-width: 320px;
  height: 100%;
  transform: translateX(100%);
  transition: transform 0.22s var(--ease-out);
  pointer-events: none;
  box-shadow: none;
  z-index: 12;
}

.workbench.has-ai-split.ai-split-collapsed.ai-split-peeking .ai-split-panel {
  transform: translateX(0);
  pointer-events: auto;
  box-shadow: -4px 0 24px var(--color-shadow);
}

.workbench.has-ai-split.ai-split-collapsed.ai-split-peeking .canvas-host {
  margin-right: var(--ai-float-w);
}

.rail {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: var(--color-ink);
  border-right: var(--rule) solid var(--color-line);
}

.rail-head {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  justify-content: space-between;
  flex-wrap: nowrap;
  gap: var(--space-2);
  flex: none;
  padding: var(--space-2) var(--space-3) 0;
}

.rail h2 {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1 1 auto;
  min-width: 56px;
  margin: 0;
  padding: 0;
  font-size: clamp(0.6875rem, 0.625vw, 0.8125rem);
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
  overflow-wrap: normal;
}

.rail h2 span:last-child {
  color: var(--color-text);
  font-size: inherit;
  font-weight: 700;
}

.rail .sub {
  margin: 0;
  padding: 0 var(--space-3) var(--space-2);
  color: var(--color-text-dim);
  font-size: var(--text-small);
  flex: none;
}

#lib-search {
  position: relative;
  z-index: 1;
  flex: none;
  margin: 6px var(--space-3) 4px;
  height: 32px;
  padding: 0 var(--space-2);
  background: var(--color-surface);
  border: var(--rule) solid var(--color-line);
}

.lib-list {
  overflow-x: hidden;
  overflow-y: auto;
  min-width: 0;
  min-height: 0;
  flex: 1 1 auto;
  height: auto;
  padding: 0 var(--space-2) var(--space-2);
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--color-line) var(--color-ink);
}

.lib-list::-webkit-scrollbar {
  width: 10px;
}

.lib-list::-webkit-scrollbar-track {
  background: var(--color-ink);
}

.lib-list::-webkit-scrollbar-thumb {
  background: var(--color-line);
  border-radius: 6px;
}

.lib-list::-webkit-scrollbar-thumb:hover {
  background: var(--color-mute);
}

.lib-cat {
  margin: 4px var(--space-1) 2px;
  color: var(--color-text-dim);
  font-size: var(--text-small);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.lib-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  width: 100%;
  height: 32px;
  padding: 0 6px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.lib-row:hover {
  background: var(--color-surface);
}

.lib-row.active {
  background: var(--color-pick);
  box-shadow: inset 3px 0 0 var(--color-accent);
}

.lib-row canvas {
  width: 22px;
  height: 22px;
}

.lib-row .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lib-row .chip {
  padding: 2px 6px;
  background: var(--color-surface);
  color: var(--color-text-dim);
  font-size: var(--text-small);
}

.lib-row.active .chip,
.lib-row:hover .chip {
  background: var(--color-ink);
}

.canvas-host {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--color-paper);
  transition: margin-right 0.22s var(--ease-out);
}

#topo {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--color-paper);
  touch-action: none;
}

.status {
  display: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  min-height: 28px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  white-space: nowrap;
  writing-mode: horizontal-tb;
  cursor: pointer;
}

.btn:hover, .btn.is-hover { background: var(--color-surface-hi); }
.btn:active, .btn.is-active { transform: translateY(1px); }
.btn:focus-visible, .btn.is-focus {
  outline: 2px solid var(--color-focus);
  outline-offset: 2px;
}
.btn:disabled, .btn.is-disabled {
  color: var(--color-mute);
  cursor: default;
  transform: none;
}
.btn[data-state="loading"] { opacity: 0.7; }
.btn[data-state="error"] { box-shadow: inset 0 0 0 1px var(--color-error); }
.btn[data-state="success"] { box-shadow: inset 0 0 0 1px var(--color-success); }

.btn.primary, .btn.selected {
  background: var(--color-accent);
  color: var(--color-on-accent);
  box-shadow: inset 0 0 0 1px var(--color-accent-rim);
}
.btn.primary:hover, .btn.selected:hover { background: var(--color-accent-hi); }
.btn.primary:active { background: var(--color-accent-press); }

.btn.danger {
  background: var(--color-danger);
  color: var(--color-on-accent);
}
.btn.danger:hover { background: var(--color-danger-hi); }
.btn.danger:active { background: var(--color-danger-press); }

.btn.secondary {
  background: var(--color-field);
  color: var(--color-text);
  box-shadow: inset 0 0 0 1px var(--color-line);
}

.btn.secondary:hover {
  background: var(--color-surface-hi);
  box-shadow: inset 0 0 0 1px var(--color-mute);
}

.btn.quiet { background: var(--color-surface); }
.btn.ghost { background: var(--color-surface); }

.btn.wide { width: 100%; height: 32px; }

.btn.warn,
.rail-head .btn {
  width: auto;
  height: 26px;
  padding: 0 6px;
  background: #e67e22;
  color: #fff;
}

.btn.warn:hover,
.btn.warn.is-hover,
.rail-head .btn:hover,
.rail-head .btn.is-hover {
  background: #f39c12;
}

.btn.warn:active,
.rail-head .btn:active {
  background: #d35400;
}

.ctx {
  display: none;
  position: fixed;
  z-index: 40;
  min-width: 200px;
  padding: var(--space-1) 0;
  background: var(--color-surface);
  border: var(--rule) solid var(--color-line);
}

.ctx.open { display: block; }

.ctx button {
  display: block;
  width: 100%;
  padding: 7px var(--space-4);
  border: 0;
  background: transparent;
  color: var(--color-text);
  text-align: left;
  cursor: pointer;
}

.ctx button:hover { background: var(--color-surface-hi); }

dialog {
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  margin: auto;
  padding: 0;
  overflow: auto;
  border: var(--rule) solid var(--color-line);
  border-radius: var(--radius-md);
  background: var(--color-card);
  color: var(--color-text);
  box-shadow: 0 18px 48px var(--color-shadow);
}

dialog:focus {
  outline: none;
}

dialog::backdrop {
  background: var(--color-overlay);
}

.dlg {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-5);
}

.dlg h3 {
  margin: 0;
  font-size: 1rem;
}

.dlg p, .dlg .mute {
  margin: 0;
  color: var(--color-mute);
}

.dlg label {
  display: grid;
  gap: var(--space-1);
  color: var(--color-text-dim);
}

.dlg input, .dlg select, .dlg textarea {
  width: 100%;
  min-width: 0;
  height: 32px;
  padding: 0 var(--space-2);
  background: var(--color-field);
  border: var(--rule) solid var(--color-field-border);
}

.dlg textarea { height: 72px; padding: var(--space-2); resize: vertical; }

.dlg-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: var(--space-4);
}

.preview-card {
  display: grid;
  place-items: center;
  min-height: 180px;
  padding: var(--space-4);
  background: var(--color-paper);
}

.preview-card canvas { width: 96px; height: 96px; }

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
}

#msg-body {
  white-space: pre-wrap;
  line-height: 1.55;
}

.dlg a {
  color: var(--color-accent-hi);
  text-underline-offset: 3px;
}

.dlg a:hover {
  color: var(--color-accent);
}

.help-body {
  white-space: pre-wrap;
  line-height: 1.55;
}

/* ⚙️ 设置面板精致样式 */
#dlg-settings {
  width: min(580px, calc(100vw - 32px));
}

.dlg-settings-form {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-5);
}

.dlg-head h3 {
  margin: 0 0 4px 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--color-text);
}

.settings-section {
  display: grid;
  gap: 10px;
  padding: 14px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-sm);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--color-accent-hi);
  padding-bottom: 4px;
  border-bottom: 1px dashed var(--color-line);
}

.section-tag {
  font-size: 0.72rem;
  font-weight: normal;
  padding: 1px 6px;
  border-radius: 10px;
  background: rgba(243, 156, 18, 0.15);
  color: #f39c12;
}

.set-hint-text {
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--color-mute);
  margin-top: -4px;
  margin-bottom: 4px;
}

.field-with-btn {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.grow-label {
  flex: 1;
  min-width: 0;
}

.btn-sm {
  height: 32px;
  padding: 0 10px;
  font-size: 0.8rem;
  white-space: nowrap;
}

.input-password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.input-password-wrap input {
  padding-right: 36px;
}

.btn-icon {
  position: absolute;
  right: 2px;
  height: 28px;
  width: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent !important;
  border: none !important;
  cursor: pointer;
  opacity: 0.7;
}

.btn-icon:hover {
  opacity: 1;
}

.model-select-row {
  display: grid;
  grid-template-columns: 1fr 140px;
  gap: 10px;
}

.model-quick-label select {
  font-size: 0.82rem;
}

.ai-test-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 4px;
}

.ai-test-status {
  font-size: 0.82rem;
  line-height: 1.4;
  word-break: break-all;
}

.ai-test-status.testing {
  color: #f39c12;
}

.ai-test-status.success {
  color: #2ecc71;
  font-weight: 500;
}

.ai-test-status.error {
  color: #e74c3c;
}

.dlg-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.list-table {
  width: 100%;
  border-collapse: collapse;
}

.list-table th, .list-table td {
  padding: 8px 6px;
  border-bottom: var(--rule) solid var(--color-line);
  text-align: left;
}

.list-table tr.active { background: var(--color-surface); }

.list-table tr { cursor: pointer; }

.list-table td.act {
  width: 1%;
  text-align: right;
  white-space: nowrap;
  padding-right: 0;
}

.list-table td.act .btn {
  min-height: 26px;
  padding: 0 10px;
}

.list-table .editing-mark {
  margin-left: 6px;
  color: var(--color-mute);
  font-size: var(--text-small);
}

.btn.danger:disabled,
.btn.danger.is-disabled,
.btn.danger:disabled:hover,
.btn.danger.is-disabled:hover {
  background: var(--color-surface);
  color: var(--color-mute);
  box-shadow: none;
}

.color-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.hidden-file { display: none; }

@media (max-width: 768px) {
  body {
    grid-template-rows: auto auto minmax(0, 1fr);
  }
  .menubar {
    display: grid;
    grid-template-columns: 1fr;
    height: auto;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-2) var(--space-2);
  }
  .menubar-left { height: 32px; z-index: auto; }
  .menubar-center {
    position: static;
    left: auto;
    top: auto;
    max-width: none;
    transform: none;
    justify-content: center;
    order: -1;
    padding: var(--space-1) 0;
  }
  .workbench {
    grid-template-columns: 1fr;
    grid-template-rows: 220px minmax(0, 1fr);
  }
  .rail { border-right: 0; border-bottom: var(--rule) solid var(--color-line); }
  .toolbar { grid-template-columns: 1fr; height: auto; padding: var(--space-2); }
  .file-bar { width: 100%; height: auto; min-width: 0; flex-wrap: wrap; z-index: auto; }
  .dlg-grid { grid-template-columns: 1fr; }
  #title { width: 320px; max-width: 90vw; }
}

html:fullscreen .menubar,
html:-webkit-full-screen .menubar,
html.is-fs .menubar {
  display: flex;
  height: var(--menu-h);
  min-height: var(--menu-h);
  gap: 0;
  padding: 0 var(--space-2);
  overflow: visible;
}

html:fullscreen .menubar-left,
html:-webkit-full-screen .menubar-left,
html.is-fs .menubar-left {
  height: 100%;
}

html:fullscreen .menubar-center,
html:-webkit-full-screen .menubar-center,
html.is-fs .menubar-center {
  position: absolute;
  left: 50%;
  top: 50%;
  order: 0;
  max-width: 48%;
  padding: 0 var(--space-3);
  transform: translate(calc(-50% - 50px), -50%);
}

html:fullscreen .file-bar,
html:-webkit-full-screen .file-bar,
html.is-fs .file-bar {
  width: auto;
  height: 100%;
  min-width: 0;
  flex-wrap: nowrap;
}

html:fullscreen .toolbar,
html:-webkit-full-screen .toolbar,
html.is-fs .toolbar {
  grid-template-columns: auto auto minmax(0, 1fr);
  height: var(--toolbar-h);
  padding: 0 var(--space-3);
}

html:fullscreen .workbench,
html:-webkit-full-screen .workbench,
html.is-fs .workbench {
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}

html:fullscreen .workbench.has-ai-split,
html:-webkit-full-screen .workbench.has-ai-split,
html.is-fs .workbench.has-ai-split {
  grid-template-columns: var(--rail-w) minmax(280px, 1fr) 6px minmax(320px, var(--ai-panel-w, 1fr));
}

html:fullscreen .workbench.has-ai-split.ai-split-maximized,
html:-webkit-full-screen .workbench.has-ai-split.ai-split-maximized,
html.is-fs .workbench.has-ai-split.ai-split-maximized {
  grid-template-columns: 0 0 0 minmax(0, 1fr);
}

html:fullscreen .workbench.has-ai-split.ai-split-collapsed,
html:-webkit-full-screen .workbench.has-ai-split.ai-split-collapsed,
html.is-fs .workbench.has-ai-split.ai-split-collapsed {
  grid-template-columns: var(--rail-w) minmax(0, 1fr) 0 0;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* AI 分析按钮与弹窗样式 */
.rail-head-actions {
  display: flex;
  flex-direction: column;
  flex: none;
  align-items: stretch;
  gap: 4px;
}

.rail-action-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.rail-head-actions .btn {
  flex: 1 1 0;
  white-space: nowrap;
}

.rail-head .btn.ai-btn {
  background: linear-gradient(135deg, #6c5ce7 0%, #8e44ad 100%);
  color: #ffffff;
  font-weight: 500;
  box-shadow: 0 2px 6px rgba(108, 92, 231, 0.35);
  border: none;
}

.rail-head .btn.ai-btn:hover {
  background: linear-gradient(135deg, #5b4bd8 0%, #7d3c98 100%);
  box-shadow: 0 3px 10px rgba(108, 92, 231, 0.55);
}

.rail-head .btn.ai-btn:active {
  background: #4834d4;
}

.rail-head .btn.ai-correct-btn,
.rail-head .btn.ai-recommend-btn {
  padding-inline: 8px;
  color: #fff;
  border: none;
  font-weight: 600;
}

.rail-head .btn.ai-correct-btn {
  background: #2474c6;
}

.rail-head .btn.ai-correct-btn:hover {
  background: #2f86dd;
}

.rail-head .btn.ai-recommend-btn {
  background: #16866f;
}

.rail-head .btn.ai-recommend-btn:hover {
  background: #1b9b81;
}

.ai-split-resizer {
  width: 6px;
  height: 100%;
  cursor: col-resize;
  background: var(--color-line);
  position: relative;
  transition: background 0.15s ease;
  user-select: none;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-split-resizer[hidden] {
  display: none !important;
}

.ai-split-resizer:hover,
.ai-split-resizer.is-dragging {
  background: var(--color-accent);
}

.ai-split-resizer::after {
  content: "";
  display: block;
  width: 2px;
  height: 32px;
  background: var(--color-mute);
  border-radius: 1px;
}

.ai-split-resizer:hover::after,
.ai-split-resizer.is-dragging::after {
  background: #ffffff;
}

.ai-split-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: var(--color-card);
  border-left: var(--rule) solid var(--color-line);
  box-shadow: -4px 0 24px var(--color-shadow);
  z-index: 5;
}

.ai-split-panel[hidden] {
  display: none !important;
}

.ai-split-peek {
  display: none;
  position: absolute;
  top: 0;
  right: 0;
  width: 18px;
  height: 100%;
  z-index: 9;
  cursor: pointer;
  background: transparent;
}

.ai-split-peek::before {
  content: "";
  position: absolute;
  top: 50%;
  right: 4px;
  width: 4px;
  height: 56px;
  border-radius: 4px;
  background: var(--color-accent);
  opacity: 0.55;
  transform: translateY(-50%);
}

.ai-split-peek:hover::before {
  opacity: 1;
  height: 72px;
}

.workbench.has-ai-split.ai-split-collapsed .ai-split-peek {
  display: block;
}

.ai-split-peek[hidden] {
  display: none !important;
}

.dlg-ai-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.dlg-ai-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: var(--rule) solid var(--color-line);
  background: var(--color-surface);
  flex: none;
}

.dlg-ai-title-wrap {
  display: flex;
  align-items: center;
  flex: none;
  gap: 12px;
}

.dlg-ai-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, #6c5ce7 0%, #a29bfe 100%);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  box-shadow: 0 2px 8px rgba(108, 92, 231, 0.4);
}

.dlg-ai-titles h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.25;
}

.dlg-ai-subtitle {
  font-size: 12px;
  color: var(--color-text-dim);
}

.dlg-ai-subtitle code {
  font-family: var(--font-mono, monospace);
  padding: 1px 5px;
  background: var(--color-field);
  border-radius: 4px;
  color: #9b59b6;
}

.dlg-ai-header-btns {
  display: flex;
  align-items: center;
  flex: none;
  gap: 6px;
  margin-left: auto;
}

.dlg-ai-tool-btn {
  background: transparent;
  border: none;
  font-size: 15px;
  line-height: 1;
  color: var(--color-text-dim);
  cursor: pointer;
  min-width: 32px;
  min-height: 32px;
  padding: 6px;
  border-radius: 4px;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 2;
}

.dlg-ai-tool-btn.is-active {
  background: var(--color-pick);
  color: #e8943a;
}

.dlg-ai-tool-btn:hover {
  background: var(--color-surface-hi);
  color: var(--color-text);
}

.dlg-ai-tool-btn.dlg-ai-x {
  font-size: 22px;
  padding: 2px 8px;
}

.dlg-ai-status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  background: var(--color-field);
  border-bottom: var(--rule) solid var(--color-line);
  font-size: 12px;
  color: var(--color-text-dim);
  flex: none;
}

.ai-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3498db;
  display: inline-block;
}

.ai-status-dot.pulsing {
  background: #2ecc71;
  box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.7);
  animation: ai-pulse 1.6s infinite;
}

.ai-status-dot.error {
  background: #e74c3c;
  animation: none;
}

.ai-status-dot.done {
  background: #27ae60;
  animation: none;
}

@keyframes ai-pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(46, 204, 113, 0.7); }
  70% { transform: scale(1.1); box-shadow: 0 0 0 8px rgba(46, 204, 113, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); }
}

.dlg-ai-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px 16px;
  scroll-behavior: smooth;
  background: var(--color-card);
}

.dlg-ai-content {
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
  word-break: break-word;
}

/* Markdown 排版增强 */
.dlg-ai-content h1, .dlg-ai-content h2, .dlg-ai-content h3, .dlg-ai-content h4 {
  margin: 0.65em 0 0.25em;
  color: var(--color-text);
  font-weight: 600;
  line-height: 1.3;
}

.dlg-ai-content h1:first-child,
.dlg-ai-content h2:first-child,
.dlg-ai-content h3:first-child,
.dlg-ai-message-body > :first-child {
  margin-top: 0;
}

.dlg-ai-content :is(h1, h2, h3, h4) + :is(h1, h2, h3, h4) {
  margin-top: 0.3em;
}

.dlg-ai-content h3 {
  font-size: 1.05rem;
  border-bottom: var(--rule) solid var(--color-line);
  padding-bottom: 3px;
  color: #3498db;
}

[data-theme="dark"] .dlg-ai-content h3 {
  color: #5dade2;
}

.dlg-ai-content p {
  margin: 0.35em 0;
}

.dlg-ai-content ul, .dlg-ai-content ol {
  margin: 0.25em 0 0.4em 20px;
  padding: 0;
}

.dlg-ai-content li {
  margin: 0.15em 0;
}

.dlg-ai-message.assistant ol li::marker {
  color: #6c8cff;
  font-weight: 700;
}

.dlg-ai-message.assistant ol li > strong:first-child {
  display: inline;
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: #f39c12;
}

.dlg-ai-content strong {
  font-weight: 600;
  color: #e67e22;
}

[data-theme="dark"] .dlg-ai-content strong {
  color: #f39c12;
}

.dlg-ai-content blockquote {
  margin: 0.5em 0;
  padding: 6px 12px;
  border-left: 4px solid #6c5ce7;
  background: var(--color-surface);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--color-text-dim);
}

.dlg-ai-content code {
  font-family: var(--font-mono, monospace);
  font-size: 0.9em;
  padding: 2px 6px;
  background: var(--color-field);
  border: var(--rule) solid var(--color-line);
  border-radius: 4px;
  color: #e74c3c;
}

[data-theme="dark"] .dlg-ai-content code {
  color: #ff7675;
}

.dlg-ai-content pre {
  margin: 1em 0;
  padding: 12px 16px;
  background: var(--color-surface);
  border: var(--rule) solid var(--color-line);
  border-radius: var(--radius-sm);
  overflow-x: auto;
}

.dlg-ai-content pre code {
  background: transparent;
  border: none;
  padding: 0;
  color: var(--color-text);
}

.ai-table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 0.6em 0;
  border-radius: var(--radius-sm);
  border: var(--rule) solid var(--color-line);
  -webkit-overflow-scrolling: touch;
}

.dlg-ai-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 0;
  font-size: 13px;
  background: var(--color-surface);
  border: none;
}

.dlg-ai-content th, .dlg-ai-content td {
  padding: 5px 8px;
  text-align: left;
  border-bottom: var(--rule) solid var(--color-line);
  border-right: var(--rule) solid var(--color-line);
}

.dlg-ai-content th:last-child, .dlg-ai-content td:last-child {
  border-right: none;
}

.dlg-ai-content th {
  background: var(--color-field);
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
}

.dlg-ai-content tbody tr:nth-child(even) {
  background: var(--color-field);
}

.dlg-ai-content tr:last-child td {
  border-bottom: none;
}

.ai-cursor {
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 3px;
  vertical-align: -2px;
  background: #6c5ce7;
  animation: ai-blink 0.8s infinite;
}

@keyframes ai-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.dlg-ai-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  border-top: var(--rule) solid var(--color-line);
  background: var(--color-surface);
  flex: none;
}

.ai-chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  width: 100%;
}

.ai-chat-form textarea {
  min-width: 0;
  min-height: 48px;
  max-height: 120px;
  resize: vertical;
  padding: 9px 11px;
  color: var(--color-text);
  background: var(--color-field);
  border: var(--rule) solid var(--color-line);
  border-radius: var(--radius-sm);
  font: inherit;
  line-height: 1.45;
}

.ai-chat-form textarea:focus {
  outline: 2px solid color-mix(in srgb, #6c5ce7 55%, transparent);
  outline-offset: 1px;
}

.btn.ai-chat-send {
  align-self: stretch;
  min-width: 64px;
  color: #fff;
  background: #6c5ce7;
  border-color: #6c5ce7;
}

.dlg-ai-message {
  margin: 0 0 8px;
  padding: 8px 10px;
  border: var(--rule) solid var(--color-line);
  border-radius: 10px;
  background: var(--color-surface);
}

.dlg-ai-message.user {
  margin-left: 12%;
  border-color: color-mix(in srgb, #6c5ce7 55%, var(--color-line));
  background: color-mix(in srgb, #6c5ce7 12%, var(--color-surface));
}

.dlg-ai-message-role {
  margin-bottom: 5px;
  color: var(--color-text-dim);
  font-size: 12px;
  font-weight: 600;
}

.dlg-ai-message-body > :first-child {
  margin-top: 0;
}

.dlg-ai-message-body > :last-child {
  margin-bottom: 0;
}

.dlg-ai-meta {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.25;
  color: #e8943a;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dlg-ai-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

.dlg-ai-actions .btn {
  height: 32px;
  min-height: 32px;
  padding: 0 14px;
  font-weight: 600;
  box-sizing: border-box;
}

.btn.btn-ai-retry {
  background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
  color: #ffffff;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 2px 6px rgba(231, 76, 60, 0.4);
}

.btn.btn-ai-retry:hover {
  background: linear-gradient(135deg, #ff5252 0%, #d63031 100%);
  box-shadow: 0 3px 10px rgba(231, 76, 60, 0.6);
}

.btn.btn-ai-retry:active {
  background: #c0392b;
}
