:root {
  --bg: #0b1020;
  --panel: #121a33;
  --panel2: #0f1730;
  --text: #e7ecff;
  --muted: rgba(231, 236, 255, 0.65);
  --line: rgba(231, 236, 255, 0.12);
  --link: #8bb7ff;
  --btn: rgba(231, 236, 255, 0.12);
  --btn2: rgba(231, 236, 255, 0.18);
  --shadow: rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji",
    "Segoe UI Emoji";
  background: radial-gradient(1200px 800px at 15% 10%, rgba(139, 183, 255, 0.14), transparent 55%),
    radial-gradient(900px 700px at 90% 30%, rgba(120, 240, 200, 0.10), transparent 60%),
    var(--bg);
  color: var(--text);
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(18, 26, 51, 0.75);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

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

.brand {
  font-weight: 700;
  letter-spacing: 0.2px;
}

.topnav {
  display: flex;
  gap: 8px;
  align-items: center;
}

.navlink {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(15, 23, 48, 0.55);
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
}

.navlink:hover {
  text-decoration: none;
  background: rgba(15, 23, 48, 0.75);
  color: var(--text);
}

.navlink.active {
  background: rgba(139, 183, 255, 0.18);
  color: var(--text);
  border-color: rgba(139, 183, 255, 0.35);
}

.meta {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 70vw;
}

.container {
  max-width: 1400px;
  margin: 18px auto;
  padding: 0 14px 28px 14px;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 14px;
  align-items: start;
}

.main { min-width: 0; }

.sidebar {
  position: sticky;
  top: 64px;
  align-self: start;
}

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }
}

.panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.01));
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 20px 60px var(--shadow);
  padding: 14px;
  margin: 12px 0;
}

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

.codex-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: end;
}

.codex-check .dlg-k {
  margin-bottom: 6px;
}

.checkline {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  user-select: none;
  color: var(--muted);
  font-size: 13px;
}

.checkline input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

.codex-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.codex-head-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.codex-events {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#ctrlTraceEvents {
  margin-top: 8px;
  max-height: 40vh;
  overflow: auto;
  padding-right: 2px;
}

#ctrlTraceRaw {
  margin-top: 8px;
  max-height: 40vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

#ctrlState {
  max-height: 52vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

#ctrlLogs {
  max-height: 34vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

#ctrlTraceSelect {
  max-width: 100%;
}

#ctrlTraceEvents .code {
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 26vh;
}

#ctrlTraceEvents .kv-v {
  white-space: normal;
  word-break: break-word;
}

#ctrlTraceEvents .codex-card-body {
  overflow-wrap: anywhere;
}

#ctrlTraceEvents li,
#ctrlTraceEvents p,
#ctrlTraceEvents a,
#ctrlTraceEvents .kv-v {
  word-break: break-word;
  overflow-wrap: anywhere;
}

.codex-card {
  border: 1px solid var(--line);
  background: rgba(15, 23, 48, 0.35);
  border-radius: 12px;
  padding: 10px 12px;
}

.codex-card.compact { padding: 8px 10px; }

.codex-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.codex-card-title {
  font-weight: 650;
  font-size: 13px;
}

.codex-card-meta {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.codex-card-body {
  margin-top: 8px;
  color: var(--text);
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}

.md {
  white-space: normal;
  word-break: break-word;
}

.md p {
  margin: 8px 0;
  line-height: 1.45;
}

.md p:first-child { margin-top: 0; }
.md p:last-child { margin-bottom: 0; }

.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 {
  margin: 10px 0 8px 0;
  line-height: 1.25;
}

.md h1 { font-size: 20px; }
.md h2 { font-size: 18px; }
.md h3 { font-size: 16px; }
.md h4, .md h5, .md h6 { font-size: 14px; color: var(--text); }

.md ul, .md ol {
  margin: 8px 0;
  padding-left: 20px;
}

.md li {
  margin: 4px 0;
  line-height: 1.4;
}

.md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  padding: 1px 6px;
  border-radius: 7px;
  border: 1px solid rgba(231, 236, 255, 0.14);
  background: rgba(18, 26, 51, 0.38);
}

.md pre.code {
  margin: 10px 0;
}

.codex-card-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  background: rgba(18, 26, 51, 0.35);
}

