:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #5b6573;
  --border: #d6dbe1;
  --accent: #2456a6;
  --accent-text: #ffffff;
  --focus: #f0b429;
  --info-bg: #e8f0fc;
  --warn-bg: #fff4d6;
  --warn-border: #d9a400;
  --error-bg: #fde8e8;
  --error-border: #c62828;
  --hit-hover: #eef3fb;
  --radius: 8px;
  --header-h: 3.25rem;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1b2027;
    --text: #e6e9ed;
    --muted: #9aa4b1;
    --border: #2f3742;
    --accent: #6ea0f0;
    --accent-text: #0c1320;
    --info-bg: #17263d;
    --warn-bg: #3a2f10;
    --error-bg: #3d1a1a;
    --hit-hover: #222a35;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); line-height: 1.5; font-size: 16px; }
a { color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.92em; overflow-wrap: anywhere; }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.5rem; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 0.5rem 1rem; z-index: 10; }
.skip:focus { left: 0.5rem; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.25rem; max-width: 72rem; margin: 0 auto; padding: 0.6rem 1rem; min-height: var(--header-h); }
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
nav { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; }
nav a { text-decoration: none; }
nav a:hover { text-decoration: underline; }
.who { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; }
.user { font-weight: 600; }
form.inline { display: inline; margin: 0; }

/* layout */
.page { max-width: 72rem; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; }
.narrow { max-width: 32rem; margin: 1rem auto; }
.hero { margin-bottom: 1.5rem; }
.cards { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); }
.link-card { display: block; color: inherit; text-decoration: none; transition: border-color 0.15s; }
.link-card:hover { border-color: var(--accent); }
.link-card h2 { color: var(--accent); }
.link-card p { margin: 0 0 0.5rem; }
.url { color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }
.copyrow { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.copyrow code { background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 0.25rem 0.5rem; }

/* forms */
.stack { display: flex; flex-direction: column; gap: 0.4rem; }
.stack button { margin-top: 0.75rem; align-self: flex-start; }
input[type=text], input[type=password], input[type=search], input:not([type]), input[type=file] {
  font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 0.55rem 0.7rem; width: 100%;
}
button { font: inherit; cursor: pointer; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 0.5rem 1rem; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.small { padding: 0.2rem 0.6rem; font-size: 0.85rem; }
button.danger { color: var(--error-border); border-color: var(--error-border); background: transparent; }
button.link { border: none; background: none; color: var(--accent); padding: 0; text-decoration: underline; }
button[disabled] { opacity: 0.6; cursor: progress; }
.searchbox { display: flex; gap: 0.5rem; margin: 0 0 1rem; }
.searchbox input { flex: 1; min-width: 0; }

.alert { border-radius: 6px; padding: 0.6rem 0.8rem; border-left: 4px solid var(--accent); background: var(--info-bg); }
.alert.warn { background: var(--warn-bg); border-left-color: var(--warn-border); }
.alert.error { background: var(--error-bg); border-left-color: var(--error-border); }
.alert.ok { border-left-color: #2e7d32; }

/* library */
.group { margin: 1.5rem 0; }
.doclist { list-style: none; padding: 0; margin: 0; }
.doclist li { padding: 0.5rem 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

/* uploads table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.status { font-weight: 600; }
.status-ready { color: #2e7d32; }
.status-error { color: var(--error-border); }

/* search split view + reader */
body.full { display: flex; flex-direction: column; min-height: 100vh; }
.split { flex: 1; display: grid; grid-template-columns: minmax(18rem, 26rem) 1fr; min-height: 0; height: calc(100vh - var(--header-h) - 1px); }
.results { overflow-y: auto; padding: 1rem; border-right: 1px solid var(--border); background: var(--surface); }
.pane { min-height: 0; }
.viewer { width: 100%; height: 100%; border: 0; display: block; background: var(--bg); }
.reader { flex: 1; height: calc(100vh - var(--header-h) - 1px); display: flex; flex-direction: column; }
/* The parent's height comes from flex, which Chrome does not treat as definite for height: 100%; flex the iframe instead. */
.reader > .viewer { flex: 1; height: auto; min-height: 0; }
.hits { list-style: none; padding: 0; margin: 0; }
.hit { display: block; padding: 0.65rem 0.6rem; border-radius: 6px; color: inherit; text-decoration: none; border: 1px solid transparent; }
.hit:hover { background: var(--hit-hover); }
.hit.active { border-color: var(--accent); background: var(--hit-hover); }
.hit-doc { display: block; font-size: 0.85rem; }
.hit-title { display: block; font-weight: 600; color: var(--accent); }
.hit-snippet { display: block; font-size: 0.9rem; overflow-wrap: anywhere; }

@media (max-width: 760px) {
  .split { display: flex; flex-direction: column; height: auto; }
  .results { border-right: none; border-bottom: 1px solid var(--border); max-height: none; }
  .pane { height: 80vh; }
  .reader { height: calc(100vh - 6rem); }
  .who { margin-left: 0; }
  h1 { font-size: 1.35rem; }
}
