/* 4m application stylesheet.
 *
 * Design tokens are CSS custom properties so a theme is just a different
 * set of values. Color schemes other than the two defaults (and per-tenant
 * branding) will be expressed by overriding these variables on <html>.
 */

/* Light scheme (default) */
/* Color scheme tokens are generated from internal/theme and served as
 * css/schemes.css; see views.SetAssets wiring. Only non-color design
 * tokens live here. */
:root {
  --radius-s: 4px;
  --radius-m: 8px;
  --radius-l: 14px;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2.5rem;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --measure: 72ch;
  --container: 68rem;
}



/* Branding */
.site-header__brand { display: inline-flex; align-items: center; gap: var(--space-2); }
.site-header__logo { height: 1.75rem; width: auto; }
.site-tagline { color: var(--text-muted); font-size: 0.9rem; margin: 0 0 var(--space-4); }

/* Theme picker */
.theme-picker { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.theme-picker button {
  width: 2.2rem; height: 2.2rem;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
}
.theme-picker button[aria-pressed="true"] { border-color: var(--accent); outline: 2px solid var(--focus-ring); }
.theme-picker input[type="color"] { padding: 0; border: none; }

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

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

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}

img, video { max-width: 100%; height: auto; }

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

h1, h2, h3 { line-height: 1.25; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }

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

code, pre, kbd {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--code-bg);
  border-radius: var(--radius-s);
}
code { padding: 0.1em 0.35em; }
pre { padding: var(--space-3); overflow-x: auto; }
pre code { padding: 0; background: none; }

blockquote {
  margin: var(--space-3) 0;
  padding: var(--space-2) var(--space-4);
  border-left: 3px solid var(--accent);
  background: var(--surface-2);
  border-radius: 0 var(--radius-s) var(--radius-s) 0;
  color: var(--text-muted);
}
blockquote > :first-child { margin-top: 0; }
blockquote > :last-child { margin-bottom: 0; }

table { border-collapse: collapse; width: 100%; }
th, td { padding: var(--space-2) var(--space-3); border: 1px solid var(--border); text-align: left; }
th { background: var(--surface-2); }

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: var(--radius-s);
}

/* Skip link — first focusable element on every page */
.skip-link {
  position: absolute;
  left: var(--space-4);
  top: -3rem;
  z-index: 100;
  padding: var(--space-2) var(--space-4);
  background: var(--surface);
  border: 2px solid var(--focus-ring);
  border-radius: var(--radius-m);
  transition: top 0.1s ease-out;
}
.skip-link:focus { top: var(--space-4); }

/* Layout */
.container {
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--space-4);
}

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.site-header__inner {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  align-items: center;
  padding-block: var(--space-3);
}
.site-header__brand {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text);
  text-decoration: none;
}
.site-header__brand:hover { text-decoration: none; }
.site-header__nav { margin-left: auto; display: flex; gap: var(--space-4); align-items: center; flex-wrap: wrap; }

main { padding-block: var(--space-5) var(--space-6); }

.page-title { display: flex; align-items: baseline; gap: var(--space-3); flex-wrap: wrap; }
.page-title h1, .page-title h2 { margin: 0; }
.page-title__actions { margin-left: auto; display: flex; gap: var(--space-2); flex-wrap: wrap; }

.site-footer {
  border-top: 1px solid var(--border);
  padding-block: var(--space-4);
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Cards & panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow);
}
.panel__header {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.panel__header h2, .panel__header h3 { margin: 0; font-size: 1.05rem; }
.panel__body { padding: var(--space-4); }
.panel__body > :last-child { margin-bottom: 0; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-m);
  background: var(--accent);
  color: var(--accent-contrast);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn--secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn--danger { background: var(--danger); color: #fff; }
.btn--small { padding: var(--space-1) var(--space-3); font-size: 0.875rem; font-weight: 500; }

/* Forms */
.form { display: grid; gap: var(--space-4); max-width: 30rem; }
.form--wide { max-width: var(--measure); }
.field { display: grid; gap: var(--space-1); }
.field label { font-weight: 600; font-size: 0.95rem; }
.field__hint { color: var(--text-muted); font-size: 0.85rem; }
.field__error { color: var(--danger); font-size: 0.85rem; }

input[type="text"], input[type="email"], input[type="password"], input[type="url"], textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: var(--space-2) var(--space-3);
  width: 100%;
}
textarea { min-height: 8rem; resize: vertical; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 0; border-color: var(--focus-ring); }

.form-error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius-m);
  padding: var(--space-3);
}
.form-success {
  background: var(--accent-soft);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: var(--radius-m);
  padding: var(--space-3);
}

