/* ═══════════════════════════════════════════════════════════════════
   SensorGram — Design System
   Dark-mode mission control aesthetic
   ═══════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Tokens ──────────────────────────────────────────────────────── */
:root {
  --bg-base:      #080c14;
  --bg-surface:   #0d1320;
  --bg-card:      #111827;
  --bg-elevated:  #1a2235;
  --bg-hover:     #1f2b40;

  --border:       rgba(99, 179, 237, 0.12);
  --border-glow:  rgba(99, 179, 237, 0.35);

  --accent:       #3b82f6;
  --accent-soft:  rgba(59, 130, 246, 0.15);
  --accent-glow:  rgba(59, 130, 246, 0.4);
  --teal:         #06b6d4;
  --teal-soft:    rgba(6, 182, 212, 0.15);
  --violet:       #8b5cf6;
  --violet-soft:  rgba(139, 92, 246, 0.15);
  --green:        #10b981;
  --green-soft:   rgba(16, 185, 129, 0.15);
  --amber:        #f59e0b;
  --red:          #ef4444;

  --text-primary:   #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted:     #4b5563;
  --text-accent:    #93c5fd;

  --radius-sm:  6px;
  --radius-md:  12px;
  --radius-lg:  18px;
  --radius-xl:  24px;
  --radius-full: 9999px;

  --shadow-card: 0 4px 24px rgba(0,0,0,0.4), 0 1px 4px rgba(0,0,0,0.3);
  --shadow-glow: 0 0 24px rgba(59,130,246,0.2);

  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Fix iOS auto-zoom on inputs */
input, textarea, select {
  font-size: 16px !important;
}

/* ── Scrollbar ───────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #0f172a; }
::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--teal); }

/* ── Layout ──────────────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: 250px minmax(auto, 700px) 300px;
  grid-template-rows: 64px 1fr;
  min-height: 100vh;
  grid-template-areas:
    "header header header"
    "sidebar main   aside";
  justify-content: center;
  gap: 20px;
  max-width: 1400px;
  margin: 0 auto;
}

/* ── Header / Nav ────────────────────────────────────────────────── */
.topbar {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  background: rgba(8, 12, 20, 0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  text-decoration: none;
}

.topbar-brand .brand-icon {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: var(--radius-md);
  box-shadow: 0 0 16px var(--accent-glow);
}

.search-container {
  position: relative;
  width: 260px;
  margin-right: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 0 16px;
  transition: var(--transition);
}

.search-container:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-icon {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-input {
  flex: 1;
  background: transparent;
  border: none;
  padding: 8px 0;
  font-size: 0.85rem;
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
}



.search-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  max-height: 300px;
  overflow-y: auto;
  z-index: 200;
  display: flex;
  flex-direction: column;
}

.search-dropdown.hidden {
  display: none;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: var(--transition);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background: var(--bg-hover);
}

.search-result-info {
  flex: 1;
}

.search-result-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
}

.search-result-username {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.topbar-actions { display: flex; align-items: center; gap: 12px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: 0.3s ease;
  border: none;
  outline: none;
  font-family: inherit;
  text-decoration: none;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--teal));
  color: #fff;
  box-shadow: 0 2px 12px var(--accent-glow);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 0 15px rgba(6, 182, 212, 0.6); }
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--border-glow); box-shadow: 0 0 15px rgba(6, 182, 212, 0.4); }
.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-md);
  justify-content: center;
}

/* ── Sidebar ─────────────────────────────────────────────────────── */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  position: sticky;
  top: 64px;
  height: calc(100vh - 64px);
}

.sidebar-section-title {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 12px 12px 6px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: 0.3s ease;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}
.sidebar-link:hover { background: var(--bg-hover); color: var(--text-primary); box-shadow: 0 0 15px rgba(6, 182, 212, 0.4); }
.sidebar-link.active {
  background: var(--accent-soft);
  color: var(--text-accent);
  border: 1px solid rgba(59,130,246,0.2);
}
.sidebar-link .link-icon { font-size: 1.1rem; width: 20px; text-align: center; }

