:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1a2029;
  --muted: #6b7280;
  --border: #e2e5ea;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --notice-bg: #ecfdf5;
  --notice-text: #065f46;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151a;
    --surface: #1b2027;
    --text: #e7eaf0;
    --muted: #9aa3b2;
    --border: #2c333d;
    --accent: #4d84f7;
    --danger: #f08c8c;
    --danger-bg: #3a2020;
    --notice-bg: #15342a;
    --notice-text: #7fd8b4;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

main { max-width: 1160px; margin: 0 auto; padding: 1.75rem 2rem 5rem; }

/* ------------------------------------------------------------------ nav --- */
nav {
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.nav-inner {
  max-width: 1160px;
  margin: 0 auto;
  padding: 0.7rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

nav .brand { font-weight: 700; font-size: 1.02rem; color: var(--text); text-decoration: none; }
nav .nav-links { display: flex; align-items: center; gap: 1.1rem; }
nav .nav-links a { color: var(--muted); text-decoration: none; font-weight: 500; }
nav .nav-links a:hover { color: var(--text); }

/* ----------------------------------------------------------- typography --- */
h1 { font-size: 1.55rem; letter-spacing: -0.015em; margin: 0.25rem 0 0.75rem; }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }
h3 { font-size: 0.92rem; margin: 1.25rem 0 0.25rem; }

a { color: var(--accent); }
.back { margin: 0 0 0.25rem; font-size: 0.9rem; }
.back a { text-decoration: none; }
.back a:hover { text-decoration: underline; }

code {
  font-family: var(--mono);
  background: color-mix(in srgb, var(--border) 50%, transparent);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.85em;
}

pre {
  background: color-mix(in srgb, var(--border) 40%, transparent);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.83rem;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.head-meta { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; color: var(--muted); font-size: 0.88rem; }

/* ---------------------------------------------------------------- cards --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem 1.4rem;
  margin-bottom: 1.25rem;
}

/* ------------------------------------------------ collapsible collections --- */
details.collection {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 0.9rem;
  overflow: hidden;
}

details.collection > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.85rem 1.25rem;
  font-weight: 650;
  font-size: 1rem;
  user-select: none;
}

details.collection > summary::-webkit-details-marker { display: none; }

details.collection > summary::before {
  content: "";
  width: 0.5em;
  height: 0.5em;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
  flex: none;
}

details.collection[open] > summary::before { transform: rotate(45deg); }

details.collection > summary:hover { background: color-mix(in srgb, var(--accent) 4%, var(--surface)); }

summary .count {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 0.1rem 0.55rem;
}

.collection-body { padding: 0 1.25rem 1rem; }
.collection-foot { display: flex; justify-content: flex-end; margin-top: 0.5rem; }

/* --------------------------------------------------------------- tables --- */
.tablewrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }

th, td {
  text-align: left;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.1s ease; }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 4%, transparent); }
tr.inactive { opacity: 0.55; }

td.actions { text-align: right; white-space: nowrap; }
td.actions form { display: inline-block; margin-left: 0.35rem; }
td.date { white-space: nowrap; color: var(--muted); }

.page-cell { max-width: 46ch; }
.page-cell .page-title { font-weight: 600; text-decoration: none; }
.page-cell .page-title:hover { text-decoration: underline; }
.page-cell .slug { display: block; font-family: var(--mono); font-size: 0.76rem; color: var(--muted); margin-top: 0.15rem; }
.page-cell .desc { display: block; font-size: 0.83rem; color: var(--muted); margin-top: 0.15rem; }

.ver-cell { white-space: nowrap; }
.ver-cell .vnum { font-family: var(--mono); font-weight: 700; display: block; }
.ver-cell .ver-meta { display: block; font-size: 0.78rem; color: var(--muted); margin-top: 0.1rem; }
td.note { color: var(--muted); font-size: 0.86rem; max-width: 34ch; }

/* --------------------------------------------------------------- badges --- */
.badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.18rem 0.6rem;
  border-radius: 99px;
  white-space: nowrap;
}
.badge-published { background: var(--notice-bg); color: var(--notice-text); }
.badge-draft, .badge-draft-pending { background: color-mix(in srgb, #d97706 15%, var(--surface)); color: #b45309; }
.badge-unpublished { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }

@media (prefers-color-scheme: dark) {
  .badge-draft, .badge-draft-pending { color: #e3b464; }
}

/* ---------------------------------------------------------------- forms --- */
input[type="text"], input[type="email"], input[type="password"], textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  width: 100%;
}

input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.inline-form { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.75rem; }
.inline-form input, .inline-form select { width: auto; }

.stacked { display: flex; flex-direction: column; gap: 0.75rem; }
.stacked label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; color: var(--muted); font-weight: 500; }
.stacked button { align-self: flex-start; }

label.checkbox { display: flex; align-items: center; gap: 0.35rem; color: var(--muted); font-size: 0.9rem; }

button, .button {
  font: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.85rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  transition: border-color 0.12s ease, background 0.12s ease, transform 0.06s ease;
}

button:hover, .button:hover { border-color: var(--muted); }
button:active, .button:active { transform: scale(0.98); }

button.primary, .button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

button.primary:hover, .button.primary:hover {
  background: color-mix(in srgb, var(--accent) 85%, black);
  border-color: color-mix(in srgb, var(--accent) 85%, black);
}

button.danger { color: var(--danger); border-color: var(--danger); }
button.subtle { border-color: transparent; background: transparent; }
button.subtle:hover { border-color: var(--border); }

/* ---------------------------------------------------------- detail grid --- */
.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 960px) {
  .detail-grid { grid-template-columns: 1fr; }
  main { padding: 1.25rem 1rem 4rem; }
  .nav-inner { padding: 0.7rem 1rem; }
}

/* ----------------------------------------------------------------- misc --- */
.share-url { display: flex; gap: 0.5rem; align-items: center; }
.share-url input { flex: 1; font-family: var(--mono); font-size: 0.8rem; color: var(--muted); min-width: 0; }

.hint { color: var(--muted); font-size: 0.85rem; }
.empty { color: var(--muted); font-size: 0.9rem; }

.flash { border-radius: 6px; padding: 0.6rem 1rem; margin-bottom: 1rem; }
.flash.error { background: var(--danger-bg); color: var(--danger); }
.flash.notice { background: var(--notice-bg); color: var(--notice-text); }

.danger-zone { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }

.login-card {
  max-width: 360px;
  margin: 10vh auto 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2rem;
}

.login-card h1 { text-align: center; margin-top: 0; }
.login-card .stacked { max-width: none; }
.login-card button { align-self: stretch; }
