:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --panel: #ffffff;
  --line: #dfe3ea;
  --text: #172033;
  --muted: #687386;
  --accent: #1b66d2;
  --accent-dark: #154f9d;
  --danger: #b42318;
}

* {
  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;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: white;
  padding: 10px 14px;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: var(--accent-dark);
}

button:disabled,
input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.app {
  width: min(1180px, calc(100vw - 28px));
  margin: 18px auto 32px;
}

.topbar,
.page-tabs,
.controls,
.workspace,
.bottom-tools,
.summary {
  margin-bottom: 14px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 18px;
}

h3 {
  margin: 0;
  font-size: 14px;
}

.topbar p,
.status,
.panel-heading span {
  color: var(--muted);
}

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

.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
}

.user-pill strong {
  color: var(--text);
  font-weight: 600;
}

.credit-divider {
  color: var(--line);
}

.page-tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--line);
}

.admin-tabs {
  display: contents;
}

.admin-tabs[hidden] {
  display: none;
}

.page-tab {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 8px 12px;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
}

.page-tab:hover {
  color: var(--accent);
  background: #eef4ff;
}

.page-tab.active {
  color: var(--accent);
  background: var(--panel);
  border-color: var(--line);
  font-weight: 700;
  margin-bottom: -1px;
}

.language-toggle,
.logout-button {
  background: #eef4ff;
  color: var(--accent);
  border: 1px solid #c9daf8;
}

.language-toggle:hover:not(:disabled),
.logout-button:hover:not(:disabled) {
  background: #dceaff;
}

.summary-action {
  background: #0f9f6e;
}

.summary-action:hover:not(:disabled) {
  background: #0b7f59;
}

.status,
.audio-health {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: var(--panel);
}

.audio-health {
  color: var(--muted);
  min-width: 150px;
  text-align: center;
}

.controls,
.bottom-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

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

input,
select {
  min-width: 180px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 10px;
  color: var(--text);
  background: white;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 14px;
  align-items: start;
}

.captions,
.chat,
.summary {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.captions {
  padding: 10px;
}

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

.panel-heading.compact {
  margin-bottom: 8px;
}

.caption-list {
  display: grid;
  gap: 2px;
  min-height: 480px;
  max-height: 70vh;
  overflow: auto;
  align-content: start;
  font-variant-numeric: tabular-nums;
}

.language-direction {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.language-direction select {
  min-width: 150px;
}

.language-arrow {
  padding: 0 2px 10px;
  color: var(--muted);
}

.caption-list.empty {
  color: var(--muted);
  align-content: center;
  justify-content: center;
}

.caption-item {
  border: 0;
  border-left: 3px solid #7c8aa5;
  border-radius: 3px;
  padding: 4px 7px 5px 8px;
  background: transparent;
}

.caption-item:hover {
  background: #f8fafc;
}

.caption-item[hidden],
.caption-item[data-caption-status="merged"] {
  display: none;
}

.caption-item.speaker-1 { border-left-color: #1b66d2; color: #1b66d2; }
.caption-item.speaker-2 { border-left-color: #0f9f6e; color: #0f9f6e; }
.caption-item.speaker-3 { border-left-color: #a855f7; color: #a855f7; }
.caption-item.speaker-4 { border-left-color: #f59e0b; color: #f59e0b; }
.caption-item.speaker-5 { border-left-color: #ef4444; color: #ef4444; }
.caption-item.speaker-6 { border-left-color: #0891b2; color: #0891b2; }

.caption-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 1px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.1;
}

.caption-meta time {
  color: var(--muted);
}

.revision-badge {
  margin-left: auto;
  border-radius: 999px;
  padding: 1px 6px;
  background: #e8f0ff;
  color: #1b66d2;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
}

.caption-diff-insert {
  border-radius: 4px;
  padding: 0 2px;
  background: #dff8e7;
  color: #166534;
  animation: captionDiffInsert 900ms ease-out both;
}

@keyframes captionDiffInsert {
  0% {
    opacity: 0;
    filter: blur(2px);
    transform: translateY(-3px);
    background: #bbf7d0;
  }
  100% {
    opacity: 1;
    filter: blur(0);
    transform: translateY(0);
    background: transparent;
  }
}

@media (prefers-reduced-motion: reduce) {
  .caption-diff-insert {
    animation: none;
    background: transparent;
    color: inherit;
    padding: 0;
  }
}

.speaker-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}

.speaker {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.speaker.secondary {
  margin-top: 8px;
}

.teacher {
  margin: 0;
  color: var(--text);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.24;
}

.chinese {
  margin-top: 1px;
  color: #394254;
  font-size: 18px;
  font-weight: 400;
  line-height: 1.28;
}

.chat {
  min-height: 560px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
}

.chat-list {
  display: grid;
  align-content: start;
  gap: 10px;
  overflow: auto;
  max-height: 480px;
}

.message {
  border-radius: 8px;
  padding: 10px;
  line-height: 1.5;
  background: #eef4ff;
}

.message.user {
  background: #edf7ed;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.chat-form input {
  min-width: 0;
}

.summary-history-panel {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.summary-history {
  display: grid;
  gap: 8px;
  max-height: 160px;
  overflow: auto;
}

.summary-history.empty {
  color: var(--muted);
  font-size: 13px;
}

.summary-history-item {
  display: grid;
  gap: 3px;
  width: 100%;
  text-align: left;
  background: #fbfcff;
  color: var(--text);
  border: 1px solid var(--line);
  padding: 9px 10px;
}

.summary-history-item:hover,
.summary-history-item.active {
  background: #eef4ff;
  border-color: #c9daf8;
}

.summary-history-item small {
  color: var(--muted);
}

.upload {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fbfcff;
}

.summary pre {
  margin: 12px 0 0;
  white-space: pre-wrap;
  line-height: 1.55;
  color: var(--text);
}

.error {
  color: var(--danger);
}

@media (max-width: 860px) {
  .topbar {
    align-items: start;
    flex-direction: column;
  }

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

  .caption-list,
  .chat {
    min-height: 360px;
  }
}


.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-shell {
  width: min(420px, calc(100vw - 28px));
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 18px 50px rgba(23, 32, 51, 0.08);
}

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

.login-eyebrow {
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 10px;
}

.login-copy {
  color: var(--muted);
  margin-top: 8px;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.login-form input {
  width: 100%;
}

.login-error {
  min-height: 20px;
  color: var(--danger);
  margin: 0;
}

.upload-mode select {
  min-width: 150px;
}

.usage-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.usage-card {
  display: grid;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.usage-card span,
.usage-card small {
  color: var(--muted);
}

.usage-card strong {
  font-size: 28px;
  line-height: 1;
}

.usage-table-wrap {
  overflow: auto;
}

.usage-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.usage-table th,
.usage-table td {
  border-bottom: 1px solid var(--line);
  padding: 9px 8px;
  text-align: left;
  white-space: nowrap;
}

.usage-table th {
  color: var(--muted);
  font-weight: 700;
}

.admin-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
}

.admin-form {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr)) auto;
  gap: 10px;
  align-items: end;
}

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

.danger-button {
  background: var(--danger);
}

.danger-button:hover:not(:disabled) {
  background: #8f1d14;
}

.muted-button {
  background: #eef4ff;
  color: var(--accent);
  border: 1px solid #c9daf8;
}

@media (max-width: 860px) {
  .usage-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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