/* ============================================
   Adrian Thought Stream
   Premium dark-mode micro-blog UI
   Mobile-first · Surface elevation · Minimal
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  /* Surfaces — layered elevation, never pure black */
  --bg-base: #0c0c14;
  --bg-surface: #13131f;
  --bg-elevated: #1a1a2a;
  --bg-overlay: #1f1f32;
  --bg-hover: rgba(255, 255, 255, 0.03);

  /* Text */
  --text-primary: #ececf1;
  --text-secondary: #8e8ea0;
  --text-tertiary: #565869;
  --text-link: #818cf8;

  /* Accent — indigo/violet spectrum */
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.12);
  --accent-subtle: rgba(99, 102, 241, 0.06);

  /* Tags */
  --tag-bg: rgba(129, 140, 248, 0.06);
  --tag-text: #818cf8;
  --tag-border: rgba(129, 140, 248, 0.12);
  --tag-active-bg: rgba(129, 140, 248, 0.16);

  /* Semantic */
  --danger: #f87171;
  --success: #34d399;
  --warning: #fbbf24;

  /* Borders — near invisible, structural */
  --divider: rgba(255, 255, 255, 0.05);
  --divider-strong: rgba(255, 255, 255, 0.08);

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
  --shadow-glow: 0 0 40px rgba(99, 102, 241, 0.08);

  /* Typography */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;

  /* Layout */
  --max-width: 620px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  /* Motion */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration: 0.2s;
  --duration-md: 0.35s;
}

/* ============ Reset ============ */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100dvh;
  line-height: 1.6;
  overflow-x: hidden;
}

/* ============ App Container ============ */
.app {
  max-width: var(--max-width);
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
}

/* Side borders on desktop only */
@media (min-width: 641px) {
  .app {
    border-left: 1px solid var(--divider);
    border-right: 1px solid var(--divider);
  }
}

/* ============ Header ============ */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(12, 12, 20, 0.8);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  padding: 18px 20px;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.header-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

.header-subtitle {
  font-size: 0.7rem;
  color: var(--text-tertiary);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 500;
}

.header-count {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-weight: 400;
}

/* ============ Compose ============ */
.compose {
  padding: 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--divider);
}

.compose-inner {
  display: flex;
  gap: 14px;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: white;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px var(--bg-surface), 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.compose-body {
  flex: 1;
  min-width: 0;
}

.compose-textarea {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
  resize: none;
  min-height: 48px;
  max-height: 180px;
  padding: 8px 0;
}

.compose-textarea::placeholder {
  color: var(--text-tertiary);
  font-weight: 400;
}

.compose-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 12px;
  margin-top: 8px;
  border-top: 1px solid var(--divider);
}

.compose-meta {
  display: flex;
  align-items: center;
  gap: 14px;
}

.char-count {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  transition: color var(--duration) var(--ease);
  letter-spacing: 0.02em;
}

.char-count.warning {
  color: var(--warning);
}

.char-count.danger {
  color: var(--danger);
}

.tags-input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--tag-text);
  font-family: var(--font);
  font-size: 0.82rem;
  width: 120px;
  padding: 4px 0;
}

.tags-input::placeholder {
  color: var(--text-tertiary);
}

.compose-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-full);
  padding: 8px 24px;
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  letter-spacing: -0.01em;
}

.compose-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

.compose-btn:not(:disabled):hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-glow);
  transform: translateY(-1px);
}

.compose-btn:not(:disabled):active {
  transform: scale(0.96);
}

/* ============ Filter Bar ============ */
.filter-bar {
  padding: 12px 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--divider);
  overflow-x: auto;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.filter-bar::-webkit-scrollbar {
  display: none;
}

.filter-tags {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
}

.filter-tag {
  background: var(--tag-bg);
  color: var(--text-secondary);
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  padding: 5px 14px;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--duration) var(--ease);
  font-family: var(--font);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.filter-tag:hover {
  background: var(--tag-active-bg);
  color: var(--tag-text);
}

.filter-tag.active {
  background: var(--tag-active-bg);
  color: var(--tag-text);
  border-color: var(--tag-border);
  font-weight: 600;
}

/* ============ Timeline ============ */
.timeline {
  min-height: 200px;
}

/* ============ Thought Card ============ */
.thought {
  padding: 18px 20px;
  transition: background var(--duration) var(--ease);
  animation: thoughtEnter 0.5s var(--ease) both;
  position: relative;
}

.thought::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 20px;
  right: 20px;
  height: 1px;
  background: var(--divider);
}

.thought:last-child::after {
  display: none;
}

@media (hover: hover) {
  .thought:hover {
    background: var(--bg-hover);
  }
}

@keyframes thoughtEnter {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.thought-inner {
  display: flex;
  gap: 14px;
}

.thought-avatar {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.78rem;
  color: var(--text-secondary);
  flex-shrink: 0;
  border: 1px solid var(--divider-strong);
}

.thought-body {
  flex: 1;
  min-width: 0;
}

.thought-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.thought-name {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-primary);
}

.thought-sep {
  color: var(--text-tertiary);
  font-size: 0.65rem;
}