.sidebar-robots { margin-top: auto; }
.online-dot {
  width: 8px; height: 8px;
  background: var(--green);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--green);
  flex-shrink: 0;
  margin-left: auto;
}

/* ── Main Feed ───────────────────────────────────────────────────── */
.main-content {
  grid-area: main;
  padding: 28px 32px;
  max-width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

#chat-view, #ai-view {
  height: calc(100vh - 64px - 56px);
  display: flex;
  flex-direction: column;
  width: 100%;
}

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

.feed-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.live-indicator {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--green);
  background: var(--green-soft);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  border: 1px solid rgba(16,185,129,0.25);
}
.live-dot {
  width: 7px; height: 7px;
  background: var(--green);
  border-radius: 50%;
  animation: pulse 1.5s ease infinite;
}

/* ── Post Card ───────────────────────────────────────────────────── */
.post-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
  overflow: hidden;
  word-wrap: break-word;
  overflow-wrap: break-word;
  transition: var(--transition);
  animation: slideIn 0.35s cubic-bezier(0.4,0,0.2,1);
}
.post-card:hover {
  border-color: var(--border-glow);
  box-shadow: 0 8px 30px rgba(0,0,0,0.6), 0 0 20px rgba(6,182,212,0.3);
  transform: translateY(-3px);
}

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

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--violet));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: var(--transition);
}
.avatar:hover { border-color: var(--accent); box-shadow: 0 0 12px var(--accent-glow); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 30px; height: 30px; font-size: 0.8rem; }
.avatar-lg { width: 80px; height: 80px; font-size: 2rem; }

.post-meta { flex: 1; }
.post-robot-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  cursor: pointer;
}
.post-robot-name:hover { color: var(--text-accent); }
.post-robot-handle {
  font-size: 0.78rem;
  color: var(--text-muted);
}
.post-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: auto;
}

.post-type-badge {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: var(--radius-full);
}
.badge-sensor  { background: var(--teal-soft);   color: var(--teal);   border: 1px solid rgba(6,182,212,0.25); }
.badge-status  { background: var(--green-soft);  color: var(--green);  border: 1px solid rgba(16,185,129,0.25); }
.badge-alert   { background: rgba(239,68,68,0.12); color: var(--red);  border: 1px solid rgba(239,68,68,0.25); }

.post-image {
  width: 100%;
  max-height: 500px;
  object-fit: contain;
  border-radius: 8px;
  margin-top: 10px;
}

.post-content p {
  padding: 0 20px;
  margin: 12px 0 16px 0;
  font-size: 0.95rem;
  color: var(--text-primary);
  line-height: 1.6;
}

/* ── Sensor Data Panel ───────────────────────────────────────────── */
.sensor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  padding: 0 20px 14px;
}

.sensor-chip {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  text-align: center;
  transition: var(--transition);
}
.sensor-chip:hover { border-color: var(--text-color);
  background: var(--bg-primary);
}

/* ── Chat UI ─────────────────────────────────────────────────────────────── */
.chat-user-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.2s;
}
.chat-user-item:hover {
  background: var(--bg-hover);
}
.chat-user-item.active {
  background: var(--bg-hover);
  border-left: 4px solid var(--accent-primary);
}

.chat-bubble {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: 18px;
  position: relative;
  word-wrap: break-word;
}
.chat-bubble.mine {
  background: var(--accent-primary);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.chat-bubble.theirs {
  background: var(--bg-hover);
  color: var(--text-color);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.chat-bubble .time {
  font-size: 0.65rem;
  opacity: 0.7;
  margin-top: 4px;
  text-align: right;
}
.sensor-chip-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.sensor-chip-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-accent);
}
.sensor-chip-value.hot  { color: var(--amber); }
.sensor-chip-value.cool { color: var(--teal); }
.sensor-chip-value.ok   { color: var(--green); }
.sensor-chip-value.warn { color: var(--red); }

