:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --text: #121826;
  --muted: #687386;
  --line: #d9e0ea;
  --accent: #0f766e;
  --accent-strong: #0b5d56;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(18, 24, 38, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  font-size: 15px;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: "Segoe UI", Arial, sans-serif;
}

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

button,
input {
  font: inherit;
}

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

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 700;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 30px;
  color: #fff;
  background: var(--accent);
  border-radius: 7px;
  font-size: 0.78rem;
  letter-spacing: 0;
}

.topbar nav {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar form {
  margin: 0;
}

.user-chip {
  padding: 7px 10px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

main {
  padding: 28px;
}

.workspace {
  max-width: 1480px;
  margin: 0 auto;
}

.narrow-workspace {
  max-width: 920px;
}

.workspace-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  font-size: 2rem;
  line-height: 1.2;
}

h2 {
  font-size: 1.05rem;
}

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

.summary-strip {
  display: flex;
  gap: 10px;
}

.summary-strip > div {
  min-width: 104px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.summary-strip strong {
  display: block;
  font-size: 1.4rem;
}

.summary-strip span {
  color: var(--muted);
  font-size: 0.82rem;
}

.auth-nudge {
  min-width: 260px;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-nudge strong,
.auth-nudge span {
  display: block;
}

.auth-nudge span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.convert-panel,
.job-card,
.auth-panel,
.empty-state {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.convert-panel {
  --upload-preview-height: clamp(440px, 42vw, 680px);
  padding: 18px;
  margin-bottom: 20px;
}

.convert-layout {
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(240px, 320px) minmax(420px, 1fr);
  gap: 16px;
  align-items: stretch;
}

.settings-panel,
.selected-files-panel,
.selected-preview-panel {
  min-width: 0;
}

.panel-heading {
  margin-bottom: 12px;
}

.panel-heading h2 {
  font-size: 1rem;
}

.panel-heading p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.form-stack.compact {
  margin-top: 0;
  gap: 12px;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 126px;
  gap: 12px;
}

.server-key-card,
.service-wait-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 82px;
  padding: 13px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.server-key-card strong,
.server-key-card small {
  display: block;
}

.server-key-card small {
  margin-top: 3px;
  color: var(--muted);
}

.server-key-card a {
  flex: 0 0 auto;
  padding: 7px 10px;
  color: var(--accent);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-weight: 700;
}

.server-key-card.ready {
  background: #ecfdf5;
  border-color: #99f6e4;
}

.server-key-card.missing {
  background: #fff7ed;
  border-color: #fed7aa;
}

.service-wait-card {
  display: grid;
  align-items: center;
  justify-content: stretch;
  background: #f8fafc;
}

.service-wait-card strong,
.service-wait-card span {
  display: block;
}

.service-wait-card span {
  margin-top: 4px;
  color: var(--muted);
}

.key-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #f97316;
}

.server-key-card.ready .status-dot {
  background: var(--accent);
}

.selected-file-list {
  height: var(--upload-preview-height);
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.selected-file-button {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 46px;
  padding: 9px 10px;
  color: var(--text);
  text-align: left;
  background: #fff;
  border: 1px solid #d5dde8;
  border-radius: 7px;
  cursor: pointer;
}

.selected-file-button:hover,
.selected-file-button.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.selected-file-button.active {
  background: #ecfdf5;
}

.selected-file-name {
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selected-file-meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.selected-preview-frame {
  height: var(--upload-preview-height);
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.selected-preview-frame > img[data-selected-preview] {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center center;
  background: #fff;
}

.selected-preview-placeholder,
.empty-mini {
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.label-with-help {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.field-help {
  position: relative;
  display: inline-flex;
}

.help-button {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  padding: 0;
  color: var(--accent);
  background: #ecfdf5;
  border: 1px solid #99f6e4;
  border-radius: 999px;
  cursor: help;
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1;
}

.help-popover {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  z-index: 20;
  width: min(300px, 72vw);
  padding: 10px 12px;
  color: #fff;
  background: #111827;
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.22);
  font-size: 0.86rem;
  font-weight: 500;
  line-height: 1.45;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.help-popover::after {
  position: absolute;
  left: 50%;
  bottom: -6px;
  width: 12px;
  height: 12px;
  background: #111827;
  content: "";
  transform: translateX(-50%) rotate(45deg);
}

.field-help:hover .help-popover,
.field-help:focus-within .help-popover {
  opacity: 1;
  transform: translate(-50%, 0);
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(280px, 2fr) minmax(180px, 0.8fr) minmax(120px, 0.5fr);
  gap: 14px;
  align-items: end;
}

.form-grid .wide {
  grid-column: span 2;
}

label {
  display: grid;
  gap: 7px;
  color: #334155;
  font-weight: 650;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="file"],
input:not([type]) {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  color: var(--text);
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
}

input:focus {
  outline: 3px solid rgba(15, 118, 110, 0.16);
  border-color: var(--accent);
}

.switch-line {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
}

.switch-line input {
  width: 18px;
  height: 18px;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 16px;
}

.primary-button,
.ghost-button,
.download-button {
  min-height: 38px;
  padding: 0 15px;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
}

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

.primary-button:hover {
  background: var(--accent-strong);
}

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

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

.notice {
  padding: 12px 14px;
  margin-bottom: 16px;
  color: #064e3b;
  background: #dff7ec;
  border: 1px solid #b8ebd2;
  border-radius: 8px;
}

.inline-maintenance {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 16px;
  padding: 10px 12px;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.validation-summary,
.field-validation-error {
  color: var(--danger);
}

.job-list {
  display: grid;
  gap: 16px;
}

.job-card {
  padding: 16px;
}

.job-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.job-card-header p {
  margin: 5px 0 0;
  color: var(--muted);
}

.status-badge {
  padding: 6px 10px;
  border-radius: 999px;
  background: #eef2f7;
  color: #334155;
  font-weight: 700;
  font-size: 0.8rem;
}

.status-badge.completed {
  background: #dcfce7;
  color: #166534;
}

.status-badge.failed {
  background: #fee2e2;
  color: #991b1b;
}

.status-badge.processing {
  background: #e0f2fe;
  color: #075985;
}

.viewer-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(360px, 1.1fr);
  gap: 14px;
}

.viewer-pane {
  min-height: 360px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.pane-title {
  padding: 10px 12px;
  color: #475569;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
}

.viewer-pane img {
  display: block;
  width: 100%;
  height: 420px;
  object-fit: contain;
  background: #fff;
}

.preview-placeholder {
  display: grid;
  place-items: center;
  height: 420px;
  color: var(--muted);
}

.job-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 13px 0;
}

.job-meta span {
  padding: 6px 9px;
  color: #334155;
  background: #f1f5f9;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.82rem;
}

.json-details {
  margin-top: 10px;
}

.json-details summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 700;
}

pre {
  max-height: 320px;
  overflow: auto;
  padding: 12px;
  background: #0f172a;
  color: #dbeafe;
  border-radius: 8px;
  font-size: 0.85rem;
}

.download-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.download-button {
  display: inline-flex;
  align-items: center;
  color: #fff;
  background: #1f2937;
  border-color: #1f2937;
  font-weight: 700;
}

.download-button:hover {
  color: #fff;
  background: #111827;
}

.admin-path-box {
  display: grid;
  gap: 7px;
  margin-top: 18px;
  padding: 12px;
  color: #334155;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.admin-path-box code {
  overflow-wrap: anywhere;
  color: #0f172a;
}

.admin-path-box span {
  color: var(--muted);
}

.error-box {
  padding: 12px;
  color: #991b1b;
  background: #fff1f2;
  border: 1px solid #fecdd3;
  border-radius: 8px;
}

.empty-state {
  padding: 28px;
  text-align: center;
}

.empty-state p {
  color: var(--muted);
}

.auth-shell {
  min-height: calc(100vh - 120px);
  display: grid;
  place-items: center;
}

.auth-panel {
  width: min(460px, 100%);
  padding: 26px;
}

.form-stack {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

.auth-alt {
  margin: 18px 0 0;
  color: var(--muted);
}

@media (max-width: 980px) {
  .workspace-header,
  .panel-actions,
  .job-card-header {
    align-items: stretch;
    flex-direction: column;
  }

  .summary-strip,
  .viewer-grid,
  .form-grid {
    grid-template-columns: 1fr;
    display: grid;
  }

  .form-grid .wide {
    grid-column: auto;
  }

  .viewer-pane img,
  .preview-placeholder {
    height: 320px;
  }

  .convert-layout {
    grid-template-columns: 1fr;
  }

  .two-column {
    grid-template-columns: 1fr;
  }

  .selected-file-list,
  .selected-preview-frame {
    height: 320px;
  }
}
