/* ===== CSS Variables ===== */
:root {
  --primary: #3498db;
  --primary-dark: #2980b9;
  --secondary: #2c3e50;
  --accent: #e74c3c;
  --bg: #f0f4f8;
  --card-bg: #ffffff;
  --text: #2c3e50;
  --text-muted: #6c757d;
  --border: #dde3ec;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.07);
  --shadow-hover: 0 6px 20px rgba(0, 0, 0, 0.12);
  --radius: 12px;
  --filter-bg: rgba(255, 255, 255, 0.96);
  --transition: 0.2s ease;
}

/* ===== Dark Mode Variables ===== */
body.dark-mode {
  --primary: #4da6e0;
  --primary-dark: #3498db;
  --secondary: #1a1a2e;
  --accent: #e94560;
  --bg: #0f0f1a;
  --card-bg: #1a1a2e;
  --text: #dde0f0;
  --text-muted: #8888aa;
  --border: #2a2a42;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  --shadow-hover: 0 6px 20px rgba(0, 0, 0, 0.45);
  --filter-bg: rgba(20, 20, 38, 0.97);
}

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

html, body {
  height: 100%;
  margin: 0;
}

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  transition: background-color 0.3s, color 0.3s;
  line-height: 1.5;
}

/* ===== Page Layout ===== */
.page-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.content-wrap { flex: 1; }

/* ===== Header ===== */
.site-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  padding: 2rem 0 1.5rem;
  text-align: center;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.18);
}

.site-header h1 {
  color: #fff;
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0 0 0.4rem;
  letter-spacing: -0.02em;
}

.site-header p {
  color: rgba(255, 255, 255, 0.82);
  margin: 0;
  font-size: 0.93rem;
}

.site-header a {
  color: #fff;
  background: rgba(255, 255, 255, 0.2);
  padding: 0.1rem 0.55rem;
  border-radius: 5px;
  text-decoration: none;
  transition: background var(--transition);
}

.site-header a:hover {
  background: rgba(255, 255, 255, 0.32);
}

/* ===== Sticky Filter Bar ===== */
.filter-bar {
  position: sticky;
  top: 0;
  z-index: 200;
  background: var(--filter-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding: 0.65rem 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

/* ── Quick Presets ── */
.presets {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.6rem;
}

.preset-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.preset-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.28rem 0.7rem;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  font-size: 0.78rem;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), color var(--transition);
  white-space: nowrap;
  line-height: 1.4;
}

.preset-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.preset-btn.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

/* ── Filter Controls ── */
.filter-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.filter-label {
  font-size: 0.76rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.filter-select {
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--card-bg);
  color: var(--text);
  font-size: 0.8rem;
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  transition: border-color var(--transition);
  max-width: 155px;
}

.filter-select:focus {
  outline: none;
  border-color: var(--primary);
}

.filter-check-label {
  display: flex;
  align-items: center;
  gap: 0.38rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}

.filter-check-label input[type="checkbox"] {
  cursor: pointer;
  accent-color: var(--primary);
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.btn-reset {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.75rem;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
  white-space: nowrap;
  margin-left: auto;
}

.btn-reset:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Filter Stats ── */
.filter-stats {
  margin-top: 0.45rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  min-height: 1em;
}

/* ===== Repo Grid ===== */
#repoContainer {
  padding-top: 0.5rem;
}

/* ===== Card ===== */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.22s ease, box-shadow 0.22s ease;
  height: 100%;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
}

.card-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  padding: 0.85rem 1rem;
  cursor: pointer;
  border: none;
  border-radius: 0 !important;
  user-select: none;
}

.card-header:hover {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--secondary) 100%);
}

.card-header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.repo-title {
  color: #fff;
  font-size: 0.88rem;
  font-weight: 600;
  margin: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-header-right {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
}

.tag-badge {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  border-radius: 20px;
  padding: 0.15rem 0.65rem;
  font-size: 0.73rem;
  font-weight: 500;
  white-space: nowrap;
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tag-badge.syncing {
  background: rgba(255, 255, 255, 0.1);
  font-style: italic;
}

.chevron-icon {
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.78rem;
  transition: transform 0.3s ease;
  flex-shrink: 0;
}

.chevron-icon.rotated {
  transform: rotate(180deg);
}

/* ===== Collapsible ===== */
.collapsible-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease-out;
}

.collapsible-content.open {
  max-height: 9999px;
  transition: max-height 0.5s ease-in;
}

/* ===== Asset List ===== */
.asset-list {
  max-height: 360px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--primary) transparent;
}

.asset-list::-webkit-scrollbar { width: 4px; }
.asset-list::-webkit-scrollbar-thumb {
  background: var(--primary);
  border-radius: 4px;
}

/* Remove height limit when actively filtering */
.filtering .asset-list {
  max-height: none;
  overflow-y: visible;
}

