:root {
  --bg: #0f1115;
  --bg-2: #161922;
  --bg-3: #1d2230;
  --line: #262b3a;
  --text: #e6e8ee;
  --mut: #9aa3b6;
  --acc: #ffd34a;
  --acc-2: #ff7a59;
  --danger: #ff5d5d;
  --safe: #6dd58c;
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.55;
}

a { color: var(--acc); }
a:hover { color: var(--acc-2); }

/* ================================================ TOP BAR ====== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 18px;
  padding: 14px 22px;
  background: rgba(15, 17, 21, 0.85);
  backdrop-filter: saturate(160%) blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: baseline; gap: 12px; }
.brand-link { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); }
.brand-mark { font-size: 22px; color: var(--acc); }
.brand-name { font-weight: 700; letter-spacing: 0.2px; }
.brand-meta { color: var(--mut); font-size: 13px; }

.search { flex: 1 1 320px; position: relative; max-width: 560px; }
.search input {
  width: 100%;
  padding: 10px 36px 10px 14px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  font-size: 15px;
  outline: none;
  transition: border-color .12s;
}
.search input:focus { border-color: var(--acc); }
.search button {
  position: absolute;
  right: 6px; top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: 0;
  font-size: 22px;
  color: var(--mut);
  cursor: pointer;
  padding: 0 8px;
  line-height: 1;
}

/* ============================================== LAYOUT ====== */
.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 0;
  min-height: calc(100vh - 60px);
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 18px 18px 28px;
  background: var(--bg);
  position: sticky;
  top: 61px;
  align-self: start;
  max-height: calc(100vh - 61px);
  overflow-y: auto;
}

.sidebar-h {
  margin: 4px 4px 10px;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--mut);
  font-weight: 700;
}

