:root {
  color-scheme: dark;
  --bg: #131418;
  --panel: #1b1d23;
  --panel-2: #22252d;
  --line: #2f333d;
  --line-soft: #282b33;
  --text: #ececf1;
  --muted: #9a9fab;
  --accent: #8bc6ad;
  --accent-soft: rgba(139, 198, 173, 0.14);
  --accent-strong: #c9e8d8;
  --on-accent: #10201a;
  --warning: #e2b17d;
  --notice-bg: rgba(226, 177, 125, 0.1);
  --notice-text: #f0d4ae;
  --user-bubble: #2b4237;
  --user-avatar: #3d4250;
  --user-avatar-text: #ececf1;
  font-family:
    Inter, "PingFang SC", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f7f8;
  --panel: #ffffff;
  --panel-2: #f1f2f4;
  --line: #d9dbe1;
  --line-soft: #e6e8ec;
  --text: #202123;
  --muted: #6e7280;
  --accent: #2f8a63;
  --accent-soft: rgba(47, 138, 99, 0.1);
  --accent-strong: #23684b;
  --on-accent: #ffffff;
  --warning: #b97f36;
  --notice-bg: rgba(185, 127, 54, 0.1);
  --notice-text: #8a5c22;
  --user-bubble: #dcefe5;
  --user-avatar: #d5d7dd;
  --user-avatar-text: #202123;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

/* ---------- 整体框架 ---------- */

.app-frame {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex: 0 0 auto;
  padding: 0 20px;
  height: 52px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--panel);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-name {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.02em;
  background: linear-gradient(120deg, var(--accent), var(--accent-strong));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}

.brand-sub {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  max-width: 52%;
}

.topbar-status {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.theme-toggle {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-size: 15px;
  line-height: 1;
  padding: 0;
}

.theme-toggle:hover {
  border-color: var(--accent);
}

.spinner {
  flex: 0 0 auto;
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  vertical-align: -2px;
  animation: spin 0.9s linear infinite;
}

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

.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  z-index: 100;
  max-width: min(520px, calc(100vw - 40px));
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 18px;
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
  opacity: 1;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast.hidden {
  display: block !important;
  opacity: 0;
  transform: translateX(-50%) translateY(12px);
  pointer-events: none;
}

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

/* ---------- 侧栏 ---------- */

.sidebar {
  overflow-y: auto;
  padding: 18px 16px 28px;
  background: var(--panel);
}

.sidebar-left {
  border-right: 1px solid var(--line-soft);
}

.sidebar-right {
  border-left: 1px solid var(--line-soft);
}

.side-section {
  margin-bottom: 26px;
}

.side-section h3 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.side-hint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.side-section dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 14px;
  margin: 0;
  font-size: 13px;
}

.side-section dt {
  color: var(--muted);
}

.side-section dd {
  margin: 0;
  color: var(--accent-strong);
  font-variant-numeric: tabular-nums;
}

.profile-analysis {
  display: grid;
  gap: 8px;
}

.analysis-line {
  display: grid;
  gap: 3px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 9px 11px;
  background: var(--panel-2);
}

.analysis-line strong {
  color: var(--accent-strong);
  font-size: 11px;
}

.analysis-line span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.side-list {
  display: grid;
  gap: 8px;
}

.recent-item {
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.recent-item strong {
  color: var(--text);
}

.recent-audio-link {
  display: inline-block;
  margin-top: 6px;
  color: var(--accent-strong);
  font-size: 13px;
  text-decoration: none;
}

.recent-audio-link:hover {
  text-decoration: underline;
}

.recent-item-footer {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin-top: 10px;
}

.play-icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0 0 0 2px;
  border: none;
  border-radius: 50%;
  color: var(--on-accent);
  background: var(--accent);
  font-size: 12px;
  line-height: 1;
}

.play-icon-button:hover {
  filter: brightness(1.1);
}

.upload-form {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.upload-form input[type="file"],
.upload-form input:not([type="file"]) {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 10px;
  color: var(--text);
  background: var(--panel-2);
  font-size: 13px;
}

/* ---------- 中间对话列 ---------- */

.chat-column {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}

.chat-scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 28px 0 12px;
}

.chat-message {
  display: flex;
  gap: 12px;
  width: min(760px, calc(100% - 48px));
  margin: 0 auto 22px;
}

.chat-status {
  width: min(760px, calc(100% - 48px));
  margin: 0 auto 16px;
  color: var(--muted);
  font-size: 13px;
}

.chat-message span {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  color: var(--on-accent);
  background: var(--accent);
  overflow: hidden;
  white-space: nowrap;
}

.chat-message p {
  margin: 2px 0 0;
  line-height: 1.75;
  white-space: pre-wrap;
  color: var(--text);
  min-width: 0;
}

.chat-listening-button {
  display: block;
  margin-top: 10px;
  padding: 8px 14px;
  border: 1px solid var(--accent);
  border-radius: 12px;
  background: transparent;
  color: var(--accent);
}

.chat-message.user {
  flex-direction: row-reverse;
}

.chat-message.user span {
  color: var(--text);
  background: var(--user-avatar);
}

.chat-message.user p {
  background: var(--user-bubble);
  border-radius: 16px;
  padding: 10px 15px;
  max-width: 82%;
}

/* ---------- 底部输入区 ---------- */

.composer-dock {
  flex: 0 0 auto;
  width: min(760px, calc(100% - 48px));
  margin: 0 auto;
  padding-bottom: 14px;
}

.agent-hints {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.agent-hints button {
  min-height: 30px;
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 0 13px;
  color: var(--muted);
  background: var(--panel);
  font-size: 12px;
}

.agent-hints button:hover {
  color: var(--text);
  border-color: var(--accent);
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 10px 10px 16px;
  background: var(--panel);
}

.composer:focus-within {
  border-color: var(--accent);
}

.composer textarea {
  flex: 1 1 auto;
  max-height: 180px;
  min-height: 24px;
  resize: none;
  border: none;
  padding: 4px 0;
  color: var(--text);
  background: transparent;
  outline: none;
  line-height: 1.6;
}

.send-button {
  flex: 0 0 auto;
  min-height: 36px;
  border: none;
  border-radius: 10px;
  padding: 0 16px;
  font-weight: 700;
  color: var(--on-accent);
  background: var(--accent);
}

.composer-note {
  margin: 8px 4px 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

/* ---------- 右栏：今晚内容 ---------- */

.now-title {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.5;
}

.now-meta {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.primary-action,
.ghost-action {
  min-height: 38px;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 650;
  font-size: 13px;
}

.primary-action {
  color: var(--on-accent);
  background: var(--accent);
}

.ghost-action {
  color: var(--text);
  background: var(--panel-2);
  border-color: var(--line);
}

.quality-notice {
  margin-top: 12px;
  border: 1px solid rgba(226, 177, 125, 0.4);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--notice-bg);
  color: var(--notice-text);
  font-size: 12px;
  line-height: 1.6;
}

#retryAudioButton {
  width: 100%;
  margin-top: 10px;
}

.audio-player {
  display: none;
  width: 100%;
  margin-top: 12px;
}

.audio-player[src] {
  display: block;
}

.feedback-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.feedback-row button {
  min-height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: var(--panel-2);
  font-size: 12px;
}

.feedback-row button:hover {
  color: var(--text);
  border-color: var(--accent);
}

/* ---------- 生成日志 ---------- */

.gen-log {
  display: grid;
  gap: 5px;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--panel-2);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.gen-log div {
  color: var(--muted);
  line-height: 1.55;
}

.gen-log div:last-child {
  color: var(--text);
}

.gen-log time {
  margin-right: 6px;
  color: var(--accent-strong);
}

/* ---------- 结构与脚本 ---------- */

.structure-details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  list-style: none;
}

.structure-details summary::before {
  content: "▸ ";
}

.structure-details[open] summary::before {
  content: "▾ ";
}

.segment-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.segment-item {
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--panel-2);
}

