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

:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --accent: #0066cc;
  --accent-dark: #0052a3;
  --danger: #cc2200;
  --text: #1a1a1a;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.05);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.16);
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding-bottom: 6rem;
}

/* ── Header ───────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--accent);
  color: #fff;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0,0,102,0.2);
}

.app-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.component-count {
  font-size: 0.8rem;
  opacity: 0.85;
  background: rgba(255,255,255,0.2);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
}

/* ── Main layout ──────────────────────────────────────── */
.app-main { padding: 1rem; max-width: 720px; margin: 0 auto; }

/* ── Search bar ───────────────────────────────────────── */
.search-bar { margin-bottom: 1rem; }

.search-input {
  width: 100%;
  padding: 0.65rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.search-input:focus { border-color: var(--accent); }

/* ── Component grid ───────────────────────────────────── */
.component-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

@media (min-width: 540px) {
  .component-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Component card ───────────────────────────────────── */
.component-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem;
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.1s;
  border: 1.5px solid transparent;
}

.component-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
  border-color: var(--border);
}

.component-card:active { transform: translateY(0); }

.card-thumb {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: contain;
  background: var(--bg);
  flex-shrink: 0;
}

.card-thumb-placeholder {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  background: var(--bg);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: var(--text-muted);
}

.card-body { flex: 1; min-width: 0; }

.card-name {
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-mfr {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-meta {
  margin-top: 0.35rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.chip {
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: #e8f0fe;
  color: var(--accent);
  font-weight: 500;
}

.chip-gray {
  background: var(--bg);
  color: var(--text-muted);
}

/* ── Empty state ──────────────────────────────────────── */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-icon { font-size: 3rem; margin-bottom: 0.75rem; }
.empty-state p { margin-top: 0.25rem; font-size: 0.95rem; }

/* ── FAB ──────────────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 20;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.75rem 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,102,204,0.4);
  transition: background 0.15s, transform 0.1s;
}

.fab:hover { background: var(--accent-dark); }
.fab:active { transform: scale(0.97); }

/* ── Scanner modal ────────────────────────────────────── */
.scanner-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
}

.scanner-modal[hidden] { display: none; }

.scanner-overlay {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
}

.scanner-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #fff;
  font-size: 0.9rem;
}

.scanner-close {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scanner-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  max-width: 360px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
}

.scanner-viewport video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner-frame {
  position: absolute;
  inset: 15%;
  border: 3px solid rgba(255,255,255,0.7);
  border-radius: 8px;
  pointer-events: none;
}

.scanner-frame::before,
.scanner-frame::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border-color: #fff;
  border-style: solid;
}

.scanner-hint {
  color: rgba(255,255,255,0.7);
  font-size: 0.85rem;
  text-align: center;
}

/* ── Detail modal ─────────────────────────────────────── */
.detail-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
}

.detail-modal[hidden] { display: none; }

.detail-sheet {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 1rem;
  animation: slide-up 0.25s ease;
}

@keyframes slide-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.detail-header {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.5rem;
}

.detail-close {
  background: var(--bg);
  border: none;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.detail-image {
  width: 100%;
  max-height: 200px;
  object-fit: contain;
  border-radius: var(--radius);
  background: var(--bg);
  margin-bottom: 1rem;
}

.detail-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
  line-height: 1.3;
}

.detail-sub {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.detail-fields { display: grid; gap: 0.5rem; margin-bottom: 1rem; }

.detail-field {
  display: flex;
  gap: 0.5rem;
  font-size: 0.875rem;
}

.detail-field-label {
  color: var(--text-muted);
  flex-shrink: 0;
  width: 7rem;
}

.detail-field-value { font-weight: 500; word-break: break-all; }

.detail-links {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.detail-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.9rem;
  background: var(--bg);
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--accent);
  text-decoration: none;
  border: 1.5px solid var(--border);
}

.detail-link:hover { background: #e8f0fe; }

.detail-dates {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
  line-height: 1.8;
}

.btn-danger {
  width: 100%;
  padding: 0.75rem;
  background: none;
  border: 1.5px solid var(--danger);
  color: var(--danger);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-danger:hover { background: #fff0ee; }

/* ── Toast ────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 5.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a1a;
  color: #fff;
  padding: 0.65rem 1.2rem;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 100;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  animation: toast-in 0.2s ease;
}

.toast[hidden] { display: none; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
