/* Reset & base styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", sans-serif;
}

body {
  background-color: #1e1e1e;
  color: white;
  padding-top: 60px;
  transition: background-color 0.3s ease, color 0.3s ease;
  min-height: 100vh;
  line-height: 1.4;
}

body.light {
  background-color: #fafafa;
  color: #222;
}

/* Header */
header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  background-color: #111;
  border-bottom: 1px solid #333;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  z-index: 999;
  transition: background-color 0.3s ease;
}

body.light header {
  background-color: #eee;
  border-bottom-color: #ccc;
}

.logo h3 {
  margin: 0;
  font-weight: 600;
  font-size: 20px;
  color: white;
  user-select: none;
}

body.light .logo h3 {
  color: #222;
}

/* Navigation Buttons */
.nav-right {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  /* Removed stray ;a */
}

button,
#sort-select {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.4rem 1rem;
  border-radius: 1rem;
  border: none;
  background-color: #333;
  color: white;
  cursor: pointer;
  transition: background-color 0.3s ease;
  user-select: none;
  white-space: nowrap;
}

button:hover,
button:focus,
#sort-select:hover,
#sort-select:focus {
  background-color: #555;
  outline: none;
}

body.light button,
body.light #sort-select {
  background-color: #ddd;
  color: #222;
}

body.light button:hover,
body.light button:focus,
body.light #sort-select:hover,
body.light #sort-select:focus {
  background-color: #bbb;
}

/* Container */
.container {
  max-width: 900px;
  margin: 2rem auto 4rem auto;
  padding: 0 2rem;
}

/* Typography */
h2 {
  margin-bottom: 0.5rem;
  user-select: none;
  font-weight: 700;
  font-size: 1.8rem;
}

p {
  color: #ccc;
  margin-bottom: 1.5rem;
  user-select: none;
  font-size: 1rem;
}

body.light p {
  color: #444;
}

/* Toolbar layout */
.toolbar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 2rem;
}

/* Filter and sort row */
.filter-sort-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Search bar */
#search-input {
  width: 100%;
  height: 40px;
  padding: 0.5rem 1rem;
  border-radius: 1rem;
  border: none;
  font-size: 1rem;
  background-color: #333;
  color: white;
  transition: background-color 0.3s ease, color 0.3s ease;
}

#search-input::placeholder {
  color: #aaa;
}

#search-input:focus {
  outline: 2px solid #5cafff;
  background-color: #444;
}

body.light #search-input {
  background-color: #eee;
  color: #222;
}

body.light #search-input::placeholder {
  color: #888;
}

body.light #search-input:focus {
  background-color: #ddd;
  outline-color: #3399ff;
}

/* Filter Buttons */
.filter-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  flex: 1 1 auto;
}

.filter-container button {
  flex: 1 1 auto;
  height: 40px;
  background-color: #333;
  font-weight: 600;
  font-size: 0.95rem;
}

.filter-container button.active,
.filter-container button:hover,
.filter-container button:focus {
  background-color: #5cafff;
  color: white;
}

body.light .filter-container button {
  background-color: #ddd;
  color: #222;
}

body.light .filter-container button.active,
body.light .filter-container button:hover,
body.light .filter-container button:focus {
  background-color: #3399ff;
  color: white;
}

/* Sort Dropdown */
#sort-select {
  height: 40px;
  flex-shrink: 0;
}

/* Tags */
.source-tag {
  background-color: #5cafff;
  color: white;
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 0.75rem;
  margin-left: 0.5rem;
  flex-shrink: 0;
  font-weight: 600;
  letter-spacing: 0.03em;
}

body.light .source-tag {
  background-color: #3399ff;
  color: white;
}

/* Resource Card */
.resource-item {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  background-color: #333;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  border-radius: 12px;
  color: white;
  text-decoration: none;
  transition: background-color 0.3s ease;
  cursor: pointer;
  overflow: hidden;
  user-select: none;
}

.resource-item:hover,
.resource-item:focus {
  background-color: #444;
  outline: none;
}

body.light .resource-item {
  background-color: #eee;
  color: #222;
}

body.light .resource-item:hover,
body.light .resource-item:focus {
  background-color: #ddd;
}

/* Top row of resource item */
.resource-item .top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

/* Resource name area */
.resource-item .name {
  font-weight: 600;
  display: flex;
  align-items: center;
  font-size: 1.1rem;
  gap: 0.5rem;
}

.source-logo {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  flex-shrink: 0;
  object-fit: contain;
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.6));
}

body.light .source-logo {
  filter: none;
}

.verified {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: #00FFCC;
  flex-shrink: 0;
}

/* Right side controls */
.right-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
  flex-wrap: nowrap;
}

/* Trust indicator */
.trust-circle {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #222;
  box-sizing: border-box;
  cursor: default;
  position: relative;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.resource-item[data-trust="trusted"] .trust-circle {
  background-color: #5CFF56;
  border-color: #4CAF50;
}

.resource-item[data-trust="mostly-trusted"] .trust-circle {
  background-color: #FFBC56;
  border-color: #E67E22;
}

.resource-item[data-trust="not-trusted"] .trust-circle {
  background-color: #FF5656;
  border-color: #C0392B;
}

/* Copy Link Button */
.copy-link-btn {
  background-color: #555;
  padding: 0.4rem 0.8rem;
  font-size: 0.9rem;
  border-radius: 1rem;
  color: white;
  border: none;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.3s ease;
}

.copy-link-btn:hover,
.copy-link-btn:focus {
  background-color: #777;
  outline: none;
}

body.light .copy-link-btn {
  background-color: #bbb;
  color: #222;
}

body.light .copy-link-btn:hover,
body.light .copy-link-btn:focus {
  background-color: #999;
}

/* Details section */
.details {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.35s ease, opacity 0.3s ease, padding 0.3s ease;
  padding: 0 1rem;
  margin-top: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  box-sizing: border-box;
  color: #ccc;
  font-size: 0.9rem;
  background-color: rgba(255 255 255 / 0.05);
  border-radius: 8px;
}

.resource-item.expanded .details {
  opacity: 1;
  padding-top: 0.75rem;
  padding-bottom: 0.5rem;
  margin-top: 0.5rem;
  /* max-height is NOT set here, JS does it dynamically */
}

/* Tooltip for trust level */
.trust-circle::after {
  content: attr(title);
  position: absolute;
  bottom: 125%;
  left: 50%;
  transform: translateX(-50%);
  background-color: #333;
  color: white;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  border-radius: 0.5rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  white-space: nowrap;
  user-select: none;
  z-index: 10;
}

.trust-circle:hover::after,
.trust-circle:focus::after {
  opacity: 1;
}

body.light .trust-circle::after {
  background-color: #ddd;
  color: #222;
}

/* Responsive Layout */
@media (max-width: 600px) {
  .resource-item .top-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .right-controls {
    width: 100%;
    justify-content: flex-start;
    gap: 0.5rem;
    flex-wrap: wrap;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-sort-row {
    flex-direction: column;
    align-items: stretch;
  }

  #search-input,
  #sort-select,
  .filter-container {
    width: 100%;
  }

  .filter-container {
    justify-content: space-between;
  }
}