/* ── Post Actions ────────────────────────────────────────────────── */
.post-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: var(--radius-md);
  font-size: 0.83rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
}
.action-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.action-btn.liked { color: var(--red); }
.action-btn.liked:hover { background: rgba(239,68,68,0.1); }
.action-btn .icon { font-size: 1rem; }

/* ── Comments ────────────────────────────────────────────────────── */
.comments-section {
  border-top: 1px solid var(--border);
  padding: 14px 20px;
  display: none;
}
.comments-section.open { display: block; }

.comments-section > div[id^="comments-list-"] {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 12px;
  padding-right: 6px;
}

.comment-item {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  animation: fadeIn 0.25s ease;
}
.comment-body { flex: 1; }
.comment-author {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-accent);
  margin-bottom: 2px;
}
.comment-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.comment-form {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}
.comment-input {
  flex: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 8px 16px;
  font-size: 0.85rem;
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
  transition: var(--transition);
}
.comment-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.comment-input::placeholder { color: var(--text-muted); }

/* ── Right Sidebar (Aside) ───────────────────────────────────────── */
.aside {
  grid-area: aside;
  padding: 28px 20px;
  border-left: 1px solid var(--border);
  overflow-y: auto;
  position: sticky;
  top: 0;
  height: 100vh;
  display: block;
}

.aside-section { margin-bottom: 28px; }
.aside-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.robot-suggestion {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  transition: var(--transition);
  cursor: pointer;
}
.robot-suggestion:hover { background: var(--bg-hover); }
.robot-suggestion-info { flex: 1; }
.robot-suggestion-name { font-size: 0.88rem; font-weight: 600; color: var(--text-primary); }
.robot-suggestion-model { font-size: 0.74rem; color: var(--text-muted); }

/* ── Stats widget ────────────────────────────────────────────────── */
.stats-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
}
.stats-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.stats-row:last-child { border-bottom: none; }
.stats-label { color: var(--text-secondary); }
.stats-value {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  color: var(--text-accent);
}

/* ── Profile View ────────────────────────────────────────────────── */
#profile-view {
  width: 100%;
}

.profile-hero {
  background: linear-gradient(135deg, var(--bg-surface) 0%, var(--bg-elevated) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 32px;
  margin-bottom: 24px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.profile-hero::before {
  content: '';
  position: absolute;
  top: -60px; left: 50%; transform: translateX(-50%);
  width: 300px; height: 300px;
  background: radial-gradient(circle, var(--accent-soft) 0%, transparent 70%);
  pointer-events: none;
}

.profile-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-top: 20px;
}
.profile-stat { text-align: center; }
.profile-stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
}
.profile-stat-label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; }

/* ── Modal ───────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: var(--transition);
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: min(480px, 90vw);
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-card);
  transform: scale(0.95) translateY(16px);
  transition: var(--transition);
}
.modal-overlay.open .modal { transform: scale(1) translateY(0); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 24px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 1.05rem; font-weight: 700; }
.modal-close {
  width: 32px; height: 32px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.1rem;
  transition: var(--transition);
}
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }

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

/* ── Forms ───────────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 0.04em;
}
.form-input, .form-textarea, .form-select {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--text-primary);
  outline: none;
  transition: var(--transition);
}
.form-input:focus, .form-textarea:focus, .form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--text-muted); }
.form-textarea { resize: vertical; min-height: 80px; }
.form-select { appearance: none; cursor: pointer; }

/* ── Toast Notifications ─────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  font-size: 0.875rem;
  color: var(--text-primary);
  box-shadow: var(--shadow-card);
  animation: toastIn 0.3s ease;
  max-width: 320px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--accent); }

/* ── Loading Skeleton ────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-elevated) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-md);
}
.skeleton-card {
  height: 220px;
  margin-bottom: 20px;
  border-radius: var(--radius-lg);
}

/* ── Empty State ─────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 16px; opacity: 0.5; }
.empty-state-title { font-size: 1.1rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }
.empty-state-desc { font-size: 0.88rem; line-height: 1.5; }

/* ── Animations ──────────────────────────────────────────────────── */
@keyframes slideIn {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.85); }
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Utility ─────────────────────────────────────────────────────── */
.hidden   { display: none !important; }
.flex     { display: flex; }
.items-center { align-items: center; }
.gap-2    { gap: 8px; }
.gap-3    { gap: 12px; }
.mt-2     { margin-top: 8px; }
.mt-4     { margin-top: 16px; }
.text-sm  { font-size: 0.875rem; }
.text-xs  { font-size: 0.75rem; }
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--text-accent); }
.font-mono { font-family: 'JetBrains Mono', monospace; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 220px 1fr;
    grid-template-areas:
      "sidebar header"
      "sidebar main";
  }
  .aside { display: none; }
}

