/* Element defaults and the shared layout. Colors, sizes and fonts come only from
   tokens.css (linked first); never put raw color values here. */

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

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

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--text-base);
  font-weight: var(--weight-regular);
  line-height: var(--leading);
}

/* Headings */
h1, h2, h3, h4 {
  line-height: var(--leading-tight);
  font-weight: var(--weight-semibold);
  margin: var(--space-6) 0 var(--space-3);
}
h1 { font-size: var(--text-2xl); font-weight: var(--weight-bold); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
h4 { font-size: var(--text-base); }

p, ul, ol, dl { margin: 0 0 var(--space-4); }

small { font-size: var(--text-xs); }

code, pre, kbd { font-family: var(--font-mono); font-size: 0.9em; }
pre { background: var(--surface-2); border-radius: var(--radius); padding: var(--space-3); overflow-x: auto; }

hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-6) 0; }

/* Links */
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }

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

/* Forms */
label { font-weight: var(--weight-medium); }

input, select, textarea, button { font: inherit; color: inherit; }

input:not([type="checkbox"], [type="radio"], [type="submit"], [type="button"], [type="hidden"]),
select,
textarea {
  padding: var(--space-2) var(--space-3);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  max-width: 100%;
}
/* Single-line inputs and selects are exactly --control tall, the same as .btn, so a button
   next to an input lines up without local height fixes. */
input:not([type="checkbox"], [type="radio"], [type="submit"], [type="button"], [type="hidden"], [type="file"]),
select {
  min-height: var(--control);
  padding-top: 0;
  padding-bottom: 0;
  line-height: var(--leading-tight);
}

input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

button, input[type="submit"], input[type="button"] {
  padding: var(--space-2) var(--space-4);
  background: var(--accent);
  color: var(--accent-fg);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
}
button:hover, input[type="submit"]:hover, input[type="button"]:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-3) var(--space-4); margin: 0 0 var(--space-4); }
legend { font-weight: var(--weight-medium); padding: 0 var(--space-1); }

.field { display: flex; flex-direction: column; gap: var(--space-1); margin-bottom: var(--space-4); max-width: 28rem; }
.field-invalid input, .field-invalid select, .field-invalid textarea { border-color: var(--bad-fg); }
.field-error { color: var(--bad-fg); margin: 0; }

.inline-form { display: inline; margin: 0; }

/* Tables */
table { border-collapse: collapse; width: 100%; margin: 0 0 var(--space-4); font-size: var(--text-sm); }
th, td { text-align: left; padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-muted); font-weight: var(--weight-semibold); }

/* App shell: top bar, content container, footer. Narrow-screen rules at the end of this
   section; the desktop nav and the <details> phone menu carry the same links. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.container {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding-left: var(--space-12);
  padding-right: var(--space-12);
}

.site-header { position: relative; background: var(--surface); border-bottom: 1px solid var(--border); }
.shell-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-6); min-height: var(--bar-height); }

.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text);
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  text-decoration: none;
  white-space: nowrap;
}
.brand:hover { color: var(--text); }
.brand-mark { width: var(--logo-mark); height: var(--logo-mark); border-radius: var(--radius-full); }

.nav-links, .menu-links { list-style: none; margin: 0; padding: 0; }
.nav-links { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1); }
.nav-desktop { flex: 1; min-width: 0; }
.account-desktop, .account-signed-out { margin-left: auto; }

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: var(--leading-tight);
  text-decoration: none;
  white-space: nowrap;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link[aria-current="page"] { background: var(--surface-2); color: var(--text); }
.nav-button { background: none; border: 0; cursor: pointer; }
.nav-button:hover { background: var(--surface-2); border: 0; color: var(--text); }

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--avatar);
  height: var(--avatar);
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  color: var(--accent-soft-fg);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
}

/* Phone menu: hidden on desktop. */
.nav-phone { display: none; }
.menu-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--tap-target);
  height: var(--tap-target);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  list-style: none;
}
.menu-button::-webkit-details-marker { display: none; }
.menu-button:hover, .nav-phone[open] .menu-button { background: var(--surface-2); }
.menu-icon, .menu-icon::before, .menu-icon::after {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: var(--radius-full);
  background: currentColor;
}
.menu-icon { position: relative; }
.menu-icon::before, .menu-icon::after { content: ""; position: absolute; left: 0; }
.menu-icon::before { top: -6px; }
.menu-icon::after { top: 6px; }
.nav-phone[open] .menu-icon { background: transparent; }
.nav-phone[open] .menu-icon::before { top: 0; transform: rotate(45deg); }
.nav-phone[open] .menu-icon::after { top: 0; transform: rotate(-45deg); }

.menu-panel {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: var(--space-2) var(--space-4) var(--space-4);
}
.menu-links .nav-link, .menu-links .inline-form, .menu-links .nav-button {
  display: flex;
  width: 100%;
  min-height: var(--tap-target);
  font-size: var(--text-base);
}
.menu-account { border-top: 1px solid var(--border); margin-top: var(--space-2); padding-top: var(--space-2); }

main { flex: 1; padding-top: var(--space-6); padding-bottom: var(--space-12); }

.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: var(--text-xs);
  margin-top: auto;
}
.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-1) var(--space-4);
  padding-top: var(--space-4);
  padding-bottom: var(--space-4);
}
.site-footer p { margin: 0; }

/* The full bar needs ~960px (admins have one more link), so narrower screens get the menu
   button too; phones (640px and under) also get the shorter bar and 16px gutters. */
@media (max-width: 960px) {
  .nav-desktop, .account-desktop { display: none; }
  .nav-phone { display: block; margin-left: auto; margin-right: calc(-1 * var(--space-2)); }
  .menu-panel { padding-left: var(--space-12); padding-right: var(--space-12); }
}

@media (max-width: 640px) {
  .container, .menu-panel { padding-left: var(--space-4); padding-right: var(--space-4); }
  .shell-bar { min-height: var(--bar-height-sm); gap: var(--space-3); }
  main { padding-top: var(--space-4); }
}

/* Flash messages */
.flash {
  background: var(--accent-soft);
  color: var(--accent-soft-fg);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
}
.flash-success { background: var(--good-bg); color: var(--good-fg); }
.flash-warning { background: var(--warn-bg); color: var(--warn-fg); }
.flash-error { background: var(--bad-bg); color: var(--bad-fg); }
/* Markdown inside a flash: no outer margins, its h1 sized as a note. */
.flash > :first-child { margin-top: 0; }
.flash > :last-child { margin-bottom: 0; }
.flash :is(h1, h2, h3) { font-size: var(--text-base); margin: 0 0 var(--space-2); }

.muted { color: var(--text-muted); }
