:root {
  --bg: #1a1a2e;
  --bg-card: #222244;
  --bg-card-hover: #2a2a50;
  --text: #e0e0e8;
  --text-dim: #8888aa;
  --accent: #e8a850;
  --accent-dim: #c08030;
  --danger: #d04040;
  --success: #40a060;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', monospace;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px;
}

.hidden {
  display: none !important;
}

/* ── Navigation Bar ── */
#bc-navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid #222244;
  margin-bottom: 8px;
}

.bc-brand {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
}

.bc-brand-light {
  color: var(--text-dim);
  font-weight: 400;
}

.bc-links {
  display: flex;
  gap: 20px;
  list-style: none;
}

.bc-links a {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 500;
  transition: color 0.15s;
  padding-bottom: 2px;
  border-bottom: 2px solid transparent;
}

.bc-links a:hover {
  color: var(--accent);
}

.bc-links a.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.bc-hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  flex-direction: column;
  gap: 4px;
  padding: 4px;
}

.bc-hamburger span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text-dim);
  border-radius: 1px;
}

@media (max-width: 640px) {
  .bc-links {
    display: none;
    position: absolute;
    top: 52px;
    right: 16px;
    background: var(--bg-card);
    border: 1px solid #333366;
    border-radius: 8px;
    flex-direction: column;
    padding: 8px 0;
    z-index: 50;
    min-width: 140px;
  }

  .bc-links.open {
    display: flex;
  }

  .bc-links a {
    padding: 8px 16px;
    border-bottom: none;
  }

  .bc-hamburger {
    display: flex;
  }
}

/* ── Top Bar ── */
#top-bar {
  padding: 0 0 20px;
  border-bottom: 1px solid #222244;
}

#top-bar h1 {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.brand {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--accent);
}

.brand-sub {
  font-size: 0.85rem;
  color: var(--text-dim);
}

/* ── Stats Bar ── */
#stats-bar {
  padding: 16px 0;
  text-align: center;
}

#stats-text {
  font-size: 0.9rem;
  color: var(--text-dim);
}

#stats-text strong {
  color: var(--accent);
  font-weight: 600;
}

/* ── Filter Bar ── */
#filter-bar {
  padding: 0 0 20px;
}

.filter-section {
  display: flex;
  align-items: center;
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  background: var(--bg-card);
  color: var(--text-dim);
  border: 1px solid transparent;
  transition:
    background 0.15s,
    color 0.15s,
    border-color 0.15s;
}

.pill:hover {
  background: var(--bg-card-hover);
  color: var(--text);
}

.pill.active {
  background: rgba(232, 168, 80, 0.15);
  color: var(--accent);
  border-color: var(--accent-dim);
}

.pill .pill-count {
  margin-left: 4px;
  font-size: 0.7rem;
  opacity: 0.7;
}

/* ── State Containers ── */
.state-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 16px;
}

.empty-msg {
  font-size: 1.1rem;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.empty-hint {
  font-size: 0.85rem;
  color: var(--text-dim);
  opacity: 0.6;
}

/* ── Loading Spinner ── */
.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #333366;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Devices Grid ── */
.devices-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-bottom: 32px;
}

.device-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  transition:
    background 0.15s,
    transform 0.1s;
  border: 1px solid transparent;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.device-card:hover {
  background: var(--bg-card-hover);
}

.device-card:active {
  transform: scale(0.98);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.card-model {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
  flex: 1;
  min-width: 0;
}

.card-manufacturer {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.card-id {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--text-dim);
  opacity: 0.7;
}

.card-date {
  font-size: 0.7rem;
  color: var(--text-dim);
  opacity: 0.7;
}

.card-description {
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}

/* ── Level Badge ── */
.level-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 10px;
  white-space: nowrap;
}

.level-badge.l1 {
  background: rgba(64, 160, 96, 0.15);
  color: var(--success);
}

.level-badge.l2 {
  background: rgba(100, 140, 220, 0.15);
  color: #8cb4f0;
}

.level-badge.l3 {
  background: rgba(232, 168, 80, 0.15);
  color: var(--accent);
}

.card-open {
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 500;
}

