/* Financial Library search UI — restrained, macOS-friendly, fully local. */

:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #d8dbe0;
  --border-strong: #c3c7cf;
  --text: #1d2129;
  --muted: #6a707c;
  --accent: #145da0;
  --accent-dark: #0f4a80;
  --accent-soft: #e3edfa;
  --danger: #b3261e;
  --warn-bg: #fdf3e0;
  --warn-border: #f0dfc0;
  --warn-text: #8a5a00;
  --badge-bg: #eceef2;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

.wrap {
  max-width: none;
  margin: 0;
  padding: 0 20px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Sticky header */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 10px 0 10px;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.site-header h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
}

.lang-box {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.lang-box select {
  font: inherit;
  padding: 4px 6px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}

.library-totals {
  margin: 4px 0 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

.privacy-note {
  margin: 0;
  padding: 6px 10px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius);
  color: #6b4e00;
  font-size: 0.8rem;
}

/* Filter form */

main.wrap {
  height: calc(100vh - var(--header-height));
  padding: 12px 20px 0;
  overflow: hidden;
}

#search-form {
  flex: 0 0 auto;
  max-height: 38%;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px 12px;
  margin: 0 0 12px;
}

.form-head {
  margin-bottom: 10px;
}

.filters-toggle {
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  text-align: left;
}

.toggle-arrow {
  font-size: 0.75em;
  color: var(--muted);
  transition: transform 0.15s ease;
}

#search-form.collapsed {
  max-height: none;
  overflow-y: visible;
}

#search-form.collapsed .form-head {
  margin-bottom: 0;
}

#search-form.collapsed .toggle-arrow {
  transform: rotate(-90deg);
}

#search-form.collapsed #filters-body {
  display: none;
}

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px 14px;
}

.field {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.field-wide {
  grid-column: 1 / -1;
}

.field label {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 3px;
}

.field input,
.field select {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  width: 100%;
}

.field input:focus-visible,
.field select:focus-visible,
.lang-box select:focus-visible,
.btn:focus-visible,
.sort-btn:focus-visible,
.filters-toggle:focus-visible,
a:focus-visible,
tr[data-doc-id]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

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

.btn {
  font: inherit;
  padding: 7px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}

.btn:hover {
  background: #f0f2f5;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-dark);
}

.btn-small {
  padding: 4px 10px;
  font-size: 0.8rem;
  white-space: nowrap;
}

/* Two-pane layout */

:root {
  --header-height: 112px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 11fr) minmax(0, 9fr);
  gap: 14px;
  height: 100%;
  min-height: 0;
}

