:root {
  --bg: #f7f9fc;
  --panel: #ffffff;
  --panel-soft: #f8fbff;
  --text: #111827;
  --muted: #5d6b84;
  --line: #dbe4f0;
  --line-soft: #edf2f8;
  --blue: #2563eb;
  --blue-soft: #edf4ff;
  --green: #16a34a;
  --green-soft: #e8f8ef;
  --amber: #f59e0b;
  --amber-soft: #fff6df;
  --red: #ef4444;
  --red-soft: #fff0f0;
  --purple: #7c3aed;
  --purple-soft: #f2eaff;
  --shadow: 0 18px 50px rgba(15, 23, 42, .055);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  background: linear-gradient(180deg, #fbfdff 0%, var(--bg) 100%);
  color: var(--text);
  margin: 0;
  min-width: 320px;
}

a { color: var(--blue); text-decoration: none; }

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

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  background: rgba(255, 255, 255, .94);
  border-right: 1px solid var(--line);
  box-shadow: 8px 0 34px rgba(15, 23, 42, .035);
  display: flex;
  flex: 0 0 216px;
  flex-direction: column;
  gap: 18px;
  height: 100vh;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  width: 216px;
}

.brand {
  align-items: center;
  color: var(--text);
  display: flex;
  gap: 12px;
  font-size: 20px;
  font-weight: 850;
  letter-spacing: 0;
}

.brand-mark {
  align-items: center;
  background: linear-gradient(180deg, #2f7fff, #1f63f3);
  border-radius: 7px;
  color: #fff;
  display: flex;
  height: 32px;
  justify-content: center;
  width: 32px;
}

.brand-mark svg {
  fill: none;
  height: 20px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 2;
  width: 20px;
}

.sidebar nav {
  display: grid;
  gap: 4px;
}

.sidebar nav a {
  align-items: center;
  border-radius: 8px;
  color: #1f2a44;
  display: flex;
  font-size: 14px;
  font-weight: 700;
  gap: 10px;
  min-height: 40px;
  padding: 9px 10px;
}

.sidebar nav a:hover,
.sidebar nav a.active {
  background: linear-gradient(90deg, #eef5ff 0%, #f8fbff 100%);
  color: #005cff;
}

.nav-icon {
  align-items: center;
  color: #425577;
  display: flex;
  font-size: 16px;
  font-weight: 800;
  height: 22px;
  justify-content: center;
  width: 22px;
}

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

.sidebar-status strong,
.sidebar-status small {
  display: block;
}

.sidebar-status small,
.sidebar-version,
.help,
.row-note,
.muted {
  color: var(--muted);
}

.sidebar-version {
  font-size: 13px;
  padding: 0 8px;
}

.container {
  flex: 1;
  min-width: 0;
  padding: 18px 24px 32px;
}

.topbar {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(260px, 1.1fr) repeat(3, 120px) auto;
  margin: -18px -24px 18px;
  min-height: 64px;
  padding: 0 24px;
}

.system-pill {
  align-items: center;
  border-left: 1px solid var(--line);
  display: grid;
  gap: 12px;
  grid-template-columns: 10px minmax(0, 1fr);
  padding-left: 18px;
}

.system-pill strong,
.system-pill small,
.top-metric span {
  display: block;
}

.system-pill strong span {
  color: var(--green);
}

.system-pill small,
.top-metric span {
  color: var(--muted);
  font-size: 12px;
}

.top-metric strong {
  display: block;
  font-size: 18px;
  margin-top: 4px;
}

.top-metric.danger strong {
  color: var(--red);
}

.status-dot {
  border-radius: 50%;
  display: inline-block;
  height: 8px;
  width: 8px;
}

.status-dot.ok { background: var(--green); }

.dashboard-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1.05fr) minmax(420px, .95fr);
}

.work-grid,
.result-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(0, 1.08fr) minmax(420px, .92fr);
  margin-top: 16px;
}

.panel,
.login-box,
.form,
.stats div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  overflow: hidden;
}

.panel-title,
.page-head {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 14px;
  justify-content: space-between;
  min-height: 48px;
  padding: 12px 16px;
}

.page-head {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.25;
  margin-bottom: 0;
}

h2 {
  font-size: 16px;
  margin-bottom: 0;
}

h3 {
  font-size: 13px;
}

.actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.button,
button {
  align-items: center;
  background: var(--blue);
  border: 1px solid var(--blue);
  border-radius: 7px;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  font-weight: 750;
  justify-content: center;
  min-height: 36px;
  padding: 8px 13px;
}

.primary {
  box-shadow: 0 10px 22px rgba(37, 99, 235, .18);
}

.secondary {
  background: #475569;
  border-color: #475569;
}

