:root {
  --surface: #f8f9ff;
  --surface-low: #eff4ff;
  --surface-container: #e5eeff;
  --surface-high: #dce9ff;
  --surface-highest: #d3e4fe;
  --white: #ffffff;
  --text: #0b1c30;
  --muted: #565e74;
  --muted-2: #3d4a3c;
  --outline: #bccbb8;
  --primary: #006e27;
  --primary-bright: #00ae42;
  --on-primary: #ffffff;
  --amber: #f46f10;
  --error: #ba1a1a;
  --error-soft: #ffdad6;
  --cyan: #0284c7;
  --shadow: 0 1px 8px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 4px 20px -2px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --radius: 8px;
  --radius-lg: 12px;
  --header-h: 64px;
  --sidebar-w: 256px;
  --gutter: 1.5rem;
  --font: Inter, "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 20px;
  color: var(--text);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary-bright); text-decoration: none; }
a:hover { color: var(--primary); }
img { max-width: 100%; }
button, input, textarea, select { font: inherit; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 1rem; top: 1rem; z-index: 80; background: #fff; padding: .5rem; }

.icon {
  font-family: "Material Symbols Outlined", sans-serif;
  font-weight: 400;
  font-style: normal;
  font-size: 20px;
  line-height: 1;
  letter-spacing: normal;
  display: inline-block;
  vertical-align: middle;
  font-variation-settings: "FILL" 0, "wght" 400, "GRAD" 0, "opsz" 24;
}

/* Header */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--header-h);
  display: flex; align-items: center; gap: 1rem;
  padding: 0 var(--gutter);
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  z-index: 50;
}
.brand { display: flex; align-items: center; gap: .5rem; color: inherit; flex-shrink: 0; }
.brand:hover { color: inherit; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--primary-bright); color: #fff;
  display: grid; place-items: center;
}
.brand-mark .icon { font-size: 18px; color: #fff; }
.brand-name { font-weight: 600; font-size: 20px; letter-spacing: -0.01em; color: var(--primary); }
.brand-name span { color: var(--muted); font-weight: 400; font-size: 16px; margin-left: .35rem; }
.top-nav { display: none; gap: 1.25rem; }
.top-nav a { color: var(--muted-2); font-weight: 600; font-size: 14px; }
.top-nav a:hover, .top-nav a.is-on { color: var(--primary); }
.search-wrap { flex: 1; max-width: 36rem; display: none; position: relative; }
.search-wrap .icon { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-wrap input {
  width: 100%; height: 40px; border: 0; border-radius: 8px;
  background: var(--surface-low); padding: 0 3.2rem 0 2.5rem; color: var(--text);
}
.search-wrap input:focus { outline: none; background: #fff; box-shadow: 0 0 0 1px #00ae42; }
.kbd {
  position: absolute; right: .5rem; top: 50%; transform: translateY(-50%);
  background: var(--surface-high); color: var(--muted); font-family: var(--mono); font-size: 11px;
  padding: 2px 6px; border-radius: 4px;
}
.top-actions { display: flex; align-items: center; gap: .5rem; margin-left: auto; }
.icon-btn {
  width: 32px; height: 32px; border: 0; border-radius: 8px; background: transparent;
  color: var(--muted-2); cursor: pointer; display: grid; place-items: center; position: relative;
}
.icon-btn:hover { background: var(--surface-high); color: var(--text); }
.icon-btn .dot {
  position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--primary-bright); box-shadow: 0 0 0 2px #fff;
}
.menu-toggle { display: grid; }

/* Sidebar */
.sidebar {
  position: fixed; top: var(--header-h); left: 0; bottom: 0; width: var(--sidebar-w);
  background: #fff; box-shadow: var(--shadow); z-index: 40;
  padding: 1.25rem .875rem; overflow: auto;
  display: flex; flex-direction: column; gap: 1.25rem;
  transform: translateX(-110%); transition: transform .2s ease;
}
.sidebar.is-open { transform: none; }
.scrim { display: none; position: fixed; inset: var(--header-h) 0 0 0; background: rgba(11,28,48,.35); z-index: 35; }
.scrim.is-on { display: block; }
.side-label {
  font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); padding: 0 .5rem;
}
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a {
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; padding: .4rem .5rem; border-radius: 8px; color: var(--muted-2);
}
.side-nav a:hover { background: var(--surface-container); color: var(--text); }
.side-nav a.is-on { background: var(--surface-high); color: var(--primary); font-weight: 700; }
.side-nav a .left { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.side-nav a .count { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.chip-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 .5rem; }
.tag {
  font-family: var(--mono); font-size: 12px; padding: 2px 8px; border-radius: 8px;
  background: var(--surface-container); color: var(--muted-2);
}
.tag:hover { background: var(--surface-high); color: var(--text); }
.side-cta { margin-top: auto; padding-top: .875rem; border-top: 1px solid rgba(188,203,184,.4); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  height: 36px; padding: 0 .9rem; border: 0; border-radius: 8px; cursor: pointer;
  font-weight: 600; font-size: 14px;
}
.btn-primary { background: var(--primary-bright); color: #fff; width: 100%; box-shadow: 0 1px 4px rgba(0,174,66,.2); }
.btn-primary:hover { background: var(--primary); color: #fff; }
.btn-ghost { background: var(--surface-low); color: var(--text); }
.btn-ghost:hover { background: var(--surface-container); }
.btn-sm { height: 32px; font-size: 12px; padding: 0 .7rem; }

.shell { padding-top: var(--header-h); min-height: 100vh; }
.main { padding: 1rem .75rem 3rem; }

.flash { margin: 0 0 1rem; padding: .7rem 1rem; border-radius: 8px; }
.flash-ok { background: #e8f7ee; color: var(--primary); }
.flash-error { background: var(--error-soft); color: var(--error); }

.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; color: var(--muted); font-size: 12px; margin-bottom: .75rem; }
.stat-pills { display: none; gap: .5rem; }
.pill {
  display: flex; align-items: center; gap: .4rem;
  background: var(--surface-low); padding: .25rem .7rem; border-radius: 999px;
  font-family: var(--mono); font-size: 12px; color: var(--muted);
}
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--primary-bright); }

.filter-card {
  background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow);
  padding: .5rem; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center;
  margin-bottom: 1.25rem;
}
.seg { display: flex; background: var(--surface-low); border-radius: 8px; padding: 4px; flex-wrap: wrap; }
.seg a {
  height: 28px; padding: 0 .75rem; border-radius: 6px; color: var(--muted); font-weight: 500; font-size: 12px;
  display: inline-flex; align-items: center; gap: .3rem;
}
.seg a.is-on { background: #fff; color: var(--primary); font-weight: 600; box-shadow: var(--shadow); }

.banner {
  position: relative; overflow: hidden;
  background: linear-gradient(90deg, #fff, var(--surface-low) 60%, rgba(218,226,253,.35));
  border-radius: var(--radius-lg); padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1.25rem;
}
.banner h2 { margin: .35rem 0 .25rem; font-size: 16px; }
.banner p { margin: 0; color: var(--muted); }
.badge-official {
  display: inline-block; background: var(--primary-bright); color: #fff;
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  padding: 2px 8px; border-radius: 4px;
}

.feed { background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden; }
.feed-head, .topic-row {
  display: grid; grid-template-columns: 1fr 56px 72px;
  gap: .5rem; align-items: center; padding: .75rem 1rem;
}
.feed-head {
  background: var(--surface-low); color: var(--muted); font-size: 11px;
  font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
}
.topic-row { border-top: 1px solid var(--surface-low); }
.topic-row:hover { background: rgba(239,244,255,.7); }
.topic-main { display: flex; gap: .6rem; min-width: 0; }
.topic-title { color: var(--text); font-weight: 600; font-size: 15px; display: block; }
.topic-title:hover { color: var(--primary); }
.topic-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.cat-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-container); padding: 2px 8px; border-radius: 4px; font-size: 12px; color: var(--text);
}
.mono { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.num { font-family: var(--mono); text-align: center; font-weight: 600; }
.num.hot { color: #9d4300; }
.parts { display: none; }
.solved { display: inline-flex; align-items: center; gap: 4px; color: var(--primary); font-size: 11px; font-weight: 700; text-transform: uppercase; background: #e8f7ee; padding: 1px 6px; border-radius: 4px; }
.pinned { background: var(--primary); color: #fff; font-size: 11px; font-weight: 700; text-transform: uppercase; padding: 2px 8px; border-radius: 4px; }

.avatar {
  display: grid; place-items: center; border-radius: 50%;
  background: hsl(var(--h, 140) 35% 42%); color: #fff; font-weight: 700; font-size: 11px;
  flex-shrink: 0; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.has-photo { background: #d3e4fe; padding: 0; }
.avatar-sm { width: 28px; height: 28px; }
.avatar-md { width: 32px; height: 32px; }
.avatar-lg { width: 72px; height: 72px; font-size: 22px; }
.avatar-xl { width: 112px; height: 112px; font-size: 32px; }
.stack { display: flex; }
.stack .avatar { box-shadow: 0 0 0 2px #fff; margin-left: -8px; }
.stack .avatar:first-child { margin-left: 0; }

.cards { display: grid; gap: 1.25rem; margin-top: 2rem; }
.card { background: #fff; border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 1rem; }
.card h3 { margin: 0 0 .5rem; font-size: 14px; display: flex; align-items: center; gap: .5rem; }

.form-card { max-width: 420px; margin: 2rem auto; background: #fff; padding: 1.5rem; border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.form-card.form-wide { max-width: 820px; }
.form-card h1 { margin: 0 0 1rem; font-size: 22px; }
label { display: block; font-weight: 600; margin: .75rem 0 .3rem; }
input[type=text], input[type=email], input[type=password], textarea, select {
  width: 100%; border: 1px solid #cbd5e1; border-radius: 8px; padding: .55rem .7rem; background: #fff;
}
input:focus, textarea:focus, select:focus { outline: none; box-shadow: 0 0 0 1px #00ae42; border-color: #00ae42; }
textarea { min-height: 140px; resize: vertical; }

.composer { border: 1px solid #cbd5e1; border-radius: 8px; background: #fff; overflow: hidden; }
.composer:focus-within { box-shadow: 0 0 0 1px #00ae42; border-color: #00ae42; }
.composer-bar, .composer-align {
  display: flex; flex-wrap: wrap; align-items: center; gap: .35rem;
  padding: .4rem .5rem; background: var(--surface-low); border-bottom: 1px solid var(--surface-container);
}
.composer-sep { width: 1px; height: 18px; background: #cbd5e1; }
.composer-hint { color: var(--muted); font-size: 12px; font-weight: 500; }
.composer-photo { position: relative; overflow: hidden; cursor: pointer; }
.composer-edit {
  min-height: 200px; padding: .85rem .9rem; outline: none; font-size: 16px; line-height: 1.55;
}
.composer-edit:empty:before { content: attr(data-placeholder); color: #94a3b8; }
.composer-edit img, .prose-html img.post-photo {
  max-width: 100%; height: auto; border-radius: 8px; display: block; margin: .75rem auto; cursor: move;
}
.composer-edit img.is-on { outline: 2px solid var(--primary-bright); }
.composer-edit img.align-left, .prose-html img.align-left { float: left; margin: 0 1rem .75rem 0; max-width: 46%; }
.composer-edit img.align-right, .prose-html img.align-right { float: right; margin: 0 0 .75rem 1rem; max-width: 46%; }
.composer-edit img.align-center, .prose-html img.align-center { float: none; margin: .75rem auto; }
.prose-html::after { content: ""; display: block; clear: both; }
.composer-status { padding: 0 .9rem .6rem; color: var(--error); }

.tagbox { position: relative; border: 1px solid #cbd5e1; border-radius: 8px; padding: .4rem .5rem; background: #fff; }
.tagbox:focus-within { box-shadow: 0 0 0 1px #00ae42; border-color: #00ae42; }
.tagbox-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tagbox-chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: #e8f7ee; color: var(--primary); border-radius: 999px;
  padding: 2px 8px; font-family: var(--mono); font-size: 12px; font-weight: 600;
}
.tagbox-chip button { border: 0; background: none; cursor: pointer; color: var(--primary); font-size: 14px; line-height: 1; }
.tagbox-input { border: 0 !important; box-shadow: none !important; padding: .35rem .2rem !important; min-width: 12rem; flex: 1; }
.tagbox-suggest {
  list-style: none; margin: .35rem 0 0; padding: 0; position: absolute; left: 0; right: 0; top: 100%;
  background: #fff; border-radius: 8px; box-shadow: var(--shadow-lg); z-index: 20; max-height: 220px; overflow: auto;
}
.tagbox-suggest li { padding: .45rem .7rem; cursor: pointer; display: flex; justify-content: space-between; gap: .5rem; }
.tagbox-suggest li:hover, .tagbox-suggest li.is-on { background: var(--surface-low); }
.tagbox-suggest .new { color: var(--primary); font-weight: 600; }

.footer-note { text-align: center; color: var(--muted); font-size: 13px; padding: 2rem 0 1rem; opacity: .7; }

.thread-head { background: #fff; border-radius: var(--radius-lg); padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1.25rem; }
.thread-head h1 { margin: .2rem 0; font-size: 22px; letter-spacing: -0.02em; }
.post {
  background: #fff; border-radius: var(--radius-lg); padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1rem; position: relative;
}
.post.is-op { border-left: 4px solid var(--primary-bright); }
.post.is-solution { box-shadow: 0 0 0 1px var(--primary-bright), var(--shadow); }
.post-top { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: .75rem; }
.post-author { display: flex; gap: .75rem; align-items: center; }
.prose p, .prose li, .prose-html { margin: 0 0 .75rem; line-height: 1.55; font-size: 16px; }
.prose-html { margin: 0; }
.prose-html p:last-child { margin-bottom: 0; }
.prose blockquote {
  margin: 0 0 .75rem; padding: .6rem .9rem; border-left: 3px solid var(--primary-bright);
  background: var(--surface-low); border-radius: 0 8px 8px 0; color: var(--muted-2);
}
.prose ol { padding-left: 1.25rem; }
.post-actions { display: flex; justify-content: space-between; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.btn.is-liked { color: var(--primary); font-weight: 700; }
.pager { display: flex; align-items: center; justify-content: center; gap: .75rem; padding: 1rem 0 1.5rem; }
.people-grid { display: grid; grid-template-columns: 1fr; gap: .75rem; }
.person-card { display: flex; gap: .85rem; align-items: center; color: inherit; }
.person-card:hover { color: inherit; }
.admin-user-row { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: center; justify-content: space-between; padding: .45rem 0; border-bottom: 1px solid var(--surface-container); }
.admin-inline { display: flex; gap: .35rem; align-items: center; }
.admin-inline select { width: auto; }

.profile-hero { background: #fff; border-radius: var(--radius-lg); padding: 1.5rem; box-shadow: var(--shadow); margin-bottom: 1.5rem; }
.metrics { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; margin-bottom: 1.5rem; }
.metric { background: #fff; border-radius: 8px; padding: .75rem; box-shadow: var(--shadow); }
.metric b { font-family: var(--mono); font-size: 18px; display: block; }
.metric span { color: var(--muted); font-size: 13px; }

.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; }
.page-head h1 { margin: 0 0 .35rem; }
.cat-card-actions { display: flex; gap: .4rem; margin-top: .75rem; }
.cat-add { display: flex; flex-direction: column; justify-content: center; min-height: 140px; border: 1px dashed var(--outline); background: var(--surface-low); color: inherit; }
.cat-add:hover { background: var(--surface-container); color: inherit; }
.form-card input[type=color] { height: 40px; padding: 4px; width: 80px; }

.avatar-editor { margin-bottom: 1.25rem; padding-bottom: 1rem; border-bottom: 1px solid var(--surface-container); }
.avatar-editor-row { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.avatar-editor-preview .avatar { width: 88px; height: 88px; font-size: 28px; }
.crop-wrap { margin-top: .85rem; }
.crop-frame {
  width: 280px; height: 280px; max-width: 100%;
  position: relative; overflow: hidden; cursor: grab;
  border-radius: 12px; background: #0b1c30; touch-action: none;
  aspect-ratio: 1 / 1;
}
.crop-frame.is-drag { cursor: grabbing; }
.crop-frame img { position: absolute; max-width: none; user-select: none; pointer-events: none; }
.crop-tools { display: flex; align-items: center; gap: .45rem; margin-top: .6rem; flex-wrap: wrap; }
.crop-tools input[type=range] { width: 140px; }

.dropdown { position: relative; }
.dropdown-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 6px);
  background: #fff; border-radius: 8px; box-shadow: var(--shadow-lg); min-width: 180px; padding: .4rem; z-index: 60;
}
.dropdown.is-open .dropdown-menu { display: block; }
.dropdown-menu a, .dropdown-menu button {
  display: block; width: 100%; text-align: left; background: none; border: 0; padding: .45rem .6rem; border-radius: 6px; color: var(--text); cursor: pointer;
}
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--surface-low); }

@media (min-width: 768px) {
  .search-wrap { display: block; }
  [data-focus-search] { display: none; }
  .feed-head, .topic-row { grid-template-columns: 1fr 120px 56px 56px 72px; }
  .parts { display: flex; }
  .stat-pills { display: flex; }
  .metrics { grid-template-columns: repeat(3, 1fr); }
  .cards { grid-template-columns: repeat(3, 1fr); }
  .people-grid { grid-template-columns: repeat(2, 1fr); }
  .main { padding: 1.25rem 2rem 3rem; }
}

@media (min-width: 1024px) {
  .menu-toggle { display: none; }
  .sidebar { transform: none; }
  .shell { padding-left: var(--sidebar-w); }
  .top-nav { display: flex; }
  .metrics { grid-template-columns: repeat(5, 1fr); }
  .people-grid { grid-template-columns: repeat(3, 1fr); }
  --gutter: 1.5rem;
}

@media (max-width: 1023px) {
  .brand-name span { display: none; }
}