.thought-time {
  font-size: 0.78rem;
  color: var(--text-tertiary);
  font-weight: 400;
}

.thought-content {
  font-size: 0.94rem;
  line-height: 1.7;
  color: var(--text-primary);
  word-wrap: break-word;
  white-space: pre-wrap;
  font-weight: 400;
}

.thought-tags {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.thought-tag {
  background: var(--tag-bg);
  color: var(--tag-text);
  border-radius: var(--radius-full);
  padding: 2px 10px;
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--duration) var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.thought-tag:hover {
  background: var(--tag-active-bg);
}

/* Thought actions — only visible on hover (desktop) or always on mobile */
.thought-actions {
  display: flex;
  gap: 2px;
  margin-top: 10px;
  opacity: 0;
  transition: opacity var(--duration) var(--ease);
}

@media (hover: hover) {
  .thought:hover .thought-actions {
    opacity: 1;
  }
}

@media (hover: none) {
  .thought-actions {
    opacity: 0.7;
  }
}

.thought-action-btn {
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-family: var(--font);
  font-weight: 500;
  transition: all var(--duration) var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.thought-action-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-secondary);
}

.thought-action-btn.delete:hover {
  color: var(--danger);
  background: rgba(248, 113, 113, 0.06);
}

/* ============ Loading States ============ */
.loading {
  display: flex;
  justify-content: center;
  padding: 60px 20px;
}

.loading-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--divider-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Infinite scroll sentinel */
.scroll-sentinel {
  height: 1px;
  width: 100%;
}

/* Bottom loading indicator */
.loading-more {
  display: flex;
  justify-content: center;
  padding: 24px 20px;
}

.loading-more .loading-spinner {
  width: 20px;
  height: 20px;
}

/* ============ Empty State ============ */
.empty-state {
  text-align: center;
  padding: 100px 24px 80px;
  color: var(--text-tertiary);
}

.empty-icon {
  font-size: 3.5rem;
  margin-bottom: 20px;
  filter: grayscale(0.3);
}

.empty-state p {
  font-size: 0.92rem;
  font-weight: 400;
  line-height: 1.6;
}

/* ============ Toast ============ */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg-elevated);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 500;
  border: 1px solid var(--divider-strong);
  box-shadow: var(--shadow-md);
  transition: transform var(--duration-md) var(--ease-spring);
  z-index: 1000;
  pointer-events: none;
  backdrop-filter: blur(12px);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.toast.success {
  border-color: rgba(52, 211, 153, 0.2);
}

.toast.error {
  border-color: rgba(248, 113, 113, 0.2);
}

/* ============ Edit Mode ============ */
.thought-edit-textarea {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--divider-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.94rem;
  line-height: 1.7;
  padding: 10px 14px;
  resize: none;
  outline: none;
  min-height: 60px;
  transition: border-color var(--duration) var(--ease);
}

.thought-edit-textarea:focus {
  border-color: var(--accent);
}

.thought-edit-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.edit-save-btn,
.edit-cancel-btn {
  padding: 6px 16px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-family: var(--font);
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--duration) var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.edit-save-btn {
  background: var(--accent);
  color: white;
}

.edit-save-btn:hover {
  background: var(--accent-hover);
}

.edit-cancel-btn {
  background: var(--bg-overlay);
  color: var(--text-secondary);
}

.edit-cancel-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

/* ============ Scrollbar ============ */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--divider-strong);
  border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* ============ Mobile Optimizations ============ */
@media (max-width: 640px) {
  .header {
    padding: 14px 16px;
  }

  .compose {
    padding: 16px;
  }

  .thought {
    padding: 14px 16px;
  }

  .thought::after {
    left: 16px;
    right: 16px;
  }

  .avatar {
    width: 36px;
    height: 36px;
    font-size: 0.78rem;
  }

  .thought-avatar {
    width: 34px;
    height: 34px;
    font-size: 0.72rem;
  }

  .compose-inner,
  .thought-inner {
    gap: 12px;
  }

  .compose-textarea {
    font-size: 16px;
    /* Prevents iOS zoom on focus */
  }

  .compose-footer {
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
  }

  .compose-meta {
    width: 100%;
    justify-content: space-between;
  }

  .compose-btn {
    width: 100%;
    padding: 12px;
    font-size: 0.9rem;
    text-align: center;
  }

  .tags-input {
    flex: 1;
    width: auto;
  }

  .filter-bar {
    padding: 10px 16px;
  }

  .thought-content {
    font-size: 0.92rem;
  }

  .thought-action-btn {
    padding: 8px 14px;
    min-height: 36px;
  }

  .empty-state {
    padding: 80px 20px 60px;
  }
}

/* ============ Touch Targets ============ */
@media (pointer: coarse) {
  .filter-tag {
    padding: 8px 16px;
    font-size: 0.78rem;
  }

  .thought-tag {
    padding: 4px 12px;
    font-size: 0.75rem;
  }

  .thought-action-btn {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* Safe area for iOS */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .app {
    padding-bottom: env(safe-area-inset-bottom);
  }

  .toast {
    bottom: calc(32px + env(safe-area-inset-bottom));
  }
}