/* ════════════════════════════════════════════════════════
   twitter-archive.marcomaroni.it — Stylesheet
   ════════════════════════════════════════════════════════ */

/* ── CSS Variables ─────────────────────────────────────── */
:root {
  --tw-blue:        #1DA1F2;
  --tw-blue-dark:   #1a8cd8;
  --tw-dark:        #0f1419;
  --tw-gray-dark:   #536471;
  --tw-gray:        #71767b;
  --tw-gray-light:  #eff3f4;
  --tw-border:      #e7e7e8;
  --tw-white:       #ffffff;
  --tw-bg:          #f7f9f9;
  --tw-card-bg:     #ffffff;
  --tw-link:        #1DA1F2;
  --tw-mention:     #1DA1F2;
  --tw-hashtag:     #1DA1F2;
  --tw-rt-color:    #00ba7c;
  --tw-thread-color:#1DA1F2;

  --sidebar-width:  290px;
  --main-max-width: 600px;
  --header-h:       53px;

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'SFMono-Regular', Consolas, monospace;
  --radius: 16px;
  --radius-sm: 8px;
}

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

html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--tw-bg);
  color: var(--tw-dark);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--tw-link); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; }

button {
  font-family: var(--font);
  cursor: pointer;
  border: none;
  background: none;
}

/* ── Layout ─────────────────────────────────────────────── */
.app-layout {
  display: flex;
  max-width: 1100px;
  margin: 0 auto;
  min-height: 100vh;
  align-items: flex-start;
}

/* ── Sidebar ────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid var(--tw-border);
  background: var(--tw-card-bg);
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--tw-border); border-radius: 2px; }

/* ── Profile Card ───────────────────────────────────────── */
.profile-card {
  border-bottom: 1px solid var(--tw-border);
}

.profile-header-img {
  height: 80px;
  overflow: hidden;
  background: var(--tw-blue);
}

.header-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-avatar-wrap {
  padding: 0 12px;
  margin-top: -32px;
  margin-bottom: 4px;
}

.profile-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 3px solid var(--tw-white);
  background: var(--tw-gray-light);
  object-fit: cover;
}

.profile-info {
  padding: 4px 16px 16px;
}

.profile-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--tw-dark);
  line-height: 1.2;
}

.profile-username {
  font-size: 0.875rem;
  color: var(--tw-gray);
  margin-top: 1px;
}

.profile-bio {
  font-size: 0.875rem;
  color: var(--tw-dark);
  margin-top: 8px;
  white-space: pre-wrap;
}

.profile-website {
  font-size: 0.8rem;
  margin-top: 6px;
}

.profile-since {
  font-size: 0.8rem;
  color: var(--tw-gray);
  margin-top: 4px;
}

.profile-since svg {
  vertical-align: middle;
  margin-right: 3px;
  fill: var(--tw-gray);
}

.profile-stats {
  display: flex;
  gap: 16px;
  margin-top: 12px;
}

.stat {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--tw-dark);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--tw-gray);
}

/* ── Sidebar Nav ────────────────────────────────────────── */
.sidebar-nav {
  flex: 1;
  padding: 8px 0;
}

.nav-section-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--tw-gray);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 12px 16px 6px;
}

.year-nav {
  list-style: none;
}

.year-nav li {
  display: block;
}

.year-nav li.nav-loading {
  padding: 8px 16px;
  color: var(--tw-gray);
  font-size: 0.85rem;
}

.year-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  font-size: 0.9rem;
  color: var(--tw-dark);
  cursor: pointer;
  transition: background 0.15s;
  border-radius: 0;
}

.year-item:hover {
  background: var(--tw-gray-light);
}

.year-item.active {
  color: var(--tw-blue);
  font-weight: 700;
  background: rgba(29, 161, 242, 0.08);
}

.year-item .year-label { font-weight: 500; }
.year-item .year-count {
  font-size: 0.78rem;
  color: var(--tw-gray);
  font-weight: 400;
}
.year-item.active .year-count { color: var(--tw-blue); opacity: 0.8; }

/* ── Sidebar Footer ─────────────────────────────────────── */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--tw-border);
  font-size: 0.72rem;
  color: var(--tw-gray);
  line-height: 1.6;
}

/* ── Main Column ────────────────────────────────────────── */
.main-column {
  flex: 1;
  max-width: var(--main-max-width);
  border-right: 1px solid var(--tw-border);
  min-height: 100vh;
  background: var(--tw-card-bg);
}

/* ── Search Bar ─────────────────────────────────────────── */
.search-bar-wrap {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 10px 16px;
  border-bottom: 1px solid var(--tw-border);
}

.search-bar {
  display: flex;
  align-items: center;
  background: var(--tw-gray-light);
  border-radius: 9999px;
  padding: 0 14px;
  gap: 8px;
  border: 1px solid transparent;
  transition: border-color 0.15s, background 0.15s;
}

.search-bar:focus-within {
  background: var(--tw-white);
  border-color: var(--tw-blue);
}

.search-icon {
  width: 18px;
  height: 18px;
  fill: var(--tw-gray);
  flex-shrink: 0;
}

#search-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 0.9rem;
  color: var(--tw-dark);
  padding: 8px 0;
  font-family: var(--font);
}

#search-input::placeholder { color: var(--tw-gray); }

.search-clear {
  color: var(--tw-gray);
  font-size: 0.85rem;
  padding: 2px 4px;
  border-radius: 50%;
  line-height: 1;
  transition: color 0.15s;
}
.search-clear:hover { color: var(--tw-blue); }

/* ── Status Bar ─────────────────────────────────────────── */
.status-bar {
  padding: 6px 16px;
  font-size: 0.8rem;
  color: var(--tw-gray);
  border-bottom: 1px solid var(--tw-border);
  min-height: 30px;
}

