:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-soft: #eef3f1;
  --ink: #17211d;
  --muted: #66736d;
  --line: #dce4e0;
  --brand: #136f63;
  --brand-strong: #0b5148;
  --accent: #b7791f;
  --danger: #b42318;
  --info: #285b9a;
  --shadow: 0 14px 34px rgba(23, 33, 29, .08);
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 74px;
}

* {
  box-sizing: border-box;
}

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

a {
  color: inherit;
  text-decoration: none;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #f7faf9, #e8efed);
}

.login-card {
  width: min(420px, calc(100vw - 32px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-title {
  margin: 0 0 4px;
  font-size: 28px;
}

.login-subtitle {
  margin: 0 0 24px;
  color: var(--muted);
}

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

.app-shell.sidebar-collapsed {
  grid-template-columns: var(--sidebar-collapsed-width) minmax(0, 1fr);
}

.sidebar {
  background: #17211d;
  color: #f4f7f6;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-toggle {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  min-height: 30px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 6px;
  background: rgba(255, 255, 255, .08);
  color: #f4f7f6;
  font-size: 20px;
  line-height: 1;
}

.sidebar-toggle:hover {
  background: rgba(255, 255, 255, .14);
}

.sidebar-resizer {
  position: absolute;
  top: 0;
  right: 0;
  width: 8px;
  height: 100%;
  cursor: col-resize;
}

.sidebar-resizer::after {
  content: "";
  position: absolute;
  top: 0;
  right: 2px;
  width: 1px;
  height: 100%;
  background: rgba(255, 255, 255, .12);
}

.sidebar-resizing {
  cursor: col-resize;
  user-select: none;
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 10px 18px;
  font-size: 19px;
  font-weight: 750;
  min-width: 0;
  flex: 1;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #f6f4f2;
  overflow: hidden;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.brand-label,
.nav-link span,
.nav-section {
  transition: opacity .12s ease;
}

.app-shell.sidebar-collapsed .sidebar {
  padding-left: 10px;
  padding-right: 10px;
}

.app-shell.sidebar-collapsed .sidebar-header {
  align-items: center;
  flex-direction: column;
}

.app-shell.sidebar-collapsed .brand {
  justify-content: center;
  padding: 6px 0 12px;
}

.app-shell.sidebar-collapsed .brand-label,
.app-shell.sidebar-collapsed .nav-link span,
.app-shell.sidebar-collapsed .nav-section {
  opacity: 0;
  pointer-events: none;
  position: absolute;
}

.app-shell.sidebar-collapsed .nav-link {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

.app-shell.sidebar-collapsed .sidebar-toggle {
  transform: rotate(180deg);
}

.app-shell.sidebar-collapsed .sidebar-resizer {
  display: none;
}

.nav-section {
  margin: 12px 0 4px;
  padding: 0 10px;
  color: #aebdb7;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  padding: 8px 10px;
  border-radius: 6px;
  color: #e8efed;
}

.nav-link:hover,
.nav-link.active {
  background: rgba(255, 255, 255, .10);
}

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
}

.main {
  min-width: 0;
}

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 28px;
  background: rgba(255, 255, 255, .88);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(12px);
}

.search {
  width: min(420px, 42vw);
}

.search input,
input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 38px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
}

textarea {
  min-height: 110px;
}

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

.content {
  padding: 28px;
}

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

.page-title {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
}

.page-kicker {
  color: var(--muted);
  margin-top: 5px;
}

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

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

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

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

.panel,
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 0 rgba(23, 33, 29, .03);
}

.panel {
  padding: 18px;
}

.panel-title {
  margin: 0 0 14px;
  font-size: 16px;
}

.stat {
  padding: 16px;
}

.stat-value {
  font-size: 30px;
  line-height: 1;
  font-weight: 800;
}

.stat-label {
  margin-top: 8px;
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

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

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

th {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  background: #f9fbfa;
}

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

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

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 700;
  background: var(--panel-soft);
  color: var(--brand-strong);
}

.badge.warn {
  background: #fff3d8;
  color: #87530d;
}

.badge.info {
  background: #e8f1fb;
  color: var(--info);
}

.badge.danger {
  background: #fee4e2;
  color: var(--danger);
}

.badge.neutral {
  background: #edf0ef;
  color: #53605a;
}

.btn,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 12px;
  background: var(--brand);
  color: white;
  font-weight: 750;
  cursor: pointer;
}

