:root {
  color-scheme: dark;
  --bg: #121216;
  --surface: #1e1e24;
  --surface-2: #25252b;
  --border: #3a3a44;
  --text: #e4e4e7;
  --muted: #9a9aa3;
  --accent: #6ea8fe;
  --accent-hover: #8bb9ff;
  --danger: #f87171;
  --success: #34d399;
  --toolbar-h: 52px;
  --log-h: 140px;
  --speakers-w: 200px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: 1fr;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.app-shell:has(#swWarning:not([hidden])) {
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}

.app-shell:has(#swWarning:not([hidden])):has(.log-panel[open]) {
  grid-template-rows: auto auto minmax(0, 1fr) minmax(0, var(--log-h));
}

.sw-warning {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #92400e;
  background: #422006;
  color: #fde68a;
  font-size: 0.8125rem;
  line-height: 1.4;
}

.sw-warning p {
  margin: 0;
  flex: 1;
}

.sw-warning[hidden] {
  display: none !important;
}

.app-shell:has(.log-panel[open]) {
  grid-template-rows: auto minmax(0, 1fr) minmax(0, var(--log-h));
}

.toolbar {
  display: flex;
  align-items: center;
  align-content: flex-start;
  gap: 0.5rem;
  padding: 0.375rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
  min-height: var(--toolbar-h);
}

.toolbar-title {
  font-size: 0.9375rem;
  font-weight: 600;
  margin-right: 0.5rem;
  white-space: nowrap;
}

.toolbar-spacer {
  flex: 1;
}

.load-progress-wrap {
  display: flex;
  align-items: center;
  min-width: 96px;
}

.load-progress-wrap[hidden] {
  display: none !important;
}

#loadProgress {
  width: 96px;
  height: 6px;
  margin: 0;
  accent-color: var(--accent);
}

#status {
  font-size: 0.8125rem;
  color: var(--muted);
  max-width: min(420px, 38vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#status:not(:empty) {
  padding: 0.25rem 0.5rem;
  background: var(--surface-2);
  border-radius: 4px;
}

#recordTimer {
  font-variant-numeric: tabular-nums;
  font-size: 0.8125rem;
  color: var(--danger);
}

#recordTimer.visible.live {
  color: var(--success);
}

button,
.btn {
  background: var(--accent);
  color: #0d1117;
  border: none;
  border-radius: 6px;
  padding: 0.4rem 0.85rem;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}

button:hover:not(:disabled),
.btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

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

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

button.secondary:hover:not(:disabled) {
  border-color: var(--accent);
}

button.recording {
  background: #c0392b;
  color: #fff;
}

button.live.recording {
  background: #1e7e46;
  color: #fff;
}

button.stop-transcribing:not(:disabled) {
  border-color: var(--danger);
  color: var(--danger);
}

button.stop-transcribing:not(:disabled):hover {
  background: rgba(248, 113, 113, 0.12);
}

button.btn-icon {
  padding: 0.25rem 0.5rem;
  min-width: 2rem;
}

.toolbar-settings-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  min-width: 2.25rem;
  padding: 0;
  margin-left: 0.25rem;
  flex-shrink: 0;
}

.toolbar-settings-btn svg {
  display: block;
}

input[type='file'] {
  font-size: 0.8125rem;
  color: var(--muted);
  max-width: 180px;
}

.toolbar-audio-url {
  font: inherit;
  font-size: 0.8125rem;
  width: min(220px, 28vw);
  min-width: 8rem;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}

.editor-main {
  display: grid;
  /* говорящие слева, субтитры занимают всё оставшееся место (без пустой центральной колонки) */
  grid-template-columns: var(--speakers-w) minmax(0, 1fr);
  grid-template-rows: minmax(140px, 28vh) minmax(0, 1fr);
  gap: 0;
  min-height: 0;
  overflow: hidden;
}

.waveform-panel {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  min-height: 0;
}