.badge.ok { color: rgba(120, 240, 200, 0.95); border-color: rgba(120, 240, 200, 0.22); }
.badge.fail { color: rgba(255, 120, 120, 0.95); border-color: rgba(255, 120, 120, 0.22); }
.badge.run { color: rgba(139, 183, 255, 0.95); border-color: rgba(139, 183, 255, 0.22); }

.kv-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 10px;
  padding: 4px 0;
  border-top: 1px dashed rgba(231, 236, 255, 0.12);
}

.kv-row:first-child { border-top: none; }
.kv-k { color: var(--muted); font-size: 12px; }
.kv-v { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12px; }

details {
  margin-top: 8px;
}

summary {
  cursor: pointer;
  color: var(--link);
  font-size: 13px;
}

.codex-out {
  min-height: 260px;
  max-height: 60vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

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

@media (max-width: 780px) {
  .codex-grid { grid-template-columns: 1fr; }
}

.actions {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.filter {
  width: min(480px, 100%);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  outline: none;
  background: rgba(15, 23, 48, 0.8);
  color: var(--text);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--btn);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
}

.btn.active {
  background: rgba(139, 183, 255, 0.18);
  border-color: rgba(139, 183, 255, 0.35);
}

.btn-sm {
  padding: 6px 10px;
  border-radius: 9px;
  font-size: 12px;
}

.btn:hover { background: var(--btn2); text-decoration: none; }

.btn.disabled,
.btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}

.breadcrumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
}

.crumb { color: var(--link); }
.sep { color: var(--muted); }

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th, .table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.table th {
  color: var(--muted);
  text-align: left;
  font-weight: 600;
  font-size: 13px;
}

.table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.name a { font-weight: 520; }
.meta { text-align: right; font-variant-numeric: tabular-nums; }

.name-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.thumb {
  width: 46px;
  height: 46px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
  flex: 0 0 auto;
}

.name-text {
  word-break: break-word;
}

.row.dir .name a { color: #9fffc0; }
.row.file .name a { color: var(--link); }

.filebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.filename {
  font-weight: 650;
  word-break: break-all;
}

.fileactions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.viewer img.preview-image {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.2);
}

.viewer-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.viewer-count {
  color: var(--muted);
  font-size: 13px;
  padding: 0 6px;
  white-space: nowrap;
}

.viewer audio, .viewer video {
  width: 100%;
}

.code {
  overflow: auto;
  padding: 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line);
  max-height: 70vh;
  white-space: pre;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 13px;
  line-height: 1.45;
}

.note {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 10px;
}

.h1 { margin: 0 0 8px 0; font-size: 18px; }
.p { margin: 0 0 10px 0; color: var(--muted); }

.kv {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.kv:last-child { border-bottom: none; }
.k { color: var(--muted); }
.v { word-break: break-all; }

.staging-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.staging-title {
  font-weight: 650;
}

.staging-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.staging-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 62vh;
  overflow: auto;
  padding-right: 2px;
}

.staging-item {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.18);
}

.staging-thumb {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  object-fit: cover;
  background: rgba(0, 0, 0, 0.25);
}

.staging-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
  background: rgba(0, 0, 0, 0.25);
}

.staging-main {
  min-width: 0;
}

.staging-name {
  font-weight: 560;
  word-break: break-word;
}

.staging-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.staging-foot {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.dlg {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0;
  background: rgba(18, 26, 51, 0.92);
  color: var(--text);
  box-shadow: 0 30px 90px var(--shadow);
  width: min(640px, calc(100vw - 24px));
}

.dlg::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

.dlg-form {
  padding: 14px;
  margin: 0;
}

.dlg-title {
  font-weight: 700;
  margin-bottom: 12px;
}

.dlg-label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.dlg-k {
  color: var(--muted);
  font-size: 13px;
}

.dlg-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  outline: none;
  background: rgba(15, 23, 48, 0.92);
  color: var(--text);
  -webkit-text-fill-color: var(--text);
  transition: border-color 120ms ease, background-color 120ms ease, box-shadow 120ms ease;
}

.dlg-input::placeholder {
  color: var(--muted);
  opacity: 1;
}

.dlg-input:hover {
  border-color: rgba(139, 183, 255, 0.38);
}

.dlg-input:focus {
  border-color: rgba(139, 183, 255, 0.6);
  background: rgba(15, 23, 48, 0.98);
  box-shadow: 0 0 0 3px rgba(139, 183, 255, 0.16);
}

.dlg-input:-webkit-autofill,
.dlg-input:-webkit-autofill:hover,
.dlg-input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  box-shadow: 0 0 0 1000px rgba(15, 23, 48, 0.98) inset;
}