.ghost,
.button.ghost {
  background: #fff;
  border-color: var(--line);
  color: #31415f;
}

.danger {
  background: var(--red);
  border-color: var(--red);
}

.compact {
  font-size: 12px;
  min-height: 30px;
  padding: 5px 10px;
}

input,
select,
textarea {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  min-height: 34px;
  padding: 8px 10px;
  width: 100%;
}

textarea {
  resize: vertical;
}

label {
  color: #2a3956;
  display: grid;
  font-size: 13px;
  font-weight: 650;
  gap: 6px;
}

.create-panel {
  min-height: 318px;
}

.create-layout {
  display: grid;
  gap: 26px;
  grid-template-columns: minmax(300px, .95fr) minmax(280px, 1fr);
  padding: 16px;
}

.drop-zone,
.url-form {
  display: grid;
  gap: 12px;
}

.file-drop {
  align-content: center;
  border: 1.5px dashed #a9b9d2;
  border-radius: 8px;
  cursor: pointer;
  justify-items: center;
  min-height: 140px;
  padding: 22px;
  text-align: center;
}

.file-drop input {
  height: 1px;
  opacity: 0;
  position: absolute;
  width: 1px;
}

.file-drop small {
  color: var(--blue);
}

.upload-icon {
  color: #111827;
  font-size: 28px;
}

.drop-help {
  color: var(--muted);
  font-size: 12px;
  margin: 0;
}

.option-grid {
  display: grid;
  gap: 9px;
}

.check {
  align-items: start;
  display: grid;
  gap: 4px 8px;
  grid-template-columns: 16px minmax(0, 1fr);
  line-height: 1.2;
  margin: 0;
}

.check input {
  margin: 1px 0 0;
  min-height: 0;
  width: auto;
}

.check small {
  color: var(--muted);
  display: block;
  font-weight: 500;
  grid-column: 2;
}

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

.metric-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 4px 12px;
  grid-template-columns: 44px minmax(0, 1fr);
  min-height: 106px;
  padding: 20px 18px;
}

.metric-card span:first-child {
  align-items: center;
  border-radius: 50%;
  display: flex;
  font-size: 18px;
  grid-row: span 2;
  height: 38px;
  justify-content: center;
  width: 38px;
}

.metric-card strong {
  display: block;
  font-size: 24px;
  line-height: 1;
}

.metric-card small {
  color: var(--muted);
}

.metric-card.blue span:first-child { background: var(--blue-soft); color: var(--blue); }
.metric-card.green span:first-child { background: var(--green-soft); color: var(--green); }
.metric-card.amber span:first-child { background: var(--amber-soft); color: var(--amber); }
.metric-card.red span:first-child { background: var(--red-soft); color: var(--red); }
.metric-card.purple span:first-child { background: var(--purple-soft); color: var(--purple); }

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

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

.panel .table-wrap {
  border: 0;
  border-radius: 0;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  padding: 9px 12px;
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  background: #fbfcff;
  color: #52617a;
  font-size: 11px;
  font-weight: 850;
}