/* ── Apply Section ── */
#apply-section {
  margin-bottom: 32px;
}

.apply-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px 24px;
  border: 1px solid rgba(232, 168, 80, 0.2);
}

.apply-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.apply-desc {
  font-size: 0.82rem;
  color: var(--text-dim);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 24px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s;
}

.btn:active {
  opacity: 0.8;
}

.btn-primary {
  background: var(--accent);
  color: #1a1a2e;
  flex: 1;
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid #333366;
  flex: 1;
}

/* ── Footer ── */
#footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 0;
  margin-top: auto;
  border-top: 1px solid #222244;
  font-size: 0.78rem;
  color: var(--text-dim);
}

#footer a {
  color: var(--text-dim);
  text-decoration: none;
}

#footer a:hover {
  color: var(--text);
}

/* ── Detail Overlay ── */
#detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.detail-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
}

.detail-card {
  position: relative;
  background: var(--bg-card);
  border-radius: 16px 16px 0 0;
  padding: 28px 24px 32px;
  max-width: 520px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.detail-header {
  text-align: center;
}

.detail-logo-container {
  width: 64px;
  height: 64px;
  margin: 0 auto 12px;
  border-radius: 12px;
  overflow: hidden;
  background: #333366;
  display: flex;
  align-items: center;
  justify-content: center;
}

.detail-logo-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.detail-logo-container .detail-logo-placeholder {
  font-size: 1.5rem;
  color: var(--text-dim);
  font-weight: 700;
}

.detail-header h2 {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.detail-header p {
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.detail-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.detail-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.detail-label {
  font-size: 0.78rem;
  color: var(--text-dim);
  min-width: 72px;
  flex-shrink: 0;
}

.detail-value {
  font-size: 0.85rem;
  font-family: var(--font-mono);
  color: var(--text);
}

.detail-description-text {
  font-size: 0.85rem;
  color: var(--text);
  line-height: 1.6;
}

.detail-level-info {
  background: rgba(232, 168, 80, 0.08);
  border-radius: 8px;
  padding: 14px;
  font-size: 0.8rem;
  color: var(--text-dim);
  line-height: 1.5;
}

.detail-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

/* ── Responsive ── */
@media (min-width: 600px) {
  .devices-grid {
    grid-template-columns: 1fr 1fr;
  }

  .detail-card {
    border-radius: 16px;
    margin-bottom: 24px;
  }

  #detail-overlay {
    align-items: center;
  }
}

@media (min-width: 900px) {
  .devices-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }

  #app {
    padding: 0 24px;
  }
}

@media (max-width: 400px) {
  .brand {
    font-size: 1.4rem;
  }

  .card-model {
    font-size: 0.92rem;
  }

  .detail-card {
    padding: 20px 16px 24px;
  }

  .apply-card {
    flex-direction: column;
    text-align: center;
  }
}

/* ══════════════════════════════════════════════════════════
   Light Theme Overrides
   ══════════════════════════════════════════════════════════ */
[data-theme='light'] {
  #bc-navbar {
    background: #f5f0eb;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  }
  .bc-links a {
    color: #1a1a2e;
  }
  .bc-links a:hover {
    color: #b87333;
  }
  .bc-links a.active {
    color: #b87333;
    border-bottom-color: #b87333;
  }

  #top-bar {
    border-bottom-color: rgba(0, 0, 0, 0.1);
  }

  .pill {
    background: #e8e4dc;
    color: #666680;
  }
  .pill.active {
    background: rgba(184, 115, 51, 0.15);
    color: #b87333;
    border-color: #b87333;
  }

  .device-card {
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.1);
  }
  .device-card:hover {
    border-color: rgba(0, 0, 0, 0.15);
  }

  .card-meta-sep {
    color: #bbbbcc;
  }

  .detail-card {
    background: #ffffff;
  }

  .apply-card {
    background: #ffffff;
    border-color: rgba(0, 0, 0, 0.1);
  }

  .btn-ghost {
    border-color: rgba(0, 0, 0, 0.1);
  }

  #footer {
    border-top-color: rgba(0, 0, 0, 0.1);
  }
}