select.dlg-input option,
select.dlg-input optgroup {
  background: #121a33;
  color: #e7ecff;
}

textarea.dlg-input,
textarea.ab-text {
  line-height: 1.5;
}

.dlg-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.dlg-spacer { flex: 1 1 auto; }

/* Services */
.services-grid {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 14px;
  align-items: start;
}

.pools-grid {
  grid-template-columns: 420px 1fr;
}

.dest-box {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.services-json {
  width: 100%;
  min-height: 360px;
  resize: vertical;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(15, 23, 48, 0.8);
  color: var(--text);
  padding: 12px;
}

.job-grid {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 14px;
  align-items: start;
}

#controllerApp .job-grid {
  grid-template-columns: minmax(340px, 0.95fr) minmax(420px, 1.05fr);
}

.job-left,
.job-right {
  min-width: 0;
}

.job-logs {
  max-height: 520px;
  overflow: auto;
}

.terminal-wrap {
  height: 65vh;
  min-height: 320px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  overflow: hidden;
  background: #0b0e14;
}

.terminal-wrap .xterm {
  padding: 10px;
}

.job-result {
  max-height: 220px;
  overflow: auto;
}

.job-head {
  display: flex;
  gap: 12px;
  align-items: baseline;
  justify-content: space-between;
}

/* Jobs list */
.services-jobs {
  margin-top: 14px;
}

.services-controller {
  margin-top: 14px;
}

.ctrl-grid {
  grid-template-columns: 360px 1fr;
}

.jobs-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.jobs-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.jobs-item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(15, 23, 48, 0.45);
}

.pool-item {
  align-items: flex-start;
}

.jobs-main {
  min-width: 0;
  flex: 1 1 auto;
}

.jobs-title {
  font-weight: 650;
  word-break: break-word;
}

.jobs-meta {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
  word-break: break-word;
}

.jobs-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

@media (max-width: 980px) {
  .services-grid,
  .job-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1180px) {
  #controllerApp .job-grid {
    grid-template-columns: 1fr;
  }
}

/* Audiobook */
.audiobook-grid {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 14px;
  align-items: start;
}

.studio-card {
  position: relative;
  overflow: hidden;
}

.studio-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(600px 280px at 15% 10%, rgba(255, 255, 255, 0.06), transparent 55%),
    radial-gradient(520px 260px at 85% 20%, rgba(120, 240, 200, 0.10), transparent 60%),
    linear-gradient(180deg, rgba(139, 183, 255, 0.06), transparent 35%);
  pointer-events: none;
}

.studio-card > * { position: relative; }

.studio-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.studio-title {
  font-weight: 800;
  letter-spacing: 0.25px;
}

.studio-actions {
  display: flex;
  gap: 8px;
}

.studio-aside {
  position: sticky;
  top: 64px;
}

.ab-text {
  width: 100%;
  min-height: 280px;
  resize: vertical;
  white-space: pre-wrap;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(15, 23, 48, 0.92);
  color: var(--text);
}

.ab-voice-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr 0.7fr;
  gap: 10px;
  align-items: center;
}

.ab-outputs {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.ab-out {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: rgba(15, 23, 48, 0.45);
}

.ab-out-k {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.ab-out-v {
  font-size: 13px;
  line-height: 1.35;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.20);
  color: var(--muted);
  font-size: 11px;
  margin-left: 8px;
}

.pill-running {
  background: rgba(139, 183, 255, 0.14);
  border-color: rgba(139, 183, 255, 0.32);
  color: var(--text);
}

.pill-done {
  background: rgba(120, 240, 200, 0.14);
  border-color: rgba(120, 240, 200, 0.30);
  color: var(--text);
}

.pill-failed {
  background: rgba(255, 124, 124, 0.14);
  border-color: rgba(255, 124, 124, 0.30);
  color: var(--text);
}

.pill-stopped {
  background: rgba(255, 210, 120, 0.14);
  border-color: rgba(255, 210, 120, 0.30);
  color: var(--text);
}

#abErr {
  margin-top: 2px;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 124, 124, 0.35);
  background: rgba(255, 124, 124, 0.1);
  color: #ffd9d9;
}

@media (max-width: 980px) {
  .audiobook-grid { grid-template-columns: 1fr; }
  .studio-aside { position: static; }
  .ab-voice-row { grid-template-columns: 1fr; }
}
