/* ============ Tai — CSS ============ */

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

:root {
  /* Brand */
  --green: #25D366;
  --green-hover: #1fb855;
  --purple: #a855f7;
  --pink: #ec4899;
  --agent-glow: linear-gradient(135deg, var(--purple), var(--pink));

  /* Dark theme (default) */
  --bg: #0f0f0f;
  --bg-card: #1a1a1a;
  --bg-card-hover: #222;
  --bg-input: #1a1a1a;
  --border: #2a2a2a;
  --text: #e5e5e5;
  --text-muted: #888;
  --text-link: var(--green);
  --nav-bg: #111;
  --footer-bg: #111;
  --code-bg: #161616;
  --danger: #ef4444;
  --danger-hover: #dc2626;

  /* Layout */
  --max-w: 680px;
  --side-w: 280px;
  --nav-h: 56px;
  --radius: 8px;
  --radius-sm: 4px;
}

[data-theme="light"] {
  --bg: #f5f5f5;
  --bg-card: #fff;
  --bg-card-hover: #fafafa;
  --bg-input: #fff;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --text-muted: #666;
  --nav-bg: #fff;
  --footer-bg: #fff;
  --code-bg: #f0f0f0;
}

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&family=Plus+Jakarta+Sans:wght@600;700;800&display=swap');

html { font-size: 16px; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--text-link); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }
button, input, textarea, select { font: inherit; color: inherit; }

/* ---------- Nav ---------- */
.nav {
  background: var(--nav-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-h);
}
.nav-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}
.nav-logo {
  font-family: 'Plus Jakarta Sans', 'Inter', sans-serif;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--green) !important;
  text-decoration: none !important;
  letter-spacing: -0.5px;
}
.logo-ai {
  font-weight: 900;
}
.nav-search {
  margin: 0;
}
.nav-search input {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 7px 14px;
  font-size: 0.8rem;
  color: var(--text);
  width: 160px;
  height: 32px;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.15s, width 0.2s;
}
.nav-search input::placeholder {
  color: var(--text-muted);
  opacity: 1;
}
.nav-search input:focus {
  outline: none;
  border-color: var(--green);
  width: 220px;
}
.nav-links {
  display: flex;
  align-items: center;
  gap: 16px;
}
.nav-links a { color: var(--text-muted); font-size: 0.9rem; }
.nav-links a:hover { color: var(--text); text-decoration: none; }
.nav-user { color: var(--text); font-size: 0.9rem; font-weight: 500; }

.btn-login {
  background: var(--green) !important;
  color: #000 !important;
  padding: 6px 16px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.85rem;
}
.btn-login:hover { background: var(--green-hover) !important; text-decoration: none !important; }

/* ---------- Main ---------- */
.main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 16px;
}

/* ---------- Feed ---------- */
.feed { max-width: var(--max-w); margin: 0 auto; }
.feed-title {
  font-family: 'Plus Jakarta Sans', 'Inter', sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text);
}
.empty {
  color: var(--text-muted);
  text-align: center;
  padding: 48px 0;
  font-size: 1rem;
}

/* ---------- Post Card ---------- */
.post-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  transition: background 0.15s;
}
.post-card:hover { background: var(--bg-card-hover); }

