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

:root {
  --brand: #AE3E06;
  --white: #FFFFFF;
  --font-serif: "Playfair Display", Georgia, serif;
  --font-sans: "DM Sans", "Avenir Next", Arial, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", monospace;
  --radius: 8px;
  --hairline: 1px;
  --shadow: 0 16px 40px rgba(174, 62, 6, 0.12);
}

html { min-height: 100%; background: var(--white); color: var(--brand); }
body {
  min-height: 100vh;
  font-family: var(--font-sans);
  background: var(--white);
  color: var(--brand);
  line-height: 1.5;
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  top: 5.5rem;
  right: max(1.5rem, calc((100vw - 960px) / 2));
  width: clamp(116px, 18vw, 172px);
  aspect-ratio: 1;
  pointer-events: none;
  z-index: 0;
  background:
    linear-gradient(rgba(174, 62, 6, 0.35), rgba(174, 62, 6, 0.35)) center / 1px 100% no-repeat,
    linear-gradient(90deg, rgba(174, 62, 6, 0.35), rgba(174, 62, 6, 0.35)) center / 100% 1px no-repeat,
    radial-gradient(circle,
      var(--brand) 0 2px,
      var(--white) 2px 25%,
      var(--brand) 25% calc(25% + 1px),
      var(--white) calc(25% + 1px) 50%,
      var(--brand) 50% calc(50% + 1px),
      var(--white) calc(50% + 1px) 75%,
      var(--brand) 75% calc(75% + 1px),
      var(--white) calc(75% + 1px) calc(100% - 1px),
      var(--brand) calc(100% - 1px) 100%);
}

a { color: var(--brand); text-decoration: underline; text-decoration-thickness: var(--hairline); text-underline-offset: 0.18em; }
a:hover { text-decoration-style: dashed; }
button, input { font: inherit; color: inherit; }
button { border-radius: var(--radius); }
::placeholder { color: var(--brand); }

.container {
  position: relative;
  z-index: 1;
  max-width: 960px;
  margin: 0 auto;
  padding: 2.25rem 1rem;
}

.nav {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1.5rem;
  background: var(--white);
  border-bottom: var(--hairline) solid var(--brand);
}

.nav-brand {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.86rem;
  color: var(--brand);
  text-decoration: none;
  text-transform: uppercase;
}

.nav-logout button,
.btn,
.viewer-nav button {
  display: inline-block;
  padding: 0.5rem 0.9rem;
  border: var(--hairline) solid var(--brand);
  background: var(--white);
  color: var(--brand);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
}

.nav-logout button:hover,
.btn:hover,
.viewer-nav button:hover {
  background: var(--brand);
  color: var(--white);
}

.btn-primary,
.auth-form button,
.gate-card button {
  background: var(--brand);
  color: var(--white);
  border-color: var(--brand);
}

.btn-primary:hover,
.auth-form button:hover,
.gate-card button:hover {
  background: var(--white);
  color: var(--brand);
}

.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.76rem; }
.btn-xs { padding: 0.2rem 0.45rem; font-size: 0.68rem; }

.auth-form,
.gate-card {
  max-width: 400px;
  width: 100%;
  padding: 2rem;
  background: var(--white);
  border: var(--hairline) solid var(--brand);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-form {
  margin: 4rem auto;
}

.auth-form h1,
.gate-card h1,
.dashboard-header h1,
.doc-detail-header h1,
.section h2 {
  font-family: var(--font-serif);
  font-weight: 400;
  color: var(--brand);
  line-height: 1.05;
}

.auth-form h1 { margin-bottom: 1.5rem; font-size: 3rem; }
.gate-card h1 { margin-bottom: 0.75rem; font-size: 3rem; }
.dashboard-header h1,
.doc-detail-header h1 { font-size: 4.5rem; max-width: 12ch; }
.section h2 { margin-bottom: 1rem; font-size: 1.7rem; }

.auth-form label,
.gate-card label {
  display: block;
  margin-bottom: 1rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.auth-form input,
.gate-card input {
  display: block;
  width: 100%;
  padding: 0.62rem 0.7rem;
  margin-top: 0.35rem;
  border: var(--hairline) solid var(--brand);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--brand);
  font-family: var(--font-sans);
  font-size: 0.96rem;
}

.auth-form button,
.gate-card button {
  width: 100%;
  padding: 0.68rem;
  border: var(--hairline) solid var(--brand);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  margin-top: 0.5rem;
}

.auth-link {
  text-align: left;
  margin-bottom: 1rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--brand);
  text-transform: uppercase;
}

