:root {
  --bg: #eef1f4;
  --panel: #ffffff;
  --panel2: #f8fafc;
  --border: #d9dde3;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --danger: #dc2626;
  --success: #16a34a;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.forum-wrap { min-height: 100vh; display: flex; flex-direction: column; }

.forum-header {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.forum-brand { display: flex; align-items: center; gap: 12px; }
.forum-logo { font-weight: 900; font-size: 18px; color: var(--text); }
.forum-links { display: flex; gap: 10px; }
.forum-link { color: var(--muted); font-size: 14px; }
.forum-link:hover { color: var(--text); }

.forum-userbox { display: flex; align-items: center; gap: 10px; }
.forum-userbox .user { display: flex; gap: 10px; align-items: center; padding: 6px 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel2); }
.forum-userbox .ava { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; background: #fff; }
.forum-userbox .meta { display: flex; flex-direction: column; }
.forum-userbox .login { font-weight: 800; }
.forum-userbox .sub { display: flex; gap: 6px; flex-wrap: wrap; }
.forum-userbox .tag { font-size: 12px; color: var(--muted); }

.actions { display: flex; gap: 8px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { border-color: rgba(169,123,255,0.6); }
.btn.primary { background: rgba(169,123,255,0.15); border-color: rgba(169,123,255,0.45); }
.btn.danger { background: rgba(255,77,79,0.15); border-color: rgba(255,77,79,0.45); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.forum-main { width: min(1100px, 100%); margin: 0 auto; padding: 16px; flex: 1; }

.forum-alert {
  width: min(1100px, 100%);
  margin: 12px auto 0;
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(17,24,39,0.04);
}
.forum-alert.danger { border-color: rgba(255,77,79,0.45); background: rgba(255,77,79,0.09); }
.forum-alert.success { border-color: rgba(46,204,113,0.45); background: rgba(46,204,113,0.10); }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 14px;
}

.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card-title { font-size: 18px; font-weight: 900; }
.card-sub { font-size: 13px; color: var(--muted); }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { color: var(--muted); font-size: 13px; text-align: left; font-weight: 700; }
.table td { font-size: 14px; }

.row-actions { display: flex; gap: 8px; justify-content: flex-end; }

.muted { color: var(--muted); }
.small { font-size: 12px; color: var(--muted); }

.topic-title { font-weight: 900; color: var(--text); }
.topic-meta { color: var(--muted); font-size: 12px; }

.post {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 12px;
}
@media (max-width: 780px) {
  .post { grid-template-columns: 1fr; }
}
.post-left {
  border-right: 1px solid var(--border);
  padding-right: 12px;
}
@media (max-width: 780px) {
  .post-left { border-right: none; border-bottom: 1px solid var(--border); padding-right: 0; padding-bottom: 12px; }
}
.post-user { display: flex; align-items: center; gap: 10px; }
.post-user img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: #fff; }
.post-user .name { font-weight: 900; }
.post-user .rank { color: var(--muted); font-size: 12px; }

.post-right { min-width: 0; }
.post-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.post-id { color: var(--muted); font-size: 12px; }
.post-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.post-body { line-height: 1.55; word-break: break-word; }
.post-body img.bbcode-img { max-width: 100%; border-radius: 12px; border: 1px solid var(--border); }

.bbcode-quote { margin: 10px 0; padding: 10px; border-left: 3px solid rgba(169,123,255,0.6); background: rgba(17,24,39,0.04); border-radius: 12px; }
.bbcode-quote-head { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.bbcode-code { padding: 10px; background: rgba(0,0,0,0.25); border-radius: 12px; border: 1px solid var(--border); overflow: auto; }

.forum-editor { display: flex; flex-direction: column; gap: 10px; }
.forum-editor textarea {
  width: 100%;
  min-height: 170px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  resize: vertical;
}
.forum-editor input[type="text"], .forum-editor select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
}

.editor-toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
.tool { padding: 8px 10px; border-radius: 12px; border: 1px solid var(--border); background: rgba(17,24,39,0.03); color: var(--text); font-weight: 800; font-size: 13px; cursor: pointer; }
.tool:hover { border-color: rgba(169,123,255,0.6); }

.forum-pagination { display: flex; gap: 6px; align-items: center; justify-content: center; margin: 16px 0 6px; }
.forum-pagination a { padding: 8px 10px; border: 1px solid var(--border); border-radius: 12px; color: var(--text); }
.forum-pagination a.active { border-color: rgba(169,123,255,0.6); background: rgba(169,123,255,0.12); }
.forum-pagination .dots { color: var(--muted); padding: 0 6px; }

.forum-reactions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.react-btn {
  border: 1px solid var(--border);
  background: rgba(17,24,39,0.03);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 10px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.react-btn .emo { font-size: 18px; line-height: 1; }
.react-btn .cnt { color: var(--muted); font-weight: 900; }
.react-btn.active { border-color: rgba(169,123,255,0.6); background: rgba(169,123,255,0.12); }

.forum-footer { width: min(1100px, 100%); margin: 0 auto; padding: 18px 16px 26px; border-top: 1px solid var(--border); }

.form-row { display: flex; gap: 12px; align-items: center; }
.form-row > * { flex: 1; }

hr.sep { border: none; border-top: 1px solid var(--border); margin: 14px 0; }

.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .admin-grid { grid-template-columns: 1fr; } }

.checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(17,24,39,0.03);
}

/* --- Жёсткая изоляция от внешних стилей проекта --- */
.forum-root .post-body {
  display: block !important;
  color: var(--text) !important;
  font-size: 14px !important;
  line-height: 1.55;
  min-height: 1em;
  word-break: break-word;
}
.forum-root .post-body * { color: inherit; }

/* --- Аватары в постах: ограничиваем размер (в игре могут быть большие "плашки") --- */
.forum-root .post-left img.ava {
  width: 120px;
  max-width: 100%;
  height: auto;
  max-height: 90px;
  object-fit: contain;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(17,24,39,0.03);
}
@media (max-width: 780px) {
  .forum-root .post-left img.ava {
    width: 100px;
    max-height: 76px;
  }
}

/* --- Совместимость с разметкой форума (forum-card/forum-head/...) --- */
.forum-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 14px;
}
.forum-card.inner { background: rgba(17,24,39,0.02); }

.forum-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.forum-head h1 { margin: 4px 0 0; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { color: var(--muted); }
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(17,24,39,0.03);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-top: 6px;
}

.forum-list { display: flex; flex-direction: column; gap: 10px; }
.forum-list .row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(17,24,39,0.02);
}
@media (max-width: 780px){
  .forum-list .row { flex-direction: column; }
}
.forum-list .title { font-weight: 900; color: var(--text); }
.forum-list .meta { text-align: right; font-size: 13px; color: var(--muted); }
@media (max-width: 780px){
  .forum-list .meta { text-align: left; }
}
.empty { padding: 14px; color: var(--muted); }

