:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-soft: #f1f5f9;
  --border: #dde2e8;
  --text: #17202a;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --teal: #0f766e;
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr);
}

.sidebar {
  background: #101827;
  color: #e5e7eb;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

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

.brand-mark,
.voice-avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.brand-title {
  font-weight: 700;
  font-size: 16px;
}

.brand-subtitle,
.voice-meta,
.sidebar-heading {
  color: #9ca3af;
  font-size: 12px;
}

.nav-list,
.sidebar-section {
  display: grid;
  gap: 8px;
}

.nav-item,
.voice-chip {
  width: 100%;
  min-height: 42px;
  border: 1px solid transparent;
  background: transparent;
  color: #cbd5e1;
  border-radius: 8px;
  padding: 9px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
}

.nav-item.active,
.nav-item:hover,
.voice-chip.active,
.voice-chip:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.nav-icon {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 12px;
  font-weight: 700;
}

.voice-avatar {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  flex: 0 0 auto;
}

.voice-avatar.teal {
  background: var(--teal);
}

.voice-name {
  display: block;
  font-weight: 600;
}

.workspace {
  min-width: 0;
  padding: 20px;
}

.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.topbar h1,
.panel h2,
.job-card h3 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 22px;
}

.topbar p,
.panel p {
  margin: 4px 0 0;
  color: var(--muted);
}

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

.status-pill {
  min-width: 72px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: #dcfce7;
  color: #166534;
  font-weight: 700;
  font-size: 13px;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
}

.mode-tabs {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  margin-bottom: 16px;
}

.mode-tab {
  min-height: 34px;
  border: 0;
  background: transparent;
  border-radius: 6px;
  padding: 0 14px;
  color: var(--muted);
  font-weight: 700;
}

.mode-tab.active {
  background: var(--primary);
  color: #fff;
}

.studio-grid {
  display: grid;
  grid-template-columns: minmax(420px, 1.1fr) minmax(360px, 0.9fr);
  gap: 16px;
  align-items: start;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.panel h2 {
  font-size: 18px;
}

.field-label {
  display: block;
  margin: 14px 0 8px;
  font-weight: 700;
}

.text-editor,
.instruction-editor,
#transcriptText,
.text-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  resize: vertical;
  color: var(--text);
  background: #fff;
  outline: none;
}

.text-editor {
  min-height: 220px;
  line-height: 1.55;
}

.instruction-editor,
#transcriptText {
  min-height: 92px;
}

.text-editor:focus,
.instruction-editor:focus,
#transcriptText:focus,
.text-input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.text-input {
  height: 40px;
  resize: none;
}

.field-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  margin-top: 8px;
}

.hidden {
  display: none !important;
}

.upload-panel {
  border: 1px dashed #9fb4d8;
  background: #f8fbff;
  border-radius: 8px;
  padding: 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  position: relative;
}

.upload-panel.dragging {
  border-color: var(--primary);
  background: #eff6ff;
}

.upload-panel input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-copy {
  display: grid;
  gap: 4px;
  pointer-events: none;
}

.upload-copy span,
.audio-preview span {
  color: var(--muted);
  font-size: 13px;
}

.audio-preview {
  margin-top: 10px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}

.audio-preview audio {
  width: 100%;
}

.trim-panel {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
  display: grid;
  gap: 12px;
}

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

.trim-header span {
  color: var(--muted);
  font-size: 13px;
}

.trim-slider {
  position: relative;
  height: 88px;
  border-radius: 22px;
  background: #eef1f4;
  overflow: hidden;
  touch-action: none;
  user-select: none;
}

.trim-waveform {
  position: absolute;
  inset: 18px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.trim-waveform span {
  width: 3px;
  height: 32px;
  border-radius: 999px;
  background: #4b5563;
  opacity: 0.9;
}

.trim-waveform span:nth-child(3n) { height: 46px; }
.trim-waveform span:nth-child(4n) { height: 24px; }
.trim-waveform span:nth-child(5n) { height: 56px; }

.trim-selection {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(37, 99, 235, 0.2);
  border-inline: 2px solid rgba(37, 99, 235, 0.45);
  cursor: grab;
  z-index: 1;
}

.trim-selection:active {
  cursor: grabbing;
}

.trim-handle {
  position: absolute;
  top: 0;
  width: 14px;
  height: 100%;
  border: 0;
  border-radius: 999px;
  background: #0b0b0c;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.9);
  transform: translateX(-50%);
  cursor: ew-resize;
  z-index: 3;
}

.trim-handle::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  height: 28px;
  background: rgba(255, 255, 255, 0.75);
  border-radius: 999px;
  transform: translate(-50%, -50%);
}