.btn.secondary {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.btn.ghost {
  background: transparent;
  color: var(--ink);
}

.filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr)) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 16px 0;
}

.tab {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 7px 11px;
  color: var(--muted);
  font-weight: 700;
}

.detail-list {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr);
  gap: 10px 16px;
}

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

.detail-list dd {
  margin: 0;
}

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

.field.full {
  grid-column: 1 / -1;
}

.field label {
  display: block;
  margin-bottom: 6px;
  font-weight: 750;
}

.field .helptext,
.errorlist {
  color: var(--danger);
  margin: 6px 0 0;
}

.messages {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.message {
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand);
  background: #fff;
  border-radius: 6px;
  padding: 10px 12px;
}

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

.pagination {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    overflow: visible;
  }

  .sidebar-toggle,
  .sidebar-resizer {
    display: none;
  }

  .app-shell.sidebar-collapsed .sidebar {
    padding: 18px 14px;
  }

  .app-shell.sidebar-collapsed .sidebar-header {
    align-items: flex-start;
    flex-direction: row;
  }

  .app-shell.sidebar-collapsed .brand {
    justify-content: flex-start;
    padding: 8px 10px 18px;
  }

  .app-shell.sidebar-collapsed .brand-label,
  .app-shell.sidebar-collapsed .nav-link span,
  .app-shell.sidebar-collapsed .nav-section {
    opacity: 1;
    pointer-events: auto;
    position: static;
  }

  .app-shell.sidebar-collapsed .nav-link {
    justify-content: flex-start;
    padding: 8px 10px;
  }

  .grid-2,
  .grid-3,
  .grid-4,
  .form-grid,
  .filters {
    grid-template-columns: 1fr;
  }

  .topbar,
  .page-header {
    align-items: stretch;
    flex-direction: column;
    height: auto;
    padding: 16px;
  }

  .content {
    padding: 16px;
  }

  .search {
    width: 100%;
  }
}

.recording-workspace {
  display: grid;
  gap: 16px;
}

.recording-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

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

.device-check {
  display: grid;
  gap: 14px;
}

.device-check-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.device-status {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  padding: 5px 10px;
  white-space: nowrap;
}

.device-status.ready {
  background: #e7f7ef;
  border-color: #b7e5c9;
  color: #11643b;
}

.device-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

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

.device-preview-wrap {
  display: grid;
  grid-template-columns: minmax(0, 420px) minmax(220px, 1fr);
  gap: 12px;
  align-items: center;
}

.device-preview-wrap video {
  width: 100%;
  max-height: 230px;
  background: #101816;
  border-radius: 8px;
}

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

.terp-source-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(340px, .65fr);
  gap: 16px;
  align-items: stretch;
}

.terp-source-layout.transcript-hidden {
  grid-template-columns: minmax(0, 1fr);
}

.terp-source-layout.transcript-hidden .transcript-panel {
  display: none;
}

.source-panel,
.transcript-panel {
  min-height: 460px;
}

.source-frame {
  width: 100%;
  min-height: 420px;
  display: grid;
  place-items: center;
  background: #101816;
  border-radius: 8px;
  overflow: hidden;
}

.source-frame audio {
  width: min(680px, 92%);
}

.source-frame video {
  width: 100%;
  max-height: 68vh;
  background: #101816;
}

.source-frame.locked audio,
.source-frame.locked video {
  pointer-events: none;
}

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

.transcript-scroll {
  height: 410px;
  overflow-y: auto;
  padding-right: 6px;
  line-height: 1.75;
}

.speaker-block {
  margin-bottom: 14px;
}

.speaker-label {
  display: inline-flex;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.transcript-word {
  border: 0;
  background: transparent;
  border-radius: 4px;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  padding: 1px 2px;
}

.transcript-word:hover {
  background: #e8f1fb;
}

.transcript-word.active {
  background: #ffe8a6;
  color: #382a00;
}

.modal-transcript .transcript-word {
  cursor: default;
  pointer-events: none;
}

.recording-modal,
.uploading-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(7, 12, 10, .82);
}

