:root {
  --bg: oklch(0.97 0.006 225);
  --bg-2: oklch(0.94 0.008 220);
  --bg-3: oklch(0.90 0.01 215);
  --ink: oklch(0.22 0.012 70);
  --ink-2: oklch(0.42 0.014 75);
  --ink-3: oklch(0.58 0.012 90);
  --rule: oklch(0.86 0.01 210);
  --rule-2: oklch(0.80 0.014 205);
  --paper: oklch(0.99 0.003 230);
  --accent: oklch(0.58 0.10 155);
  --accent-ink: oklch(0.30 0.09 155);
  --ok: oklch(0.56 0.10 145);
  --warn: oklch(0.66 0.13 75);
  --bad: oklch(0.55 0.15 28);
  --serif: "Newsreader", "Iowan Old Style", Georgia, serif;
  --sans: "Inter Tight", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

[data-density="dense"] { --row-pad-y: 12px; --gap: 14px; }
[data-density="balanced"] { --row-pad-y: 18px; --gap: 20px; }
[data-density="spacious"] { --row-pad-y: 26px; --gap: 28px; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input { font: inherit; }
button { color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
button:disabled, .action[disabled] { cursor: default; opacity: 0.45; }
a { color: inherit; }

.shell {
  display: grid;
  grid-template-columns: minmax(320px, 380px) 1fr;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

.left {
  background: var(--bg);
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand {
  align-items: baseline;
  border-bottom: 1px solid var(--rule);
  display: flex;
  justify-content: space-between;
  padding: 22px 28px 18px;
}

.brand h1 {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: 0;
  margin: 0;
}

.brand h1 em {
  color: var(--ink-2);
  font-style: italic;
  font-weight: 400;
}

.brand-meta,
.device-row,
.device-stats,
.list-head h2,
.count,
.row-time,
.row-sub,
.status,
.action,
.tab,
.preview-toolbar,
.page-num,
.source,
.toast {
  font-family: var(--mono);
}

.brand-meta,
.list-head h2,
.count,
.row-sub,
.status,
.action,
.tab,
.preview-toolbar,
.page-num,
.toast {
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.brand-meta,
.count,
.row-time,
.row-sub,
.doc-meta,
.preview-toolbar,
.page-num {
  color: var(--ink-3);
}

.brand-meta,
.device-row,
.device-stats,
.list-head h2,
.count,
.row-time,
.row-sub,
.status,
.action,
.tab,
.preview-toolbar,
.page-num {
  font-size: 11px;
}

.device {
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
  padding: 18px 28px 20px;
}

.device-row {
  align-items: center;
  color: var(--ink-2);
  display: flex;
  gap: 10px;
}

.device-dot {
  animation: pulse 2.4s ease-in-out infinite;
  background: var(--ok);
  border-radius: 999px;
  box-shadow: 0 0 0 4px color-mix(in oklch, var(--ok) 18%, transparent);
  height: 8px;
  width: 8px;
}

.device-dot.warn {
  background: var(--warn);
  box-shadow: 0 0 0 4px color-mix(in oklch, var(--warn) 22%, transparent);
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 4px color-mix(in oklch, var(--ok) 18%, transparent); }
  50% { box-shadow: 0 0 0 8px color-mix(in oklch, var(--ok) 8%, transparent); }
}

.device-name {
  color: var(--ink);
  font-weight: 500;
}

.device-state {
  margin-left: auto;
}

.device-stats {
  color: var(--ink-3);
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr 1fr 1fr;
  margin-top: 14px;
}

.device-stats b {
  color: var(--ink);
  display: block;
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: 0;
  margin-top: 4px;
  text-transform: none;
}

.list-head {
  align-items: baseline;
  display: flex;
  justify-content: space-between;
  padding: 22px 28px 10px;
}

.list-head h2 {
  color: var(--ink-3);
  font-weight: 500;
  margin: 0;
}

.list {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 24px;
}

.list::-webkit-scrollbar,
.body::-webkit-scrollbar { width: 10px; }
.list::-webkit-scrollbar-track,
.body::-webkit-scrollbar-track { background: transparent; }
.list::-webkit-scrollbar-thumb,
.body::-webkit-scrollbar-thumb {
  background: color-mix(in oklch, var(--ink-3) 25%, transparent);
  border: 3px solid var(--bg);
  border-radius: 999px;
}

.list-empty {
  color: var(--ink-3);
  font-family: var(--serif);
  font-size: 17px;
  font-style: italic;
  padding: 28px 12px;
}

.row {
  border-bottom: 1px solid var(--rule);
  border-radius: 6px;
  display: block;
  padding: var(--row-pad-y, 18px) 12px;
  position: relative;
  text-align: left;
  transition: background 120ms ease;
  width: 100%;
}

.row:hover,
.row.is-active { background: var(--bg-2); }

.row.is-active::before {
  background: var(--accent);
  border-radius: 2px;
  bottom: 22px;
  content: "";
  left: 0;
  position: absolute;
  top: 22px;
  width: 2px;
}

.row-top {
  align-items: baseline;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 6px;
}

.row-title {
  color: var(--ink);
  font-family: var(--serif);
  font-size: 16.5px;
  font-weight: 500;
  letter-spacing: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-time {
  white-space: nowrap;
}

.row-sub {
  align-items: center;
  display: flex;
  gap: 10px;
}

.sep { color: var(--rule-2); }

.status {
  align-items: center;
  color: var(--ink-3);
  display: inline-flex;
  gap: 6px;
}

.status::before {
  background: var(--ink-3);
  border-radius: 999px;
  content: "";
  height: 6px;
  width: 6px;
}

.status[data-state="converting"],
.status[data-state="uploading"] { color: var(--accent-ink); }
.status[data-state="converting"]::before,
.status[data-state="uploading"]::before { animation: blink 1s steps(2) infinite; background: var(--accent); }
.status[data-state="ready"] { color: var(--ok); }
.status[data-state="ready"]::before { background: var(--ok); }
.status[data-state="failed"] { color: var(--bad); }
.status[data-state="failed"]::before { background: var(--bad); }

@keyframes blink { 50% { opacity: 0.25; } }

.mock-bar {
  border-top: 1px solid var(--rule);
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
  padding: 14px 20px 18px;
}

.mock-bar input[type="text"],
#document-id {
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 4px;
  color: var(--ink);
  grid-column: 1 / -1;
  min-height: 36px;
  padding: 8px 10px;
  width: 100%;
}

.mock-btn {
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 4px;
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  padding: 11px 12px;
  text-align: center;
  text-transform: uppercase;
  transition: all 120ms ease;
}

.mock-btn:hover,
.action:hover,
.pager button:hover {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

.file-action input {
  display: none;
}

.right {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.right-head {
  align-items: center;
  border-bottom: 1px solid var(--rule);
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: space-between;
  padding: 22px 44px 18px;
}

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

.doc-title h2 {
  color: var(--ink);
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 500;
  letter-spacing: 0;
  margin: 0 0 6px;
  overflow-wrap: anywhere;
}

.doc-meta {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  font-family: var(--mono);
  font-size: 11px;
  gap: 10px;
  letter-spacing: 0.04em;
}

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

.action {
  background: var(--bg);
  border: 1px solid var(--rule);
  border-radius: 4px;
  color: var(--ink-2);
  display: inline-flex;
  padding: 9px 14px;
  text-decoration: none;
  transition: all 120ms ease;
  white-space: nowrap;
}

.action.primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}

.action.primary:hover {
  background: var(--accent-ink);
  border-color: var(--accent-ink);
}

.tabs {
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
  display: flex;
  gap: 2px;
  overflow-x: auto;
  padding: 0 44px;
}

.tab {
  border-bottom: 2px solid transparent;
  color: var(--ink-3);
  margin-bottom: -1px;
  padding: 14px 16px;
  white-space: nowrap;
}

.tab:hover { color: var(--ink-2); }
.tab.is-active {
  border-bottom-color: var(--accent);
  color: var(--ink);
}

.body {
  flex: 1;
  overflow-y: auto;
  padding: 36px 44px 80px;
}

.body.split {
  display: grid;
  gap: 36px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.preview-toolbar {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin: 0 auto 14px;
  max-width: 720px;
}

.body.split .preview-toolbar { max-width: none; }

.pager {
  align-items: center;
  display: flex;
  gap: 10px;
}

.pager button {
  border: 1px solid var(--rule);
  border-radius: 4px;
  color: var(--ink-2);
  height: 28px;
  width: 28px;
}

.preview {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 3px;
  box-shadow: 0 1px 0 var(--rule-2), 0 20px 40px -28px rgba(35, 45, 65, 0.22);
  margin: 0 auto;
  max-width: 720px;
  min-height: 720px;
  overflow: hidden;
  padding: 48px 52px;
  position: relative;
}

.body.split .preview {
  max-width: none;
  min-height: 0;
  padding: 36px;
}

.preview-grid {
  background-image: repeating-linear-gradient(to bottom, transparent 0 31px, color-mix(in oklch, var(--ink-3) 12%, transparent) 31px 32px);
  inset: 0;
  opacity: 0.7;
  pointer-events: none;
  position: absolute;
}

.page-image {
  display: block;
  height: auto;
  margin: 0 auto;
  max-height: 760px;
  max-width: 100%;
  object-fit: contain;
  position: relative;
  z-index: 1;
}

.placeholder-sheet {
  min-height: 540px;
  position: relative;
  z-index: 1;
}

.scribble {
  align-items: center;
  display: flex;
  height: 28px;
  margin: 4px 0;
  position: relative;
}

.scribble::before {
  background: repeating-linear-gradient(90deg, color-mix(in oklch, var(--ink) 80%, transparent) 0 var(--dash, 18px), transparent var(--dash, 18px) calc(var(--dash, 18px) + var(--gap, 6px)));
  border-radius: 2px;
  content: "";
  display: block;
  height: 2.5px;
  opacity: 0.86;
  width: var(--w, 70%);
}

.scribble.heading::before {
  height: 4px;
  opacity: 0.92;
}

.scribble.thin::before {
  height: 2px;
  opacity: 0.72;
}

.sheet-gap {
  height: 18px;
}

.placeholder-note {
  bottom: 34px;
  color: var(--ink-3);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  position: absolute;
}

.page-num {
  bottom: 22px;
  left: 0;
  position: absolute;
  right: 0;
  text-align: center;
}

.pdf-frame {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 4px;
  height: min(78vh, 920px);
  width: 100%;
}

.rendered {
  color: var(--ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 1.65;
  margin: 0 auto;
  max-width: 680px;
}

.body.split .rendered {
  font-size: 16px;
  max-width: none;
}

body[data-serif="false"] .rendered {
  font-family: var(--sans);
  font-size: 15.5px;
}

.rendered h1,
.rendered h2,
.rendered h3 {
  color: var(--ink);
  font-family: var(--serif);
  font-weight: 500;
  letter-spacing: 0;
}

.rendered h1 { font-size: 30px; margin: 0 0 6px; }
.rendered h2 { font-size: 22px; margin: 36px 0 10px; }
.rendered h3 { color: var(--ink-2); font-size: 17px; font-style: italic; margin: 26px 0 8px; }
.rendered p { margin: 0 0 16px; }
.rendered ul,
.rendered ol { margin: 0 0 18px; padding-left: 22px; }
.rendered li { margin: 4px 0; }
.rendered li::marker { color: var(--ink-3); }
.rendered blockquote {
  border-left: 2px solid var(--accent);
  color: var(--ink-2);
  font-style: italic;
  margin: 20px 0;
  padding: 2px 0 2px 20px;
}
.rendered code {
  background: var(--bg-2);
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 0.86em;
  padding: 1px 5px;
}
.rendered hr { border: 0; border-top: 1px solid var(--rule); margin: 28px 0; }
.rendered table {
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 14px;
  margin: 14px 0 20px;
}
.rendered th,
.rendered td {
  border-bottom: 1px solid var(--rule);
  padding: 8px 14px 8px 0;
  text-align: left;
}
.rendered th {
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.source {
  background: var(--bg-2);
  border: 1px solid var(--rule);
  border-radius: 4px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.7;
  margin: 0 auto;
  max-width: 820px;
  overflow: auto;
  padding: 24px 28px;
  white-space: pre-wrap;
  word-break: break-word;
}

.body.split .source {
  font-size: 12.5px;
  max-width: none;
}

.file-table-wrap {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 4px;
  overflow-x: auto;
}

.file-table {
  border-collapse: collapse;
  min-width: 780px;
  width: 100%;
}

.file-table th,
.file-table td {
  border-bottom: 1px solid var(--rule);
  padding: 10px 14px;
  text-align: left;
  vertical-align: top;
}

.file-table th {
  color: var(--ink-3);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.file-table td:first-child {
  overflow-wrap: anywhere;
}

.state-card {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 4px;
  margin: 80px auto;
  max-width: 520px;
  padding: 48px 32px;
  text-align: center;
}

.state-card h3 {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: 0;
  margin: 0 0 8px;
}

.state-card p {
  color: var(--ink-2);
  font-family: var(--serif);
  font-size: 16px;
  margin: 0 0 24px;
}

.progress {
  background: var(--rule);
  height: 2px;
  margin: 0 auto;
  max-width: 300px;
  overflow: hidden;
  position: relative;
}

.progress-fill {
  animation: progress-run 1.8s ease-in-out infinite;
  background: var(--accent);
  bottom: 0;
  left: 0;
  position: absolute;
  top: 0;
  width: 48%;
}

@keyframes progress-run {
  0% { transform: translateX(-90%); }
  50% { transform: translateX(60%); }
  100% { transform: translateX(220%); }
}

.progress-label {
  color: var(--ink-3);
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  margin-top: 14px;
  text-transform: uppercase;
}

.empty {
  color: var(--ink-3);
  display: grid;
  font-family: var(--serif);
  font-size: 18px;
  font-style: italic;
  height: 100%;
  place-items: center;
}

.toast {
  background: var(--ink);
  border-radius: 4px;
  bottom: 24px;
  box-shadow: 0 12px 30px -12px rgba(0, 0, 0, 0.35);
  color: var(--bg);
  left: 50%;
  padding: 10px 16px;
  position: fixed;
  transform: translateX(-50%);
  z-index: 40;
}

.toast[hidden] {
  display: none;
}

@media (max-width: 920px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(320px, 42vh) 1fr;
  }

  .left {
    border-bottom: 1px solid var(--rule);
    border-right: 0;
    min-height: 0;
  }

  .body.split {
    display: block;
  }

  .body.split > * + * {
    margin-top: 32px;
  }

  .right-head,
  .tabs,
  .body {
    padding-left: 22px;
    padding-right: 22px;
  }
}

@media (max-width: 560px) {
  .brand,
  .device,
  .list-head {
    padding-left: 18px;
    padding-right: 18px;
  }

  .mock-bar {
    grid-template-columns: 1fr;
  }

  .right-head {
    align-items: stretch;
    flex-direction: column;
  }

  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  .action {
    justify-content: center;
  }

  .preview {
    min-height: 520px;
    padding: 28px 24px;
  }
}