.trim-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.trim-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.trim-grid input,
.trim-grid output {
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  color: var(--text);
  background: #fff;
  font-weight: 700;
}

.trim-actions {
  display: grid;
  grid-template-columns: auto auto auto 1fr;
}

#useRecommendedClipButton {
  justify-self: end;
}

.advanced {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 16px;
  background: #fff;
}

.advanced summary {
  min-height: 46px;
  padding: 12px;
  cursor: pointer;
  font-weight: 700;
}

.advanced summary span {
  margin-left: 8px;
  color: var(--muted);
  font-weight: 500;
}

.settings-grid {
  display: grid;
  gap: 12px;
  padding: 0 12px 12px;
}

.toggle-row,
.range-field,
.select-field {
  display: grid;
  gap: 8px;
}

.toggle-row {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.range-field {
  grid-template-columns: 150px 1fr 42px;
  align-items: center;
}

.select-field select {
  width: 160px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 0 10px;
  background: #fff;
}

.primary-button,
.secondary-button,
.ghost-button {
  border-radius: 8px;
  min-height: 40px;
  padding: 0 14px;
  font-weight: 700;
}

.primary-button {
  width: 100%;
  margin-top: 16px;
  border: 0;
  background: var(--primary);
  color: #fff;
}

.primary-button.compact {
  width: auto;
}

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

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.secondary-button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.ghost-button {
  border: 0;
  background: var(--surface-soft);
  color: var(--text);
}

.output-stage {
  min-height: 260px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #f8fafc);
  padding: 18px;
  display: grid;
  align-content: center;
  gap: 20px;
}

.waveform {
  height: 86px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.waveform span {
  width: 8px;
  height: 28px;
  border-radius: 999px;
  background: #93c5fd;
  transform-origin: center;
}

.waveform span:nth-child(2n) { height: 52px; background: #60a5fa; }
.waveform span:nth-child(3n) { height: 68px; background: #2563eb; }
.waveform span:nth-child(5n) { height: 40px; background: #0f766e; }

.waveform.active span {
  animation: pulse 900ms ease-in-out infinite alternate;
}

.waveform.active span:nth-child(2n) {
  animation-delay: 120ms;
}

.waveform.active span:nth-child(3n) {
  animation-delay: 220ms;
}

@keyframes pulse {
  from { transform: scaleY(0.45); }
  to { transform: scaleY(1); }
}

.output-empty {
  color: var(--muted);
  text-align: center;
}

.output-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 14px 0;
}

.job-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface-soft);
}

.job-card h3 {
  font-size: 15px;
  margin-bottom: 12px;
}

.job-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.job-list div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.job-list dt {
  color: var(--muted);
}

.job-list dd {
  margin: 0;
  font-weight: 700;
  text-align: right;
}

.api-dashboard {
  max-width: 1120px;
}

.api-panel {
  box-shadow: var(--shadow);
}

.api-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.api-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
  display: grid;
  align-content: start;
  gap: 10px;
}

.api-card h3 {
  margin: 0;
  font-size: 15px;
}

.api-card p {
  margin: 0;
}

.copy-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

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

.code-box {
  min-height: 112px;
  margin: 0;
  padding: 12px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0f172a;
  color: #e5e7eb;
  font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.api-result {
  min-height: 42px;
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-soft);
}

@media (max-width: 1050px) {
  .app-shell {
    grid-template-columns: 80px minmax(0, 1fr);
  }

  .brand-title,
  .brand-subtitle,
  .nav-item:not(.active),
  .voice-chip span:not(.voice-avatar),
  .sidebar-heading {
    display: none;
  }

  .brand,
  .nav-item,
  .voice-chip {
    justify-content: center;
  }

  .studio-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    display: none;
  }

  .workspace {
    padding: 14px;
  }

  .topbar,
  .panel-header,
  .field-row {
    align-items: stretch;
    flex-direction: column;
  }

  .mode-tabs {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
  }

  .studio-grid {
    gap: 12px;
  }

  .range-field {
    grid-template-columns: 1fr;
  }

  .upload-panel,
  .audio-preview,
  .trim-grid,
  .api-grid,
  .copy-row {
    grid-template-columns: 1fr;
  }
}