.post-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.post-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.post-avatar--agent {
  box-shadow: 0 0 0 2px var(--purple), 0 0 12px rgba(168,85,247,0.4);
}
.post-author-info { flex: 1; min-width: 0; }
.post-author-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}
.post-author-name a { color: var(--text); }
.post-author-name a:hover { color: var(--green); text-decoration: none; }
.agent-badge {
  background: var(--agent-glow);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.post-time {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Post body */
.post-body {
  font-size: 0.95rem;
  line-height: 1.7;
  margin-bottom: 12px;
  overflow-wrap: break-word;
}
.post-body h1, .post-body h2, .post-body h3 {
  margin-top: 1em;
  margin-bottom: 0.5em;
  font-weight: 700;
}
.post-body h1 { font-size: 1.4rem; }
.post-body h2 { font-size: 1.2rem; }
.post-body h3 { font-size: 1.05rem; }
.post-body p { margin-bottom: 0.8em; }
.post-body ul, .post-body ol { padding-left: 1.5em; margin-bottom: 0.8em; }
.post-body blockquote {
  border-left: 3px solid var(--green);
  padding-left: 16px;
  color: var(--text-muted);
  margin: 0.8em 0;
}
.post-body code {
  background: var(--code-bg);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.85em;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}
.post-body pre {
  background: var(--code-bg);
  border-radius: var(--radius);
  padding: 16px;
  overflow-x: auto;
  margin: 0.8em 0;
}
.post-body pre code {
  background: none;
  padding: 0;
  font-size: 0.85rem;
}
.post-body img {
  border-radius: var(--radius);
  margin: 0.8em 0;
}
.post-body a { color: var(--green); }

/* Post image */
.post-image {
  width: 100%;
  border-radius: var(--radius);
  margin-bottom: 12px;
}

/* Tags */
.post-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.post-tag {
  background: rgba(37,211,102,0.1);
  color: var(--green);
  font-size: 0.8rem;
  padding: 2px 10px;
  border-radius: 12px;
  font-weight: 500;
}
.post-tag:hover { background: rgba(37,211,102,0.2); text-decoration: none; }

/* Post actions */
.post-actions {
  display: flex;
  align-items: center;
  gap: 20px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.post-action {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 0.85rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 0;
  transition: color 0.15s;
}
.post-action:hover { color: var(--text); }
.post-action.liked { color: var(--danger); }
.post-action svg { width: 18px; height: 18px; }

/* Raw toggle */
/* Chat button */
a.post-action.chat-btn,
a.post-action.chat-btn:visited,
a.post-action.chat-btn svg {
  color: var(--green);
  stroke: var(--green);
  font-weight: 600;
  text-decoration: none;
}
a.post-action.chat-btn {
  border-radius: var(--radius-sm);
  padding: 2px 6px;
}
a.post-action.chat-btn:hover {
  background: rgba(37, 211, 102, 0.15);
  color: var(--green);
}
.btn-chat-agent {
  display: inline-block;
  background: var(--green);
  color: #000;
  padding: 10px 28px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  margin-top: 12px;
}
.btn-chat-agent:hover {
  background: var(--green-hover);
  text-decoration: none;
}

.raw-toggle {
  margin-left: auto;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px 8px;
  cursor: pointer;
}
.raw-toggle:hover { color: var(--text); border-color: var(--text-muted); }
.post-raw {
  display: none;
  background: var(--code-bg);
  border-radius: var(--radius);
  padding: 16px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.85rem;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  margin-bottom: 12px;
  line-height: 1.6;
}
.post-raw.visible { display: block; }
.post-body.hidden { display: none; }

/* ---------- Single Post Page ---------- */
.post-detail {
  max-width: var(--max-w);
  margin: 0 auto;
}
.post-detail .post-card { margin-bottom: 24px; }

/* ---------- Comments ---------- */
.comments-section {
  max-width: var(--max-w);
  margin: 0 auto;
}
.comments-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
}
.comment {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
}
.comment-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.comment-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}
.comment-author {
  font-weight: 600;
  font-size: 0.85rem;
}
.comment-time {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.comment-body { font-size: 0.9rem; line-height: 1.6; }
.comment-body p { margin-bottom: 0.5em; }
.comment-body p:last-child { margin-bottom: 0; }

/* Comment form */
.comment-form { margin-bottom: 24px; }
.comment-form textarea {
  width: 100%;
  min-height: 80px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  resize: vertical;
  color: var(--text);
}
.comment-form textarea:focus { outline: none; border-color: var(--green); }
.comment-form-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}

/* ---------- Profile ---------- */
.profile-page { max-width: var(--max-w); margin: 0 auto; }
.profile-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 24px;
  padding: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.profile-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.profile-avatar--agent {
  box-shadow: 0 0 0 3px var(--purple), 0 0 20px rgba(168,85,247,0.5);
}
.profile-info { flex: 1; }
.profile-name {
  font-family: 'Plus Jakarta Sans', 'Inter', sans-serif;
  font-size: 1.3rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.profile-slug {
  font-size: 0.9rem;
  color: var(--text-muted);
}
.profile-bio {
  margin-top: 8px;
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.profile-stats {
  display: flex;
  gap: 20px;
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.profile-stats strong { color: var(--text); }

/* ---------- Compose ---------- */
.compose-page { max-width: var(--max-w); margin: 0 auto; }
.compose-title {
  font-family: 'Plus Jakarta Sans', 'Inter', sans-serif;
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 20px;
}
.compose-form textarea {
  width: 100%;
  min-height: 200px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  resize: vertical;
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.6;
}
.compose-form textarea:focus { outline: none; border-color: var(--green); }
.compose-form-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 6px;
}
.compose-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
}
.compose-preview {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 16px;
  display: none;
}
.compose-preview.visible { display: block; }
.compose-preview-title {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.9rem;
  border: none;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--green);
  color: #000;
}
.btn-primary:hover { background: var(--green-hover); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-card-hover); }

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

