/* Doc Search demo: design tokens, then layout, then components. Light and dark themes share the same tokens. */
:root {
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-2: #f0eee7;
  --ink: #1b1d21;
  --ink-2: #4a5059;
  --muted: #6b717a;
  --line: #e3e0d6;
  --accent: #2c6b5a;
  --accent-ink: #ffffff;
  --accent-soft: #e2efe9;
  --mark: #fbe7a1;
  --warn: #b45309;
  --bad: #b42318;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(20, 24, 28, .04), 0 4px 16px rgba(20, 24, 28, .05);
  --focus: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "Noto Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131518;
    --surface: #1b1e22;
    --surface-2: #23272c;
    --ink: #e8e8e4;
    --ink-2: #c2c5ca;
    --muted: #949aa3;
    --line: #2d3238;
    --accent: #5fb39b;
    --accent-ink: #0c1411;
    --accent-soft: #1d2e29;
    --mark: #5c4d16;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-sm); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 16px; top: 12px; z-index: 10; padding: 8px 12px; background: var(--surface); border-radius: var(--radius-sm); }

/* ---------------------------------------------------------------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px max(16px, calc((100vw - 1180px) / 2));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand strong { display: block; font-size: 16px; white-space: nowrap; }
.brand span { display: block; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo { width: 32px; height: 32px; flex: none; }
.logo rect { fill: var(--accent); }
.logo circle, .logo path { fill: none; stroke: var(--accent-ink); stroke-width: 3; stroke-linecap: round; }

.status { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; font-size: 13px; color: var(--ink-2);
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px; white-space: nowrap; min-width: 0; }
.status #status-text { overflow: hidden; text-overflow: ellipsis; }
.status .dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--warn); }
.status[data-state="loading"] .dot { animation: pulse 1s ease-in-out infinite alternate; }
.status[data-state="ready"] .dot { background: var(--accent); }
.status[data-state="error"] .dot { background: var(--bad); }
@keyframes pulse { from { opacity: .3; } to { opacity: 1; } }

/* ---------------------------------------------------------------- layout */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start;
  max-width: 1180px; margin: 0 auto; padding: 24px 16px 64px;
}
.search-area { min-width: 0; }
.library { position: sticky; top: 76px; max-height: calc(100vh - 92px); overflow: auto; }
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 16px; padding-top: 16px; }
  .status { max-width: 58vw; }
  .library { position: static; max-height: none; }
  .brand span { display: none; }
}

/* ---------------------------------------------------------------- buttons */
button { cursor: pointer; border-radius: var(--radius-sm); }
button:disabled { cursor: not-allowed; opacity: .5; }
.primary { padding: 10px 18px; font-weight: 600; color: var(--accent-ink); background: var(--accent); border: 1px solid var(--accent); }
.primary:hover:not(:disabled) { filter: brightness(1.06); }
.secondary { padding: 8px 14px; color: var(--accent); background: var(--surface); border: 1px solid var(--line); }
.secondary:hover:not(:disabled) { border-color: var(--accent); }
.link { padding: 2px 4px; font-size: 13px; color: var(--muted); background: none; border: 0; }
.link:hover:not(:disabled) { color: var(--bad); }

/* ---------------------------------------------------------------- search */
.searchbar { position: relative; display: flex; gap: 8px; padding: 6px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow); }
.searchbar:focus-within { border-color: var(--accent); box-shadow: var(--focus); }
.searchicon { position: absolute; left: 18px; top: 50%; width: 20px; height: 20px; transform: translateY(-50%); fill: none;
  stroke: var(--muted); stroke-width: 2; stroke-linecap: round; pointer-events: none; }
.searchbar input { flex: 1; min-width: 0; padding: 10px 10px 10px 40px; font-size: 16px; background: transparent; border: 0; }
.searchbar input:focus { outline: none; box-shadow: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chips:empty { display: none; }
.chip { padding: 5px 12px; font-size: 13px; color: var(--ink-2); background: var(--surface); border: 1px solid var(--line); border-radius: 999px; }
.chip:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }

