:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #eef4f8;
  --ink: #17202c;
  --muted: #657386;
  --line: #d8e2ec;
  --blue: #1769e0;
  --blue-soft: #e8f1ff;
  --teal: #0f8b8d;
  --green: #168a4a;
  --red: #b42318;
  --shadow: 0 18px 48px rgba(25, 39, 62, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, #eef6ff 0, rgba(238, 246, 255, 0) 320px),
    var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 42px;
  padding: 10px 13px;
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: #9bb4cf;
}

button:disabled {
  opacity: 0.46;
  cursor: not-allowed;
}

button.primary {
  color: #ffffff;
  border-color: var(--blue);
  background: var(--blue);
}

.app {
  width: min(1440px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  font-size: clamp(26px, 3vw, 40px);
  line-height: 1.08;
}

h2 {
  font-size: 21px;
}

h3 {
  font-size: 16px;
}

.service-pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
}

.service-pill span {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #f59e0b;
}

.service-pill.ok span {
  background: var(--green);
}

.service-pill.fail span {
  background: var(--red);
}

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

.control-panel,
.preview-panel,
.history-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.control-panel {
  display: grid;
  gap: 14px;
  padding: 16px;
  position: sticky;
  top: 16px;
}

.dropzone {
  position: relative;
  display: grid;
  gap: 7px;
  min-height: 148px;
  place-items: center;
  padding: 18px;
  border: 1px dashed #9fb2c6;
  border-radius: 8px;
  background: var(--surface-soft);
  text-align: center;
  cursor: pointer;
}

.dropzone.is-dragging {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.dropzone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.dropzone span {
  font-size: 18px;
  font-weight: 850;
}

.dropzone small,
.progress-card small,
.mode-card small,
.empty-state span,
.history-item small,
.result-meta {
  color: var(--muted);
}

.mode-list {
  display: grid;
  gap: 9px;
}

.mode-card {
  display: grid;
  gap: 4px;
  min-height: auto;
  padding: 12px;
  text-align: left;
  background: #f8fafc;
}

.mode-card.is-active {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.actions .primary {
  grid-column: 1 / -1;
}

.progress-card {
  display: grid;
  gap: 3px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.preview-panel {
  min-width: 0;
  padding: 16px;
}

.preview-head,
.section-title,
.text-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.preview-head {
  margin-bottom: 14px;
}

#lineCounter {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #e8f7f4;
  color: #075f64;
  font-weight: 800;
}

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

.page-pane {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.pane-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.document-preview,
.text-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.document-preview {
  position: relative;
  overflow: auto;
  min-height: 620px;
  max-height: calc(100vh - 190px);
}

#previewCanvas,
#wordCanvas {
  display: none;
  width: 100%;
  height: auto;
  background: #ffffff;
}

.word-preview {
  background: #e7edf4;
}

#pdfPreview {
  display: none;
  width: 100%;
  height: 100%;
  min-height: 620px;
  border: 0;
  background: #ffffff;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 6px;
  text-align: center;
}

.text-preview {
  grid-column: 1 / -1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 220px;
  max-height: 360px;
  overflow: hidden;
}

.text-head {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

#resultList {
  display: grid;
  align-content: start;
  gap: 8px;
  margin: 0;
  padding: 12px 12px 12px 34px;
  overflow: auto;
}

#resultList li {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.result-text {
  display: block;
  font-weight: 780;
  overflow-wrap: anywhere;
}

.result-meta {
  display: block;
  margin-top: 4px;
  font-size: 12px;
}

.history-panel {
  margin-top: 18px;
  padding: 16px;
}

.history-list {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.history-item strong,
.history-item span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #111827;
  color: #ffffff;
  box-shadow: var(--shadow);
  transform: translateY(140%);
  transition: transform 180ms ease;
  z-index: 50;
}

.toast.show {
  transform: translateY(0);
}

@media (max-width: 1100px) {
  .workspace,
  .preview-grid {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: static;
  }

  .document-preview,
  .text-preview {
    min-height: 420px;
    max-height: none;
  }
}

@media (max-width: 680px) {
  .app {
    width: min(100vw - 20px, 1440px);
    padding-top: 14px;
  }

  .topbar,
  .preview-head,
  .section-title,
  .history-item {
    display: grid;
  }

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