/* Thread lists */
.thread-list { list-style: none; margin: 0; padding: 0; }
.thread-list li {
  display: flex;
  gap: var(--space-3);
  align-items: baseline;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}
.thread-list li:last-child { border-bottom: 0; }
.thread-list__main { flex: 1; min-width: 0; }
.thread-list__title { font-weight: 600; }
.thread-list__meta { color: var(--text-muted); font-size: 0.875rem; }
.thread-list__stats { color: var(--text-muted); font-size: 0.875rem; white-space: nowrap; text-align: right; }
.badge {
  display: inline-block;
  padding: 0.05rem var(--space-2);
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  vertical-align: middle;
}
.badge--pinned { background: var(--accent-soft); color: var(--accent); }
.badge--locked { background: var(--danger-soft); color: var(--danger); }

/* Forum index */
.forum-list { list-style: none; margin: 0; padding: 0; }
.forum-list li { border-bottom: 1px solid var(--border); }
.forum-list li:last-child { border-bottom: 0; }
.forum-list__item {
  display: flex;
  gap: var(--space-4);
  align-items: baseline;
  padding: var(--space-4);
  color: inherit;
  text-decoration: none;
}
.forum-list__item:hover { background: var(--surface-2); text-decoration: none; }
.forum-list__main { flex: 1; }
.forum-list__title { font-weight: 700; font-size: 1.05rem; }
.forum-list__desc { color: var(--text-muted); font-size: 0.925rem; }
.forum-list__stats { color: var(--text-muted); font-size: 0.875rem; white-space: nowrap; }

/* Posts */
.post {
  display: grid;
  grid-template-columns: minmax(9rem, 12rem) 1fr;
  gap: var(--space-4);
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
}
.post:last-child { border-bottom: 0; }
.post__aside { color: var(--text-muted); font-size: 0.9rem; }
.post__author { font-weight: 700; color: var(--text); }
.post__role { font-size: 0.8rem; }
.post__body { min-width: 0; overflow-wrap: break-word; }
.post__body > :first-child { margin-top: 0; }
.post__body > :last-child { margin-bottom: 0; }
.post__footer {
  display: flex;
  gap: var(--space-4);
  margin-top: var(--space-3);
  color: var(--text-muted);
  font-size: 0.85rem;
}
.post__footer a { color: var(--text-muted); }
.post__footer a:hover { color: var(--accent); }
.post--deleted .post__body { opacity: 0.55; font-style: italic; }

@media (max-width: 40rem) {
  .post { grid-template-columns: 1fr; gap: var(--space-2); }
  .post__aside { display: flex; gap: var(--space-3); align-items: baseline; }
  .thread-list li { flex-wrap: wrap; }
  .thread-list__stats { width: 100%; text-align: left; }
}

/* Pagination */
.pagination {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-3) var(--space-4);
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Admin tables */
.table-list { width: 100%; border-collapse: collapse; }
.table-list th, .table-list td {
  padding: var(--space-2) var(--space-3);
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
}
.table-list th { color: var(--text-muted); font-weight: 600; }
.table-list tr:last-child td { border-bottom: 0; }

/* Utility */
.muted { color: var(--text-muted); }
.spacer { flex: 1; }
.stack { display: grid; gap: var(--space-4); }
.row { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }

/* EasyMDE integration */
.EasyMDEContainer .editor-toolbar { border-color: var(--border); background: var(--surface-2); }
.EasyMDEContainer .CodeMirror {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  font-family: var(--font-mono);
}
.CodeMirror-cursor { border-left-color: var(--text); }
.editor-preview { background: var(--surface); }

