:root {
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-alt: #f0eee7;
  --ink: #222831;
  --muted: #68707a;
  --line: #ddd8ca;
  --line-strong: #c9c1ad;
  --accent: #295d72;
  --accent-dark: #1f4656;
  --success: #2f7d5c;
  --warning: #a56a19;
  --danger: #b4473e;
  --info: #376da0;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
  overflow-x: hidden;
}

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

button {
  cursor: pointer;
}

.app-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 22px;
  width: min(1320px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.sidebar {
  position: sticky;
  top: 24px;
  align-self: start;
  min-width: 0;
  min-height: calc(100vh - 48px);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffaf0;
}

.sidebar-brand {
  padding-bottom: 18px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.content-shell {
  min-width: 0;
  max-width: 100%;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 16px;
  margin-bottom: 14px;
}

.tabs {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tab,
.btn-outline,
.btn-primary,
.btn-small {
  display: inline-block;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  padding: 8px 13px;
  font-size: 14px;
  text-decoration: none;
  transition:
    background 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease;
}

.tab {
  width: 100%;
  text-align: left;
}

.tab.active,
.btn-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.tab:hover,
.btn-outline:hover,
.btn-small:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-dark);
}

.btn-small {
  padding: 5px 9px;
  font-size: 12px;
}

.status-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 22px;
}

.stat,
.box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.stat {
  padding: 14px 18px;
}

.stat .label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 4px;
}

.stat strong {
  font-size: 24px;
  font-weight: 800;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.grid {
  display: grid;
  gap: 16px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.split {
  grid-template-columns: minmax(300px, 0.8fr) minmax(420px, 1.2fr);
  align-items: start;
}

.box {
  padding: 18px;
}

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

.form-stack {
  display: grid;
  gap: 16px;
}

.form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

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

.field-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.choice-list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-alt);
}

.choice-item {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 2px 8px;
  align-items: start;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: #fff;
}

.choice-item input {
  width: 16px;
  height: 16px;
  margin-top: 2px;
}

.choice-item span {
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

.choice-item small {
  grid-column: 2;
  color: var(--muted);
  font-size: 12px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(41, 93, 114, 0.12);
}

textarea {
  resize: vertical;
}

.script-input {
  min-height: 260px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.actions {
  display: flex;
  gap: 10px;
}

.preview {
  min-height: 150px;
  max-height: 280px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-alt);
  color: #313840;
  font-size: 13px;
  white-space: pre-wrap;
}

.script-detail-preview {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-alt);
}

.script-detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.script-detail-head h3 {
  margin-bottom: 4px;
}

.script-detail-head span {
  color: var(--muted);
  font-size: 13px;
}

.script-detail-errors {
  margin: 12px 14px 0;
  padding: 10px;
  border: 1px solid rgba(180, 71, 62, 0.28);
  border-radius: 6px;
  background: rgba(180, 71, 62, 0.08);
  color: var(--danger);
  font-size: 12px;
}

.script-lines {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
  padding: 14px;
}

.script-line {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.script-line-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(41, 93, 114, 0.12);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.script-line strong {
  display: block;
  margin-bottom: 4px;
}

.script-line p {
  margin: 0;
  color: #313840;
  font-size: 13px;
}

.script-raw-detail {
  padding: 0 14px 14px;
}

.script-raw-detail summary {
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.script-raw-detail pre {
  max-height: 220px;
  overflow: auto;
  margin: 10px 0 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  white-space: pre-wrap;
}

.table-wrap {
  max-height: 560px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.table-wrap.compact {
  max-height: 360px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

tr:last-child td {
  border-bottom: 0;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 22px 12px;
}

.status-tag {
  display: inline-block;
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.tag-pending,
.tag-created,
.tag-invalid {
  background: rgba(165, 106, 25, 0.12);
  color: var(--warning);
}

.tag-running,
.tag-processing {
  background: rgba(55, 109, 160, 0.12);
  color: var(--info);
}

.tag-completed,
.tag-success {
  background: rgba(47, 125, 92, 0.12);
  color: var(--success);
}

.tag-failed,
.tag-error {
  background: rgba(180, 71, 62, 0.12);
  color: var(--danger);
}

.muted {
  color: var(--muted);
}

.task-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.task-audio {
  display: block;
  width: min(260px, 100%);
  height: 32px;
  margin-top: 8px;
}

.task-error {
  max-width: 360px;
  margin-top: 8px;
  color: var(--danger);
  font-size: 12px;
  line-height: 1.5;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100% - 44px));
  padding: 12px 16px;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-error {
  background: var(--danger);
}

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

.role-voice-item {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(180px, 220px);
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}

.role-voice-item strong,
.role-voice-item small {
  display: block;
}

.role-voice-item small {
  margin-top: 3px;
  color: var(--muted);
}

@media (max-width: 860px) {
  .app-layout {
    display: block;
    width: min(calc(100vw - 40px), 1180px);
    padding-top: 16px;
  }

  .sidebar {
    position: static;
    min-height: 0;
    max-width: 100%;
    margin-bottom: 16px;
  }

  .sidebar-brand {
    padding-bottom: 12px;
    margin-bottom: 12px;
  }

  .sidebar-brand h1 {
    font-size: 22px;
  }

  .tabs {
    align-items: stretch;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .tabs,
  .actions {
    width: 100%;
  }

  .tab {
    flex: 1 1 auto;
  }

  .status-bar,
  .grid.two,
  .grid.split,
  .form-row,
  .role-voice-item {
    grid-template-columns: 1fr;
  }

  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }
}