.tag-list, .source-list { list-style: none; padding: 0; margin: 0 0 16px; display: flex; flex-direction: column; gap: 2px; }
.tag-list li button, .source-list li button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--text);
  padding: 7px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  transition: background .12s;
  font-family: inherit;
}
.tag-list li button:hover, .source-list li button:hover { background: var(--bg-2); }
.tag-list li button.active, .source-list li button.active { background: var(--acc); color: #1c1500; font-weight: 600; }
.tag-list li button.active .count, .source-list li button.active .count { color: rgba(28,21,0,.65); }
.tag-list .count, .source-list .count { color: var(--mut); font-variant-numeric: tabular-nums; font-size: 12px; }

.source-list li button .src-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 8px;
  vertical-align: middle;
}
.src-dot-arnika { background: #6dd58c; }
.src-dot-epa { background: #ff7a59; }
.src-dot-echa { background: #ffd34a; }
.src-dot-stockholm { background: #5fbcd3; }
.src-dot-iarc { background: #d36df0; }

.src { color: var(--mut); font-size: 12px; margin-top: 22px; padding: 0 4px; }

.results { padding: 18px 22px 60px; }
.results-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 4px 9px 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.chip button {
  background: transparent;
  border: 0;
  color: var(--mut);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.chip button:hover { color: var(--danger); }

.sort label { color: var(--mut); font-size: 13px; }
.sort select {
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
  margin-left: 6px;
}

/* ============================================ CARD GRID ====== */
.card-grid {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 14px;
  cursor: pointer;
  transition: transform .12s, border-color .12s, background .12s;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  color: var(--text);
  font: inherit;
}
.card:hover {
  border-color: var(--acc);
  transform: translateY(-2px);
  background: var(--bg-3);
}
.card-name {
  font-size: 17px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: .1px;
  word-break: break-word;
  overflow-wrap: anywhere;
  /* Ostrá hranice pro extrémně dlouhé IUPAC názvy. */
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-fullname {
  font-size: 11px;
  color: var(--mut);
  line-height: 1.4;
  word-break: break-all;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: -2px;
}
.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--mut);
}
.card-meta b { color: var(--text); font-weight: 500; }
.card-intro {
  color: var(--mut);
  font-size: 13px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-tags {
  margin-top: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.card-tag {
  font-size: 10.5px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--mut);
  border: 1px solid var(--line);
  padding: 2px 6px;
  border-radius: 4px;
}

.card-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 4px;
}
.src-badge {
  display: inline-flex;
  align-items: center;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--bg-3);
  border: 1px solid var(--line);
}
.src-badge.arnika { color: #6dd58c; border-color: #6dd58c44; background: #6dd58c14; }
.src-badge.epa { color: #ff7a59; border-color: #ff7a5944; background: #ff7a5914; }
.src-badge.echa { color: #ffd34a; border-color: #ffd34a44; background: #ffd34a14; }
.src-badge.stockholm { color: #5fbcd3; border-color: #5fbcd344; background: #5fbcd314; }
.src-badge.iarc { color: #d36df0; border-color: #d36df044; background: #d36df014; }
.src-badge.iarc-1 { background: #ff5d5d22; color: #ff7777; border-color: #ff5d5d77; }

.detail-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.detail-sources .src-badge { font-size: 11px; padding: 4px 10px; }
.detail-sources a.src-badge { text-decoration: none; }

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

/* ================================================ DETAIL ====== */
dialog.detail {
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0;
  margin: 0 auto;
  max-width: 900px;
  width: calc(100% - 32px);
}
dialog.detail::backdrop { background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(4px); }

.detail-inner {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 30px 36px;
  margin: 24px auto;
  position: relative;
  max-height: 92vh;
  overflow-y: auto;
}

.detail-close {
  position: sticky;
  float: right;
  top: 0;
  margin-right: -12px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  z-index: 1;
}
.detail-close:hover { background: var(--danger); border-color: var(--danger); color: #fff; }

.detail h1 {
  font-size: 28px;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
  word-break: break-word;
}
.detail .h-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 22px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--mut);
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.detail .h-meta b { color: var(--text); font-weight: 500; margin-right: 6px; }
.detail .h-meta sub { font-size: 9px; }
.detail .h-meta sup { font-size: 9px; }

.detail .h-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.detail .h-tag {
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--acc);
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  cursor: pointer;
}
.detail .h-tag:hover { background: var(--acc); color: #1c1500; border-color: var(--acc); }

.detail-image {
  float: right;
  margin: 0 0 12px 18px;
  max-width: 240px;
  border-radius: 10px;
  background: #fff;
  padding: 6px;
}
.detail-image img { display: block; max-width: 100%; height: auto; border-radius: 6px; }

.detail h2 {
  font-size: 16px;
  margin: 28px 0 8px;
  letter-spacing: 0.02em;
  font-weight: 600;
  color: var(--acc);
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.16em;
}

.detail-section { margin-bottom: 6px; }
.detail-section:first-of-type { margin-top: 0; }
.detail-section p { margin: 0 0 10px; }
.detail-section a { word-break: break-all; }
.detail-section img.arnika-img {
  display: inline-block;
  vertical-align: middle;
  background: #fff;
  border-radius: 6px;
  padding: 4px;
  max-width: 90px;
  max-height: 110px;
  margin: 4px 8px 8px 0;
  object-fit: contain;
}
.detail-section img.arnika-img.diagram {
  max-width: 100%;
  max-height: 400px;
  display: block;
  margin: 12px auto;
  padding: 0;
  background: #fff;
}
.detail-section img.broken {
  display: none;
}
.detail-section ul {
  margin: 0 0 10px 18px;
  padding: 0;
}
.detail-section ul li { margin: 4px 0; }

.detail-foot {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--mut);
  font-size: 12.5px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 22px;
}

/* ================================================ MOBILE ====== */
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: none;
    padding: 12px 14px 16px;
  }
  .sidebar-h { margin-top: 0; }
  .tag-list {
    flex-direction: row;
    overflow-x: auto;
    gap: 6px;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }
  .tag-list li button {
    white-space: nowrap;
    border: 1px solid var(--line);
    padding: 6px 12px;
    font-size: 13px;
  }
  .src { display: none; }
  .results { padding: 14px; }
  .topbar { padding: 10px 14px; gap: 10px; }
  .brand-meta { display: none; }
  .detail-image { float: none; max-width: 100%; margin: 0 0 14px; }
  .detail-inner { padding: 22px 18px 28px; margin: 8px auto; }
  .detail h1 { font-size: 22px; }
}

/* === Kent Filters Best integration === */
.kfb-breadcrumb {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  background: #0b0f17;
  border-bottom: 1px solid #1f2937;
  font-size: 13px;
  color: #94a3b8;
}
.kfb-breadcrumb .kfb-back {
  color: #93c5fd;
  text-decoration: none;
  font-weight: 500;
}
.kfb-breadcrumb .kfb-back:hover { text-decoration: underline; }
.kfb-breadcrumb .kfb-sep { color: #475569; }
.kfb-breadcrumb .kfb-current { color: #e2e8f0; }
.detail-cross-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 6px 0 14px;
  padding: 8px 14px;
  border: 1px solid #2563eb;
  background: rgba(37, 99, 235, 0.1);
  color: #93c5fd;
  border-radius: 8px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
}
.detail-cross-link:hover {
  background: rgba(37, 99, 235, 0.2);
  text-decoration: none;
}

/* Embed mode (inside KFB iframe modal) — hide breadcrumb, dim outer chrome. */
html.kfb-embed .kfb-breadcrumb { display: none; }
html.kfb-embed .topbar { padding-top: 14px; }
