:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --text: #1f2a24;
  --text-muted: #5b6b62;
  --border: #dfe6de;
  --brand: #2f6b4f;
  --brand-light: #e6f0e9;
  --valid: #2f8a4e;
  --valid-bg: #e6f4ea;
  --expiring: #b5760a;
  --expiring-bg: #fbeed9;
  --expired: #b3392f;
  --expired-bg: #fbe6e4;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10140f;
    --surface: #1a2119;
    --text: #eef2ee;
    --text-muted: #a3b0a8;
    --border: #2a3327;
    --brand: #7fc79a;
    --brand-light: #223229;
    --valid: #6fd08a;
    --valid-bg: #1c3324;
    --expiring: #e3ac52;
    --expiring-bg: #3a2c14;
    --expired: #e88478;
    --expired-bg: #3a2320;
  }
}

/* 手動亮暗模式切換（優先於系統設定） */
:root[data-theme="light"] {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --text: #1f2a24;
  --text-muted: #5b6b62;
  --border: #dfe6de;
  --brand: #2f6b4f;
  --brand-light: #e6f0e9;
  --valid: #2f8a4e;
  --valid-bg: #e6f4ea;
  --expiring: #b5760a;
  --expiring-bg: #fbeed9;
  --expired: #b3392f;
  --expired-bg: #fbe6e4;
}
:root[data-theme="dark"] {
  --bg: #10140f;
  --surface: #1a2119;
  --text: #eef2ee;
  --text-muted: #a3b0a8;
  --border: #2a3327;
  --brand: #7fc79a;
  --brand-light: #223229;
  --valid: #6fd08a;
  --valid-bg: #1c3324;
  --expiring: #e3ac52;
  --expiring-bg: #3a2c14;
  --expired: #e88478;
  --expired-bg: #3a2320;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Noto Sans TC", "Inter", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ── Masthead（品牌橫幅，寬度跟內容欄／搜尋框同寬，高度依 logo 原比例縮放） ── */
.masthead {
  background: #060f0a;
  padding: 14px 0;
}
.masthead-logo {
  width: 100%;
  height: auto;
  display: block;
}

/* ── Hero header（跟頁面背景同色，不做獨立色塊，避免變成一條突兀的橫 bar） ── */
.site-header {
  background: var(--bg);
  color: var(--text);
  padding-bottom: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 0;
  flex-wrap: wrap;
}
.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.01em;
  color: var(--text);
}
.brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
}

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.78rem;
  color: var(--brand);
  background: var(--brand-light);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 12px;
  white-space: nowrap;
}
.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand);
}

.theme-toggle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.theme-toggle:hover { background: var(--brand-light); }

.hero-content {
  padding: 22px 16px 0;
  border-top: 1px solid var(--border);
  margin-top: 16px;
}
.hero-badge {
  display: block;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  color: var(--brand);
  margin-bottom: 6px;
}
.hero-title {
  margin: 0 0 8px;
  font-size: clamp(1.5rem, 3.6vw, 2.15rem);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--text);
}
.hero-sub {
  margin: 0;
  max-width: 34rem;
  color: var(--text-muted);
  font-size: 0.92rem;
}

/* ── Search panel ─────────────────────────────────────────── */
.search-panel {
  margin-top: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.search-box {
  position: relative;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.search-icon {
  position: absolute;
  left: 30px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
#searchInput {
  width: 100%;
  padding: 12px 36px 12px 38px;
  font-size: 1.05rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}
#searchInput:focus { outline: 2px solid var(--brand); }
.clear-search {
  position: absolute;
  right: 28px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
}
.clear-search:hover { color: var(--text); }

.filter-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.filter-section:last-of-type { border-bottom: none; }
.filter-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }
@media (min-width: 640px) {
  .chip-row { flex-wrap: wrap; overflow-x: visible; }
}

.chip {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 4px;
  padding: 6px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.chip:hover { border-color: var(--brand); }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip-all { font-weight: 600; }

.chip-photo {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 14px 4px 4px;
}
.chip-photo img {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.filter-section-sort {
  display: flex;
  align-items: center;
  gap: 10px;
}
.filter-section-sort .filter-label { margin-bottom: 0; }

select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
}

.result-meta-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0 8px;
}
.result-meta-row[hidden] { display: none; }
.result-meta {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.clear-filters {
  border: none;
  background: transparent;
  color: var(--brand);
  font-size: 0.85rem;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}

.result-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
  margin-bottom: 40px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: border-color 0.15s ease;
}
.card:hover { border-color: var(--brand); }

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.drug-name { margin: 0; font-size: 1.05rem; }
.drug-name-en { margin: 2px 0 6px; color: var(--text-muted); font-size: 0.85rem; font-family: "Inter", sans-serif; }
.license-no { margin: 0 0 8px; font-size: 0.8rem; color: var(--text-muted); font-family: "Inter", monospace; }

.status-badge {
  flex-shrink: 0;
  font-size: 0.75rem;
  padding: 3px 10px;
  border-radius: 4px;
  white-space: nowrap;
}
.status-badge.valid { background: var(--valid-bg); color: var(--valid); }
.status-badge.expiring { background: var(--expiring-bg); color: var(--expiring); }
.status-badge.expired { background: var(--expired-bg); color: var(--expired); }

.tag-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.tag {
  font-size: 0.75rem;
  background: var(--brand-light);
  color: var(--brand);
  padding: 2px 9px;
  border-radius: 4px;
}

.indication-preview {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-details { margin-top: 10px; }
.card-details summary {
  cursor: pointer;
  color: var(--brand);
  font-size: 0.88rem;
}
.card-details dl { margin: 10px 0 0; font-size: 0.88rem; }
.card-details dt { color: var(--text-muted); margin-top: 8px; }
.card-details dd { margin: 2px 0 0; white-space: pre-line; }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 0;
}

.start-prompt {
  text-align: center;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px 20px;
  margin-bottom: 40px;
}
.start-prompt p { margin: 0 0 8px; font-size: 0.98rem; }
.start-prompt-lead { font-weight: 500; }
.start-prompt-hint { font-size: 0.82rem; opacity: 0.85; margin: 16px 0 0 !important; }

.species-picker {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  max-width: 460px;
  margin: 16px auto 0;
}
@media (min-width: 480px) {
  .species-picker { grid-template-columns: repeat(4, 1fr); }
}
.species-card {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 0;
  cursor: pointer;
  overflow: hidden;
  font-family: inherit;
}
.species-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
}
.species-card span {
  display: block;
  padding: 8px 4px;
  font-size: 0.85rem;
  color: var(--text);
}
.species-card:hover { border-color: var(--brand); }
.species-card:hover span { color: var(--brand); }

mark {
  background: #ffe58a;
  color: inherit;
  border-radius: 2px;
}
@media (prefers-color-scheme: dark) {
  mark { background: #6b5a1f; }
}
:root[data-theme="dark"] mark { background: #6b5a1f; }
:root[data-theme="light"] mark { background: #ffe58a; }

.site-footer {
  border-top: 1px solid var(--border);
  padding: 20px 0 40px;
  color: var(--text-muted);
  font-size: 0.78rem;
}
.site-footer a { color: var(--brand); }

.photo-credit {
  margin-top: 10px;
  font-size: 0.72rem;
  opacity: 0.75;
}

.brand-footer {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px dashed var(--border);
}
.visit-counter {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 0.78rem;
  white-space: nowrap;
}
.visit-counter #visitCount {
  color: var(--brand);
  font-weight: 700;
  font-family: "Inter", monospace;
}