.waveform-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.35rem 0.75rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.waveform-header #fileName {
  font-size: 0.8125rem;
  color: var(--muted);
  margin-left: auto;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
}

.waveform-container {
  flex: 1;
  min-height: 80px;
  position: relative;
  cursor: crosshair;
}

.waveform-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.waveform-hint {
  font-size: 0.75rem;
  color: var(--muted);
  padding: 0 0.75rem 0.35rem;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.panel-speakers {
  grid-column: 1;
  grid-row: 2;
}

.panel-transcript {
  grid-column: 2;
  grid-row: 2;
  border-right: none;
  border-left: 1px solid var(--border);
  min-width: 0;
  overflow: hidden;
}

.panel-body--transcript {
  display: flex;
  flex-direction: column;
  padding: 0;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.panel-body--transcript .transcript-list {
  flex: 1;
  min-height: 0;
  min-width: 0;
}

.panel-header {
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  min-height: 0;
}

.speaker-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.speaker-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

.speaker-name-input {
  flex: 1;
  font: inherit;
  font-size: 0.875rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 0.3rem 0.45rem;
}

.panel-hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0.5rem 0 0;
  line-height: 1.35;
}

.transcript-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.transcript-toolbar button {
  font-size: 0.75rem;
  padding: 0.3rem 0.55rem;
}

.transcript-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  min-height: 0;
}

.transcript-empty {
  color: var(--muted);
  font-size: 0.875rem;
  padding: 0.75rem;
}

.transcript-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-start;
  padding: 0.5rem;
  margin-bottom: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  cursor: pointer;
  min-width: 0;
}

.transcript-row--selected {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.transcript-row--active {
  background: #1f2430;
}

.transcript-meta {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 0 0 7.5rem;
}

.transcript-time {
  font: 0.7rem/1.3 ui-monospace, Menlo, monospace;
  color: var(--accent);
  background: transparent;
  border: none;
  padding: 0.2rem 0;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
}

.transcript-speaker {
  width: 100%;
  font: inherit;
  font-size: 0.8125rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 0.25rem;
}

.transcript-text {
  flex: 1 1 12rem;
  min-width: 0;
  width: 100%;
  font: inherit;
  font-size: 0.875rem;
  line-height: 1.4;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 0.35rem 0.5rem;
  resize: vertical;
  min-height: 2.5rem;
  box-sizing: border-box;
}

.log-panel {
  border-top: 1px solid var(--border);
  background: var(--surface);
  min-height: 0;
  overflow: hidden;
}

.log-panel[open] {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  max-height: 100%;
}

.log-panel summary {
  flex-shrink: 0;
  padding: 0.35rem 0.75rem;
  font-size: 0.8125rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  list-style: none;
}

.log-panel summary::-webkit-details-marker {
  display: none;
}

.log-panel[open] .log-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

#log {
  margin: 0;
  padding: 0.5rem 0.75rem;
  font: 0.75rem/1.45 ui-monospace, Menlo, monospace;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}

.settings-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(400px, 100vw);
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 100;
  transform: translateX(100%);
  transition: transform 0.2s ease;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.4);
}

.settings-drawer.open {
  transform: translateX(0);
}

.settings-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.settings-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.settings-section {
  margin-bottom: 1.25rem;
}

.settings-section h3 {
  margin: 0 0 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
}

.field {
  margin-bottom: 0.65rem;
}

.field label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.field input,
.field select {
  width: 100%;
  font: inherit;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.4rem 0.5rem;
}

.field-hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0.35rem 0 0;
  line-height: 1.35;
}

.field-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.vad-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.settings-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.settings-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

#preview {
  display: none;
}

@media (max-width: 900px) {
  .editor-main {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(120px, 22vh) auto 1fr;
  }

  .panel-speakers {
    grid-column: 1;
    max-height: 140px;
  }

  .panel-transcript {
    grid-column: 1;
  }
}
