:root {
  --bg: #ffffff;
  --text: #262626;
  --muted: #808080;
  --line: #dedede;
  --bar: rgba(250, 250, 250, 0.86);
  --hover: rgba(0, 0, 0, 0.055);
  --select: #0a63d8;
  --viewer-bg: #e6e6e8;
  --error: #b3261e;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Cantarell, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1e1e1e;
    --text: #e6e6e6;
    --muted: #9a9a9a;
    --line: #383838;
    --bar: rgba(40, 40, 40, 0.86);
    --hover: rgba(255, 255, 255, 0.07);
    --viewer-bg: #2b2b2d;
    --error: #ff8a80;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
}

body.is-viewing { background: var(--viewer-bg); }

a { color: inherit; }
main:focus { outline: none; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  min-height: 48px;
  padding: 8px 20px;
  background: var(--bar);
  border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  backdrop-filter: saturate(180%) blur(16px);
}

.crumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 13px;
}

.crumb { white-space: nowrap; }
a.crumb { color: var(--muted); text-decoration: none; border-radius: 4px; padding: 2px 4px; margin: -2px -4px; }
a.crumb:hover { color: var(--text); background: var(--hover); }
.crumb.current { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.sep { color: var(--muted); }

.tools { display: flex; align-items: center; flex-shrink: 0; }
.tools[hidden] { display: none; }

.file-nav { display: flex; gap: 4px; }
.file-link {
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
a.file-link:hover { background: var(--hover); }
.file-link.is-disabled { color: var(--muted); opacity: 0.5; }

a.crumb:focus-visible, a.file-link:focus-visible, .note a:focus-visible {
  outline: 2px solid var(--select);
  outline-offset: 1px;
}

/* ---------- folder / file grid (Finder icon view) ---------- */

.grid {
  list-style: none;
  margin: 0;
  padding: 36px 32px 64px;
  display: grid;
  grid-template-columns: repeat(auto-fill, 152px);
  gap: 24px 0;
}

.item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 4px;
  text-decoration: none;
  color: var(--text);
  outline: none;
}

.item-icon {
  display: grid;
  place-items: center;
  width: 104px;
  height: 88px;
  border-radius: 8px;
}
.item-icon svg { width: 96px; height: 77px; }

.item-label {
  max-width: 144px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 13px;
  line-height: 1.35;
  text-align: center;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.item:hover .item-icon { background: var(--hover); }

/* Keyboard focus looks like a Finder selection */
.item:focus-visible .item-icon { background: var(--hover); box-shadow: inset 0 0 0 1px var(--line); }
.item:focus-visible .item-label { background: var(--select); color: #fff; }

/* ---------- notes and status ---------- */

.note, .status {
  max-width: 34em;
  margin: 72px auto;
  padding: 0 24px;
  text-align: center;
  color: var(--muted);
}
.note-title { color: var(--text); font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.note a { color: var(--select); }
.status.is-error { color: var(--error); }
.status[hidden] { display: none; }

/* ---------- viewer: stock pdf.js viewer fills the window below the bar ---------- */

body.is-viewing {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}
body.is-viewing main { flex: 1; min-height: 0; }

.viewer-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--viewer-bg);
}

/* ---------- small screens ---------- */

@media (max-width: 640px) {
  .topbar { padding: 8px 12px; }
  .crumbs { flex: 1 1 auto; }
  .crumbs .crumb:not(.current), .crumbs .sep { display: none; }
  .crumbs .crumb:nth-last-child(3) { display: inline; }        /* keep the parent link */
  .crumbs .sep:nth-last-child(2) { display: inline; }
  .tools { margin-left: auto; }

  .grid { padding: 20px 8px 48px; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 16px 0; }
  .item-icon { width: 84px; height: 72px; }
  .item-icon svg { width: 78px; height: 62px; }
  .item-label { max-width: 108px; }

}