.content-column {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.results-pane {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.preview-pane {
  /* No height here: a percentage height on a grid item in an auto-sized row
     resolves to auto and disables the default stretch, collapsing the pane
     to its content height. align-self: stretch (the default) does the job. */
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  background: #f8f9fb;
}

.preview-title {
  font-size: 0.82rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.preview-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.preview-actions .btn-small {
  min-width: 30px;
  text-align: center;
}

.preview-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#preview-frame {
  flex: 1;
  min-height: 0;
  width: 100%;
  border: 0;
  background: #fff;
}

.preview-note {
  margin: 0;
  padding: 24px 16px;
  color: var(--muted);
  font-size: 0.88rem;
}

/* Full-page image view served by /imgview: width comes from the <img>
   width attribute (100% by default, more when zoomed), scrolls vertically,
   whole page stays visible like a paper sheet. */

body.imgview {
  height: auto;
  overflow: auto;
  background: #525659;
}

body.imgview img {
  display: block;
  margin: 0 auto;
  background: #fff;
}

/* Results */

.results-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 16px;
  margin-bottom: 8px;
}

.result-count {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 500;
}

.status {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.status-error {
  color: var(--danger);
  font-weight: 500;
}

.status-loading {
  color: var(--accent);
}

.table-scroll {
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

table.results {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

table.results th,
table.results td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

table.results thead th {
  background: #f8f9fb;
  border-bottom: 2px solid var(--border-strong);
  white-space: nowrap;
  font-weight: 600;
  font-size: 0.78rem;
}

table.results tbody tr {
  cursor: pointer;
}

table.results tbody tr:nth-child(even) {
  background: #fafbfc;
}

table.results tbody tr:hover {
  background: #eef4fb;
}

table.results tbody tr.selected {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

th.num,
td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

td.negative {
  color: var(--danger);
}

td.thumbcell {
  width: 64px;
}

.thumb {
  display: block;
  width: 56px;
  max-height: 72px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
}

.thumb-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 40px;
  border: 1px dashed var(--border-strong);
  border-radius: 4px;
  background: #f4f5f7;
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.sort-btn {
  font: inherit;
  font-weight: 600;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  color: inherit;
  text-align: left;
}

th.sorted .sort-btn::after {
  content: " ▼";
  font-size: 0.7em;
  color: var(--accent);
}

th.sorted.asc .sort-btn::after {
  content: " ▲";
}

.th-static {
  font-weight: 600;
}

.sub {
  color: var(--muted);
  font-size: 0.76rem;
}

.filename {
  display: block;
  max-width: 320px;
  overflow-wrap: anywhere;
}

.snippet {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
  max-width: 360px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.badge {
  display: inline-block;
  padding: 1px 7px;
  margin: 0 4px 3px 0;
  border-radius: 999px;
  background: var(--badge-bg);
  color: var(--text);
  font-size: 0.7rem;
  font-weight: 500;
  white-space: nowrap;
}

.badge-review {
  background: var(--warn-bg);
  color: var(--warn-text);
  border: 1px solid var(--warn-border);
}

.badge-dup {
  background: #e8eaf6;
  color: #3f51b5;
}

.empty-state {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 14px;
}

.page-info {
  font-size: 0.88rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.site-footer {
  display: none;
  border-top: 1px solid var(--border);
  padding: 10px 0 20px;
  color: var(--muted);
  font-size: 0.78rem;
}

.noscript {
  padding: 16px 20px;
  color: var(--danger);
}

/* Stack panes on narrower windows */

@media (max-width: 800px) {
  html,
  body {
    height: auto;
  }

  body {
    overflow: auto;
  }

  main.wrap {
    height: auto;
    overflow: visible;
  }

  .workspace {
    display: block;
    height: auto;
  }

  .content-column {
    display: block;
  }

  #search-form {
    max-height: none;
    overflow: visible;
  }

  .results-pane {
    overflow: visible;
  }

  .preview-pane {
    width: 100%;
    height: 72vh;
    margin-bottom: 16px;
  }

  .site-footer {
    display: block;
  }
}

/* Responsive: table becomes stacked cards */

@media (max-width: 920px) {
  table.results thead {
    display: none;
  }

  .table-scroll {
    background: transparent;
    border: 0;
    overflow-x: visible;
  }

  table.results,
  table.results tbody {
    display: block;
    width: 100%;
  }

  table.results tr {
    display: block;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    padding: 8px 12px;
  }

  table.results tbody tr:nth-child(even),
  table.results tbody tr:hover {
    background: var(--panel);
  }

  table.results tbody tr.selected {
    background: var(--accent-soft);
  }

  table.results td {
    display: flex;
    gap: 10px;
    border-bottom: 0;
    padding: 4px 0;
    text-align: left;
  }

  table.results td::before {
    content: attr(data-label);
    flex: 0 0 110px;
    color: var(--muted);
    font-size: 0.73rem;
    padding-top: 2px;
  }

  td.num {
    text-align: left;
  }

  .filename,
  .snippet {
    max-width: none;
  }
}

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

  .actions .btn {
    flex: 1;
  }

  .preview-pane {
    height: 60vh;
  }
}

.archive-heading {
  min-width: 0;
}

.archive-brand {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.header-tools,
.logout-form {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
}

.login-page {
  min-height: 100vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  background: #eef1f4;
  color: #172538;
}

.login-shell {
  width: min(960px, calc(100% - 40px));
  margin: 40px auto 20px;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  overflow: hidden;
  border: 1px solid #d7dde3;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(23, 37, 56, 0.12);
}

.login-brand {
  padding: 58px 52px;
  background: #172f46;
  color: #fff;
}

.brand-mark {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  margin-bottom: 54px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 12px;
  color: #e7c98e;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.login-kicker {
  margin: 0 0 10px;
  color: #b58a43;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.login-brand .login-kicker {
  color: #e7c98e;
}

.login-brand h1 {
  margin: 0 0 20px;
  font-size: clamp(2.2rem, 5vw, 3.4rem);
  line-height: 1.05;
  font-weight: 600;
  letter-spacing: -0.04em;
}

.login-brand > p:not(.login-kicker) {
  max-width: 340px;
  color: #d6e0e8;
  font-size: 1rem;
  line-height: 1.65;
}

.login-features {
  margin: 42px 0 0;
  padding: 24px 0 0;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
  list-style: none;
  color: #d6e0e8;
  font-size: 0.84rem;
  line-height: 2;
}

.login-features li::before {
  content: "—";
  margin-right: 9px;
  color: #e7c98e;
}

.login-card {
  padding: 58px 52px 42px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login-card-heading h2 {
  margin: 0 0 10px;
  color: #172538;
  font-size: 1.75rem;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.login-card-heading > p:last-child,
.login-help {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.login-form {
  display: grid;
  gap: 18px;
  margin-top: 30px;
}

.login-form .field label {
  margin-bottom: 6px;
  color: #344457;
  font-size: 0.8rem;
  font-weight: 600;
}

.login-form .field input {
  padding: 11px 12px;
  border-radius: 7px;
}

.login-submit {
  margin-top: 4px;
  padding: 11px 18px;
}

.login-error {
  margin: 22px 0 -8px;
  padding: 10px 12px;
  border: 1px solid #e8bcbc;
  border-radius: 7px;
  background: #fff2f2;
  color: #9e2424;
  font-size: 0.85rem;
}

.login-help {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  font-size: 0.76rem;
}

.login-footer {
  margin: 0 auto 30px;
  color: #75808c;
  font-size: 0.75rem;
}

@media (max-width: 720px) {
  .login-shell {
    grid-template-columns: 1fr;
    width: min(480px, calc(100% - 28px));
    margin-top: 24px;
  }

  .login-brand {
    padding: 32px;
  }

  .brand-mark {
    margin-bottom: 28px;
  }

  .login-brand h1 {
    font-size: 2.4rem;
  }

  .login-features {
    display: none;
  }

  .login-card {
    padding: 34px 32px;
  }

  .header-tools {
    gap: 7px;
  }

  .lang-box label {
    display: none;
  }
}
