:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --text: #18202f;
  --muted: #657083;
  --line: #dce2ea;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --brand-soft: #e7f3f1;
  --accent: #c2410c;
  --shadow: 0 18px 50px rgba(24, 32, 47, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.modal-open {
  overflow: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 68px;
  padding: 0 32px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand {
  color: var(--brand-dark);
  font-size: 1.15rem;
  font-weight: 800;
}

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

.nav a {
  min-width: 62px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 650;
  text-align: center;
}

.nav a:hover {
  background: #edf7f5;
  color: var(--brand-dark);
}

main {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 34px 0 56px;
}

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

.workspace[data-page="search"],
.workspace[data-page="browse"] {
  grid-template-columns: minmax(0, 1fr);
}

.panel,
.filters-panel,
.results-shell {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.intro-panel {
  padding: 42px;
  background:
    linear-gradient(120deg, rgba(15, 118, 110, 0.12), rgba(194, 65, 12, 0.1)),
    var(--surface);
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 24px;
  font-size: clamp(2rem, 4vw, 3.8rem);
  line-height: 1.03;
}

h2 {
  margin-bottom: 0;
  font-size: 1.15rem;
}

.searchbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
}

input,
select,
button {
  min-height: 44px;
  border-radius: 8px;
  font: inherit;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 0 14px;
}

button,
.download-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 750;
  cursor: pointer;
}

button:hover,
.download-button:hover {
  background: var(--brand-dark);
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.ghost-button {
  min-height: 36px;
  border: 1px solid #b8c5d3;
  background: #fff;
  color: #0f1f35;
  font-weight: 750;
}

.ghost-button:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand-dark);
}

.filters-panel {
  position: sticky;
  top: 92px;
  display: grid;
  gap: 16px;
  max-height: calc(100vh - 116px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px;
  scrollbar-width: thin;
  scrollbar-color: #9fb2c3 transparent;
}

.filters-panel::-webkit-scrollbar {
  width: 10px;
}

.filters-panel::-webkit-scrollbar-track {
  background: transparent;
}

.filters-panel::-webkit-scrollbar-thumb {
  background: #9fb2c3;
  border: 3px solid #fff;
  border-radius: 999px;
}

.filters-panel::-webkit-scrollbar-thumb:hover {
  background: #74889a;
}

.filters-panel label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--line);
}

.section-head span {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
  white-space: nowrap;
}

.results-shell {
  overflow: hidden;
}

.filter-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.filter-toggle {
  min-width: 132px;
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand-dark);
}

.result-status {
  min-height: 39px;
  padding: 11px 22px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 650;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 54px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
}

.filter-chips[hidden] {
  display: none;
}

.filter-chip {
  gap: 8px;
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid #bee1dc;
  background: var(--brand-soft);
  color: var(--brand-dark);
}

.filter-chip:hover {
  background: #dff0ed;
  color: var(--brand-dark);
}

.filter-chip strong {
  font-size: 1rem;
  line-height: 1;
}

.filter-drawer[hidden] {
  display: none;
}

.filter-drawer {
  position: fixed;
  inset: 0;
  z-index: 110;
}

.filter-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(24, 32, 47, 0.55);
}

.filter-dialog {
  position: absolute;
  inset: 0 0 0 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(520px, 100%);
  background: var(--surface);
  box-shadow: -24px 0 70px rgba(0, 0, 0, 0.22);
}

.filter-dialog-head,
.filter-dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.filter-dialog-actions {
  border-top: 1px solid var(--line);
  border-bottom: 0;
  align-items: stretch;
}

.filter-dialog-actions .download-button,
.filter-dialog-actions .ghost-button {
  flex: 1;
}

.checkbox-groups {
  overflow-y: auto;
  padding: 8px 22px 22px;
}

.checkbox-group {
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.checkbox-group h3 {
  margin-bottom: 12px;
  font-size: 1rem;
  color: var(--brand-dark);
}

.checkbox-options {
  display: grid;
  gap: 12px;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 8px;
}

.checkbox-option {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  color: var(--text);
  font-weight: 650;
  line-height: 1.35;
}

.checkbox-option input {
  width: 18px;
  min-height: 18px;
  margin: 2px 0 0;
}

.paper-list {
  display: grid;
}

.paper-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  min-height: 88px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}

.paper-row:last-child {
  border-bottom: 0;
}

.paper-row h3 {
  margin-bottom: 6px;
  overflow-wrap: anywhere;
  font-size: 1rem;
}

.paper-row p {
  margin-bottom: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.paper-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 300px;
}

.paper-actions .ghost-button,
.paper-actions .download-button {
  min-width: 128px;
}

.empty-state {
  display: grid;
  gap: 6px;
  padding: 34px 22px;
  color: var(--muted);
}

.empty-state strong {
  color: var(--text);
}

.results-actions {
  display: flex;
  justify-content: center;
  min-height: 72px;
  padding: 16px 22px;
  border-top: 1px solid var(--line);
}

.results-actions:has([hidden]) {
  display: none;
}

.preview-modal[hidden] {
  display: none;
}

.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
}

.preview-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(24, 32, 47, 0.62);
}

.preview-dialog {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1120px, 100%);
  height: min(840px, calc(100vh - 48px));
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.28);
}

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.preview-head h2 {
  margin: 0;
  overflow-wrap: anywhere;
}

.preview-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 10px;
}

.preview-actions .ghost-button,
.preview-actions .download-button {
  min-width: 104px;
}

#preview-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #f2f5f8;
}

#preview-frame[hidden] {
  display: none;
}

.preview-status {
  display: grid;
  place-items: center;
  min-height: 180px;
  padding: 24px;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.preview-status[hidden] {
  display: none;
}

@media (max-width: 760px) {
  .topbar {
    padding: 0 16px;
  }

  main {
    width: min(100% - 20px, 1180px);
    padding-top: 18px;
  }

  .workspace,
  .workspace[data-page="search"],
  .workspace[data-page="browse"] {
    grid-template-columns: 1fr;
  }

  .filters-panel {
    position: static;
    max-height: none;
    overflow-y: visible;
  }

  .intro-panel {
    padding: 26px 18px;
  }

  .searchbar,
  .paper-row {
    grid-template-columns: 1fr;
  }

  .paper-actions {
    display: grid;
    grid-template-columns: 1fr;
    justify-content: stretch;
    min-width: 0;
  }

  .download-button,
  .paper-actions button {
    width: 100%;
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .preview-modal {
    padding: 10px;
  }

  .preview-dialog {
    height: calc(100vh - 20px);
  }

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

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