:root {
  --bg-start: #fff9ef;
  --bg-end: #edf4f7;
  --panel: rgba(255, 255, 255, 0.86);
  --line: #cad6dc;
  --text-main: #16313c;
  --text-dim: #48626e;
  --accent: #11606d;
  --accent-strong: #0a4a54;
  --ok: #29795f;
  --warn: #b66628;
  --error: #a62929;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", sans-serif;
  color: var(--text-main);
  background: linear-gradient(140deg, var(--bg-start), var(--bg-end));
  min-height: 100vh;
}

.backdrop {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 10% 10%, rgba(16, 96, 109, 0.1), transparent 35%),
    radial-gradient(circle at 88% 30%, rgba(23, 83, 98, 0.09), transparent 40%);
}

.shell {
  width: min(1160px, 92vw);
  margin: 2rem auto 3rem;
  position: relative;
  z-index: 1;
}

.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 16px;
  backdrop-filter: blur(4px);
  box-shadow: 0 12px 30px rgba(22, 49, 60, 0.08);
}

.upload-panel {
  max-width: 760px;
  margin: 3rem auto 0;
  padding: 2rem;
}

.panel-header h1,
.results-topbar h1 {
  margin: 0.35rem 0 0;
  font-family: "Space Grotesk", sans-serif;
  font-size: clamp(1.8rem, 2.4vw, 2.5rem);
  line-height: 1.08;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.11em;
  color: var(--accent-strong);
  font-weight: 600;
}

.lede {
  margin: 0.65rem 0 0;
  color: var(--text-dim);
}

.upload-form {
  margin-top: 1.5rem;
  display: grid;
  gap: 1rem;
}

.status-panel {
  margin-top: 1rem;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.75);
  border-radius: 12px;
  padding: 0.75rem;
}

.progress-wrap {
  margin-top: 0.5rem;
  height: 10px;
  border-radius: 999px;
  background: #d7e4ea;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  transition: width 240ms ease;
}

.history-panel h2 {
  margin: 0.35rem 0 0;
  font-family: "Space Grotesk", sans-serif;
}

.history-list {
  margin-top: 0.9rem;
  display: grid;
  gap: 0.55rem;
}

.history-item {
  display: grid;
  gap: 0.2rem;
  text-decoration: none;
  color: var(--text-main);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
}

.history-item span {
  color: var(--text-dim);
  font-size: 0.87rem;
}

.range-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(2, minmax(140px, 1fr));
}

label {
  display: grid;
  gap: 0.35rem;
}

.label-title {
  font-size: 0.87rem;
  color: var(--text-dim);
}

input[type="file"],
input[type="number"],
input[type="search"] {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.72rem 0.8rem;
  font: inherit;
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.94);
}

input:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(17, 96, 109, 0.18);
}

.btn-primary,
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 0.65rem 1.1rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  width: fit-content;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #ffffff;
}

.btn-secondary {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.9);
  color: var(--text-main);
}

.notice {
  border-radius: 10px;
  padding: 0.62rem 0.8rem;
  font-size: 0.92rem;
  margin-top: 0.85rem;
}

.notice-error {
  border: 1px solid rgba(166, 41, 41, 0.4);
  background: rgba(166, 41, 41, 0.1);
  color: var(--error);
}

.notice-info {
  border: 1px solid rgba(182, 102, 40, 0.35);
  background: rgba(182, 102, 40, 0.08);
  color: var(--warn);
}

.hint {
  margin: 0;
  font-size: 0.88rem;
}

.subtle {
  color: var(--text-dim);
}

.results-shell {
  display: grid;
  gap: 1rem;
}

.results-topbar {
  padding: 1.2rem 1.4rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
}

.topbar-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.results-grid {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 1rem;
  min-height: 60vh;
}

.search-panel,
.pages-panel {
  padding: 1rem;
}

.search-hits {
  margin-top: 0.85rem;
  display: grid;
  gap: 0.5rem;
  max-height: 62vh;
  overflow-y: auto;
}

.search-hit {
  text-align: left;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.95);
  border-radius: 10px;
  padding: 0.58rem;
  cursor: pointer;
}

.search-hit-page {
  font-size: 0.72rem;
  color: var(--accent-strong);
  font-weight: 600;
}

.search-hit-snippet {
  display: block;
  margin-top: 0.2rem;
  color: var(--text-main);
  font-size: 0.85rem;
}

.pages-panel {
  max-height: 72vh;
  overflow-y: auto;
  display: block;
}

.page-card {
  border: 1px solid var(--line);
  background: #ffffff;
  border-radius: 12px;
  overflow: visible;
  margin-bottom: 0.8rem;
}

.page-card-header {
  position: sticky;
  top: 0;
  z-index: 1;
  font-size: 0.84rem;
  font-weight: 600;
  padding: 0.48rem 0.72rem;
  border-bottom: 1px solid var(--line);
  background: #eef6f9;
}

.ocr-page-text {
  margin: 0;
  padding: 0.82rem;
  display: block;
  min-height: 3.5rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  unicode-bidi: plaintext;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.86rem;
  line-height: 1.48;
  color: #1b3641;
  overflow: visible;
}

/* Backward-compat fallback if an older cached template still renders textarea bodies. */
textarea.ocr-page-text {
  width: 100%;
  min-height: 12rem !important;
  height: auto !important;
  overflow: auto !important;
  resize: vertical;
  border: none;
  background: #ffffff;
}

mark {
  background: rgba(255, 215, 102, 0.75);
  border-radius: 3px;
}

.page-card.flash {
  outline: 2px solid rgba(17, 96, 109, 0.55);
  transition: outline 350ms ease;
}

@media (max-width: 940px) {
  .results-grid {
    grid-template-columns: 1fr;
  }

  .pages-panel {
    max-height: none;
  }
}

@media (max-width: 640px) {
  .upload-panel,
  .results-topbar,
  .search-panel,
  .pages-panel {
    padding: 0.95rem;
  }

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