:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --ink: #161d2b;
  --ink-2: #5a6478;
  --ink-3: #8b95a8;
  --rule: #e2e7ef;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --accent-soft: #e8efff;
  --ok-bg: #e6f6ec; --ok-ink: #17603a;
  --warn-bg: #fdf3e0; --warn-ink: #8a5a00;
  --err-bg: #fdecec; --err-ink: #a12a25;
  --danger: #d9534f;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 8px 24px rgba(16,24,40,.05);
  --radius: 12px;
}
[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b23;
  --ink: #e6edf5;
  --ink-2: #a2adbd;
  --ink-3: #737f92;
  --rule: #262d38;
  --accent: #4d84ff;
  --accent-soft: #1b2740;
  --ok-bg: #10301f; --ok-ink: #62d69a;
  --warn-bg: #322512; --warn-ink: #e0aa4a;
  --err-bg: #3a1c1c; --err-ink: #f08a86;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
}
[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.5rem; margin: 0 0 .2rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em;
       background: var(--bg); padding: .1em .35em; border-radius: 5px; border: 1px solid var(--rule); }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* topbar */
.topbar {
  display: flex; align-items: center; gap: 1.25rem;
  padding: .7rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 650; color: var(--ink); font-size: 1.02rem; }
.topbar nav { display: flex; gap: .25rem; }
.topbar nav a {
  padding: .35rem .7rem; border-radius: 8px; color: var(--ink-2); font-weight: 500;
}
.topbar nav a:hover { background: var(--bg); color: var(--ink); }
.topbar nav a.active { background: var(--accent-soft); color: var(--accent); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.who { font-size: .85rem; color: var(--ink-2); display: flex; flex-direction: column; line-height: 1.25; }
.who em { font-style: normal; color: var(--ink-3); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; }
.icon-btn {
  border: 1px solid var(--rule); background: var(--surface); color: var(--ink-2);
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 1rem;
}
.icon-btn:hover { background: var(--bg); }

/* layout */
.wrap { max-width: 1060px; margin: 0 auto; padding: 1.75rem 1.25rem 4rem; }
.center { min-height: 100dvh; display: grid; place-items: center; padding: 1.25rem; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }

.card {
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.25rem;
}

/* login */
.login { width: min(380px, 100%); }
.login h1 { text-align: center; }
.login > p { text-align: center; margin-top: 0; }
label { display: block; margin: .85rem 0; font-size: .85rem; color: var(--ink-2); font-weight: 500; }
input[type=text], input[type=password], input[type=search], input:not([type]), select {
  width: 100%; margin-top: .3rem; padding: .55rem .7rem;
  border: 1px solid var(--rule); border-radius: 9px;
  background: var(--bg); color: var(--ink); font: inherit;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--surface); }
input[type=file] { font: inherit; color: var(--ink-2); max-width: 100%; }

