:root {
  --bg: #edf1ee;
  --surface: #fbfdfb;
  --surface-strong: #ffffff;
  --ink: #18211f;
  --muted: #65736f;
  --line: #d9e2dd;
  --line-strong: #c2cec8;
  --teal: #087f76;
  --teal-dark: #0f4f4c;
  --coral: #c84e62;
  --amber: #e3a727;
  --green: #2d7d58;
  --soft: #f4f7f4;
  --danger: #a9344c;
  --shadow: 0 18px 48px rgba(24, 33, 31, 0.10);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(8, 127, 118, 0.08), transparent 34%),
    linear-gradient(180deg, #f8fbf8 0%, var(--bg) 72%, #e7ece8 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  width: min(100%, 1720px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 12px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
}

.topbar {
  min-height: 82px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(251, 253, 251, 0.96);
  box-shadow: var(--shadow);
}

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

.brand-mark {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  border-radius: var(--radius);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  align-items: end;
  padding: 9px;
  background: #102521;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.brand-mark span {
  border-radius: 4px;
}

.brand-mark span:nth-child(1) {
  height: 21px;
  background: var(--green);
}

.brand-mark span:nth-child(2) {
  height: 34px;
  background: var(--teal);
}

.brand-mark span:nth-child(3) {
  height: 27px;
  background: var(--amber);
}

.eyebrow,
.section-kicker {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 2.1rem;
  line-height: 1;
}

h2 {
  font-size: 1.16rem;
  line-height: 1.15;
}

.topbar-status {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.status-pill,
.clock-box {
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.status-pill {
  min-width: 128px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 0 13px;
  color: var(--muted);
  font-size: 0.92rem;
}

.status-pill span {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--amber);
  box-shadow: 0 0 0 4px rgba(227, 167, 39, 0.15);
}

.status-pill[data-state="ready"] span {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(45, 125, 88, 0.16);
}

.status-pill[data-state="recording"] span {
  background: var(--coral);
  box-shadow: 0 0 0 4px rgba(200, 78, 98, 0.18);
}

.status-pill[data-state="error"] span {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(169, 52, 76, 0.17);
}

.status-pill strong {
  white-space: nowrap;
}

.clock-box {
  min-width: 126px;
  display: grid;
  align-content: center;
  justify-items: end;
  padding: 8px 12px;
}

.clock-box span {
  font-size: 1.24rem;
  font-variant-numeric: tabular-nums;
  font-weight: 820;
  line-height: 1;
}

.clock-box small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 720;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(330px, 430px) minmax(0, 1fr);
  gap: 14px;
  min-height: 0;
}

.control-panel,
.transcript-panel {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(251, 253, 251, 0.96);
  box-shadow: var(--shadow);
}

.control-panel {
  padding: 14px;
  display: grid;
  align-content: start;
  gap: 12px;
  overflow: auto;
}

.transcript-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.section-head,
.transcript-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.transcript-head {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.model-count {
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--muted);
  background: var(--surface-strong);
  font-size: 0.8rem;
  font-weight: 760;
}

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

.button,
.file-label {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 14px;
  color: var(--ink);
  background: var(--surface-strong);
  font-weight: 800;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease, color 140ms ease;
  user-select: none;
  white-space: nowrap;
}

.button:hover,
.file-label:hover {
  border-color: rgba(8, 127, 118, 0.42);
  transform: translateY(-1px);
}

.button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
  transform: none;
}

.button-primary {
  color: #fff;
  border-color: var(--teal);
  background: var(--teal);
}

.button-danger {
  color: #fff;
  border-color: var(--danger);
  background: var(--danger);
}

.button-ghost {
  min-width: 86px;
  background: var(--soft);
}

.control-stack {
  display: grid;
  gap: 13px;
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field label,
.label {
  color: var(--muted);
  font-size: 0.79rem;
  font-weight: 800;
}

select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 38px 0 12px;
  color: var(--ink);
  background: var(--surface-strong);
  font-weight: 720;
  overflow: hidden;
  text-overflow: ellipsis;
}

select:focus-visible,
textarea:focus-visible,
.button:focus-visible,
.file-label:focus-visible {
  outline: 3px solid rgba(8, 127, 118, 0.18);
  outline-offset: 2px;
}

select:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

.segmented {
  min-height: 44px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--soft);
}

.segmented button {
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
  cursor: pointer;
}

.segmented button.active {
  color: #fff;
  background: #142a27;
}

