/* ---------- Tokens ---------- */
:root {
  --bg: #0f1115;
  --bg-elev: #161a22;
  --bg-elev-2: #1d2230;
  --border: #2a2f3d;
  --text: #e8eaed;
  --text-muted: #9aa3b2;
  --primary: #5b8def;
  --primary-hover: #4477e0;
  --danger: #e85d5d;
  --warn: #f0b86b;
  --success: #5dd28d;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 12px rgba(0,0,0,0.4);
  --max-w: 1100px;
}

[data-theme="light"] {
  --bg: #f5f7fb;
  --bg-elev: #ffffff;
  --bg-elev-2: #eef1f6;
  --border: #d8dde6;
  --text: #1a1d24;
  --text-muted: #5a6473;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; display: block; }

/* ---------- Topbar ---------- */
.topbar {
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 700;
  font-size: 18px;
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.topnav {
  display: flex;
  gap: 4px;
  flex: 1;
}
.topnav a {
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 14px;
}
.topnav a:hover { background: var(--bg-elev-2); color: var(--text); text-decoration: none; }
.topnav a.active { color: var(--primary); background: var(--bg-elev-2); }

.user-menu { position: relative; display: flex; align-items: center; gap: 8px; }

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  transition: background 0.15s, color 0.15s;
}
.theme-toggle:hover { background: var(--bg-elev-2); color: var(--text); }

/* Welches Icon ist sichtbar */
[data-theme="dark"] .icon-sun  { display: block; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun  { display: none; }
[data-theme="light"] .icon-moon { display: block; }
.user-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  cursor: pointer;
  color: var(--text);
  font-size: 14px;
}
.user-toggle:hover { background: var(--bg-elev-2); }
.dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 200px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 200;
}
.dropdown a {
  display: block;
  padding: 8px 12px;
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.dropdown a:hover { background: var(--bg-elev-2); text-decoration: none; }
.dropdown hr { margin: 6px 0; border: none; border-top: 1px solid var(--border); }

.dropdown-quota { padding: 8px 12px; }
.dropdown-quota-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); margin-bottom: 5px; }

.quota-bar-wrap { background: var(--bg-elev-2); border-radius: 4px; height: 5px; overflow: hidden; border: 1px solid var(--border); }
.quota-bar { height: 100%; background: var(--primary); border-radius: 4px; transition: width 0.3s; min-width: 2px; }
.quota-bar-warn { background: var(--warn); }

/* ---------- Layout ---------- */
.main-content {
  flex: 1;
  max-width: var(--max-w);
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px 40px;
}
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-header h1 { margin: 0; font-size: 24px; }

.footer {
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  padding: 16px 0;
}
.footer-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  justify-content: space-between;
  color: var(--text-muted);
  font-size: 13px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
}
.btn:hover { background: var(--bg-elev); text-decoration: none; }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: #d04848; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-block { width: 100%; }

.btn-link-danger {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 13px;
  padding: 0;
}
.btn-link-danger:hover { text-decoration: underline; }

.btn-icon {
  background: rgba(0,0,0,0.7);
  color: white;
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}

/* ---------- Forms ---------- */
.form-box {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.form-box label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}
.form-box label.checkbox {
  flex-direction: row;
  align-items: center;
  color: var(--text);
}
.form-box small { font-size: 12px; color: var(--text-muted); font-weight: normal; }

input[type=text], input[type=email], input[type=password], input[type=search],
input[type=file], textarea, select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91, 141, 239, 0.2);
}
textarea { resize: vertical; min-height: 80px; }

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

.inline-form { display: inline-block; margin: 0; }

/* ---------- Auth ---------- */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  background: linear-gradient(135deg, #0f1115 0%, #1a1f2e 100%);
}
.auth-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  max-width: 400px;
  width: 100%;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 4px; font-size: 24px; }
.auth-sub { color: var(--text-muted); margin: 0 0 24px; font-size: 14px; }
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-muted); font-weight: 500; }
.auth-alt { text-align: center; margin-top: 20px; font-size: 14px; color: var(--text-muted); }
.checkbox-label { flex-direction: row !important; align-items: center; gap: 10px !important; cursor: pointer; color: var(--text) !important; font-weight: 400 !important; }
.checkbox-label input[type="checkbox"] { width: 16px; height: 16px; flex-shrink: 0; accent-color: var(--primary); cursor: pointer; }

/* ---------- Flash ---------- */
.flash-container {
  max-width: var(--max-w);
  margin: 16px auto 0;
  padding: 0 16px;
}
.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  font-size: 14px;
  border: 1px solid;
}
.flash-success { background: rgba(93,210,141,0.1); border-color: var(--success); color: var(--success); }
.flash-error   { background: rgba(232,93,93,0.1);  border-color: var(--danger);  color: var(--danger); }
.flash-warn    { background: rgba(240,184,107,0.1); border-color: var(--warn);   color: var(--warn); }