/* buttons */
.btn {
  display: inline-block; padding: .5rem .9rem; border-radius: 9px; border: 1px solid var(--rule);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 500;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn-quiet { color: var(--ink-2); }
.btn-danger { color: var(--danger); border-color: transparent; background: transparent; }
.btn-danger:hover { background: var(--err-bg); }
.btn-sm { padding: .3rem .6rem; font-size: .82rem; }
.btn-block { width: 100%; margin-top: .5rem; }

/* flash + badges */
.flash { padding: .6rem .85rem; border-radius: 9px; margin-bottom: 1rem; font-size: .9rem;
         background: var(--ok-bg); color: var(--ok-ink); }
.flash-error { background: var(--err-bg); color: var(--err-ink); }
.badge { display: inline-block; padding: .1rem .45rem; border-radius: 20px; font-size: .72rem;
         font-weight: 600; background: var(--bg); color: var(--ink-2); border: 1px solid var(--rule);
         text-transform: uppercase; letter-spacing: .03em; font-style: normal; }
.badge-ok { background: var(--ok-bg); color: var(--ok-ink); border-color: transparent; }
.badge-warn { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; }
.badge-error { background: var(--err-bg); color: var(--err-ink); border-color: transparent; }

/* library grid */
.search { max-width: 260px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.doc-card { color: var(--ink); transition: transform .12s ease, box-shadow .12s ease; }
.doc-card:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(16,24,40,.08), 0 12px 32px rgba(16,24,40,.08); }
.doc-icon { font-size: 1.6rem; }
.doc-card h2 { margin: .5rem 0 .35rem; font-size: 1rem; line-height: 1.35; }
.meta { margin: 0; color: var(--ink-3); font-size: .82rem; }
.empty { text-align: center; color: var(--ink-2); padding: 2.5rem 1rem; }

/* upload + tables */
.upload { margin-bottom: 1.25rem; }
.upload-row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-top: .75rem; }
.upload-row input[type=text], .upload-row input[name=username], .upload-row input[name=password] { flex: 1 1 200px; width: auto; margin-top: 0; }
.upload-row select { width: auto; margin-top: 0; }
.table-card { padding: 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .65rem .85rem; text-align: left; border-bottom: 1px solid var(--rule); vertical-align: middle; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); background: var(--bg); }
tbody tr:last-child td { border-bottom: none; }
.inline-form { display: inline-flex; gap: .3rem; align-items: center; }
.title-input { width: min(260px, 40vw); margin-top: 0; padding: .3rem .5rem; font-size: .9rem; }
.pw-input { width: 130px; margin-top: 0; padding: .3rem .5rem; font-size: .82rem; }
.file-label { margin: 0; font-weight: 500; color: var(--ink-2); font-size: .82rem; padding: .3rem .6rem; }

/* viewer — the guide gets the whole viewport; no app chrome competing with it */
.viewer-body { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.viewer-main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.doc-frame { flex: 1; width: 100%; border: 0; background: var(--surface); min-height: 0; }

/* Floating controls, bottom-left: clear of the guide's own sticky header, which
   puts its menu top-left and its theme toggle top-right.
   At rest this is just the back button — a solid circle reads as a control,
   where a translucent bar reads as a smudge over the text. The secondary
   actions unfurl on hover or keyboard focus. */
.reader-controls {
  position: fixed; left: 12px; bottom: 12px; z-index: 50;
  display: flex; align-items: center; padding: 3px;
  border-radius: 999px;
  background: rgba(16, 22, 32, .82);
  border: 1px solid rgba(255, 255, 255, .13);
  box-shadow: 0 3px 12px rgba(0, 0, 0, .3);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  backdrop-filter: blur(12px) saturate(140%);
  opacity: .5;
  transition: opacity .18s ease;
}
.reader-controls:hover, .reader-controls:focus-within { opacity: 1; }

.rc-btn {
  flex: none; width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 999px; color: #eef2f8; text-decoration: none;
}
.rc-btn:hover { background: rgba(255, 255, 255, .16); }
.rc-btn:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--accent); }
.rc-btn svg {
  width: 14px; height: 14px; fill: none; stroke: currentColor;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* Collapsed until wanted. Width rather than display so it can animate. */
.rc-extra, .rc-sep {
  width: 0; opacity: 0; pointer-events: none;
  overflow: hidden; transition: width .2s ease, opacity .16s ease, margin .2s ease;
}
.rc-sep { height: 14px; background: rgba(255, 255, 255, .18); margin: 0; }
.reader-controls:hover .rc-extra,
.reader-controls:focus-within .rc-extra { width: 26px; opacity: 1; pointer-events: auto; }
.reader-controls:hover .rc-sep,
.reader-controls:focus-within .rc-sep { width: 1px; opacity: 1; margin: 0 3px; }

/* No hover on touch: everything is visible, and the targets stay finger-sized
   rather than shrinking to the compact desktop dimensions. */
@media (hover: none) {
  .reader-controls { opacity: .9; padding: 4px; }
  .rc-btn { width: 34px; height: 34px; }
  .rc-btn svg { width: 16px; height: 16px; }
  .rc-extra { width: 34px; opacity: 1; pointer-events: auto; }
  .rc-sep { width: 1px; height: 18px; opacity: 1; margin: 0 4px; }
}

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: .6rem; }
  .who { display: none; }
  .viewer-actions .btn:last-child { display: none; }
  .page-head { align-items: stretch; }
  .search { max-width: none; }
}