/* Media gallery / tube */
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-4);
}
.media-grid--wide { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

.media-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
}
.media-card:hover { text-decoration: none; border-color: var(--accent); }
.media-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  background: var(--surface-2);
}
.media-card__thumb { position: relative; display: block; }
.media-card__duration {
  position: absolute;
  right: var(--space-2);
  bottom: var(--space-2);
  padding: 0.05rem var(--space-2);
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: var(--radius-s);
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
}
.media-card__title {
  padding: var(--space-2) var(--space-3) 0;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.media-card .muted { padding: 0 var(--space-3) var(--space-3); font-size: 0.85rem; }

.media-view {
  max-width: 100%;
  max-height: 70vh;
  border-radius: var(--radius-m);
  display: block;
  margin-inline: auto;
}

/* EasyMDE toolbar icons without bundling Font Awesome: map the few
   classes the editor uses to plain glyphs. */
.editor-toolbar a:before,
.editor-toolbar button:before {
  font-family: inherit !important;
  font-size: 0.95rem !important;
}
.editor-toolbar .fa-bold:before { content: "B"; font-weight: 700; }
.editor-toolbar .fa-italic:before { content: "I"; font-style: italic; }
.editor-toolbar .fa-header:before, .editor-toolbar .fa-heading:before { content: "H"; }
.editor-toolbar .fa-quote-left:before { content: "❝"; }
.editor-toolbar .fa-list-ul:before { content: "•≡"; }
.editor-toolbar .fa-list-ol:before { content: "1≡"; }
.editor-toolbar .fa-link:before { content: "🔗"; }
.editor-toolbar .fa-code:before { content: "</>"; font-size: 0.7rem; }
.editor-toolbar .fa-eye:before { content: "👁"; }
.editor-toolbar .fa-columns:before { content: "⇹"; }
.editor-toolbar .fa-question-circle:before, .editor-toolbar .fa-question:before { content: "?"; }
.editor-toolbar .fa-image:before { content: "🖼"; }
.editor-toolbar .fa-arrows-alt:before { content: "⤢"; }

/* Notifications */
.notif-list { list-style: none; margin: 0; padding: 0; }
.notif-list li { border-bottom: 1px solid var(--border); }
.notif-list li:last-child { border-bottom: 0; }
.notif-list a {
  display: block;
  padding: var(--space-3) var(--space-4);
  color: inherit;
  text-decoration: none;
}
.notif-list a:hover { background: var(--surface-2); text-decoration: none; }
.notif--unread a { background: var(--accent-soft); }
.notif--unread a:hover { filter: brightness(0.97); }
.notif .badge { margin-right: var(--space-2); text-transform: uppercase; }
.post--mine { background: var(--accent-soft); }

/* Social: wall posts, feed, reactions, awards, profile */
.spost { padding: var(--space-3) var(--space-4); }
.spost--comment { padding: var(--space-2) 0; border-top: 1px solid var(--border); }
.spost__comments { margin-top: var(--space-2); padding-left: var(--space-4); display: grid; gap: var(--space-2); }
.spost__head { margin-bottom: var(--space-1); }
.spost__author { font-weight: 700; text-decoration: none; }
.spost__author:hover { text-decoration: underline; }
.spost__body { min-width: 0; overflow-wrap: anywhere; }
.spost__body > :last-child { margin-bottom: 0; }
.spost__reactions { display: flex; gap: var(--space-2); margin-top: var(--space-2); }
.react-chip {
  padding: 0.05rem var(--space-2);
  font-size: 0.85rem;
  border-radius: 999px;
  background: var(--surface-2);
}
.react-chip--mine { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.spost__actions { margin-top: var(--space-2); gap: var(--space-1); }
.spost__commentform { margin-top: var(--space-2); }
.profile-card h1 { font-size: 1.4rem; }
.award-list { list-style: none; margin: 0; padding: var(--space-3) var(--space-4); display: grid; gap: var(--space-3); }
.award { display: flex; gap: var(--space-3); align-items: baseline; }
.award__icon { font-size: 1.4rem; }

/* Color editor (branding) */
.color-editor { display: grid; gap: var(--space-3); }
.color-editor__group {
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  padding: var(--space-3);
  margin: 0;
  display: grid;
  gap: var(--space-2);
}
.color-editor__group legend { font-size: 0.85rem; font-weight: 600; padding: 0 var(--space-2); color: var(--text-muted); }
.color-editor__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.color-editor__row input[type="color"] { width: 3rem; height: 1.9rem; padding: 0; flex: none; }

/* Avatars */
.avatar {
  width: 2rem; height: 2rem;
  border-radius: 50%;
  object-fit: cover;
  display: inline-block;
  vertical-align: middle;
  background: var(--surface-2);
  flex: none;
}
.avatar--lg { width: 3.5rem; height: 3.5rem; }
.avatar--sm { width: 1.25rem; height: 1.25rem; }
.post__aside .avatar { margin-bottom: var(--space-1); }
.spost__head .avatar { margin-right: var(--space-1); }
/* Shoutbox */
.shoutbox__stream { display: block; }
.shoutbox__log {
  max-height: 18rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-2) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: 2px;
  scroll-behavior: smooth;
}
.shout {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-s);
  font-size: 0.925rem;
  line-height: 1.5;
}
.shout:hover { background: var(--surface-2); }
.shout .avatar { margin-top: 0.15rem; flex: none; }
.shout__main { min-width: 0; flex: 1; }
.shout__author { font-weight: 700; }
.shout__body { overflow-wrap: anywhere; }
.shout__body a { overflow-wrap: anywhere; }
.shout__body p { margin: 0; display: inline; }
.shout__time {
  margin-left: auto;
  flex: none;
  align-self: flex-end;
  padding-bottom: 0.15rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  white-space: nowrap;
}
.shoutbox__form {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
}
.shoutbox__form input[type="text"] { flex: 1; }