/* ---------- Avatars ---------- */
.avatar-sm { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.avatar-md { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; }
.avatar-xl { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; }

/* ---------- Threads / Forum ---------- */
.thread-list { display: flex; flex-direction: column; gap: 12px; }
.thread-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  gap: 16px;
  transition: border-color 0.15s;
}
.thread-card:hover { border-color: var(--primary); }
.thread-card.pinned { border-left: 3px solid var(--warn); }
.thread-thumb {
  flex-shrink: 0;
  width: 100px;
  height: 100px;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.thread-thumb img { width: 100%; height: 100%; object-fit: contain; background: var(--bg-elev-2); }
.thread-body { flex: 1; min-width: 0; }
.thread-meta-top {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.username { color: var(--text); font-weight: 500; }
.thread-title { margin: 0 0 6px; font-size: 17px; }
.thread-title a { color: var(--text); }
.thread-title a:hover { color: var(--primary); }
.thread-excerpt { color: var(--text-muted); margin: 0 0 8px; font-size: 14px; }
.thread-meta-bottom {
  display: flex;
  gap: 14px;
  font-size: 13px;
  color: var(--text-muted);
}

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--bg-elev-2);
  color: var(--text-muted);
}
.badge-pin { background: rgba(240,184,107,0.15); color: var(--warn); }

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

