/* ========================================
   CNWebAI Community Forum Styles
   Modern social-media style, responsive
   ======================================== */

/* ── CSS Variables ── */
:root {
  --primary: #409eff;
  --primary-light: #66b1ff;
  --primary-dark: #3a8ee6;
  --primary-bg: rgba(64, 158, 255, 0.08);
  --success: #67c23a;
  --warning: #e6a23c;
  --danger: #f56c6c;
  --info: #909399;
  --bg: #f5f7fa;
  --bg-card: #ffffff;
  --border: #e4e7ed;
  --border-light: #ebeef5;
  --text: #303133;
  --text-secondary: #606266;
  --text-muted: #909399;
  --text-placeholder: #c0c4cc;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  --shadow-hover: 0 4px 20px rgba(0, 0, 0, 0.1);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans SC', sans-serif;
  --max-width: 900px;
  --header-height: 60px;
  --transition: all 0.2s ease;
}

/* ── Reset ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: var(--transition);
}
a:hover {
  color: var(--primary-light);
}

img {
  max-width: 100%;
  height: auto;
}

/* ── Top Navigation ── */
.top-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #fff;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
  height: var(--header-height);
}

.nav-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 20px;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
}

.nav-logo {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.nav-logo span {
  color: var(--primary);
}
.nav-logo:hover {
  color: var(--text);
}

.nav-search {
  flex: 1;
  max-width: 320px;
  position: relative;
}
.nav-search input {
  width: 100%;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 0 16px 0 36px;
  font-size: 0.875rem;
  background: var(--bg);
  transition: var(--transition);
  outline: none;
}
.nav-search input:focus {
  border-color: var(--primary);
  background: #fff;
}
.nav-search .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.875rem;
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  white-space: nowrap;
}

.nav-user .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  color: var(--primary);
  font-weight: 600;
  overflow: hidden;
}
.nav-user .avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
  background: none;
  font-family: inherit;
  white-space: nowrap;
}
.btn:active {
  transform: scale(0.97);
}
.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover {
  background: var(--primary-light);
  border-color: var(--primary-light);
}
.btn-outline {
  border-color: var(--border);
  color: var(--text-secondary);
}
.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.btn-text {
  color: var(--text-secondary);
  padding: 4px 8px;
}
.btn-text:hover {
  color: var(--primary);
  background: var(--primary-bg);
}
.btn-sm {
  padding: 4px 10px;
  font-size: 0.8125rem;
}
.btn-lg {
  padding: 10px 24px;
  font-size: 1rem;
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  opacity: 0.85;
}
.btn-block {
  width: 100%;
  justify-content: center;
}

/* ── Main Container ── */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 20px;
}

/* ── Page Header ── */
.page-header {
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
}
.page-header .desc {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 4px;
}

/* ── Category Grid (Home) ── */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}

.category-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: flex-start;
  gap: 14px;
}
.category-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}
.category-card .cat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}
.category-card .cat-info h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 2px;
}
.category-card .cat-info p {
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.4;
}
.category-card .cat-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ── Thread List ── */
.section-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.thread-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border-light);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border-light);
}

.thread-item {
  background: var(--bg-card);
  padding: 14px 18px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  transition: var(--transition);
  cursor: pointer;
}
.thread-item:hover {
  background: var(--primary-bg);
}
.thread-item.pinned {
  border-left: 3px solid var(--warning);
}
.thread-item.essence {
  border-left: 3px solid var(--danger);
}

.thread-main {
  flex: 1;
  min-width: 0;
}
.thread-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 4px;
  line-height: 1.4;
}
.thread-title a {
  color: var(--text);
}
.thread-title a:hover {
  color: var(--primary);
}
.thread-title .badge {
  display: inline-block;
  font-size: 0.6875rem;
  padding: 1px 6px;
  border-radius: 3px;
  margin-left: 4px;
  vertical-align: middle;
  font-weight: 500;
}
.badge-pin {
  background: #fdf6ec;
  color: var(--warning);
}
.badge-essence {
  background: #fef0f0;
  color: var(--danger);
}
.badge-hot {
  background: #fef0f0;
  color: var(--danger);
}
.badge-closed {
  background: var(--bg);
  color: var(--text-muted);
}
.badge-category {
  background: var(--primary-bg);
  color: var(--primary);
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 10px;
}

.thread-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}
.thread-meta .sep {
  color: var(--border);
}

.thread-stats {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-align: right;
}
.thread-stats .stat-item {
  display: flex;
  align-items: center;
  gap: 3px;
}

/* ── Sort Bar ── */
.sort-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.sort-btn {
  padding: 6px 14px;
  border-radius: 16px;
  font-size: 0.8125rem;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-secondary);
  font-family: inherit;
}
.sort-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.sort-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ── Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin: 24px 0;
}
.page-btn {
  min-width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-secondary);
  padding: 0 8px;
  font-family: inherit;
}
.page-btn:hover:not(.active):not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
}
.page-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Thread Detail Page ── */
.thread-detail {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px;
  margin-bottom: 16px;
}

.thread-detail .thread-title-lg {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 8px;
  line-height: 1.4;
}

.thread-detail .thread-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.thread-info .user-avatar-s {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: var(--primary);
  font-weight: 600;
}

.thread-content {
  font-size: 0.9375rem;
  line-height: 1.75;
  color: var(--text);
  padding: 16px 0;
  border-top: 1px solid var(--border-light);
  border-bottom: 1px solid var(--border-light);
  min-height: 100px;
  overflow-wrap: break-word;
}