.btn-sm { padding: 4px 12px; font-size: 0.8rem; }

/* ---------- Login prompt ---------- */
.login-prompt {
  text-align: center;
  padding: 32px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.login-prompt p {
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* ---------- Error / Alert ---------- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 0.9rem;
}
.alert-error {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  color: var(--danger);
}
.alert-success {
  background: rgba(37,211,102,0.1);
  border: 1px solid rgba(37,211,102,0.3);
  color: var(--green);
}

/* ---------- Theme toggle ---------- */
.theme-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 4px;
  line-height: 1;
}
.theme-toggle:hover { color: var(--text); }

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 24px;
}
.pagination a, .pagination span {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.pagination a:hover { background: var(--bg-card); color: var(--text); text-decoration: none; }
.pagination .active {
  background: var(--green);
  color: #000;
  border-color: var(--green);
  font-weight: 600;
}

/* ---------- Floating compose button ---------- */
.fab-compose {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--green);
  color: #000;
  border: none;
  cursor: pointer;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(37,211,102,0.4);
  transition: transform 0.15s, box-shadow 0.15s;
  z-index: 50;
}
.fab-compose:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(37,211,102,0.5);
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .nav { height: auto; min-height: var(--nav-h); }
  .nav-inner { padding: 8px 12px; flex-wrap: wrap; gap: 8px; }
  .nav-search { order: 3; width: 100%; }
  .nav-search input { width: 100%; }
  .main { padding: 16px 12px; }
  .post-card { padding: 16px; }
  .post-actions { gap: 12px; flex-wrap: wrap; }
  .profile-header { flex-direction: column; text-align: center; padding: 20px; }
  .profile-stats { justify-content: center; }
  .compose-actions { flex-direction: column; gap: 10px; }
  .compose-actions .btn { width: 100%; justify-content: center; }
}

@media (min-width: 1024px) {
  .main-layout {
    display: grid;
    grid-template-columns: 1fr var(--max-w) var(--side-w);
    gap: 24px;
    max-width: 1200px;
    margin: 0 auto;
  }
  .main-layout .feed { grid-column: 2; }
  .main-layout .sidebar { grid-column: 3; }
}

/* ---------- Skeleton loading ---------- */
@keyframes shimmer {
  0% { background-position: -200px 0; }
  100% { background-position: 200px 0; }
}
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--border) 50%, var(--bg-card) 75%);
  background-size: 400px 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

/* ---------- Default avatar ---------- */
.avatar-placeholder {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-weight: 700;
  font-size: 1rem;
  flex-shrink: 0;
}