/* Shoutbox channel picker */
.shoutbox__channels { display: flex; gap: var(--space-2); align-items: center; }
.shoutbox__channels select { width: auto; padding: 0.15rem var(--space-2); font-size: 0.85rem; }

/* Media tags */
.tag-list { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
.tag-chip {
  display: inline-block;
  padding: 0.1rem var(--space-2);
  font-size: 0.85rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  text-decoration: none;
}
.tag-chip:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }
.tag-chip--active { background: var(--accent); color: var(--accent-contrast); }

/* Forum category sections */
.cat-section { margin-bottom: var(--space-4); }
/* Sub-categories live inside the parent block; indent with a rail. */
.cat-section .cat-section {
  margin: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  padding-left: var(--space-3);
  border-left: 2px solid var(--border);
}
.cat-section .cat-section .cat-section__head h2 { font-size: 1rem; }
.shoutbox__toggle {
  background: none;
  border: none;
  padding: 0 var(--space-1);
  font-size: 0.9rem;
  color: var(--text-muted);
  cursor: pointer;
}
.shoutbox__toggle[aria-expanded="false"] { color: var(--text-muted); }
.shoutbox__body[hidden] { display: none; }
.cat-section__head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
}
.cat-section__toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  cursor: pointer;
  color: inherit;
}
.cat-section__toggle h2 { font-size: 1.05rem; margin: 0; }
.cat-section__arrow { display: inline-block; width: 1em; color: var(--text-muted); transition: transform 0.15s ease; }
.cat-section__count { font-size: 0.85rem; }
.cat-section__body[hidden] { display: none; }
.cat-section__body > .forum-list { padding-top: 0; }

/* Search results */
.search-results { list-style: none; margin: 0; padding: 0; }
.search-hit {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
}
.search-hit:last-child { border-bottom: 0; }
.search-hit__main { min-width: 0; flex: 1; }
.search-hit__title { font-weight: 600; }
.search-hit__snippet { margin: var(--space-1) 0; color: var(--text-muted); overflow-wrap: anywhere; }
.search-hit__snippet mark {
  background: var(--warning);
  color: var(--text);
  padding: 0 0.1em;
  border-radius: 2px;
}

/* Footer content (site-admin configured) */
.site-footer__content { margin-bottom: var(--space-2); }
.site-footer__content > :first-child { margin-top: 0; }
.site-footer__content > :last-child { margin-bottom: 0; }

/* Emoji picker */
.emoji-picker {
  position: absolute;
  bottom: 100%;
  right: 0;
}
.emoji-picker[hidden] { display: none; }
.emoji-picker {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 2px;
  padding: var(--space-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow);
  z-index: 10;
}
.emoji-picker button {
  background: none;
  border: none;
  font-size: 1.2rem;
  padding: 0.2rem 0.3rem;
  cursor: pointer;
  border-radius: var(--radius-s);
}
.emoji-picker button:hover { background: var(--surface-2); }
.shoutbox__form { position: relative; }
.shoutbox__form input[name="body"] { flex: 1; }

/* Shout mod controls + edited mark */
.shout__mod { display: flex; gap: var(--space-1); align-items: center; flex: none; }
.shout__mod a { text-decoration: none; font-size: 0.85rem; }
.shout__mod button { background: none; border: none; cursor: pointer; font-size: 0.85rem; padding: 0; }