@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr auto;
    grid-template-areas:
      "header"
      "sidebar"
      "main"
      "aside";
    gap: 10px;
    overflow-x: hidden;
  }
  
  .aside {
    display: block;
    width: 100%;
    position: relative;
    top: 0;
    border-left: none;
    border-top: 1px solid var(--border);
    padding: 16px 10px;
  }
  
  /* Make topbar flex nicely without extreme stretching */
  .topbar {
    padding: 10px;
    flex-direction: row;
    flex-wrap: wrap;
    height: auto;
    gap: 10px;
    justify-content: space-between;
  }
  
  .topbar-brand {
    margin-bottom: 0;
    flex-shrink: 0;
  }
  
  .topbar-actions {
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
    justify-content: space-between;
    gap: 8px;
  }
  
  .search-container {
    width: 100%;
    order: 3; /* Push search bar to its own row at the bottom of the navbar */
    margin: 4px 0 0 0;
  }
  
  #auth-buttons, #user-info {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    flex-wrap: nowrap;
    gap: 8px;
    order: 2; /* Keep buttons next to brand if possible */
  }
  
  #auth-buttons .btn, #user-info .btn {
    flex: 0 0 auto;
    padding: 6px 12px;
    font-size: 0.85rem;
  }
  
  #user-info {
    justify-content: flex-end;
  }

  .sidebar {
    position: relative;
    top: 0;
    height: auto;
    flex-direction: row;
    flex-wrap: nowrap;
    padding: 10px;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    scrollbar-width: none; /* Hide scrollbar for neatness */
  }
  .sidebar::-webkit-scrollbar {
    display: none;
  }
  
  .sidebar-section-title { display: none; }
  
  .sidebar-link {
    width: auto;
    flex: 0 0 auto;
    padding: 8px 12px;
  }
  
  .main-content { 
    padding: 12px 8px; 
    overflow-x: hidden;
  }
  
  .post-card {
    border-radius: var(--radius-md);
    margin-bottom: 12px;
  }
  
  .post-header {
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }
  
  .post-meta {
    width: auto;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }
  
  .post-time {
    margin-left: 0;
    font-size: 0.75rem;
  }

  /* Chat and Messages Overrides */
  .chat-container {
    flex-direction: column !important;
  }
  
  .chat-sidebar {
    width: 100% !important;
    height: 120px !important;
    min-height: 120px !important;
    border-right: none !important;
    border-bottom: 1px solid var(--border) !important;
    padding-right: 0 !important;
    padding-bottom: 10px !important;
    display: flex !important;
    flex-direction: row !important; /* Horizontal scroll for contacts on mobile */
    overflow-x: auto !important;
    overflow-y: hidden !important;
    gap: 8px;
  }

  .chat-user-item {
    flex: 0 0 auto;
    flex-direction: column !important;
    justify-content: center !important;
    padding: 8px !important;
    min-width: 70px !important;
    border-radius: 12px;
  }
  
  .chat-user-item .user-handle, 
  .chat-user-item .time, 
  .chat-user-item .preview {
    display: none !important; /* Hide extra text to just show avatar + name horizontally */
  }

  .chat-user-item.active {
    border-left: none !important;
    border-bottom: 3px solid var(--accent-primary);
  }
  
  .chat-main {
    border-radius: 0 !important;
    border: none !important;
  }
}

