:root {
  color: #17212b;
  background: #eef1f3;
  font-family: "Segoe UI", "Microsoft JhengHei", sans-serif;
  font-size: 16px;
  letter-spacing: 0;
  --ink: #17212b;
  --muted: #67737d;
  --line: #d6dce0;
  --surface: #ffffff;
  --surface-soft: #f7f8f9;
  --blue: #1769aa;
  --blue-dark: #0f568e;
  --green: #1f7a52;
  --green-soft: #e6f4ed;
  --red: #ba3b3b;
  --red-soft: #faeaea;
  --amber: #9c6400;
  --amber-soft: #fff1cf;
  --shadow: 0 12px 34px rgba(25, 42, 56, 0.10);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--surface-soft);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

input[type="file"] {
  width: 100%;
  color: var(--muted);
}

input[type="file"]::file-selector-button {
  min-height: 38px;
  margin-right: 10px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  cursor: pointer;
}

.conditional-panel {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid #b8d4e8;
  border-radius: 6px;
  background: #f1f7fb;
}

.conditional-panel > strong {
  display: block;
  color: var(--blue-dark);
}

.conditional-panel label:first-of-type {
  margin-top: 12px;
}

.engine-note {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-left: 3px solid var(--blue);
  background: #eef6fb;
  color: #36556b;
  font-size: 13px;
  line-height: 1.5;
}

select:disabled,
input:disabled {
  cursor: not-allowed;
  background: #eef1f3;
  color: #7b858c;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(90deg, rgba(23, 105, 170, 0.06) 1px, transparent 1px),
    linear-gradient(rgba(23, 105, 170, 0.06) 1px, transparent 1px),
    #eef2f4;
  background-size: 32px 32px;
}

.login-panel {
  width: min(400px, 100%);
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.brand-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  background: var(--blue);
  color: white;
  border-radius: 8px;
  font-weight: 800;
  font-size: 18px;
}

.brand-mark.small {
  width: 40px;
  height: 40px;
  font-size: 14px;
}

.login-panel h1 {
  margin: 20px 0 4px;
  font-size: 24px;
}

.login-panel p {
  margin: 0 0 28px;
  color: var(--muted);
}

label {
  display: block;
  margin: 18px 0 7px;
  color: #33404b;
  font-size: 14px;
  font-weight: 650;
}

input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  border: 1px solid #bdc6cc;
  border-radius: 6px;
  background: white;
  color: var(--ink);
  outline: none;
}

input[type="password"],
input[type="number"],
select {
  height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 100px;
  padding: 12px;
  resize: vertical;
  line-height: 1.6;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(23, 105, 170, 0.12);
}

.password-row,
.select-refresh {
  display: grid;
  grid-template-columns: 1fr 42px;
  gap: 8px;
}

.primary,
.secondary,
.danger {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-weight: 700;
}

.primary {
  color: white;
  background: var(--blue);
}

.primary:hover {
  background: var(--blue-dark);
}

.secondary {
  color: #263540;
  background: white;
  border-color: var(--line);
}

.secondary:hover {
  border-color: #9daab3;
  background: #f9fafb;
}

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

.full {
  width: 100%;
}

.login-panel .primary {
  margin-top: 24px;
}

.icon-button {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #52606b;
}

.icon-button:hover {
  color: var(--blue);
  background: #eaf2f8;
}

.icon-button.bordered {
  border: 1px solid var(--line);
  background: white;
}

.icon-button svg,
button svg {
  width: 18px;
  height: 18px;
}

.form-error {
  min-height: 20px;
  margin-top: 10px;
  color: var(--red);
  font-size: 14px;
}

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

.topbar {
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
}

.brand span {
  color: var(--muted);
  font-size: 13px;
}

.service-status {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 14px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #a9b2b9;
}

.status-dot.online {
  background: #21a269;
  box-shadow: 0 0 0 4px rgba(33, 162, 105, 0.12);
}

.status-dot.offline {
  background: var(--red);
}