.forum-form { display: flex; flex-direction: column; gap: 12px; }
.forum-form label { display: flex; flex-direction: column; gap: 6px; }
.forum-form label > span { font-size: 13px; color: var(--muted); font-weight: 700; }
.forum-form input[type="text"],
.forum-form input[type="password"],
.forum-form textarea {
  width: 100%;
  padding: 11px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
}
.forum-form textarea { resize: vertical; min-height: 140px; line-height: 1.55; }
.hint { font-size: 12px; color: var(--muted); }

.bb-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(17,24,39,0.02);
}
.bb-toolbar button {
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(17,24,39,0.03);
  color: var(--text);
  font-weight: 900;
  font-size: 13px;
  cursor: pointer;
}
.bb-toolbar button:hover { border-color: rgba(169,123,255,0.6); }
.bb-toolbar button:disabled { opacity: .5; cursor: not-allowed; }

.post-body { line-height: 1.55; word-break: break-word; }
.post-body img.bbcode-img { max-width: 100%; border-radius: 12px; border: 1px solid var(--border); }

.post-signature {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
  color: var(--muted);
  font-size: 13px;
}

.post.highlight { outline: 2px solid rgba(169,123,255,0.55); border-radius: 16px; }

/* Профиль */
.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px){ .profile-grid { grid-template-columns: 1fr; } }
.profile-box { display: flex; gap: 12px; align-items: center; }
.ava.big { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; background: #fff; }
.login.big { font-size: 18px; font-weight: 900; }
.profile-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin-top: 12px; }
.stat { padding: 12px; border: 1px solid var(--border); border-radius: 16px; background: rgba(17,24,39,0.02); }
.stat span { display:block; font-size: 12px; color: var(--muted); }
.stat b { font-size: 18px; }
.profile-perms ul { margin: 8px 0 0; padding-left: 18px; }