.task-title {
  color: var(--text);
  display: block;
  font-weight: 800;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.data-table td small {
  color: var(--muted);
  display: block;
  font-size: 11px;
  margin-top: 3px;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status {
  border-radius: 999px;
  display: inline-flex;
  font-size: 11px;
  font-weight: 800;
  padding: 4px 8px;
}

.status-done,
.status-sent {
  background: var(--green-soft);
  color: var(--green);
}

.status-failed {
  background: var(--red-soft);
  color: var(--red);
}

.status-pending {
  background: var(--amber-soft);
  color: #b66b00;
}

.status-downloading,
.status-extracting_audio,
.status-transcribing,
.status-detecting_language,
.status-refining,
.status-translating,
.status-exporting,
.status-sending_to_rag {
  background: var(--blue-soft);
  color: var(--blue);
}

.table-progress {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: 38px 88px;
}

.progress-bar {
  background: #edf2f7;
  border-radius: 999px;
  height: 6px;
  overflow: hidden;
}

.progress-bar span {
  background: var(--blue);
  border-radius: inherit;
  display: block;
  height: 100%;
}

.progress-bar.mini {
  width: 88px;
}

.row-menu {
  color: var(--muted);
  font-size: 20px;
}

.task-focus {
  min-height: 318px;
  padding: 0;
}

.task-focus-head {
  align-items: start;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding: 16px;
}

.task-focus-head h1,
.task-focus-head h2 {
  margin: 0 0 4px;
}

.task-focus-head small,
.task-meta-line {
  color: var(--muted);
  font-size: 12px;
}

.icon-link {
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
}

.task-meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 0 16px 14px;
}

.stage-line {
  align-items: start;
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  padding: 14px 18px 10px;
}

.stage-step {
  color: var(--muted);
  display: grid;
  font-size: 11px;
  gap: 8px;
  justify-items: center;
  position: relative;
  text-align: center;
}

.stage-step::before {
  background: var(--line);
  content: "";
  height: 1px;
  left: calc(-50% + 16px);
  position: absolute;
  top: 15px;
  width: calc(100% - 32px);
}

.stage-step:first-child::before {
  display: none;
}

.stage-step span {
  background: #f3f6fb;
  border: 1px solid var(--line);
  border-radius: 50%;
  display: block;
  height: 30px;
  width: 30px;
  z-index: 1;
}

.stage-step.done span {
  background: var(--green-soft);
  border-color: #bcebd0;
}

.stage-step.active span {
  background: var(--blue-soft);
  border-color: #b9d3ff;
  box-shadow: inset 0 0 0 8px #fff, inset 0 0 0 14px var(--blue);
}

.stage-step.failed span {
  background: var(--red-soft);
  border-color: #ffd0d0;
}

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

.ok-box,
.issue-box {
  border-radius: 7px;
  font-size: 13px;
  margin: 8px 18px 12px;
  padding: 10px 12px;
}

.ok-box {
  background: #f0fdf4;
  border: 1px solid #bcebd0;
  color: var(--green);
}

.issue-box {
  background: var(--red-soft);
  border: 1px solid #ffd0d0;
  color: var(--red);
}

.task-actions {
  border-top: 1px solid var(--line);
  padding: 12px 18px;
}

.transcript-panel {
  min-height: 270px;
}

.transcript-editor {
  display: grid;
  gap: 8px;
  padding: 14px 16px 18px;
}

.transcript-editor p {
  display: grid;
  gap: 12px;
  grid-template-columns: 72px minmax(0, 1fr);
  line-height: 1.45;
  margin: 0;
}

.transcript-editor time {
  color: var(--blue);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.export-panel {
  padding: 16px;
}

.export-buttons {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 14px 0 20px;
}

.export-buttons a,
.export-buttons span {
  background: #fbfcff;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: #34425e;
  font-weight: 800;
  padding: 14px;
}

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

.form,
.wide-form,
.login-box {
  padding: 18px;
}

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

.stats b {
  display: block;
  font-size: 28px;
}

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

.grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 16px;
}

.detail-focus {
  margin-bottom: 16px;
}

.raw-grid pre,
.result,
pre {
  line-height: 1.55;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.result {
  padding: 16px;
}

.meta {
  display: grid;
  gap: 8px 14px;
  grid-template-columns: 130px minmax(0, 1fr);
}

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

.compact-meta {
  font-size: 13px;
  grid-template-columns: 86px minmax(0, 1fr);
}

.inline-form {
  align-items: end;
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 16px;
}

.rag-send-form label {
  min-width: 260px;
}

.alert {
  color: var(--red);
}

.notice {
  color: var(--green);
}

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

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

fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 14px 0;
}

.settings-actions,
.provider-list,
.setup-flow,
.rag-results {
  display: grid;
  gap: 12px;
}

.add-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.add-panel summary {
  background: var(--blue);
  border-radius: 7px;
  color: #fff;
  cursor: pointer;
  font-weight: 800;
  min-height: 44px;
  padding: 12px 16px;
}

.settings-form,
.provider-form {
  display: grid;
  gap: 0 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 18px;
}

.row-actions,
.modal-actions,
.step-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.modal {
  border: 0;
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, .3);
  padding: 0;
  width: min(760px, calc(100vw - 32px));
}

.modal::backdrop {
  background: rgba(15, 23, 42, .45);
}

.modal-head,
.modal-actions {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 14px 18px;
}

.modal-actions {
  border-bottom: 0;
  border-top: 1px solid var(--line);
  justify-content: flex-end;
}

.role-grid,
.rag-status-grid {
  display: grid;
  gap: 8px 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

.rag-status-grid div,
.rag-result {
  background: #fbfcff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.status-ok { color: var(--green); }
.status-danger { color: var(--red); }
.status-muted { color: var(--muted); }

@media (max-width: 1280px) {
  .dashboard-grid,
  .work-grid,
  .result-grid {
    grid-template-columns: 1fr;
  }

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

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

  .sidebar {
    height: auto;
    position: static;
    width: auto;
  }

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

  .container {
    padding: 16px;
  }

  .topbar {
    grid-template-columns: 1fr;
    margin: -16px -16px 16px;
    padding: 12px 16px;
  }

  .create-layout,
  .metric-grid,
  .stats,
  .grid,
  .settings-form,
  .provider-form,
  .rag-status-grid {
    grid-template-columns: 1fr;
  }

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