:root {
  --bg: #f3f5f7;
  --panel: #ffffff;
  --panel-soft: #f7f9fc;
  --ink: #11243e;
  --muted: #5b6f88;
  --line: #dbe3ee;
  --blue-900: #062d63;
  --blue-800: #0a3d87;
  --blue-700: #1356b8;
  --blue-100: #eaf2ff;
  --orange-500: #ff6500;
  --orange-400: #ff7a1c;
  --orange-100: #fff0e5;
  --shadow: 0 18px 44px rgba(9, 43, 90, 0.12);
  --radius-xl: 22px;
  --radius-lg: 16px;
  --top-offset: 138px;
  --sidebar-open-width: 372px;
  --sidebar-closed-width: 54px;
  --sidebar-gap: 18px;
  --shell-side-margin: 18px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(19, 86, 184, 0.16), transparent 24%),
    linear-gradient(180deg, #f5f7fb 0%, #eef2f8 100%);
}

.site-header {
  position: fixed;
  top: 0;
  left: var(--sidebar-open-width);
  right: 0;
  z-index: 60;
  background: linear-gradient(180deg, var(--blue-900), var(--blue-800));
  box-shadow: 0 14px 32px rgba(5, 32, 74, 0.22);
  transition: none;
}

body.sidebar-collapsed .site-header {
  left: var(--sidebar-closed-width);
}

.site-header-inner {
  width: auto;
  margin: 0;
  display: grid;
  grid-template-columns: minmax(300px, 460px) minmax(0, 1fr);
  gap: 20px;
  align-items: center;
  padding: 18px var(--shell-side-margin) 14px;
}

.brand-side {
  color: white;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 0.18em;
  font-weight: 800;
  text-transform: uppercase;
  color: #9fc2ff;
}

.brand-side h1,
.results-head h2,
.sidebar-head h3 {
  margin: 0;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}

.brand-side h1 {
  font-size: clamp(24px, 2.3vw, 34px);
  line-height: 1.06;
}

.hero-copy {
  margin: 10px 0 0;
  max-width: 48ch;
  color: #dbe9ff;
  line-height: 1.45;
}

.header-search-card {
  padding: 14px;
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.1));
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.top-controls-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.top-controls-row > * {
  min-width: 0;
}

.top-upload-bar {
  flex: 0 0 auto;
  margin-top: 0;
}

.top-actions {
  display: flex;
  gap: 10px;
}

.search-row {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 1fr 150px;
  gap: 10px;
}

.search-row input,
.search-row button,
.translate-button {
  border-radius: 14px;
  border: 0;
  font-size: 16px;
}

.search-row input {
  padding: 15px 18px;
  color: var(--ink);
  background: white;
}

.search-row button,
.translate-button,
#translate-current-button {
  font-weight: 800;
  cursor: pointer;
}

.search-row button {
  background: linear-gradient(180deg, var(--orange-500), #e25300);
  color: white;
}

.stats {
  margin-top: 10px;
  color: #d7e6ff;
  font-size: 14px;
}

.shell {
  width: auto;
  margin: 0;
  padding: calc(var(--top-offset) + 5vh) var(--shell-side-margin) 56px
    calc(var(--sidebar-open-width) + var(--shell-side-margin));
  transition: none;
}

body.sidebar-collapsed .shell {
  padding-left: calc(var(--sidebar-closed-width) + var(--shell-side-margin));
}

.results-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin: 0 2px 14px;
}

.results-head h2 {
  font-size: 28px;
  color: var(--blue-900);
}

.results-head p,
.stats,
.chunk,
.occurrence-snippet,
.image-caption,
.reader-topbar span {
  color: var(--muted);
}

.reader-shell {
  position: relative;
  display: block;
  padding-left: 0;
  min-height: calc(100vh - var(--top-offset) - 24px);
}

.reader-shell.is-expanded {
  padding-left: 0;
}

.panel,
.card,
.image-card,
.empty,
.occurrence-item {
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
}

