:root {
  --bg: #f6f5f2;
  --card: #ffffff;
  --text: #1d1c1a;
  --muted: #74706a;
  --border: #e4e1db;
  --accent: #2f6b5a;
  --accent-soft: #e3efe9;
  --danger: #b3412f;
  --code-bg: #f0eee9;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171716;
    --card: #21201e;
    --text: #e9e6e0;
    --muted: #9b968e;
    --border: #34322e;
    --accent: #7cc2a9;
    --accent-soft: #24352f;
    --danger: #e3826f;
    --code-bg: #2b2a27;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0.4rem 0 1rem; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 1.6rem 0 0.6rem; }
.wrap { max-width: 900px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-bottom: 48px; }
.muted { color: var(--muted); font-size: 0.9em; }

/* Шапка */
.top { background: var(--card); border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.top-inner { display: flex; align-items: center; gap: 16px; min-height: 56px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.brand { font-weight: 700; font-size: 1.15rem; color: var(--text); display: flex; align-items: center; gap: 10px; }
.brand:hover { text-decoration: none; }
.brand img { height: 32px; width: auto; max-width: 96px; object-fit: contain; border-radius: 6px; }

/* Шапка главной */
.hero { display: flex; align-items: center; gap: 18px; margin: 8px 0 18px; }
.hero-logo { height: 72px; width: auto; max-width: 160px; object-fit: contain; border-radius: 12px; }
.hero-title { margin: 0; font-size: 1.9rem; }
.hero-tagline { margin: 4px 0 0; color: var(--muted); }
.welcome { padding: 14px 16px; margin-bottom: 8px; }
.login-brand { text-align: center; margin-bottom: 14px; }
.login-brand img { height: 64px; width: auto; max-width: 160px; object-fit: contain; border-radius: 12px; }
.login-name { font-weight: 700; font-size: 1.2rem; margin-top: 6px; }
.login-box h1 { font-size: 1.15rem; color: var(--muted); font-weight: 600; text-align: center; }
.top-search { flex: 1; min-width: 140px; }
.top-search input { width: 100%; }
.top-nav { display: flex; align-items: center; gap: 16px; }
.badge { background: var(--accent); color: var(--card); border-radius: 999px; padding: 0 7px; font-size: 0.8em; font-weight: 600; }
.menu { position: relative; }
.menu summary { cursor: pointer; list-style: none; color: var(--accent); }
.menu summary::-webkit-details-marker { display: none; }
.menu-body {
  position: absolute; right: 0; top: 130%; z-index: 5;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 14px; display: grid; gap: 6px; min-width: 170px;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.12);
}

/* Карточки и списки */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
.list { overflow: hidden; }
.row {
  display: flex; justify-content: space-between; gap: 16px; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid var(--border); color: var(--text);
}
.row:last-child { border-bottom: 0; }
a.row:hover { background: var(--accent-soft); text-decoration: none; }
.row-main { min-width: 0; }
.row-title { font-weight: 600; overflow-wrap: anywhere; }
.row.unread .row-title { color: var(--accent); }
.row-meta { display: flex; flex-direction: column; align-items: flex-end; white-space: nowrap; font-size: 0.85em; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 8px; vertical-align: middle; }
.tag { font-size: 0.8em; margin-right: 4px; font-weight: 400; }
.empty { padding: 20px; text-align: center; }
.empty p { margin: 4px 0; }
.snippet { font-size: 0.92em; margin: 2px 0; overflow-wrap: anywhere; }
.crumbs { font-size: 0.9em; color: var(--muted); margin-bottom: 4px; }
.head-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.head-row h1 { margin-bottom: 0.6rem; overflow-wrap: anywhere; }
.pager { display: flex; gap: 16px; justify-content: center; align-items: center; margin: 14px 0; font-size: 0.92em; color: var(--muted); }

/* Сообщения */
.post { padding: 14px 16px; margin-bottom: 12px; }
.mine-msg { border-left: 3px solid var(--accent); }
.post-head { display: flex; gap: 10px; flex-wrap: wrap; align-items: baseline; margin-bottom: 6px; }
.post-foot { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.post-actions { display: flex; gap: 14px; align-items: center; font-size: 0.9em; }
.post-actions form { margin: 0; }

.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 0.7em; }
.md blockquote { margin: 0 0 0.7em; padding: 4px 12px; border-left: 3px solid var(--border); color: var(--muted); }
.md code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }
.md pre { background: var(--code-bg); padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
.md pre code { padding: 0; background: none; }
.md img { max-width: 100%; height: auto; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 4px 8px; }

.atts { margin-top: 10px; }
.att-img { display: inline-block; margin: 0 6px 6px 0; }
.att-img img { max-width: 260px; max-height: 220px; border-radius: 8px; border: 1px solid var(--border); display: block; object-fit: cover; }
.att-files { list-style: none; padding: 0; margin: 4px 0 0; font-size: 0.92em; }
.att-files li { margin: 2px 0; overflow-wrap: anywhere; }

/* Реакции: пустые показываются при наведении на сообщение */
.reactions { display: flex; flex-wrap: wrap; gap: 4px; }
.react-form { margin: 0; }
.react {
  border: 1px solid var(--border); background: transparent; color: var(--text);
  border-radius: 999px; padding: 1px 9px; font-size: 0.95em; cursor: pointer; line-height: 1.6;
}
.react span { font-size: 0.85em; }
.react.mine { background: var(--accent-soft); border-color: var(--accent); }
.react-empty { display: none; }
.post:hover .react-empty, .post:focus-within .react-empty { display: block; }
@media (hover: none) { .react-empty { display: block; } .react-empty .react { opacity: 0.55; } }

/* Формы */
.form { padding: 16px; margin-top: 16px; }
.form h2 { margin-top: 0; }
.field { margin-bottom: 14px; }
.field > label { display: block; font-weight: 600; margin-bottom: 4px; font-size: 0.95em; }
.field ul { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; }
.field ul label { font-weight: 400; }
label.check { display: block; font-weight: 400; margin: 3px 0; }
input[type=text], input[type=password], input[type=search], textarea, select {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
select { width: auto; }
textarea { resize: vertical; min-height: 120px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.hint { display: block; color: var(--muted); font-size: 0.82em; margin-top: 4px; }
.err, .errors { color: var(--danger); font-size: 0.9em; }
.errors p { margin: 0 0 10px; }
.inline-form { display: flex; gap: 8px; margin-top: 0; }
.btn {
  display: inline-block; font: inherit; font-size: 0.95em; cursor: pointer;
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); text-decoration: none; white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--card); font-weight: 600; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-align: left; }
.danger-text { color: var(--danger); }

.mod { padding: 8px 14px; margin-bottom: 12px; font-size: 0.92em; }
.mod summary { cursor: pointer; color: var(--muted); }
.mod-body { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.mod-body form { display: flex; gap: 6px; margin: 0; }

.flash { list-style: none; padding: 0; margin: 0 0 14px; }
.flash li { padding: 10px 14px; border-radius: 8px; background: var(--accent-soft); margin-bottom: 6px; }
.flash .flash-error { background: transparent; border: 1px solid var(--danger); color: var(--danger); }

.login-box, .narrow { max-width: 380px; margin: 12vh auto 0; padding: 22px; }
.narrow { margin-top: 20px; }
.login-box label { display: block; margin-bottom: 12px; font-weight: 600; font-size: 0.95em; }
.login-box input { margin-top: 4px; }
.login-box .btn { width: 100%; margin-top: 4px; }

@media (max-width: 560px) {
  .row { flex-direction: column; align-items: flex-start; gap: 4px; }
  .row-meta { flex-direction: row; gap: 10px; align-items: flex-start; }
  .top-nav { gap: 12px; font-size: 0.95em; }
  h1 { font-size: 1.35rem; }
  .att-img img { max-width: 100%; }
  .hero-logo { height: 52px; }
  .hero-title { font-size: 1.45rem; }
  .brand img + span { display: none; }
}
