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

:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --success: #22c55e;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 6px rgba(0,0,0,0.07), 0 10px 15px rgba(0,0,0,0.05);
}

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* Loading */
.loading {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Auth View */
.auth-container {
  max-width: 420px;
  margin: 80px auto 0;
  padding: 40px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}

.auth-container h1 {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.auth-container .subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 28px;
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 24px;
}

.tab {
  flex: 1;
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.15s ease;
  font-family: inherit;
}

.tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-form input {
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.15s ease;
  outline: none;
  background: var(--bg);
}

.auth-form input:focus {
  border-color: var(--primary);
  background: var(--surface);
}

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 8px 14px;
  font-size: 0.85rem;
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--bg);
}

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
}

.btn-danger:hover {
  background: #fee2e2;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.82rem;
}

.error-msg {
  background: var(--danger-bg);
  color: var(--danger);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.88rem;
  display: none;
}

.error-msg.show {
  display: block;
}

/* Main App */
.main-container {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 20px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 28px;
}

.header h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.88rem;
}

.role-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.role-badge.admin {
  background: #ede9fe;
  color: #7c3aed;
}

.role-badge.member {
  background: #dcfce7;
  color: #16a34a;
}

/* New Post Form */
.new-post {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
  border: 1.5px dashed var(--border);
}

.new-post h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text);
}

.new-post form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.new-post input[type="text"],
.new-post textarea {
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.15s ease;
  outline: none;
  background: var(--bg);
}

.new-post input[type="text"]:focus,
.new-post textarea:focus {
  border-color: var(--primary);
  background: var(--surface);
}

.new-post textarea {
  min-height: 100px;
  resize: vertical;
}

.new-post input[type="file"] {
  font-size: 0.88rem;
  color: var(--text-muted);
}

.form-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.char-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: auto;
}

.image-preview {
  max-width: 100%;
  max-height: 200px;
  border-radius: 8px;
  object-fit: cover;
  margin-top: 4px;
}

/* Posts Feed */
.posts-feed {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state p {
  font-size: 0.95rem;
}

/* Post Card */
.post-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow 0.2s ease;
}

.post-card:hover {
  box-shadow: var(--shadow-lg);
}

.post-image {
  width: 100%;
  max-height: 400px;
  object-fit: cover;
  display: block;
}

.post-body {
  padding: 20px 24px;
}

.post-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
}

.post-content {
  font-size: 0.93rem;
  color: var(--text-muted);
  white-space: pre-wrap;
  margin-bottom: 12px;
  line-height: 1.7;
}

.post-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.post-meta .separator {
  width: 3px;
  height: 3px;
  background: var(--border);
  border-radius: 50%;
}

/* Comments Section */
.comments-section {
  border-top: 1px solid var(--border);
  padding: 0 24px;
}

.comments-toggle {
  padding: 12px 0;
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  text-align: left;
}

.comments-toggle:hover {
  color: var(--primary-hover);
}

.comments-body {
  padding-bottom: 16px;
}

.comment {
  padding: 10px 0;
  border-bottom: 1px solid var(--bg);
}

.comment:last-child {
  border-bottom: none;
}

.comment-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.comment-author {
  font-weight: 600;
  font-size: 0.85rem;
}

.comment-time {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.comment-content {
  font-size: 0.9rem;
  color: var(--text-muted);
  white-space: pre-wrap;
}

.comment-form-wrap {
  display: flex;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--bg);
}

.comment-form-wrap input {
  flex: 1;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  background: var(--bg);
}

.comment-form-wrap input:focus {
  border-color: var(--primary);
  background: var(--surface);
}

/* Status messages */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 100;
  animation: slideDown 0.3s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }

@keyframes slideDown {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Disclaimer */
.disclaimer-block {
  margin-top: 24px;
  padding: 12px 16px;
  background: #fefce8;
  border: 1px solid #fde68a;
  border-radius: 8px;
  font-size: 0.78rem;
  color: #92400e;
  line-height: 1.5;
}

.disclaimer-block strong {
  color: #78350f;
}

.disclaimer-footer {
  margin-top: 32px;
  padding: 12px 0;
  text-align: center;
  font-size: 0.75rem;
  color: #94a3b8;
  border-top: 1px solid var(--border);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  width: 380px;
  max-width: calc(100vw - 40px);
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.modal-box h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: 16px;
}

.modal-box input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  background: var(--bg);
  margin-bottom: 10px;
}

.modal-box input:focus {
  border-color: var(--primary);
  background: var(--surface);
}

.modal-box .form-actions {
  margin-top: 6px;
}

.modal-box .error-msg {
  margin-bottom: 8px;
}

/* Responsive */
@media (max-width: 500px) {
  .auth-container {
    margin: 40px 12px 0;
    padding: 28px 20px;
  }
  .post-body {
    padding: 16px 18px;
  }
  .comments-section {
    padding: 0 18px;
  }
}