.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-open-width);
  max-height: none;
  overflow: hidden;
  padding-top: 10px;
  background: linear-gradient(180deg, #ffffff, #f7fbff);
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  border-left: 0;
  z-index: 25;
  transition: none;
}

.sidebar-toggle {
  display: block;
  width: 42px;
  height: 42px;
  margin: 0 0 14px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(180deg, var(--blue-700), var(--blue-800));
  color: white;
  font-size: 0;
  font-weight: 700;
  cursor: pointer;
  position: relative;
}

.sidebar-toggle::before,
.sidebar-toggle::after {
  content: "";
  position: absolute;
  left: 11px;
  width: 20px;
  height: 2px;
  background: white;
  border-radius: 999px;
  box-shadow: 0 6px 0 white, 0 -6px 0 white;
}

.sidebar-block + .sidebar-block {
  margin-top: 16px;
}

.sidebar-head,
.reader-topbar,
.card-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.sidebar-head {
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.sidebar-head h3 {
  color: var(--blue-900);
}

.open-upload-button {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f3f5f7;
  color: var(--blue-900);
  font-weight: 700;
  cursor: pointer;
}

.open-documents-page-button {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f3f5f7;
  color: var(--blue-900);
  font-weight: 700;
  cursor: pointer;
}

.open-upload-button:hover,
.open-documents-page-button:hover {
  background: #eaf1fb;
}

.upload-form {
  display: grid;
  gap: 10px;
}

.upload-form-modal {
  margin-top: 4px;
}

.upload-box {
  display: block;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px dashed rgba(159, 194, 255, 0.55);
  background: rgba(255, 255, 255, 0.94);
  cursor: pointer;
}

.upload-title {
  display: block;
  font-weight: 800;
  color: var(--blue-900);
}

.upload-subtitle,
.upload-status,
.document-meta {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.upload-button {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--blue-900);
  font-weight: 700;
  cursor: pointer;
}

.document-list {
  display: grid;
  gap: 10px;
}

.document-item {
  width: 100%;
  padding: 14px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, #fff, #f7fbff);
  cursor: pointer;
}

.document-item.is-active,
.document-item:hover {
  border-color: rgba(19, 86, 184, 0.34);
  box-shadow: 0 10px 18px rgba(19, 86, 184, 0.12);
}

.document-name {
  display: block;
  font-weight: 800;
  color: var(--blue-900);
  line-height: 1.35;
}

.documents-dialog {
  width: min(900px, calc(100vw - 24px));
  border: 0;
  padding: 0;
  background: transparent;
}

.documents-dialog::backdrop {
  background: rgba(3, 18, 42, 0.46);
}

.documents-dialog-card {
  padding: 18px;
  border-radius: 20px;
  background: white;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.documents-dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.documents-dialog-head strong {
  font-size: 20px;
  color: var(--blue-900);
}

.documents-dialog-head button {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f3f5f7;
  color: var(--blue-900);
  font-weight: 700;
  cursor: pointer;
}

.documents-page-list {
  display: grid;
  gap: 12px;
  max-height: 70vh;
  overflow: auto;
}

.occurrence-list {
  display: grid;
  gap: 10px;
  max-height: calc(100vh - var(--top-offset) - 120px);
  overflow: auto;
  padding-right: 4px;
}

.occurrence-item {
  width: 100%;
  text-align: left;
  padding: 14px;
  background: linear-gradient(180deg, #fff, #f8fbff);
}

.occurrence-item:hover,
.occurrence-item.is-active {
  border-color: rgba(255, 101, 0, 0.45);
  background: linear-gradient(180deg, #fff8f2, #fff1e6);
  box-shadow: 0 12px 24px rgba(255, 101, 0, 0.12);
}

.occurrence-section {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 800;
  color: var(--orange-500);
}

.occurrence-snippet {
  display: block;
  font-size: 14px;
  line-height: 1.46;
}

.reader {
  min-height: 70vh;
  width: 100%;
  background: linear-gradient(180deg, #ffffff, #fbfdff);
}

.reader-topbar {
  position: sticky;
  top: calc(var(--top-offset) - 14px);
  z-index: 4;
  margin: -2px -2px 18px;
  padding: 8px 8px 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98) 80%, rgba(255, 255, 255, 0));
}

.reader-topbar strong {
  font-size: 18px;
  color: var(--blue-900);
}

.results {
  display: grid;
  gap: 14px;
}

.card,
.empty,
.image-card,
.document-break {
  padding: 18px;
}

.card {
  scroll-margin-top: calc(var(--top-offset) + 28px);
}

.card-top {
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.card-tools {
  display: flex;
  gap: 8px;
  align-items: center;
}

.section {
  font-weight: 900;
  color: var(--blue-900);
}

.translate-button {
  padding: 9px 12px;
  color: white;
  background: linear-gradient(180deg, var(--blue-700), var(--blue-800));
}

.snippet,
.translated-snippet {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.7;
  font-size: 15px;
}

.translated-snippet {
  margin-top: 14px;
  padding: 14px;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, var(--orange-100), #fff7f0);
  border: 1px solid #ffd3b6;
}

.image-card {
  background: white;
}

.doc-image {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 14px;
  background: var(--panel-soft);
}

.image-caption {
  margin-top: 10px;
  line-height: 1.45;
  font-size: 13px;
}

.document-break {
  border: 1px solid rgba(19, 86, 184, 0.18);
  border-radius: var(--radius-xl);
  background: linear-gradient(180deg, #f4f8ff, #ffffff);
  box-shadow: var(--shadow);
}

.document-break-title {
  display: block;
  font-size: 24px;
  color: var(--blue-900);
}

mark {
  background: #ffe18f;
  padding: 0 3px;
  border-radius: 4px;
}

@media (max-width: 1180px) {
  :root {
    --top-offset: 180px;
  }

  .site-header-inner {
    grid-template-columns: 1fr;
  }

  .top-controls-row {
    flex-wrap: wrap;
  }

  .search-row {
    flex: 1 1 100%;
  }

  .top-upload-bar {
    width: 100%;
  }
}

@media (max-width: 980px) {
  :root {
    --top-offset: 194px;
  }

  .site-header {
    left: 0;
  }

  .reader-shell {
    padding-left: 0;
    min-height: auto;
  }

  .sidebar {
    position: static;
    width: 100%;
    padding-top: 14px;
    max-height: none;
    border-radius: var(--radius-xl);
    border-left: 1px solid var(--line);
  }

  .shell,
  body.sidebar-collapsed .shell {
    padding-left: var(--shell-side-margin);
  }

  .occurrence-list {
    max-height: 250px;
  }

  .document-list {
    max-height: 260px;
    overflow: auto;
  }

  .reader-topbar {
    top: calc(var(--top-offset) - 10px);
  }
}

@media (max-width: 720px) {
  :root {
    --top-offset: 206px;
  }

  .site-header-inner {
    padding: 14px 12px 12px;
    gap: 14px;
  }

  .brand-side h1 {
    font-size: 24px;
  }

  .header-search-card,
  .panel,
  .sidebar {
    padding: 14px;
    border-radius: 18px;
  }

  .top-controls-row,
  .top-actions {
    width: 100%;
  }

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

  .search-row {
    grid-template-columns: 1fr 140px;
  }

  .search-row input {
    grid-column: 1 / -1;
  }

  .results-head,
  .reader-topbar,
  .sidebar-head,
  .card-top {
    display: block;
  }

  .results-head p,
  .reader-topbar span {
    margin-top: 8px;
  }

  .card-tools {
    margin-top: 8px;
    justify-content: space-between;
  }

  .snippet,
  .translated-snippet {
    font-size: 14px;
  }
}

@media (min-width: 981px) {
  .sidebar.is-collapsed {
    width: var(--sidebar-closed-width);
    padding: 14px 6px;
  }

  .sidebar.is-collapsed .sidebar-block {
    opacity: 0;
    pointer-events: none;
  }
}