.thread-card-mini {
  display: flex;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

/* ---------- Thread Detail ---------- */
.thread-detail {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
}
.thread-detail-header { margin-bottom: 16px; }
.back-link { font-size: 13px; color: var(--text-muted); display: inline-block; margin-bottom: 8px; }
.thread-detail h1 { margin: 0 0 12px; font-size: 24px; }
.meta-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.thread-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.thread-content {
  font-size: 15px;
  line-height: 1.7;
  margin: 16px 0;
}
.thread-content h2, .thread-content h3, .thread-content h4 { margin-top: 1em; }
.thread-content code {
  background: var(--bg-elev-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}
.thread-content pre {
  background: var(--bg-elev-2);
  padding: 12px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
}
.thread-content blockquote {
  border-left: 3px solid var(--primary);
  margin: 8px 0;
  padding: 4px 12px;
  color: var(--text-muted);
}

.image-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}
.image-gallery img {
  aspect-ratio: 1;
  object-fit: contain;
  border-radius: var(--radius-sm);
  cursor: zoom-in;
  background: var(--bg-elev-2);
}

/* ---------- Likes ---------- */
.like-bar { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.like-btn, .like-btn-sm {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}
.like-btn:hover, .like-btn-sm:hover { border-color: var(--primary); }
.like-btn.liked, .like-btn-sm.liked {
  background: rgba(91,141,239,0.15);
  border-color: var(--primary);
  color: var(--primary);
}
.like-btn-sm { padding: 3px 10px; font-size: 12px; }

/* ---------- Comments ---------- */
.comments-section { margin-top: 24px; }
.comments-section h2 { font-size: 18px; margin-bottom: 16px; }
.comment {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  animation: slideIn 0.3s ease;
}
@keyframes slideIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.comment-body { flex: 1; min-width: 0; }
.comment-head { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }
.comment-content { font-size: 14px; line-height: 1.5; }
.comment-actions { margin-top: 6px; display: flex; gap: 12px; align-items: center; }

.comment-form {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-top: 16px;
}
.comment-form textarea {
  border: none;
  background: transparent;
  resize: vertical;
  margin-bottom: 8px;
}
.comment-form textarea:focus { box-shadow: none; }

.comment-img-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  transition: background 0.15s;
}
.comment-img-label:hover { background: var(--bg-elev-2); color: var(--text); }
.comment-img-label input[type="file"] { display: none; }

.comment-img-preview { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.comment-img-preview img { width: 64px; height: 64px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); }

.comment-images { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.comment-images img { max-width: 200px; max-height: 200px; object-fit: contain; border-radius: var(--radius-sm); background: var(--bg-elev-2); cursor: zoom-in; border: 1px solid var(--border); }

/* Thread-Edit */
.edit-images-section { margin-bottom: 16px; }
.label-text { font-size: 13px; color: var(--text-muted); font-weight: 500; margin-bottom: 8px; }
.edit-images-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.edit-img-item { position: relative; display: inline-block; }
.edit-img-item img { width: 100px; height: 100px; object-fit: contain; border-radius: var(--radius-sm); background: var(--bg-elev-2); border: 1px solid var(--border); display: block; }
.edit-img-delete-btn { position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; border-radius: 50%; background: var(--danger); color: #fff; border: none; cursor: pointer; font-size: 14px; line-height: 1; display: flex; align-items: center; justify-content: center; padding: 0; }

/* ---------- Profile ---------- */
.profile-header {
  display: flex;
  gap: 24px;
  align-items: flex-start;
  background: var(--bg-elev);
  padding: 24px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.profile-header h1 { margin: 0 0 4px; }
.role-badge {
  font-size: 11px;
  background: var(--primary);
  color: white;
  padding: 2px 8px;
  border-radius: 10px;
  vertical-align: middle;
}
.bio { margin: 12px 0; color: var(--text); }
.stat-row { display: flex; gap: 24px; margin-top: 8px; color: var(--text-muted); }

/* ---------- Settings ---------- */
.settings-layout { display: grid; grid-template-columns: 200px 1fr; gap: 24px; }
.settings-nav { display: flex; flex-direction: column; gap: 4px; }
.settings-nav a {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}
.settings-nav a.active, .settings-nav a:hover {
  background: var(--bg-elev);
  color: var(--text);
  text-decoration: none;
}
.settings-content { background: var(--bg-elev); padding: 24px; border-radius: var(--radius); border: 1px solid var(--border); }
.settings-content h2 { margin-top: 0; }
.avatar-current { display: flex; justify-content: center; margin-bottom: 16px; }
.danger-zone { border-color: var(--danger); }
.danger-zone summary { color: var(--danger); }

/* ---------- Galleries ---------- */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.gallery-tile {
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.15s, border-color 0.15s;
}
.gallery-tile:hover { transform: translateY(-2px); border-color: var(--primary); text-decoration: none; }
.gallery-tile img { aspect-ratio: 4/3; object-fit: contain; width: 100%; background: var(--bg-elev-2); }
.gallery-placeholder {
  aspect-ratio: 4/3;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elev-2);
  font-size: 48px;
}
.gallery-info { padding: 12px; }
.gallery-info h3 { margin: 0 0 4px; font-size: 15px; }

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
}
.image-tile { position: relative; }
.image-tile img {
  aspect-ratio: 1;
  object-fit: contain;
  width: 100%;
  border-radius: var(--radius-sm);
  cursor: zoom-in;
  background: var(--bg-elev-2);
}
.img-delete {
  position: absolute;
  top: 4px;
  right: 4px;
}

/* ---------- Search ---------- */
.search-form { display: flex; gap: 8px; margin-bottom: 24px; }
.search-form input { flex: 1; }
.search-results { display: flex; flex-direction: column; gap: 12px; }
.search-hit {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.search-hit h3 { margin: 4px 0; font-size: 16px; }
.hit-type { font-size: 12px; color: var(--text-muted); }
.hit-body mark, .search-hit mark {
  background: rgba(240,184,107,0.3);
  color: var(--text);
  padding: 0 2px;
  border-radius: 2px;
}

/* ---------- Admin ---------- */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.stat-card strong { display: block; font-size: 24px; }
.stat-card span { color: var(--text-muted); font-size: 13px; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-elev);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  font-size: 14px;
}
.data-table th, .data-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { background: var(--bg-elev-2); font-weight: 600; font-size: 13px; }
.data-table tr.banned { opacity: 0.5; }
.data-table .quota-bar-wrap { width: 120px; margin-bottom: 3px; height: 6px; }

/* ---------- Pagination ---------- */
.pagination { display: flex; gap: 4px; justify-content: center; margin-top: 24px; }
.pagination a {
  padding: 6px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}
.pagination a.active { background: var(--primary); color: white; border-color: var(--primary); }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  background: var(--bg-elev);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  cursor: zoom-out;
}
.lightbox img { max-width: 95vw; max-height: 95vh; object-fit: contain; }
.lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(0,0,0,0.6);
  color: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 24px;
  cursor: pointer;
}
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,0.6);
  color: white;
  border: none;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  font-size: 28px;
  cursor: pointer;
}
.lightbox-nav.prev { left: 20px; }
.lightbox-nav.next { right: 20px; }

/* ---------- Mobile ---------- */
@media (max-width: 768px) {
  .topbar-inner { gap: 8px; padding: 10px 12px; }
  .brand span { display: none; }
  .topnav { gap: 0; flex-wrap: wrap; }
  .topnav a { padding: 6px 8px; font-size: 13px; }
  .user-toggle span { display: none; }

  .main-content { padding: 16px 12px 32px; }
  .page-header h1 { font-size: 20px; }

  .thread-card { flex-direction: column; }
  .thread-thumb { width: 100%; height: 140px; }

  .settings-layout { grid-template-columns: 1fr; }
  .settings-nav { flex-direction: row; flex-wrap: wrap; overflow-x: auto; padding-bottom: 4px; }

  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 6px; }

  .stat-row { flex-direction: column; gap: 4px; }

  .thread-actions { width: 100%; }
}
