:root {
  --primary: #4F46E5;
  --primary-light: #818CF8;
  --primary-dark: #3730A3;
  --accent: #F59E0B;
  --success: #10B981;
  --danger: #EF4444;
  --bg: #F9FAFB;
  --card: #FFFFFF;
  --text: #111827;
  --text-secondary: #6B7280;
  --border: #E5E7EB;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
  --radius: 12px;
}

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

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

/* Navigation */
.navbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.navbar-brand {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.navbar-nav {
  display: flex;
  gap: 4px;
  list-style: none;
}

.navbar-nav a {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 8px;
  font-size: 14px;
  transition: all 0.2s;
}

.navbar-nav a:hover, .navbar-nav a.active {
  color: var(--primary);
  background: #EEF2FF;
}

.navbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.notification-badge {
  position: relative;
}

.notification-badge .badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--danger);
  color: white;
  font-size: 10px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
}

.user-menu:hover { background: #F3F4F6; }

/* User dropdown menu */
.user-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  min-width: 220px;
  z-index: 200;
  overflow: hidden;
}

.user-dropdown-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: #FAFBFC;
}

.user-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s;
}

.user-dropdown-item:hover { background: #F3F4F6; }

.user-dropdown-item i { width: 16px; text-align: center; color: var(--text-secondary); }

.user-dropdown-danger { color: var(--danger); }
.user-dropdown-danger i { color: var(--danger); }
.user-dropdown-danger:hover { background: #FEF2F2; }

.user-dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 0;
}

@media (max-width: 640px) {
  .user-menu-name { display: none; }
  .user-dropdown { right: -8px; min-width: 200px; }
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-light);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
}

.avatar.large { width: 48px; height: 48px; font-size: 20px; }

/* Container */
.container {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

.container-wide {
  max-width: 1024px;
  margin: 0 auto;
  padding: 16px;
}

/* Cards */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 16px;
}

