/* 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) */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #1c2430;
  --text-muted: #5b6675;
  --accent: #0b5cad;
  --accent-contrast: #ffffff;
  --accent-soft: #e3eef9;
  --danger: #b3261e;
  --danger-soft: #fdeceb;
  --success: #1a7f37;
  --warning: #9a6700;
  --border: #d4d9e0;
  --focus-ring: #0b5cad;
  --code-bg: #f0f2f5;
  --shadow: 0 1px 2px rgba(20, 30, 45, 0.08);

  --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;
}

/* Dark scheme */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14181f;
    --surface: #1d232d;
    --surface-2: #27303d;
    --text: #e6eaf0;
    --text-muted: #9aa7b6;
    --accent: #6cb2f5;
    --accent-contrast: #0e1722;
    --accent-soft: #1d3448;
    --danger: #f2a49e;
    --danger-soft: #45201d;
    --success: #7ee2a8;
    --warning: #e0ac4e;
    --border: #333e4d;
    --focus-ring: #6cb2f5;
    --code-bg: #232b36;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

/* Named schemes. "auto" (no attribute) follows the media query above;
 * every scheme below defines its full token set. Tenants pick a default
 * (tenants.settings.theme) and users override per-browser via cookie.
 */
:root[data-theme="dark"], :root[data-theme="forest"], :root[data-theme="ocean"] {
  color-scheme: dark;
}
:root[data-theme="light"], :root[data-theme="sunset"] {
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #14181f;
  --surface: #1d232d;
  --surface-2: #27303d;
  --text: #e6eaf0;
  --text-muted: #9aa7b6;
  --accent: #6cb2f5;
  --accent-contrast: #0e1722;
  --accent-soft: #1d3448;
  --danger: #f2a49e;
  --danger-soft: #45201d;
  --success: #7ee2a8;
  --warning: #e0ac4e;
  --border: #333e4d;
  --focus-ring: #6cb2f5;
  --code-bg: #232b36;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

:root[data-theme="forest"] {
  --bg: #101713;
  --surface: #182420;
  --surface-2: #223129;
  --text: #e4ece6;
  --text-muted: #93a89b;
  --accent: #6fd0a2;
  --accent-contrast: #0c1712;
  --accent-soft: #173426;
  --danger: #f2a49e;
  --danger-soft: #45201d;
  --success: #7ee2a8;
  --warning: #e0ac4e;
  --border: #2c3c33;
  --focus-ring: #6fd0a2;
  --code-bg: #1c2823;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

:root[data-theme="ocean"] {
  --bg: #0e1420;
  --surface: #161f2e;
  --surface-2: #1f2b3d;
  --text: #e3e9f2;
  --text-muted: #91a2ba;
  --accent: #5fc2e0;
  --accent-contrast: #081018;
  --accent-soft: #143443;
  --danger: #f2a49e;
  --danger-soft: #45201d;
  --success: #7ee2a8;
  --warning: #e0ac4e;
  --border: #2a3849;
  --focus-ring: #5fc2e0;
  --code-bg: #182230;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

:root[data-theme="sunset"] {
  --bg: #fbf4ec;
  --surface: #ffffff;
  --surface-2: #f4e9dd;
  --text: #2e231b;
  --text-muted: #7a6a5c;
  --accent: #b3541e;
  --accent-contrast: #ffffff;
  --accent-soft: #f9e8d9;
  --danger: #b3261e;
  --danger-soft: #fdeceb;
  --success: #1a7f37;
  --warning: #9a6700;
  --border: #e5d5c5;
  --focus-ring: #b3541e;
  --code-bg: #f3ebe1;
  --shadow: 0 1px 2px rgba(93, 58, 30, 0.10);
}

/* 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); }
.swatch-auto { background: linear-gradient(90deg, #ffffff 50%, #14181f 50%); }
.swatch-light { background: #ffffff; }
.swatch-dark { background: #14181f; }
.swatch-forest { background: #6fd0a2; }
.swatch-ocean { background: #5fc2e0; }
.swatch-sunset { background: #f4c58e; }

/* 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; }