.switch {
  min-height: 46px;
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 0.92rem;
  cursor: pointer;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch span {
  width: 42px;
  height: 24px;
  position: relative;
  border-radius: 999px;
  background: #b7c2bd;
  transition: background 140ms ease;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #fff;
  transition: transform 140ms ease;
  box-shadow: 0 2px 5px rgba(24, 33, 31, 0.24);
}

.switch input:checked + span {
  background: var(--teal);
}

.switch input:checked + span::after {
  transform: translateX(18px);
}

.switch strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.upload-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding-top: 2px;
}

.upload-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.file-name {
  min-width: 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meter-panel {
  display: grid;
  gap: 8px;
}

.meter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.meter-head span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

canvas {
  width: 100%;
  height: 132px;
  display: block;
  border: 1px solid #102521;
  border-radius: var(--radius);
  background: #102521;
}

.runtime-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 0.8fr);
  gap: 10px;
  margin: 0;
  padding: 0;
}

.runtime-grid div {
  min-width: 0;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.runtime-grid dt {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.runtime-grid dd {
  margin: 0;
  min-width: 0;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 780;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status {
  min-height: 76px;
  max-height: 120px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  color: #35413e;
  background: #f6f8f6;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

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

textarea {
  width: 100%;
  min-width: 0;
  min-height: 0;
  height: 100%;
  resize: none;
  border: 0;
  border-radius: 0;
  padding: clamp(16px, 2vw, 26px);
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(8, 127, 118, 0.035), transparent 26%),
    var(--surface-strong);
  font-size: 1.16rem;
  line-height: 1.72;
}

@media (min-width: 981px) {
  .workspace {
    height: calc(100vh - 106px);
  }
}

@media (min-width: 1400px) {
  .workspace {
    grid-template-columns: minmax(380px, 460px) minmax(0, 1fr);
  }

  canvas {
    height: 144px;
  }

  h1 {
    font-size: 2.35rem;
  }
}

@media (max-width: 980px) {
  .app-shell {
    min-height: 100vh;
    padding: 12px;
    grid-template-rows: auto auto;
  }

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

  .topbar-status {
    justify-content: stretch;
  }

  .status-pill,
  .clock-box {
    flex: 1;
  }

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

  .transcript-panel {
    min-height: 56vh;
  }

  textarea {
    min-height: 420px;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding: 8px;
    gap: 8px;
  }

  .topbar,
  .control-panel {
    padding: 12px;
  }

  .brand-mark {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
  }

  h1 {
    font-size: 1.42rem;
  }

  textarea {
    font-size: 1.05rem;
  }

  .topbar-status,
  .section-head,
  .transcript-head,
  .upload-row {
    align-items: stretch;
  }

  .topbar-status,
  .section-head,
  .transcript-head {
    flex-direction: column;
  }

  .clock-box {
    justify-items: start;
  }

  .primary-actions,
  .runtime-grid,
  .upload-row {
    grid-template-columns: 1fr;
  }

  .transcript-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .button,
  .file-label {
    min-width: 0;
    padding-inline: 10px;
  }

  canvas {
    height: 124px;
  }

  .status {
    max-height: 150px;
  }

  textarea {
    min-height: 360px;
  }
}

/* ----- Added: history panel, auto-detect toggle, SRT button ----- */
.switch-compact {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 6px;
  font-size: 12px;
  color: var(--muted);
}
.switch-compact strong {
  font-weight: 500;
  color: var(--ink);
}

.history-panel {
  margin-top: 16px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px 18px;
  box-shadow: var(--shadow);
}
.history-panel[hidden] {
  display: none;
}
.history-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
  margin-bottom: 12px;
}
.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
}
.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--soft);
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease;
}
.history-item:hover {
  background: var(--surface-strong);
  border-color: var(--line-strong);
}
.history-item .meta {
  display: flex;
  gap: 10px;
  align-items: baseline;
  font-size: 11.5px;
  color: var(--muted);
  font-family: ui-monospace, "JetBrains Mono", monospace;
}
.history-item .meta b {
  color: var(--ink);
  font-weight: 600;
}
.history-item .preview {
  font-size: 13px;
  line-height: 1.4;
  color: var(--ink);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.history-item .actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
.history-item .actions button {
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  border-radius: 999px;
  font-size: 11px;
  padding: 4px 10px;
  cursor: pointer;
}
.history-item .actions button:hover {
  color: var(--danger);
  border-color: var(--danger);
}
.history-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 18px 0;
  text-align: center;
}
