:root {
  color-scheme: light;
  --bg: #f5f6f3;
  --surface: #ffffff;
  --surface-alt: #eef3ef;
  --ink: #13211b;
  --muted: #617068;
  --line: #d8ded8;
  --green: #12705d;
  --green-dark: #0c4f43;
  --red: #9f3b32;
  --blue: #315f96;
  --gold: #9a7528;
  --shadow: 0 16px 34px rgba(32, 42, 36, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

a {
  color: inherit;
}

.topbar {
  min-height: 132px;
  padding: 28px clamp(18px, 4vw, 56px);
  background: #fbfcfa;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 5vw, 4.2rem);
  line-height: 0.98;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
  letter-spacing: 0;
}

.topbar-actions,
.filter-row,
.type-tabs,
.article-links,
.badge-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.primary-button,
.ghost-button,
.icon-button,
.type-tab,
.link-chip,
.bookmark-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  min-height: 40px;
  border-radius: 8px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  cursor: pointer;
}

.primary-button {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

.ghost-button:hover,
.type-tab:hover,
.link-chip:hover,
.bookmark-button:hover {
  border-color: var(--green);
}

.app-shell {
  width: min(1440px, calc(100% - 32px));
  margin: 20px auto 44px;
}

.control-band,
.stats-band,
.topic-panel,
.results-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-band {
  padding: 16px;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(160px, 240px) minmax(140px, 180px);
  gap: 12px;
  align-items: end;
}

.search-box,
.select-box {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.search-box input,
.select-box select {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #fbfcfa;
}

.filter-row {
  margin-top: 14px;
}

.toggle-pill {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  background: #fbfcfa;
  cursor: pointer;
}

.toggle-pill input {
  accent-color: var(--green);
}

.type-tabs {
  margin-top: 14px;
}

.type-tab {
  min-width: 92px;
}

.type-tab.is-active {
  background: var(--green-dark);
  border-color: var(--green-dark);
  color: white;
}

.stats-band {
  margin-top: 14px;
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
}

.stat-item {
  min-height: 74px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-alt);
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.stat-value {
  display: block;
  margin-top: 8px;
  font-size: 1.6rem;
  line-height: 1;
  font-weight: 850;
}

.content-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: minmax(250px, 320px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.topic-panel,
.results-panel {
  min-height: 320px;
}

.panel-header {
  min-height: 56px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-header span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.topic-list {
  padding: 10px;
  display: grid;
  gap: 8px;
}

.topic-button {
  width: 100%;
  min-height: 48px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  text-align: left;
  padding: 8px 10px;
  cursor: pointer;
}

.topic-button:hover,
.topic-button.is-active {
  background: var(--surface-alt);
  border-color: var(--line);
}

.topic-name {
  font-weight: 800;
  overflow-wrap: anywhere;
}

.topic-meta {
  color: var(--muted);
  font-size: 0.78rem;
}

.topic-count {
  min-width: 34px;
  min-height: 28px;
  border-radius: 8px;
  background: #dde8e3;
  color: var(--green-dark);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  font-weight: 900;
}

.result-list {
  padding: 12px;
  display: grid;
  gap: 12px;
}

.article-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
  padding: 16px;
  display: grid;
  gap: 12px;
}

.article-topline {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
}

.article-title {
  margin: 0;
  font-size: clamp(1.05rem, 1.8vw, 1.35rem);
  line-height: 1.28;
  letter-spacing: 0;
}

.article-meta {
  color: var(--muted);
  line-height: 1.5;
}

.badge {
  min-height: 26px;
  border-radius: 8px;
  padding: 3px 8px;
  font-size: 0.74rem;
  font-weight: 850;
  display: inline-flex;
  align-items: center;
  border: 1px solid transparent;
}

.badge.free {
  color: var(--green-dark);
  background: #dceee8;
}

.badge.exam {
  color: #6d4b08;
  background: #f4e7c3;
}

.badge.clinical {
  color: #213f6c;
  background: #dce7f5;
}

.badge.pending {
  color: var(--red);
  background: #f3dfdc;
}

.badge.type {
  color: var(--ink);
  background: #e8ebe5;
}

.key-points {
  margin: 0;
  padding-left: 18px;
  color: #334039;
  line-height: 1.6;
}

.article-links {
  gap: 8px;
}

.link-chip {
  min-height: 34px;
  font-size: 0.86rem;
}

.bookmark-button {
  min-width: 42px;
  min-height: 42px;
  padding: 0;
  font-weight: 900;
}

.bookmark-button.is-active {
  background: var(--gold);
  border-color: var(--gold);
  color: #fff;
}

.empty-state {
  min-height: 180px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

dialog {
  width: min(620px, calc(100% - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(19, 33, 27, 0.38);
}

.dialog-card {
  background: var(--surface);
}

.dialog-card p {
  padding: 0 18px 18px;
  line-height: 1.7;
  color: #334039;
}

.icon-button {
  min-width: 38px;
  min-height: 38px;
  padding: 0;
}

.site-footer {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto 30px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.6;
}

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .search-row,
  .content-grid,
  .stats-band {
    grid-template-columns: 1fr;
  }

  .type-tab {
    min-width: 0;
    flex: 1 1 132px;
  }
}

@media (max-width: 520px) {
  .app-shell,
  .site-footer {
    width: min(100% - 20px, 1440px);
  }

  .control-band,
  .article-card {
    padding: 12px;
  }

  .article-topline {
    display: grid;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions > * {
    flex: 1;
  }
}