/* ===== Asset Item ===== */
.asset-item {
  display: flex;
  align-items: flex-start;
  padding: 0.6rem 1rem;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
  min-width: 0;
}

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

.asset-item:hover { background: rgba(52, 152, 219, 0.05); }

body.dark-mode .asset-item:hover { background: rgba(255, 255, 255, 0.04); }

/* ── Asset Link ── */
.asset-link {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  color: var(--text);
  text-decoration: none;
  flex: 1;
  min-width: 0;
  transition: color var(--transition);
}

.asset-link:hover { color: var(--primary); }

.asset-link.failed {
  color: var(--text-muted);
  cursor: default;
}

.asset-link.failed:hover { color: var(--text-muted); }

/* ── Icon ── */
.asset-icon {
  flex-shrink: 0;
  margin-top: 0.18rem;
  width: 1em;
  text-align: center;
  color: var(--primary);
  font-size: 0.9rem;
}

.asset-link.failed .asset-icon { color: var(--accent); }

/* ── Filename ── the key fix for long names ── */
.asset-name {
  flex: 1;
  min-width: 0;
  word-break: break-word;
  overflow-wrap: break-word;
  white-space: normal;
  line-height: 1.45;
  font-size: 0.83rem;
}

/* ── Failed badge ── */
.failed-badge {
  flex-shrink: 0;
  font-size: 0.68rem;
  color: #fff;
  background: var(--accent);
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  align-self: flex-start;
  margin-top: 0.18rem;
  white-space: nowrap;
}

/* ── Download Button ── */
.download-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  border: none;
  font-size: 0.78rem;
  transition: background var(--transition), transform var(--transition);
  align-self: flex-start;
  margin-top: 0.08rem;
}

.download-btn:hover {
  background: var(--accent);
  transform: scale(1.12);
  color: #fff;
}

/* ===== Meta files (checksums, sigs) ===== */
.asset-item[data-meta="true"] {
  opacity: 0.45;
}

.asset-item[data-meta="true"]:hover {
  opacity: 0.7;
}

.asset-item[data-meta="true"] .asset-icon {
  color: var(--text-muted);
}

/* ===== Empty States ===== */
.no-assets {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.no-results {
  display: none;
  text-align: center;
  padding: 4rem 1rem 3rem;
  color: var(--text-muted);
}

.no-results p { margin: 0.5rem 0 1.25rem; font-size: 0.95rem; }

/* ===== Dark Mode Toggle ===== */
.dark-mode-toggle {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--secondary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.25);
  z-index: 1000;
  transition: transform 0.2s, background 0.3s;
  font-size: 1rem;
}

.dark-mode-toggle:hover { transform: scale(1.1); }

/* ===== Footer ===== */
.site-footer {
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: #fff;
  padding: 1.2rem 0;
  margin-top: 2.5rem;
  border-radius: 12px 12px 0 0;
}

.site-footer p { margin: 0; font-size: 0.88rem; }

.site-footer a {
  color: #fff;
  text-decoration: none;
  font-weight: 500;
}

.site-footer a:hover { text-decoration: underline; }

/* ===== Animations ===== */
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.repo-card-wrapper {
  animation: fadeSlideIn 0.35s ease both;
}

.repo-card-wrapper:nth-child(1)  { animation-delay: 0.03s; }
.repo-card-wrapper:nth-child(2)  { animation-delay: 0.07s; }
.repo-card-wrapper:nth-child(3)  { animation-delay: 0.11s; }
.repo-card-wrapper:nth-child(4)  { animation-delay: 0.15s; }
.repo-card-wrapper:nth-child(5)  { animation-delay: 0.19s; }
.repo-card-wrapper:nth-child(6)  { animation-delay: 0.23s; }
.repo-card-wrapper:nth-child(7)  { animation-delay: 0.27s; }
.repo-card-wrapper:nth-child(8)  { animation-delay: 0.31s; }
.repo-card-wrapper:nth-child(9)  { animation-delay: 0.35s; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .site-header { padding: 1.25rem 0 1rem; }
  .site-header h1 { font-size: 1.35rem; }

  .presets { gap: 0.35rem; }
  .preset-btn { font-size: 0.73rem; padding: 0.22rem 0.55rem; }

  .filter-controls { gap: 0.45rem; }
  .filter-select { max-width: 130px; }

  .asset-name { font-size: 0.8rem; }
  .asset-item { padding: 0.55rem 0.75rem; }
}

@media (max-width: 480px) {
  .filter-label { display: none; }

  .filter-select {
    max-width: none;
    flex: 1;
    min-width: 0;
  }

  .filter-group { flex: 1; }
  .filter-controls { gap: 0.35rem; }

  .preset-label { width: 100%; }

  .btn-reset { margin-left: 0; }
}