.card-header {
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.card-header .meta {
  flex: 1;
}

.card-header .name {
  font-weight: 600;
  font-size: 15px;
}

.card-header .role-badge {
  display: inline-block;
  background: var(--primary);
  color: white;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
}

.card-header .time {
  font-size: 12px;
  color: var(--text-secondary);
}

.card-body {
  padding: 0 16px 12px;
}

.card-body .content {
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.card-media img, .card-media video {
  width: 100%;
  max-height: 500px;
  object-fit: cover;
}

.card-stats {
  padding: 8px 16px;
  display: flex;
  gap: 16px;
  font-size: 13px;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
}

.card-actions {
  padding: 8px 16px;
  display: flex;
  gap: 8px;
  border-top: 1px solid var(--border);
}

/* Reactions */
.reaction-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
  color: var(--text-secondary);
}

.reaction-btn:hover {
  border-color: var(--primary-light);
  background: #EEF2FF;
}

.reaction-btn.active {
  border-color: var(--primary);
  background: #EEF2FF;
  color: var(--primary);
}

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

.comment {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.comment .avatar { width: 28px; height: 28px; font-size: 11px; flex-shrink: 0; }

.comment-content {
  background: #F3F4F6;
  padding: 8px 12px;
  border-radius: 12px;
  flex: 1;
}

.comment-content .name {
  font-weight: 600;
  font-size: 13px;
}

.comment-content .text {
  font-size: 14px;
  margin-top: 2px;
}

.comment-content .time {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.comment-input {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.comment-input input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 14px;
  outline: none;
}

.comment-input input:focus { border-color: var(--primary-light); }

.comment-input button {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 20px;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 14px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #E5E7EB; color: var(--text); }
.btn-secondary:hover { background: #D1D5DB; }
.btn-danger { background: var(--danger); color: white; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; }

/* Forms */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text);
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.form-control:focus { border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(79,70,229,0.1); }

textarea.form-control { resize: vertical; min-height: 100px; font-family: inherit; }

select.form-control { appearance: none; background: white url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e") right 10px center/16px no-repeat; }

/* Login page */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 16px;
}

.login-card {
  background: var(--card);
  padding: 40px;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
}

.login-card h1 {
  text-align: center;
  margin-bottom: 8px;
  color: var(--primary);
  font-size: 28px;
}

.login-card .subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-size: 14px;
}

.login-card .error {
  background: #FEF2F2;
  color: var(--danger);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

.tab-switch {
  display: flex;
  margin-bottom: 24px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.tab-switch button {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
}

.tab-switch button.active {
  background: var(--primary);
  color: white;
}

/* Post composer */
.composer {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

.composer textarea {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  font-size: 15px;
  font-family: inherit;
  min-height: 80px;
  padding: 8px 0;
}

.composer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.composer-actions .media-btns { display: flex; gap: 8px; }

.composer-actions .media-btns button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Pinned indicator */
.pinned-badge {
  background: var(--accent);
  color: white;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* Dashboard */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card);
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
}

.stat-card .value {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
}

.stat-card .label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.chart-container {
  background: var(--card);
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.chart-container h3 {
  margin-bottom: 16px;
  font-size: 16px;
}

/* Articles */
.article-card {
  display: flex;
  gap: 16px;
  padding: 16px;
}

.article-card .article-info { flex: 1; }
.article-card .article-info h3 { font-size: 16px; margin-bottom: 4px; }
.article-card .article-info h3 a { color: var(--text); text-decoration: none; }
.article-card .article-info h3 a:hover { color: var(--primary); }
.article-card .article-info .summary { font-size: 14px; color: var(--text-secondary); margin-bottom: 8px; }
.article-card .article-meta { font-size: 12px; color: var(--text-secondary); display: flex; gap: 12px; }

.article-cover {
  width: 120px;
  height: 80px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}

.article-detail { padding: 24px 16px; }
.article-detail h1 { font-size: 24px; margin-bottom: 12px; }
.article-detail .meta { font-size: 14px; color: var(--text-secondary); margin-bottom: 24px; display: flex; gap: 16px; align-items: center; }
.article-detail .body { font-size: 15px; line-height: 1.8; }
.article-detail .body h2 { margin: 24px 0 12px; font-size: 20px; }
.article-detail .body p { margin-bottom: 16px; }

.category-pills {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding: 4px 0;
}

.category-pill {
  padding: 6px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  background: white;
  white-space: nowrap;
  transition: all 0.2s;
}

.category-pill.active, .category-pill:hover {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Q&A */
.question-card {
  padding: 16px;
}

.question-card .question-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
}

.question-card .question-content {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.question-card .answer-box {
  background: #F0FDF4;
  border-left: 3px solid var(--success);
  padding: 12px;
  border-radius: 0 8px 8px 0;
  margin-top: 12px;
}

.question-card .answer-box .answer-label {
  font-size: 12px;
  color: var(--success);
  font-weight: 600;
  margin-bottom: 4px;
}

.upvote-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
}

.upvote-btn.active { border-color: var(--primary); color: var(--primary); }

/* Chat */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 56px - 56px);
  max-width: 640px;
  margin: 0 auto;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.chat-bubble.user {
  align-self: flex-end;
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-bubble.assistant {
  align-self: flex-start;
  background: var(--card);
  box-shadow: var(--shadow);
  border-bottom-left-radius: 4px;
}

.chat-input-area {
  padding: 12px 16px;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

.chat-input-area input {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 24px;
  font-size: 14px;
  outline: none;
}

.chat-input-area input:focus { border-color: var(--primary-light); }

.chat-input-area button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Loading */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-secondary);
}

.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); } }

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}

.modal {
  background: var(--card);
  border-radius: 16px;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
}

.modal h2 { margin-bottom: 16px; font-size: 18px; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state i { font-size: 48px; margin-bottom: 16px; display: block; }

/* Responsive */
@media (max-width: 768px) {
  .navbar-nav span { display: none; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .article-card { flex-direction: column; }
  .article-cover { width: 100%; height: 160px; }
  .charts-grid { grid-template-columns: 1fr !important; }
}

/* Hamburger menu for mobile */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text);
}

@media (max-width: 640px) {
  .menu-toggle { display: block; }
  .navbar-nav {
    display: none;
    position: absolute;
    top: 56px;
    left: 0;
    right: 0;
    background: var(--card);
    flex-direction: column;
    padding: 8px;
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
  }
  .navbar-nav.open { display: flex; }
  .navbar-nav.open span { display: inline; }
  .navbar-nav.open a { padding: 12px 16px; font-size: 15px; }

  /* Login */
  .login-card { padding: 24px 20px; }
  .login-card h1 { font-size: 24px; }

  /* Container */
  .container { padding: 12px; }
  .container-wide { padding: 12px; }

  /* Composer */
  .composer-actions { flex-wrap: wrap; gap: 8px; }
  .composer-actions .media-btns { flex-wrap: wrap; }

  /* Stats grid */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-card { padding: 14px 10px; }
  .stat-card .value { font-size: 24px; }
  .stat-card .label { font-size: 12px; }

  /* Reaction & upvote touch targets */
  .reaction-btn { padding: 8px 14px; font-size: 15px; min-height: 40px; }
  .card-actions { flex-wrap: wrap; gap: 6px; }
  .upvote-btn { padding: 8px 14px; font-size: 14px; min-height: 40px; }

  /* Article meta */
  .article-card .article-meta { flex-wrap: wrap; gap: 6px 12px; }
  .article-detail .meta { flex-wrap: wrap; gap: 8px; }

  /* Question card layout */
  .question-card .q-layout { flex-direction: column; gap: 8px; }
  .question-card .q-actions { flex-direction: row; }

  /* Tables scroll */
  .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Modal */
  .modal { padding: 20px 16px; }

  /* Birthday section */
  .birthday-person { flex-wrap: wrap; }
}

@media (max-width: 375px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
  .stat-card .value { font-size: 20px; }
  .reaction-btn { padding: 6px 10px; font-size: 14px; }
  .login-card { padding: 20px 16px; }
  .container { padding: 8px; }
}

/* Bottom Navigation (mobile) */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 4px 0 env(safe-area-inset-bottom, 4px);
  z-index: 100;
  box-shadow: 0 -1px 4px rgba(0,0,0,0.06);
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 10px;
  flex: 1;
  transition: color 0.2s;
}

.bottom-nav-item i { font-size: 18px; }
.bottom-nav-item.active { color: var(--primary); }
.bottom-nav-item:hover { color: var(--primary); }

/* Notification Panel */
.notif-panel-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.3);
  z-index: 150;
}

.notif-panel {
  position: fixed;
  top: 56px;
  right: 0;
  width: 360px;
  max-width: 100vw;
  background: var(--card);
  border-radius: 0 0 0 12px;
  box-shadow: var(--shadow-lg);
  z-index: 160;
}

.notif-item {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.2s;
  font-size: 13px;
}

.notif-item:hover { background: #F9FAFB; }
.notif-item.unread { background: #EEF2FF; }
.notif-item .notif-icon { font-size: 16px; color: var(--primary); flex-shrink: 0; padding-top: 2px; }
.notif-item .notif-body { flex: 1; }
.notif-item .notif-time { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }

@media (max-width: 640px) {
  .notif-panel { width: 100vw; border-radius: 0; }
}