.error {
  color: var(--brand);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  margin-bottom: 1rem;
  padding: 0.65rem 0.75rem;
  background: var(--white);
  border: var(--hairline) dashed var(--brand);
  border-radius: var(--radius);
}

.dashboard-header,
.section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.dashboard-header { margin-bottom: 2rem; }
.section-header { align-items: center; margin-bottom: 1rem; }

.doc-list,
.link-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.doc-card,
.link-card,
.metric-strip > div {
  background: var(--white);
  border: var(--hairline) solid var(--brand);
  border-radius: var(--radius);
  color: var(--brand);
}

.doc-card {
  display: block;
  padding: 1rem;
  text-decoration: none;
}

.doc-card:hover,
.link-card:hover {
  border-style: dashed;
}

.doc-card-title {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 1.35rem;
}

.doc-card-meta,
.doc-meta,
.link-meta,
.metric-label,
.viewer-table th,
#page-info {
  color: var(--brand);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
}

.doc-card-meta,
.doc-meta,
.link-meta {
  margin-top: 0.35rem;
}

.empty-state {
  border: var(--hairline) dashed var(--brand);
  border-radius: var(--radius);
  color: var(--brand);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  padding: 2rem;
  text-align: center;
  text-transform: uppercase;
}

.doc-detail-header { margin-bottom: 2rem; max-width: 680px; }

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.metric-strip > div { padding: 0.85rem; }
.metric-value {
  display: block;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 1.45rem;
  line-height: 1.1;
}
.metric-label { display: block; margin-top: 0.35rem; font-weight: 700; }

.section { margin-bottom: 2rem; }

.link-card { padding: 0.85rem; }
.link-card.inactive { border-style: dashed; }
.link-url { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.35rem; }
.link-url code {
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--brand);
}
.inactive-badge { color: var(--brand); font-weight: 700; text-transform: uppercase; }

.viewer-table {
  width: 100%;
  border-collapse: collapse;
  border-top: var(--hairline) solid var(--brand);
}

.viewer-table th,
.viewer-table td {
  padding: 0.62rem 0.5rem;
  text-align: left;
  border-bottom: var(--hairline) solid var(--brand);
  font-size: 0.875rem;
  vertical-align: top;
}

.viewer-table th { font-weight: 700; }

.gate-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.gate-card p {
  color: var(--brand);
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}

.viewer-container {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--white);
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 1rem;
  background: var(--white);
  border-bottom: var(--hairline) solid var(--brand);
  flex-shrink: 0;
}

.viewer-title {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 1.2rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 34%;
}

.viewer-nav { display: flex; align-items: center; gap: 0.5rem; }
.viewer-nav button:disabled {
  background: var(--white);
  color: var(--brand);
  border-style: dashed;
  cursor: default;
}

.viewer-canvas-wrapper {
  flex: 1;
  overflow: auto;
  display: flex;
  justify-content: center;
  background: var(--white);
  padding: 1rem;
}

.pdf-page {
  position: relative;
  max-width: 100%;
  border: var(--hairline) solid var(--brand);
  box-shadow: var(--shadow);
  line-height: 0;
}

#pdf-canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

.pdf-link-layer {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.pdf-link {
  position: absolute;
  display: block;
  border-radius: 2px;
  pointer-events: auto;
  text-decoration: none;
}

.pdf-link:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

input:focus,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

@media (max-width: 720px) {
  body::before { width: 112px; top: 5rem; right: 1rem; }
  .container { padding: 1.5rem 1rem; }
  .nav { padding: 0.75rem 1rem; }
  .auth-form { margin: 3rem auto; }
  .auth-form h1,
  .gate-card h1 { font-size: 2.35rem; }
  .dashboard-header h1,
  .doc-detail-header h1 { font-size: 2.85rem; }
  .dashboard-header { align-items: flex-start; flex-direction: column; }
  .metric-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .viewer-table { display: block; overflow-x: auto; white-space: nowrap; }
  .viewer-toolbar { align-items: flex-start; flex-direction: column; }
  .viewer-title { max-width: 100%; }
}
