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

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: #f5f5f5;
  color: #333;
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-size: 1rem;
}

a { color: #0066bb; text-decoration: underline; }
a:hover { color: #004476; }

/* === Header === */
.site-header {
  background: #004476;
  color: #fff;
  padding: 0 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: 56px;
}
.logo {
  color: #fff;
  font-weight: 700;
  font-size: 1.15rem;
  white-space: nowrap;
  text-decoration: none;
}
.logo:hover { color: #fff; text-decoration: none; opacity: 0.9; }
.header-nav { display: flex; gap: 1rem; }
.header-nav a {
  color: rgba(255,255,255,0.85);
  font-size: 1rem;
  font-weight: 500;
  text-decoration: none;
  padding: 0.5rem 0.25rem;
}
.header-nav a:hover { color: #fff; text-decoration: none; }
.built-by {
  margin-left: auto;
  color: rgba(255,255,255,0.6);
  font-size: 0.8rem;
  text-decoration: none;
  white-space: nowrap;
}
.built-by strong { color: rgba(255,255,255,0.9); }
.built-by:hover { color: #fff; text-decoration: none; }
.built-by:hover strong { text-decoration: underline; }
.header-search {
  display: flex;
  gap: 0;
}
.header-search input {
  padding: 0.5rem 0.75rem;
  border: none;
  border-radius: 4px 0 0 4px;
  font-size: 1rem;
  width: 240px;
  outline: none;
}
.header-search input:focus { box-shadow: 0 0 0 2px rgba(255,255,255,0.4); }
.header-search button {
  padding: 0.5rem 1rem;
  background: #005a9e;
  color: #fff;
  border: none;
  border-radius: 0 4px 4px 0;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  min-height: 44px;
}
.header-search button:hover { background: #006bbd; }

/* === Footer === */
.site-footer {
  background: #004476;
  color: rgba(255,255,255,0.8);
  padding: 1.5rem 1rem;
  margin-top: auto;
  font-size: 0.95rem;
  text-align: center;
}
.site-footer a { color: rgba(255,255,255,0.95); }
.footer-inner { max-width: 1200px; margin: 0 auto; }
.footer-inner p + p { margin-top: 0.25rem; }

/* === Main Content === */
#app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  width: 100%;
  flex: 1;
}

/* === Loading === */
.loading {
  text-align: center;
  padding: 3rem;
  color: #555;
}
.loading::after {
  content: '';
  display: block;
  width: 32px;
  height: 32px;
  margin: 1rem auto 0;
  border: 3px solid #ddd;
  border-top-color: #004476;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Home Page === */
.home-hero {
  text-align: center;
  padding: 2rem 1rem;
  margin-bottom: 2rem;
}
.home-hero h1 {
  font-size: 1.8rem;
  color: #004476;
  margin-bottom: 0.5rem;
}
.home-hero p {
  color: #555;
  font-size: 1.1rem;
  max-width: 600px;
  margin: 0 auto;
}
.home-search {
  margin: 1.5rem auto 0;
  max-width: 500px;
  display: flex;
  gap: 0;
}
.home-search input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 2px solid #ccc;
  border-radius: 6px 0 0 6px;
  font-size: 1.1rem;
  outline: none;
}
.home-search input:focus { border-color: #004476; }
.home-search button {
  padding: 0.75rem 1.5rem;
  background: #004476;
  color: #fff;
  border: none;
  border-radius: 0 6px 6px 0;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 48px;
}
.home-search button:hover { background: #005a9e; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: #fff;
  border-radius: 8px;
  padding: 1.25rem;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.stat-card .stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: #004476;
}
.stat-card .stat-label {
  font-size: 0.95rem;
  color: #555;
  margin-top: 0.25rem;
}

.year-chart {
  background: #fff;
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.year-chart h2 {
  font-size: 1.1rem;
  color: #004476;
  margin-bottom: 1rem;
}
.year-bars {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 120px;
  padding-bottom: 1.5rem;
  position: relative;
}
.year-bar {
  flex: 1;
  background: #004476;
  border-radius: 2px 2px 0 0;
  min-width: 8px;
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
}
.year-bar:hover { background: #005a9e; }
.year-bar .year-label {
  position: absolute;
  bottom: -1.4rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  color: #555;
  white-space: nowrap;
}
.year-bar .year-count {
  position: absolute;
  top: -1.2rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  color: #555;
  white-space: nowrap;
  display: none;
}
.year-bar:hover .year-count { display: block; }

/* === Thread List === */
.page-title {
  font-size: 1.4rem;
  color: #004476;
  margin-bottom: 0.5rem;
}
.page-subtitle {
  color: #555;
  margin-bottom: 1rem;
  font-size: 1rem;
}
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
  align-items: center;
}
.controls select, .controls input {
  padding: 0.5rem 0.75rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 1rem;
  background: #fff;
}
.year-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 1rem;
}
.year-pill {
  padding: 0.3rem 0.7rem;
  border-radius: 12px;
  font-size: 0.85rem;
  background: #e8ecf0;
  color: #444;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  min-height: 32px;
}
.year-pill:hover { background: #d0d8e0; }
.year-pill.active { background: #004476; color: #fff; }

.thread-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.thread-table th {
  background: #004476;
  color: #fff;
  padding: 0.75rem;
  text-align: left;
  font-size: 0.95rem;
  font-weight: 600;
}
.thread-table td {
  padding: 0.75rem;
  border-bottom: 1px solid #eee;
  font-size: 1rem;
}
.thread-table tr:last-child td { border-bottom: none; }
.thread-table tr:hover td { background: #f8fafc; }
.thread-table tr { cursor: pointer; }
.thread-table .thread-title-link {
  font-weight: 500;
  text-decoration: none;
}
.thread-table .thread-title-link:hover { text-decoration: underline; }
.thread-table .post-count {
  text-align: center;
  color: #555;
  white-space: nowrap;
}
.thread-table .thread-date {
  white-space: nowrap;
  color: #555;
  font-size: 0.95rem;
}
.thread-table .thread-author {
  color: #444;
  font-size: 0.95rem;
}
.thread-meta-mobile {
  display: none;
}
.author-meta-mobile {
  display: none;
}

/* === Pagination === */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.4rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}
.pagination button {
  padding: 0.5rem 0.9rem;
  border: 1px solid #ddd;
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  color: #333;
  min-height: 44px;
  min-width: 44px;
}
.pagination button:hover:not(:disabled) { background: #f0f4f8; border-color: #004476; }
.pagination button:disabled { opacity: 0.4; cursor: default; }
.pagination button.active { background: #004476; color: #fff; border-color: #004476; }
.pagination .page-info { font-size: 1rem; color: #555; }

/* === Thread Detail === */
.thread-header {
  margin-bottom: 1.5rem;
}
.thread-header h1 {
  font-size: 1.4rem;
  color: #004476;
  margin-bottom: 0.25rem;
}
.thread-meta {
  color: #555;
  font-size: 0.95rem;
}
.thread-meta .original-link {
  color: #555;
  font-size: 0.9rem;
}
.thread-meta .original-link:hover {
  color: #004476;
}
.back-link {
  display: inline-block;
  margin-bottom: 1rem;
  font-size: 1rem;
  color: #0066bb;
  min-height: 44px;
  line-height: 44px;
}

.post-card {
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.post-header {
  background: #004476;
  color: #fff;
  padding: 0.6rem 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.95rem;
}
.post-header .post-author { font-weight: 600; }
.post-header .post-author a { color: inherit; text-decoration: none; }
.post-header .post-author a:hover { text-decoration: underline; }
.post-header .post-date { opacity: 0.85; }
.post-body {
  padding: 1rem 0.75rem;
  font-size: 1rem;
  line-height: 1.7;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.post-body a { word-break: break-all; }

/* Quoted text */
.post-body blockquote {
  border-left: 3px solid #004476;
  background: #f0f4f8;
  margin: 0.75rem 0;
  padding: 0.6rem 0.75rem;
  border-radius: 0 4px 4px 0;
  font-size: 0.95rem;
  color: #444;
}
.post-body .quote-attribution {
  font-weight: 600;
  font-size: 0.9rem;
  color: #004476;
  margin-bottom: 0.25rem;
}

/* Collapsible inline quotes (email-style) */
.quote-toggle {
  display: inline-block;
  background: #e8ecf0;
  border: none;
  border-radius: 4px;
  padding: 0.25rem 0.6rem;
  font-size: 0.85rem;
  color: #555;
  cursor: pointer;
  margin: 0.4rem 0;
  letter-spacing: 1px;
  line-height: 1;
  min-height: 32px;
  min-width: 44px;
  text-align: center;
}
.quote-toggle:hover { background: #d0d8e0; color: #333; }
.collapsed-quote { display: none; }
.collapsed-quote.expanded {
  display: block;
  border-left: 3px solid #ccc;
  background: #f8f9fa;
  margin: 0.4rem 0 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: 0 4px 4px 0;
  font-size: 0.95rem;
  color: #555;
  line-height: 1.6;
}
.collapsed-quote.expanded a { color: #0066bb; }

/* Signatures */
.post-signature {
  border-top: 1px solid #eee;
  margin-top: 0.75rem;
  padding-top: 0.5rem;
  font-size: 0.9rem;
  color: #555;
  line-height: 1.5;
}

/* Attachments */
.post-attachments {
  padding: 0.75rem 1rem;
  margin: 0.5rem 0.75rem 0.75rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
}
.post-attachments-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.5rem;
}
.attachment-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}
.attachment-thumb {
  width: 360px;
  height: 270px;
  object-fit: cover;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid #ddd;
  transition: transform 0.15s, box-shadow 0.15s;
}
.attachment-thumb:hover {
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.attachment-file {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.85rem;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 0.95rem;
  color: #333;
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  min-height: 44px;
}
.attachment-file:hover {
  border-color: #0066bb;
  box-shadow: 0 1px 4px rgba(0,119,204,0.15);
  text-decoration: none;
}
.attachment-file .file-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}
.attachment-file .file-type-badge {
  font-size: 0.7rem;
  font-weight: 700;
  color: #fff;
  padding: 0.15rem 0.35rem;
  border-radius: 3px;
  letter-spacing: 0.3px;
  flex-shrink: 0;
}
.attachment-file .file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

/* === Search Results === */
.search-result {
  background: #fff;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 0.75rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.search-result h3 {
  font-size: 1.1rem;
  margin-bottom: 0.25rem;
}
.search-result h3 a { color: #004476; }
.search-result .search-meta {
  font-size: 0.9rem;
  color: #555;
  margin-bottom: 0.4rem;
}
.search-result .search-snippet {
  font-size: 1rem;
  color: #444;
  line-height: 1.6;
}
.search-result .search-snippet mark,
mark.search-highlight {
  background: #fef08a;
  padding: 0.05rem 0.15rem;
  border-radius: 2px;
}

/* === Authors === */
.author-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.author-table th {
  background: #004476;
  color: #fff;
  padding: 0.75rem;
  text-align: left;
  font-size: 0.95rem;
  font-weight: 600;
}
.author-table td {
  padding: 0.75rem;
  border-bottom: 1px solid #eee;
  font-size: 1rem;
}
.author-table tr:last-child td { border-bottom: none; }
.author-table tr:hover td { background: #f8fafc; }

/* === Error === */
.error-message {
  text-align: center;
  padding: 3rem;
  color: #c00;
}

/* === Lightbox === */
.lightbox-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.9);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.lightbox-overlay img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 4px;
  cursor: default;
}
.lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1.5rem;
  color: #fff;
  font-size: 2.5rem;
  cursor: pointer;
  background: none;
  border: none;
  line-height: 1;
  opacity: 0.8;
  min-width: 44px;
  min-height: 44px;
}
.lightbox-close:hover { opacity: 1; }
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: #fff;
  font-size: 2.5rem;
  cursor: pointer;
  background: none;
  border: none;
  padding: 1rem;
  opacity: 0.7;
  min-width: 48px;
  min-height: 48px;
}
.lightbox-nav:hover { opacity: 1; }
.lightbox-prev { left: 0.5rem; }
.lightbox-next { right: 0.5rem; }

/* === Scroll to top === */
.scroll-top {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #004476;
  color: #fff;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 900;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.scroll-top.visible {
  opacity: 0.7;
  pointer-events: auto;
}
.scroll-top:hover { opacity: 1; }

/* === Responsive === */
@media (max-width: 768px) {
  .header-inner {
    flex-wrap: wrap;
    height: auto;
    padding: 0.5rem 0;
    gap: 0.5rem;
  }
  .built-by { display: none; }
  .header-search { width: 100%; order: 3; }
  .header-search input { width: 100%; flex: 1; }

  .home-hero h1 { font-size: 1.4rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  /* Mobile thread list — compact rows */
  .thread-table thead { display: none; }
  .thread-table .post-count,
  .thread-table .thread-date { display: none; }
  .thread-table td {
    padding: 0.65rem 0.75rem;
  }
  .thread-table .thread-title-link {
    font-size: 1.1rem;
  }
  .thread-meta-mobile {
    display: block;
    font-size: 0.85rem;
    color: #555;
    margin-top: 0.2rem;
  }

  /* Mobile author list — compact rows */
  .author-table thead { display: none; }
  .author-table .author-posts,
  .author-table .author-date { display: none; }
  .author-table td {
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid #eee;
  }
  .author-meta-mobile {
    display: block;
    font-size: 0.85rem;
    color: #555;
    margin-top: 0.2rem;
  }

  .year-bars { height: 80px; }
  .year-bar .year-label { font-size: 0.5rem; }

  .attachment-thumb {
    width: 100%;
    height: auto;
    max-height: 300px;
  }
}
