:root {
  --ground: #F4F5F2;
  --ground-deep: #E7E9E5;
  --sidebar: #ECEEEA;
  --surface: #FFFFFF;
  --surface-soft: #F9FAF8;
  --ink: #15191A;
  --muted: #4F5856;
  --hairline: #D9DDD8;
  --hairline-soft: #E3E6E1;
  --border: #8A938F;
  --accent: #0A6E5A;
  --accent-hover: #07503F;
  --accent-tint: #CDE5DE;
  --error: #A32A12;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: "IBM Plex Sans", system-ui, sans-serif;
}

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
h1, h2, p, ol { margin: 0; }
ol { padding: 0; list-style: none; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  font: inherit;
  font-weight: 500;
  border-radius: 6px;
  border: 1px solid transparent;
  text-decoration: none;
  cursor: pointer;
}
.btn:disabled { cursor: default; }
.btn-primary { color: #FFFFFF; background: var(--accent); }
.btn-primary:hover { color: #FFFFFF; background: var(--accent-hover); }
.btn-primary:disabled { color: var(--muted); background: var(--hairline-soft); }
.btn-secondary { color: var(--ink); background: var(--surface); border-color: var(--border); }
.btn-secondary:hover { color: var(--ink); background: var(--ground); }
.btn-outline { color: var(--ink); background: var(--surface); border-color: var(--ink); min-height: 48px; padding: 0 24px; }
.btn-dark { min-width: 84px; color: #FFFFFF; background: var(--ink); }
.btn-large { flex: 1 1 240px; height: 56px; font-size: 17px; }
.btn-block { width: 100%; }
.icon { width: 18px; height: 18px; }

.text-button {
  min-height: 44px;
  padding: 0 12px;
  font: inherit;
  font-size: 15px;
  color: var(--accent);
  background: none;
  border: 0;
  text-decoration: underline;
  cursor: pointer;
}

.track { height: 14px; background: var(--hairline-soft); border-radius: 7px; overflow: hidden; }
.fill { width: 0; height: 100%; background: var(--accent); border-radius: 7px; transition: width 0.3s ease; }

.landing { display: flex; flex-direction: column; min-height: 100%; }
.landing-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 48px 16px;
}

.upload-card {
  width: 100%;
  max-width: 920px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 12px;
}

.zone {
  min-height: 460px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  background: var(--surface-soft);
  border: 2px dashed var(--border);
  border-radius: 8px;
  text-align: center;
}
.zone-drag { border-color: var(--accent); background: var(--accent-tint); }
.zone-active { border: 2px solid var(--hairline); }
.zone-body { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 20px; }
.zone-icon { width: 56px; height: 56px; color: var(--accent); }
.zone h1 { font-size: 52px; line-height: 1.1; font-weight: 600; letter-spacing: -0.02em; }
.zone-row { display: flex; flex-direction: column; align-items: center; gap: 20px; }
.zone-hint { font-size: 18px; color: var(--muted); }

.file-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 12px; font-size: 18px; }
.file-name { font-weight: 500; overflow-wrap: anywhere; }
.file-size { font-family: var(--mono); font-size: 15px; color: var(--muted); }

.upload-progress { width: 100%; max-width: 640px; display: flex; flex-direction: column; gap: 12px; }
.upload-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; font-size: 18px; text-align: left; }
.mono-strong { font-family: var(--mono); font-weight: 500; }
.upload-sent { font-family: var(--mono); font-size: 15px; color: var(--muted); text-align: left; }

.form-error { padding: 0 4px; font-size: 15px; color: var(--error); }

.controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px; }
.field { flex: 1 1 280px; display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 14px; font-weight: 500; }
.field select {
  height: 56px;
  padding: 0 12px;
  font: inherit;
  font-size: 17px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.field select:disabled { color: var(--muted); background: var(--ground); border-color: var(--hairline); }

.facts { max-width: 920px; font-size: 15px; line-height: 1.5; color: var(--muted); text-align: center; }

.gone { text-align: center; }
.gone h1 { font-size: 34px; font-weight: 600; letter-spacing: -0.015em; }
.gone p { color: var(--muted); }

.app { height: 100dvh; min-height: 480px; display: flex; flex-direction: column; }

.topbar {
  position: relative;
  z-index: 10;
  min-height: 64px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  padding: 8px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
}
.topbar-file { font-weight: 500; overflow-wrap: anywhere; }
.topbar-language { font-size: 15px; color: var(--muted); }
.actions { margin-left: auto; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.share { position: relative; }
.popover {
  position: absolute;
  top: 52px;
  right: 0;
  width: 380px;
  max-width: calc(100vw - 32px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(21, 25, 26, 0.16);
}
.popover label { font-size: 14px; font-weight: 600; }
.popover p { font-size: 14px; line-height: 1.45; color: var(--muted); }
.popover-row { display: flex; gap: 8px; }
.popover input {
  flex: 1 1 auto;
  min-width: 0;
  height: 44px;
  padding: 0 10px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink);
  background: var(--ground);
  border: 1px solid var(--hairline);
  border-radius: 6px;
}

.workspace { flex: 1 1 auto; min-height: 0; display: grid; grid-template-columns: 220px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }

.sidebar { min-height: 0; overflow-y: auto; padding: 20px 16px; background: var(--sidebar); border-right: 1px solid var(--hairline); }
.sidebar-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.sidebar-head h2 { font-size: 14px; font-weight: 600; }
.sidebar-head span { font-size: 13px; color: var(--muted); }
.sidebar-link { display: none; margin: -8px 0 12px; font-size: 13px; }
[data-status="done"] .sidebar-link { display: block; }

.thumbs { display: flex; flex-direction: column; gap: 6px; }
.thumb {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
.thumb:disabled { cursor: default; }
.thumb-page {
  display: block;
  width: 132px;
  background: var(--surface);
  border: 1px solid #C9CECA;
  box-shadow: 0 1px 3px rgba(21, 25, 26, 0.18);
  overflow: hidden;
}
.thumb-page img { display: block; width: 100%; height: 100%; }
.thumb-number { min-width: 28px; padding: 1px 8px; font-family: var(--mono); font-size: 12px; text-align: center; color: var(--muted); border-radius: 10px; }
.thumb-current { background: var(--accent-tint); }
.thumb-current .thumb-number { color: #FFFFFF; background: var(--accent); }

.content { min-height: 0; overflow-y: auto; padding: 40px 32px; background: var(--ground); }
[data-status="done"] .content { padding: 24px 32px 40px; background: var(--ground-deep); }

.progress-view, .failed-view { max-width: 760px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
.progress-file { display: none; }
.progress-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.progress-head h1, .failed-view h1 { font-size: 34px; line-height: 1.15; font-weight: 600; letter-spacing: -0.015em; }
.progress-percent { font-family: var(--mono); font-size: 26px; font-weight: 500; }
[data-status="queued"] .progress-percent { display: none; }
.queue-note { font-size: 18px; color: var(--muted); }
.queue-note:empty { display: none; }
.note { font-size: 15px; line-height: 1.5; color: var(--muted); }
.failed-view p { font-size: 18px; color: var(--muted); }
.failed-view .btn { align-self: flex-start; }

.stages { background: var(--surface); border: 1px solid var(--hairline); border-radius: 8px; }
.stage { min-height: 52px; display: flex; align-items: center; gap: 14px; padding: 10px 20px; border-top: 1px solid var(--hairline-soft); }
.stage:first-child { border-top: 0; }
.stage-name { flex: 1 1 auto; }
.stage-detail { font-family: var(--mono); font-size: 14px; color: var(--muted); text-align: right; }
.stage-mark { flex: 0 0 20px; width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--border); }
.stage-pending .stage-name { color: var(--muted); }
.stage-active .stage-name { font-weight: 600; }
.stage-active .stage-mark { border: 2px solid var(--accent); background: radial-gradient(circle, var(--accent) 0 4px, transparent 4.5px); }
.stage-done .stage-mark {
  border: 0;
  background: var(--accent) url("/static/check.svg") center / 14px no-repeat;
}

.result-view { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }
.result-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px; }
.result-head h1 { font-size: 20px; font-weight: 600; overflow-wrap: anywhere; }
.disclaimer { font-size: 14px; color: var(--muted); }
.pages { display: flex; flex-direction: column; gap: 16px; }
.sheet { background: var(--surface); box-shadow: 0 1px 3px rgba(21, 25, 26, 0.2); overflow: hidden; }
.sheet img { display: block; width: 100%; height: 100%; }

.phone-top, .phone-actions { display: none; }

@media (max-width: 760px) {
  .landing-main { padding: 16px; align-items: stretch; }
  .upload-card { flex: 1 1 auto; padding: 12px; }
  .zone { flex: 1 1 auto; min-height: 280px; padding: 24px 16px; }
  .zone h1 { font-size: 34px; line-height: 1.12; }
  .zone-icon { width: 48px; height: 48px; }
  .zone-hint, .file-size, .upload-sent, .facts { display: none; }
  .file-row { flex-direction: column; gap: 2px; font-size: 16px; }
  .upload-row { font-size: 15px; flex-wrap: nowrap; }
  .controls { flex-direction: column; align-items: stretch; }
  .field { flex: 0 0 auto; }
  .btn-large { flex: 0 0 auto; height: 52px; }
  .field select { height: 52px; }

  .topbar, .sidebar { display: none; }
  .workspace { display: block; flex: 1 1 auto; min-height: 0; overflow: hidden; }
  .content { height: 100%; padding: 16px; }
  [data-status="done"] .content { padding: 12px 16px; }

  .progress-view { min-height: 100%; justify-content: center; gap: 12px; padding-bottom: 96px; }
  .progress-file { display: block; order: 1; font-size: 15px; font-weight: 500; overflow-wrap: anywhere; }
  .progress-head { display: contents; }
  .progress-percent, [data-status="queued"] .progress-percent { display: block; order: 2; font-size: 64px; line-height: 1; letter-spacing: -0.03em; }
  #progress-track { order: 3; }
  .progress-head h1 { order: 4; font-size: 18px; font-weight: 500; letter-spacing: 0; }
  .note { order: 5; }
  .queue-note, .stages { display: none; }

  .failed-view { min-height: 100%; justify-content: center; }

  [data-status="done"] .phone-top { display: block; flex: 0 0 auto; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--hairline); }
  .result-view { gap: 10px; }
  .result-head h1 { font-size: 15px; font-weight: 500; }
  .disclaimer { display: none; }
  .pages { gap: 12px; }

  [data-status="done"] .phone-actions { display: flex; flex: 0 0 auto; gap: 8px; padding: 12px 16px 20px; background: var(--surface); border-top: 1px solid var(--hairline); }
  .phone-actions .btn { min-height: 48px; }
  .phone-download { flex: 1 1 auto; }
}