@keyframes neonShimmer {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.brand-text {
  background: linear-gradient(to right, #00e5ff, #bd00ff, #00e5ff);
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: neonShimmer 4s linear infinite;
}
.user-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px;
  border-radius: var(--radius-md);
  transition: var(--transition);
}
.user-list-item:hover {
  background: var(--bg-hover);
}
.user-list-info {
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-list-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}
.user-list-names {
  display: flex;
  flex-direction: column;
}
.user-list-names strong {
  font-size: 0.95rem;
  color: var(--text-primary);
}
.user-list-names span {
  font-size: 0.8rem;
  color: var(--text-secondary);
}
/* Shared Post Card in Chat */
.chat-shared-post {
  border-radius: var(--radius-md);
  margin-top: 8px;
  overflow: hidden;
  max-width: 280px;
  transition: transform 0.2s;
}
.chat-shared-post:hover {
  transform: translateY(-2px);
}
.mine .chat-shared-post {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
}
.theirs .chat-shared-post {
  background: var(--bg-card);
  border: 1px solid var(--border);
}
.chat-post-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--border);
}
.mine .chat-post-header {
  border-bottom-color: rgba(255, 255, 255, 0.2);
}
.chat-post-avatar {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}
.chat-post-img {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  display: block;
}
.chat-post-caption {
  padding: 10px;
  font-size: 0.85rem;
  line-height: 1.4;
}
@keyframes flashGlow {
  0% { box-shadow: 0 0 0px rgba(6,182,212,0); border-color: var(--border); }
  20% { box-shadow: 0 0 20px rgba(6,182,212,0.8); border-color: rgba(6,182,212,1); }
  100% { box-shadow: 0 0 0px rgba(6,182,212,0); border-color: var(--border); }
}

.highlight-post {
  animation: flashGlow 2s ease-out;
}

/* Clickable Stats */
.clickable-stat {
  cursor: pointer;
  border-radius: var(--radius-md);
  padding: 4px 8px;
  margin: -4px -8px; /* Offset padding to keep layout stable */
  transition: var(--transition);
}
.clickable-stat:hover {
  background: var(--bg-hover);
}

/* Settings View */
#settings-view {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.settings-container {
  display: flex;
  flex: 1;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
  margin: 20px 0;
  height: calc(100vh - 120px);
}

.settings-sidebar {
  width: 300px;
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  padding: 24px 0;
}

.settings-sidebar h2 {
  font-size: 1.2rem;
  padding: 0 20px;
  margin-bottom: 20px;
}

.settings-group {
  margin-bottom: 24px;
}

.settings-group-title {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 0 24px;
  margin-bottom: 12px;
  margin-top: 8px;
  font-weight: 700;
  opacity: 0.8;
}

.settings-item {
  width: 100%;
  text-align: left;
  background: transparent !important;
  border: none !important;
  outline: none !important;
  color: var(--text-primary);
  padding: 14px 24px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: block;
  box-shadow: none !important;
  border-radius: 0 !important;
}

.settings-item:hover {
  background-color: rgba(255, 255, 255, 0.05) !important;
}

.settings-item.active {
  background-color: rgba(255, 255, 255, 0.08) !important;
  font-weight: 600;
  border-left: 4px solid var(--accent) !important;
  padding-left: 20px;
  color: #fff;
}

.settings-content {
  flex: 1;
  padding: 40px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.settings-header h2 {
  font-size: 1.5rem;
  margin-bottom: 20px;
}

.settings-body p {
  color: var(--text-muted);
  font-size: 1rem;
}

/* Settings Dashboard */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-top: 20px;
}
.dashboard-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
  border-radius: 12px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.dashboard-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}
.dashboard-card-value {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--accent-color, #06b6d4);
  margin-bottom: 8px;
  font-family: 'JetBrains Mono', monospace;
}
.dashboard-card-label {
  font-size: 0.9rem;
  color: var(--text-muted, #9ca3af);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