.segment-item strong {
  display: block;
  color: var(--accent-strong);
  margin-bottom: 4px;
  font-size: 13px;
}

.segment-item span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.script-text {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.85;
  white-space: pre-wrap;
}

.hidden {
  display: none !important;
}

/* ---------- 聊天调用过程 ---------- */

.call-trace-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.call-trace-live { color: var(--muted); font-size: 11px; white-space: nowrap; }
.call-trace-list { display: grid; gap: 8px; }
.call-trace { border: 1px solid var(--line-soft); border-radius: 10px; background: var(--panel-2); overflow: hidden; }
.call-trace summary { padding: 11px 10px; cursor: pointer; list-style: none; }
.call-trace summary::-webkit-details-marker { display: none; }
.call-trace summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.call-trace-top { display: flex; gap: 8px; align-items: center; justify-content: space-between; font-size: 12px; }
.call-trace-top::after { content: "⌄"; color: var(--muted); }
.call-trace[open] .call-trace-top::after { content: "⌃"; }
.call-trace-status { flex: 1; font-weight: 650; }
.call-trace[data-status="running"] .call-trace-status { color: var(--warning); }
.call-trace[data-status="completed"] .call-trace-status { color: var(--accent); }
.call-trace[data-status="failed"] .call-trace-status { color: var(--notice-text); }
.call-trace-duration, .call-trace-ref { color: var(--muted); font-size: 11px; }
.call-trace-ref { display: block; margin-top: 6px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.call-trace-events { padding: 0 12px 10px 28px; margin: 0; list-style: none; }
.call-trace-events li { position: relative; border-left: 1px solid var(--line); padding: 0 0 13px 13px; font-size: 12px; line-height: 1.55; }
.call-trace-events li:last-child { border-color: transparent; padding-bottom: 0; }
.call-trace-events li::before { content: ""; position: absolute; left: -4px; top: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.call-trace-events li[data-outcome="ok"]::before { background: var(--accent); }
.call-trace-events li[data-outcome="error"]::before, .call-trace-events li[data-outcome="aborted"]::before { background: var(--warning); }
.call-trace-event-meta { display: block; color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.call-trace-empty { margin: 0 12px 12px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.call-trace-provider { margin-top: 7px; border: 1px solid var(--line); border-radius: 6px; }
.call-trace-provider summary { padding: 7px 8px; color: var(--notice-text); font-size: 11px; overflow-wrap: anywhere; }
.call-trace-provider summary::before { content: "+ "; }
.call-trace-provider[open] summary::before { content: "− "; }
.side-section .call-trace-error-fields { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; padding: 0 8px; margin: 7px 0; font-size: 11px; }
.call-trace-error-fields:empty { display: none; }
.call-trace-error-fields dt { color: var(--muted); }
.call-trace-error-fields dd { margin: 0 0 6px; overflow-wrap: anywhere; }
.call-trace-error-note, .call-trace-error-message { margin: 8px; font-size: 11px; line-height: 1.6; overflow-wrap: anywhere; }
.call-trace-error-note { color: var(--muted); }

/* ---------- 移动端底部标签导航 ---------- */

.mobile-nav {
  display: none;
}

/* ---------- 响应式 ---------- */

@media (max-width: 1080px) and (min-width: 761px) {
  .columns {
    grid-template-columns: 180px minmax(0, 1fr) 260px;
  }

  .sidebar {
    padding-left: 12px;
    padding-right: 12px;
  }
}

@media (max-width: 760px) {
  .columns {
    display: block;
    padding-bottom: 56px;
  }

  /* 默认显示对话；body[data-mobile-panel] 切换面板 */
  .sidebar-left,
  .sidebar-right,
  .chat-column {
    display: none;
    height: 100%;
  }

  body[data-mobile-panel="chat"] .chat-column,
  body:not([data-mobile-panel]) .chat-column {
    display: flex;
  }

  body[data-mobile-panel="left"] .sidebar-left,
  body[data-mobile-panel="right"] .sidebar-right {
    display: block;
    border: none;
  }

  .chat-scroll {
    padding-top: 16px;
  }

  .chat-message,
  .composer-dock {
    width: calc(100% - 24px);
  }

  .mobile-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 50;
    display: flex;
    height: 56px;
    border-top: 1px solid var(--line-soft);
    background: var(--panel);
  }

  .mobile-nav button {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 14px;
    font-weight: 650;
  }

  .mobile-nav button.active {
    color: var(--accent);
  }

  .toast {
    bottom: 70px;
  }
}