/* ── Tweet List ─────────────────────────────────────────── */
.tweet-list {
  /* Container for tweet cards */
}

/* ── Tweet Card ─────────────────────────────────────────── */
.tweet {
  padding: 12px 16px;
  border-bottom: 1px solid var(--tw-border);
  transition: background 0.1s;
  position: relative;
}

.tweet:hover { background: rgba(0,0,0,0.015); }

/* Thread line above self-replies */
.tweet.is-thread-reply::before {
  content: '';
  position: absolute;
  top: 0;
  left: 36px;
  width: 2px;
  height: 12px;
  background: var(--tw-border);
}

.tweet-inner {
  display: flex;
  gap: 12px;
}

/* ── Tweet Avatar ───────────────────────────────────────── */
.tweet-avatar {
  flex-shrink: 0;
}

.tweet-avatar img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--tw-gray-light);
}

/* ── Tweet Body ─────────────────────────────────────────── */
.tweet-body {
  flex: 1;
  min-width: 0;
}

/* RT label */
.tweet-rt-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--tw-gray-dark);
  margin-bottom: 4px;
  font-weight: 600;
}

.tweet-rt-label svg {
  width: 14px;
  height: 14px;
  fill: var(--tw-rt-color);
}

.tweet-rt-label span { color: var(--tw-rt-color); }

/* Thread reply label */
.tweet-thread-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--tw-thread-color);
  margin-bottom: 4px;
}

/* Tweet header: name, username, date */
.tweet-header {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 4px;
  line-height: 1.2;
}

.tweet-display-name {
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--tw-dark);
}

.tweet-username {
  font-size: 0.85rem;
  color: var(--tw-gray);
}

.tweet-date-sep { color: var(--tw-gray); font-size: 0.85rem; }

.tweet-date {
  font-size: 0.82rem;
  color: var(--tw-gray);
  white-space: nowrap;
}

.tweet-date a {
  color: var(--tw-gray);
  text-decoration: none;
}
.tweet-date a:hover { text-decoration: underline; color: var(--tw-blue); }

/* Tweet text */
.tweet-text {
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--tw-dark);
  word-break: break-word;
  white-space: pre-wrap;
}

.tweet-text a        { color: var(--tw-link); }
.tweet-text .mention { color: var(--tw-mention); }
.tweet-text .hashtag { color: var(--tw-hashtag); }
.tweet-text .rt-text { color: var(--tw-dark); }

/* RT quoted text */
.tweet-rt-text {
  margin-top: 4px;
  font-size: 0.9rem;
  color: var(--tw-dark);
  word-break: break-word;
  white-space: pre-wrap;
}

/* ── Tweet Media ────────────────────────────────────────── */
.tweet-media {
  margin-top: 10px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--tw-border);
}

.tweet-media.media-grid-2,
.tweet-media.media-grid-3,
.tweet-media.media-grid-4 {
  display: grid;
  gap: 2px;
}

.tweet-media.media-grid-2 { grid-template-columns: 1fr 1fr; }
.tweet-media.media-grid-3 { grid-template-columns: 1fr 1fr; }
.tweet-media.media-grid-4 { grid-template-columns: 1fr 1fr; }

.tweet-media.media-grid-3 .media-item:first-child {
  grid-row: span 2;
}

.media-item {
  overflow: hidden;
  position: relative;
  background: var(--tw-gray-light);
  aspect-ratio: 16/9;
}

.media-item.single { aspect-ratio: auto; max-height: 300px; }

.media-item img,
.media-item video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.media-item.single img,
.media-item.single video {
  height: auto;
  max-height: 300px;
  object-fit: contain;
  background: #000;
}

.media-fallback-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 120px;
  color: var(--tw-gray);
  font-size: 0.8rem;
}

/* ── Tweet Footer: stats ────────────────────────────────── */
.tweet-stats {
  display: flex;
  gap: 16px;
  margin-top: 10px;
}

.tweet-stat {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.82rem;
  color: var(--tw-gray);
}

.tweet-stat svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* ── Load More ──────────────────────────────────────────── */
.load-more-wrap {
  padding: 20px 16px;
  text-align: center;
}

.load-more-btn {
  background: transparent;
  color: var(--tw-blue);
  border: 1px solid var(--tw-blue);
  border-radius: 9999px;
  padding: 10px 28px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.load-more-btn:hover {
  background: rgba(29,161,242,0.1);
}

/* ── No Results ─────────────────────────────────────────── */
.no-results {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  color: var(--tw-gray);
  text-align: center;
}

.no-results-icon {
  width: 48px;
  height: 48px;
  fill: var(--tw-gray);
  margin-bottom: 16px;
  opacity: 0.4;
}

/* ── Loading placeholder ────────────────────────────────── */
.loading-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 60px 24px;
  color: var(--tw-gray);
  gap: 16px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--tw-gray-light);
  border-top-color: var(--tw-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Mobile Sidebar Toggle ──────────────────────────────── */
.sidebar-toggle {
  display: none;
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--tw-blue);
  color: white;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.sidebar-toggle svg {
  width: 24px;
  height: 24px;
  fill: white;
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 860px) {
  .app-layout {
    position: relative;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100%;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 16px rgba(0,0,0,0.1);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-column {
    max-width: 100%;
    border-right: none;
  }

  .sidebar-toggle {
    display: flex;
  }
}

@media (max-width: 500px) {
  .tweet { padding: 10px 12px; }
  .tweet-media { border-radius: 8px; }
  .media-item.single { max-height: 200px; }
}

/* ── Overlay (mobile sidebar) ───────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 40;
}
.sidebar-overlay.active { display: block; }