.tabs {
  height: 52px;
  display: flex;
  gap: 4px;
  padding: 0 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.tab {
  position: relative;
  min-width: 132px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  background: transparent;
  color: #596671;
  font-weight: 650;
}

.tab.active {
  color: var(--blue);
}

.tab.active::after {
  content: "";
  position: absolute;
  right: 12px;
  bottom: 0;
  left: 12px;
  height: 3px;
  background: var(--blue);
}

.count {
  min-width: 22px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  padding: 0 6px;
  border-radius: 10px;
  color: var(--blue);
  background: #e5f0f8;
  font-size: 12px;
}

main {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 28px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

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

.upload-section,
.settings-panel,
.jobs-list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.upload-section {
  padding: 24px;
}

.settings-panel {
  padding: 22px;
}

.section-heading,
.jobs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.section-heading h2,
.jobs-header h2 {
  margin: 0;
  font-size: 18px;
}

.section-heading p,
.jobs-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.section-heading.compact h2 {
  font-size: 16px;
}

.drop-zone {
  min-height: 230px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-top: 22px;
  padding: 32px;
  border: 2px dashed #aebbc4;
  border-radius: 8px;
  background: #fafbfc;
  text-align: center;
  cursor: pointer;
  transition: 160ms ease;
}

.drop-zone:hover,
.drop-zone.dragging {
  border-color: var(--blue);
  background: #f1f7fb;
}

.drop-zone.has-file {
  border-style: solid;
  border-color: #75ad94;
  background: var(--green-soft);
}

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

.drop-zone svg {
  width: 42px;
  height: 42px;
  margin-bottom: 15px;
  color: var(--blue);
}

.drop-zone strong {
  font-size: 17px;
}

.drop-zone span {
  margin-top: 7px;
  color: var(--muted);
  font-size: 14px;
}

.preview-block {
  margin-top: 26px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.preview-block textarea {
  margin-top: 16px;
}

.preview-block audio {
  width: 100%;
  height: 42px;
  margin-top: 12px;
}

.settings-panel > label:first-of-type {
  margin-top: 24px;
}

.range-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 20px;
}

.range-heading label {
  margin: 0;
}

.range-heading output {
  color: var(--blue);
  font-weight: 750;
}

input[type="range"] {
  width: 100%;
  margin: 14px 0 6px;
  accent-color: var(--blue);
}

.field-note {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.start-button {
  margin-top: 28px;
}

.jobs-header {
  margin-bottom: 18px;
}

.jobs-list {
  overflow: hidden;
}

.job-row {
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.job-row:last-child {
  border-bottom: 0;
}

.job-topline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.job-title {
  min-width: 0;
}

.job-title h3 {
  margin: 0;
  overflow: hidden;
  font-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.job-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
}

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

.job-actions button {
  min-height: 36px;
  padding: 0 12px;
  font-size: 13px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 0 9px;
  border-radius: 13px;
  font-size: 12px;
  font-weight: 750;
}

.badge.done {
  color: var(--green);
  background: var(--green-soft);
}

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

.badge.active {
  color: var(--blue);
  background: #e5f0f8;
}

.badge.queued {
  color: var(--amber);
  background: var(--amber-soft);
}

.progress-track {
  height: 8px;
  margin-top: 16px;
  overflow: hidden;
  border-radius: 4px;
  background: #e5e9ec;
}

.progress-bar {
  width: 0;
  height: 100%;
  background: var(--blue);
  transition: width 280ms ease;
}

.job-progress-text {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.job-error {
  margin-top: 12px;
  padding: 10px 12px;
  border-left: 3px solid var(--red);
  background: var(--red-soft);
  color: #8e2e2e;
  font-size: 13px;
  line-height: 1.5;
}

.chapter-list {
  margin-top: 14px;
  border-top: 1px solid var(--line);
}

.chapter-row {
  min-height: 42px;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 90px;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid #e8ecef;
  font-size: 13px;
}

.chapter-row:last-child {
  border-bottom: 0;
}

.chapter-row span:nth-child(2) {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chapter-download {
  color: var(--blue);
  text-decoration: none;
  font-weight: 700;
  text-align: right;
}

.empty-state {
  min-height: 320px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-align: center;
}

.empty-state svg {
  width: 44px;
  height: 44px;
  margin-bottom: 14px;
}

.empty-state strong {
  color: #47545f;
}

.empty-state span {
  margin-top: 6px;
  font-size: 14px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(380px, calc(100vw - 44px));
  padding: 12px 16px;
  border-radius: 6px;
  background: #24313a;
  color: white;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 840px) {
  .topbar {
    padding: 0 16px;
  }

  .tabs {
    padding: 0 8px;
  }

  .tab {
    min-width: 0;
    flex: 1;
  }

  main {
    padding: 16px;
  }

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

  .settings-panel {
    grid-row: 1;
  }

  .job-topline {
    display: block;
  }

  .job-actions {
    justify-content: flex-start;
    margin-top: 14px;
  }
}

@media (max-width: 520px) {
  .topbar {
    height: 62px;
  }

  .brand span,
  #healthText {
    display: none;
  }

  .brand-mark.small {
    width: 36px;
    height: 36px;
  }

  .upload-section,
  .settings-panel {
    padding: 18px;
  }

  .section-heading {
    align-items: flex-start;
  }

  .preview-block .section-heading {
    display: block;
  }

  .preview-block .secondary {
    width: 100%;
    margin-top: 12px;
  }

  .drop-zone {
    min-height: 190px;
    padding: 24px 16px;
  }

  .job-progress-text {
    display: block;
  }

  .job-progress-text span {
    display: block;
    margin-top: 4px;
  }
}