/* ---------------------------------------------------------------- empty state */
.empty { margin-top: 20px; padding: 28px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.empty h2 { font-size: 20px; margin-bottom: 18px; }
.steps { list-style: none; margin: 0 0 22px; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.steps li { display: flex; gap: 12px; }
.steps .num { flex: none; display: grid; place-items: center; width: 28px; height: 28px; font-weight: 700; font-size: 14px;
  color: var(--accent); background: var(--accent-soft); border-radius: 50%; }
.steps strong { display: block; margin-bottom: 2px; }
.steps p { font-size: 13.5px; color: var(--muted); }
.empty-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.empty-actions .secondary { display: inline-block; padding: 10px 16px; font-weight: 600; border-radius: var(--radius-sm); cursor: pointer; }
@media (max-width: 640px) { .steps { grid-template-columns: 1fr; } .empty { padding: 20px; } }

/* ---------------------------------------------------------------- results */
.summary { margin: 18px 2px 10px; font-size: 13px; color: var(--muted); }
.results { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.hits { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.hits.primary-lang { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
.hits header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; padding: 12px 16px;
  background: var(--surface-2); border-bottom: 1px solid var(--line); }
.hits header strong { font-size: 14.5px; }
.hits header small { font-size: 12.5px; color: var(--muted); }
.hits.primary-lang header strong::after { content: "matches your question's language"; margin-left: 8px; padding: 1px 8px; font-size: 11.5px;
  font-weight: 500; color: var(--accent); background: var(--accent-soft); border-radius: 999px; vertical-align: 1px; }
.hits ol { list-style: none; margin: 0; padding: 0; counter-reset: hit; }
.hits li { position: relative; padding: 12px 16px 12px 46px; border-top: 1px solid var(--line); counter-increment: hit; }
.hits li:first-child { border-top: 0; }
.hits li::before { content: counter(hit); position: absolute; left: 16px; top: 13px; width: 20px; height: 20px; display: grid; place-items: center;
  font-size: 11.5px; font-weight: 700; color: var(--muted); background: var(--surface-2); border-radius: 50%; }
.hits li > strong { font-size: 14px; overflow-wrap: anywhere; }
.snippet { margin-top: 4px; font-size: 14px; line-height: 1.55; color: var(--ink-2); overflow-wrap: anywhere; }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }
.tag { display: inline-block; margin-left: 8px; padding: 0 7px; font-size: 11px; line-height: 18px; color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px; vertical-align: 1px; }

/* ---------------------------------------------------------------- library */
.library { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.library > * { min-width: 0; }
.library-head { display: flex; align-items: center; justify-content: space-between; }
.library-head h2 { font-size: 16px; }
.dropzone { position: relative; display: grid; justify-items: center; gap: 2px; padding: 20px 16px; text-align: center; cursor: pointer;
  background: var(--surface); border: 1.5px dashed color-mix(in srgb, var(--accent) 45%, var(--line)); border-radius: var(--radius); }
.dropzone:hover, .dropzone:focus-within { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.disabled { opacity: .55; cursor: not-allowed; }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone input:disabled { cursor: not-allowed; }
.dropzone svg { width: 26px; height: 26px; margin-bottom: 4px; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.dropzone strong { font-size: 14.5px; }
.dropzone span { font-size: 12.5px; color: var(--muted); }

.activity { padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.track { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar { width: 0; height: 100%; background: var(--accent); border-radius: 999px; transition: width .2s; }
.activity p { margin-top: 8px; font-size: 13px; color: var(--ink-2); overflow-wrap: anywhere; }

.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 0; }
.facts div { padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); min-width: 0; }
.facts .wide { grid-column: 1 / -1; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-weight: 600; overflow-wrap: anywhere; }
.facts .wide dd { font-size: 13px; font-weight: 500; }

.collections { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; }
.collections:empty { display: none; }
.collection { padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.collection header { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.collection header strong { font-size: 14px; }
.collection header small { font-size: 12px; color: var(--muted); white-space: nowrap; }
.collection .meta { margin: 2px 0 8px; font-size: 12px; color: var(--muted); }
.collection ul { list-style: none; margin: 0; padding: 0; }
.collection li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); font-size: 13.5px; }
.collection li span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.collection li small { color: var(--muted); white-space: nowrap; font-size: 12px; }
.remove-doc { padding: 2px 8px; font-size: 12px; color: var(--muted); background: transparent; border: 1px solid var(--line); }
.remove-doc:hover:not(:disabled) { color: var(--bad); border-color: var(--bad); }

details { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
details > summary { padding: 10px 14px; font-size: 14px; font-weight: 600; cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::after { content: "+"; float: right; color: var(--muted); font-weight: 400; }
details[open] > summary::after { content: "–"; }
details[open] > summary { border-bottom: 1px solid var(--line); }
.settings { display: block; }
.settings[open] { padding-bottom: 14px; }
.settings > :not(summary) { margin: 12px 14px 0; }
.field { display: grid; gap: 6px; font-size: 13px; color: var(--ink-2); }
select, textarea { width: 100%; padding: 8px 10px; font-size: 14px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); }
textarea { resize: vertical; }
.field .secondary { justify-self: start; }
.about ul { margin: 0; padding: 12px 14px 14px 30px; font-size: 13px; color: var(--ink-2); display: grid; gap: 8px; }

/* ---------------------------------------------------------------- drag and drop */
.dropveil { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 24px;
  background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(3px); }
.dropveil div { padding: 40px 56px; font-size: 18px; font-weight: 600; color: var(--accent); background: var(--surface);
  border: 2px dashed var(--accent); border-radius: 16px; }
.inline-field { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: -4px; font-size: 13px; color: var(--ink-2); }
.inline-field select { width: auto; min-width: 0; max-width: 60%; padding: 6px 8px; font-size: 13px; background: var(--surface); }