/* Markdown rendering in content */
.thread-content h1, .thread-content h2, .thread-content h3 {
  margin: 16px 0 8px;
  font-weight: 600;
}
.thread-content h1 { font-size: 1.3rem; }
.thread-content h2 { font-size: 1.15rem; }
.thread-content h3 { font-size: 1.05rem; }
.thread-content p {
  margin: 8px 0;
}
.thread-content ul, .thread-content ol {
  margin: 8px 0;
  padding-left: 20px;
}
.thread-content li {
  margin: 4px 0;
}
.thread-content blockquote {
  border-left: 3px solid var(--primary);
  margin: 12px 0;
  padding: 8px 16px;
  background: var(--primary-bg);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.thread-content code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.85em;
  font-family: 'Fira Code', 'Consolas', monospace;
}
.thread-content pre {
  background: #282c34;
  color: #abb2bf;
  padding: 16px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 12px 0;
  font-size: 0.85rem;
  line-height: 1.5;
}
.thread-content pre code {
  background: none;
  padding: 0;
  color: inherit;
}
.thread-content img {
  border-radius: var(--radius-sm);
  margin: 8px 0;
}
.thread-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
}
.thread-content th, .thread-content td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.thread-content th {
  background: var(--bg);
  font-weight: 600;
}

/* ── Thread Actions ── */
.thread-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 12px;
  flex-wrap: wrap;
}
.thread-actions .action-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 0.8125rem;
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-secondary);
  font-family: inherit;
}
.thread-actions .action-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.thread-actions .action-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ── Replies ── */
.reply-section {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px 24px;
  margin-bottom: 16px;
}
.reply-section h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
}

.reply-item {
  display: flex;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border-light);
}
.reply-item:last-child {
  border-bottom: none;
}

.reply-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8125rem;
  color: var(--primary);
  font-weight: 600;
  flex-shrink: 0;
}

.reply-body {
  flex: 1;
  min-width: 0;
}
.reply-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}
.reply-header .reply-username {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}
.reply-header .reply-time {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.reply-content {
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text-secondary);
  overflow-wrap: break-word;
}

.reply-actions {
  display: flex;
  gap: 12px;
  margin-top: 6px;
}
.reply-actions button {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  transition: var(--transition);
  font-family: inherit;
}
.reply-actions button:hover {
  color: var(--primary);
}
.reply-actions button.active {
  color: var(--primary);
}

/* ── Reply Editor ── */
.reply-editor {
  margin-top: 16px;
}
.reply-editor textarea {
  width: 100%;
  min-height: 100px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 0.875rem;
  font-family: inherit;
  resize: vertical;
  transition: var(--transition);
  outline: none;
}
.reply-editor textarea:focus {
  border-color: var(--primary);
}
.reply-editor .editor-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

/* ── Create Page ── */
.create-form {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px;
  max-width: 700px;
}

.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}
.form-group .required::after {
  content: ' *';
  color: var(--danger);
}

.form-group select,
.form-group input[type="text"],
.form-group textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-family: inherit;
  transition: var(--transition);
  outline: none;
  background: #fff;
}
.form-group select:focus,
.form-group input:focus,
.form-group textarea:focus {
  border-color: var(--primary);
}
.form-group textarea {
  resize: vertical;
  min-height: 240px;
  line-height: 1.6;
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ── Login Page ── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--header-height) - 80px);
}
.login-card {
  background: #fff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}
.login-card h2 {
  text-align: center;
  margin-bottom: 8px;
  font-size: 1.3rem;
}
.login-card p {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 24px;
}

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state .empty-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}
.empty-state p {
  font-size: 0.9375rem;
}

/* ── Toast ── */
.toast-container {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.toast {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  box-shadow: var(--shadow-hover);
  animation: toastIn 0.3s ease;
  max-width: 400px;
  text-align: center;
}
.toast-success { background: #f0f9eb; color: #67c23a; border: 1px solid #e1f3d8; }
.toast-error { background: #fef0f0; color: #f56c6c; border: 1px solid #fde2e2; }
.toast-warning { background: #fdf6ec; color: #e6a23c; border: 1px solid #faecd8; }
.toast-info { background: #f4f4f5; color: #909399; border: 1px solid #e9e9eb; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Loading ── */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}
.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Back Link ── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 16px;
  transition: var(--transition);
}
.back-link:hover {
  color: var(--primary);
}

/* ── Tags ── */
.tag-list {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--primary-bg);
  color: var(--primary);
  font-size: 0.75rem;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .nav-inner {
    padding: 0 12px;
    gap: 8px;
  }
  .nav-search {
    max-width: 200px;
  }
  .nav-search input {
    font-size: 0.8125rem;
  }
  .container {
    padding: 12px;
  }
  .category-grid {
    grid-template-columns: 1fr 1fr;
  }
  .thread-item {
    padding: 10px 12px;
    flex-direction: column;
  }
  .thread-stats {
    flex-direction: row;
    gap: 8px;
    margin-top: 4px;
  }
  .thread-detail {
    padding: 16px;
  }
  .thread-detail .thread-title-lg {
    font-size: 1.2rem;
  }
  .reply-section {
    padding: 16px;
  }
  .create-form {
    padding: 16px;
  }
  .login-card {
    padding: 24px;
    margin: 0 12px;
  }
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
}

@media (max-width: 480px) {
  .nav-logo {
    font-size: 1rem;
  }
  .nav-logo .logo-text-short { display: none; }
  .category-grid {
    grid-template-columns: 1fr;
  }
  .thread-meta {
    gap: 6px;
  }
  .thread-stats .stat-item span { display: none; }
}

/* ── Utility ── */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-8 { gap: 8px; }
.hidden { display: none; }