.post-body img.bbcode-img{
  display:block;
  width:auto;
  height:auto;
  max-width: min(100%, 560px);
  max-height: 380px;
  margin:10px 0;
  border-radius:12px;
  border:1px solid rgba(255,255,255,.10);
  object-fit: contain;
  cursor: zoom-in;
}


@media (max-width:520px){
  .forum-main{ padding: 10px; }
  .forum-card{ padding: 12px; border-radius: 14px; }
  .forum-head{ gap:10px; }
  .head-actions{ width:100%; justify-content:flex-start; flex-wrap:wrap; }
  .forum-header{ flex-wrap:wrap; gap:10px; }
  .forum-links{ width:100%; justify-content:center; order:3; flex-wrap:wrap; }
  .forum-userbox{ width:100%; justify-content:center; order:2; flex-wrap:wrap; }
  .post-left{ display:flex; align-items:center; gap:12px; padding:10px; }
  .post-left .u{ text-align:left; }
  .ava{ width:64px; height:64px; }
  .forum-avatar{ width:30px; height:30px; }
  .post-right{ padding:10px; }
  .post-head{ flex-wrap:wrap; gap:8px; }
  .post-actions{ width:100%; justify-content:flex-start; flex-wrap:wrap; }
  .post-body img.bbcode-img{ max-width:100%; max-height:260px; }
  textarea{ min-height:140px; }
}


/* --- Light theme fine-tuning --- */
body { background: var(--bg); color: var(--text); }
a { color: var(--accent); }
a:hover { opacity: .9; }
.forum-card { background: var(--panel); border: 1px solid var(--border); }
.forum-card.inner { background: var(--panel2); border: 1px solid var(--border); }
.forum-header { background: var(--panel); border-bottom: 1px solid var(--border); }
.forum-logo { color: var(--text); }
.forum-link { color: var(--muted); }
.forum-link:hover { color: var(--text); }

/* list rows with thumbnails */
.row-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.row-main { min-width: 0; }
.row-thumb { width: 56px; height: 56px; border-radius: 14px; overflow: hidden; border: 1px solid var(--border); background: #fff; flex: 0 0 auto; }
.row-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* covers in headers */
.head-left { display: flex; gap: 14px; align-items: center; min-width: 0; }
.head-text { min-width: 0; }
.cover { width: 70px; height: 70px; border-radius: 18px; overflow: hidden; border: 1px solid var(--border); background: #fff; object-fit: cover; display: block; }
@media (max-width: 520px){
  .cover { width: 54px; height: 54px; border-radius: 16px; }
  .row-thumb { width: 48px; height: 48px; border-radius: 12px; }
}

/* post images: constrain size in view */
.post-body img { 
  max-width: min(100%, 640px);
  max-height: 420px;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #fff;
  margin: 10px 0;
}
@media (max-width: 520px){
  .post-body img { max-height: 280px; border-radius: 12px; }
}

/* avatar sizing */
img.ava { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border); background: #fff; }
.post-left img.ava { width: 44px; height: 44px; }

/* responsive improvements */
@media (max-width: 780px){
  .forum-head { flex-direction: column; align-items: stretch; }
  .head-actions { justify-content: flex-start; }
}
@media (max-width: 520px){
  .forum-wrap { padding: 10px; }
  .btn { padding: 8px 10px; }
  .btn.small { padding: 6px 8px; }
  .bb-toolbar { flex-wrap: wrap; }
}

/* grid helper (used in admin/categories.php and new_topic.php) */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 780px){ .grid-2 { grid-template-columns: 1fr; } }

/* reactions look */
.reaction-btn { font-size: 18px; line-height: 1; }