.recording-modal[hidden],
.uploading-modal[hidden] {
  display: none;
}

.recording-modal-card {
  width: min(1280px, 96vw);
  max-height: 94vh;
  background: #0f1715;
  color: #f7fbfa;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .38);
}

.recording-statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #121d1a;
  border-bottom: 1px solid rgba(255, 255, 255, .12);
  font-weight: 800;
}

.recording-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.recording-dot {
  width: 11px;
  height: 11px;
  border-radius: 999px;
  background: #e11d48;
  animation: recordPulse 1s infinite;
}

@keyframes recordPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .25; }
}

.recording-stage {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, .65fr);
  gap: 14px;
  padding: 14px;
  position: relative;
}

.recording-stage.transcript-hidden {
  grid-template-columns: minmax(0, 1fr);
}

.recording-stage.transcript-hidden .modal-transcript {
  display: none;
}

.recording-stage .source-frame {
  min-height: min(70vh, 620px);
}

.recording-stage .transcript-panel {
  background: #f7fbfa;
  color: var(--ink);
  min-height: min(70vh, 620px);
  padding: 14px;
  border-radius: 8px;
}

.recording-stage .transcript-scroll {
  height: min(64vh, 560px);
}

.countdown-overlay {
  position: absolute;
  inset: 14px;
  z-index: 3;
  display: grid;
  place-items: center;
  background: rgba(7, 12, 10, .64);
  color: #fff;
  font-size: clamp(42px, 10vw, 112px);
  font-weight: 900;
}

.countdown-overlay.done {
  display: none;
}

.uploading-card {
  width: min(420px, 92vw);
  padding: 24px;
  background: #fff;
  border-radius: 8px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.recording-review video,
.recording-review audio {
  width: 100%;
  max-height: 520px;
  background: #101816;
  border-radius: 8px;
}

.section-planner-header,
.recording-section-header,
.take-row,
.take-actions,
.split-points {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.section-planner-header,
.recording-section-header {
  justify-content: space-between;
}

.split-points {
  margin-top: 14px;
}

.split-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  background: #fff;
}

.split-chip button {
  min-height: 24px;
  padding: 2px 7px;
}

.recording-sections {
  display: grid;
  gap: 16px;
}

.section-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.take-list {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.take-row {
  align-items: flex-start;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfc;
}

.take-main {
  display: grid;
  gap: 8px;
  min-width: min(420px, 100%);
}

.take-main video,
.take-main audio {
  width: min(560px, 100%);
  max-height: 260px;
  background: #101816;
  border-radius: 6px;
}

.signing-end-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.signing-end-controls input {
  width: 150px;
}

.recording-modal-actions {
  padding: 0 14px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.recording-device-summary {
  color: rgba(247, 251, 250, .78);
  font-size: 12px;
  font-weight: 800;
  max-width: min(620px, 72vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.review-workspace {
  display: grid;
  gap: 16px;
}

.review-take-list,
.feedback-card-list {
  display: grid;
  gap: 14px;
}

.review-take-card,
.feedback-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  padding: 14px;
}

.review-take-card video,
.review-take-card audio {
  width: 100%;
  max-height: 460px;
  background: #101816;
  border-radius: 8px;
}

.review-marker-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 34px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.review-marker {
  min-height: 28px;
  padding: 4px 8px;
  border-color: #ffd28a;
  background: #fff6df;
  color: #6f4307;
  font-size: 12px;
}

.review-marker::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--accent);
}

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

.feedback-edit-form {
  display: grid;
  gap: 8px;
}

.feedback-edit-form input {
  max-width: 180px;
}

@media (max-width: 980px) {
  .recording-hero,
  .recording-actions,
  .device-check-header,
  .recording-modal-actions {
    flex-direction: column;
  }

  .terp-source-layout,
  .recording-stage,
  .device-grid,
  .device-preview-wrap {
    grid-template-columns: 1fr;
  }

  .source-panel,
  .transcript-panel,
  .source-frame {
    min-height: 300px;
  }
}
