:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --panel: #fff;
  --ink: #1c1e21;
  --muted: #6b7280;
  --line: #e6e8ee;
  --line-strong: #d9dce3;
  --brand-navy: #1b2a8a;
  --brand-blue: #0a6fd6;
  --brand-tint: #e9f1fb;
  --accent: var(--brand-blue);
  --accent-soft: #e8f1fc;
  --chip: #e8f1fc;
  --focus-ring: rgba(10, 111, 214, 0.18);
  --danger: #b91c1c;
  --ok: #047857;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

button, input, select { font: inherit; color: inherit; }

button { cursor: pointer; }

.app {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}

.app[hidden], .login[hidden] { display: none; }

.nav {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px 12px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: linear-gradient(160deg, var(--brand-tint) 0%, var(--bg) 60%);
}

.login-card {
  width: min(380px, 100%);
  display: grid;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 12px 32px rgba(27, 42, 138, 0.08), var(--shadow);
  padding: 32px 28px 28px;
}

.login-head {
  display: grid;
  justify-items: center;
  gap: 4px;
  margin-bottom: 16px;
  text-align: center;
}

.login-logo { width: 64px; height: 64px; margin-bottom: 8px; }

.login-title { margin: 0; font-size: 22px; font-weight: 700; color: var(--brand-navy); letter-spacing: -0.01em; }

.login-client { margin: 0; font-size: 14px; color: var(--muted); }

.login-label { font-size: 13px; font-weight: 600; color: var(--ink); }

.key-field { position: relative; }

.key-field input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 10px 88px 10px 12px;
  background: var(--panel);
  font-size: 16px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.key-field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }

.key-field input[aria-invalid="true"] { border-color: var(--danger); }

.key-toggle {
  position: absolute;
  top: 0;
  right: 0;
  min-width: 76px;
  height: 44px;
  border: 0;
  border-radius: 0 10px 10px 0;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

.key-toggle:hover { color: var(--brand-navy); }

.key-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; }

.login-help { margin: 0; color: var(--muted); font-size: 13px; }

.login-error { margin: 0; color: var(--danger); font-size: 13px; font-weight: 500; }

.login-submit {
  margin-top: 12px;
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: var(--brand-blue);
  color: white;
  font-weight: 600;
  transition: background-color 150ms ease;
}

.login-submit:hover:not(:disabled) { background: var(--brand-navy); }

.login-submit:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }

.login-submit:disabled { opacity: 0.7; cursor: progress; }

@media (prefers-reduced-motion: reduce) {
  .key-field input, .login-submit { transition: none; }
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 0 8px 8px;
}

.logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.brand strong { display: block; font-size: 14px; }
.brand span { color: var(--muted); font-size: 12px; }

.index-card {
  display: grid;
  gap: 2px;
  margin: 8px 0 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}

.index-label {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.index-name { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; font-weight: 600; }

.badge {
  justify-self: start;
  margin-top: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--brand-navy);
  font-size: 12px;
  font-weight: 600;
}

.nav-menu { display: grid; gap: 2px; }

.nav-label {
  margin: 14px 8px 6px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.nav-btn {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 8px;
  padding: 8px 10px 8px 12px;
  color: #374151;
  transition: background-color 150ms ease, color 150ms ease;
}

.nav-icon, .logout-icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-btn .nav-icon { color: var(--muted); }

.nav-btn:hover { background: #f3f4f6; }

.nav-btn.active {
  background: var(--accent-soft);
  color: var(--brand-navy);
  font-weight: 600;
}

.nav-btn.active .nav-icon { color: var(--brand-blue); }

.nav-btn.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 2px;
  background: var(--brand-blue);
}

.nav-btn:focus-visible, .logout-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }

.session {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
}

.session-user { display: flex; align-items: center; gap: 10px; padding: 0 4px; }

.session-avatar {
  width: 28px;
  height: 28px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 50%;
  object-fit: contain;
}

.session-user strong { display: block; font-size: 13px; }

.session-status { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }

.session-status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); }

.logout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 500;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.logout-btn:hover { border-color: var(--danger); color: var(--danger); background: #fef2f2; }

@media (prefers-reduced-motion: reduce) {
  .nav-btn, .logout-btn, .check, .order-row { transition: none; }
}

main { padding: 20px 22px 32px; min-width: 0; }

.banner {
  background: #fff7ed;
  color: #9a3412;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
}

.search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 12px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.search input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 0;
}

.icon {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
  color: #9aa1ad;
}

.meta {
  margin: 0;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.subbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  min-height: 36px;
  margin-top: 12px;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--chip);
  color: #243056;
  border-radius: 999px;
  padding: 4px 8px 4px 10px;
  font-size: 13px;
}

.chip button {
  border: 0;
  background: transparent;
  color: #51608a;
  padding: 0 2px;
  line-height: 1;
}

.subbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.text-btn {
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 0;
}

.sort { color: var(--muted); display: flex; align-items: center; gap: 8px; white-space: nowrap; }

.sort select {
  height: 32px;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  border-radius: 8px;
  padding: 0 8px;
}

.params {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.params pre {
  margin: 8px 0 0;
  padding: 12px;
  background: #111827;
  color: #e5e7eb;
  border-radius: 8px;
  overflow: auto;
  font-size: 12px;
  line-height: 1.5;
}

.split {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  margin-top: 12px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.facets-panel {
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  overflow: auto;
  padding-bottom: 8px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 6px;
}

.panel-head h2, .facet-block h3, .page-head h1, .card h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
}

.facet-block { padding: 8px 10px 12px; border-top: 1px solid #f1f2f5; }
.facet-block:first-child { border-top: 0; }

.facet-title { display: flex; flex-direction: column; gap: 1px; padding: 4px 4px 8px; }
.facet-title small, .hint, .page-head p { color: var(--muted); font-weight: 400; }

.facet-find, .range-row input, .syn-form input, .add-row select, .card input[type="number"] {
  width: 100%;
  height: 32px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0 8px;
  background: #fff;
}

.facet-find { margin-bottom: 6px; }

.facet-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 13px;
}

.facet-row:hover { background: #f7f8fa; }
.facet-row:has(input:checked) { background: var(--accent-soft); }

.facet-row input { accent-color: var(--accent); }

.facet-row .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.facet-row .count {
  margin-left: auto;
  color: #9aa1ad;
  font-variant-numeric: tabular-nums;
}

.more {
  margin: 4px 6px 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 0;
  font-size: 13px;
}

.range-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.range-row label, .field-label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }

.facet-note { margin: 4px 6px 0; color: var(--muted); font-size: 12px; }

.warn {
  margin: 0 6px;
  color: #9a3412;
  font-size: 12px;
}

.inspector { position: relative; padding: 8px 16px 16px; min-height: 420px; }

.hit-list { display: flex; flex-direction: column; }

.hit-card {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid #f0f1f4;
}

.hit-card:last-child { border-bottom: 0; }

.pager {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.pager button {
  height: 32px;
  min-width: 32px;
  padding: 0 10px;
  border-radius: 7px;
  border: 1px solid var(--line-strong);
  background: #fff;
}

.pager button[aria-current="page"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.pager button:disabled { opacity: 0.4; cursor: default; }

.pager-range, .pager-gap { color: var(--muted); font-size: 13px; }
.pager-range { margin-right: 6px; }

.hit-title {
  color: #2563eb;
  font-size: 16px;
  font-weight: 650;
  text-decoration: none;
  line-height: 1.35;
}

.hit-title:hover { text-decoration: underline; }

.hit-photo {
  width: 96px;
  height: 96px;
  object-fit: contain;
  background: #fafafa;
  border: 1px solid #f0f1f4;
  border-radius: 8px;
}

.hit-photo-empty { border-style: dashed; }

.hit-card .attr-row {
  grid-template-columns: 168px minmax(0, 1fr);
  padding: 3px 0;
  border-bottom: 0;
}

.hit-card .more { margin: 8px 0 0; }

.hit-card .attr-val .desc {
  margin: 0;
  color: inherit;
  font-size: 13px;
  -webkit-line-clamp: 6;
}

.attrs { margin-top: 8px; }

.attr-row {
  display: grid;
  grid-template-columns: 22px 148px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 8px 0;
  border-bottom: 1px solid #f3f4f6;
}

.attr-key { color: var(--muted); }
.attr-key small { display: block; font-size: 11px; color: #9aa1ad; }
.attr-val { word-break: break-word; }
.attr-val a { color: #2563eb; }

.pills { display: flex; flex-wrap: wrap; gap: 4px; }
.pill {
  background: #f3f4f6;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
}

.desc {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.desc.open { display: block; -webkit-line-clamp: unset; }

.empty {
  padding: 48px 16px;
  text-align: center;
  color: var(--muted);
}

.page-head { margin: 4px 0 16px; }
.page-head h1 { font-size: 20px; }
.page-head p { margin: 6px 0 0; max-width: 62ch; }

.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 16px;
  align-items: start;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
}

.card.wide { grid-column: 1 / -1; }
.card .hint { margin: 4px 0 12px; font-size: 13px; }

.card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }

.count {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--brand-navy);
  font-size: 12px;
  font-weight: 600;
}

.card-actions { display: flex; gap: 4px; margin-left: auto; }

.link-btn {
  min-height: 32px;
  padding: 0 8px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
}

.link-btn:hover { background: var(--accent-soft); color: var(--brand-navy); }

.link-btn:focus-visible, .icon-btn:focus-visible, .secondary-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--focus-ring); }

.list-filter {
  width: 100%;
  height: 36px;
  margin-bottom: 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0 10px;
  background: var(--panel);
}

.check-list, .order-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.order-list:empty { display: none; }

.check, .order-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 8px 12px;
  font-size: 13px;
  border-top: 1px solid var(--line);
  transition: background-color 150ms ease;
}

.check:first-child, .order-row:first-child { border-top: 0; }

.check { cursor: pointer; }
.check[hidden] { display: none; }
.check:hover, .order-row:hover { background: #f8fafc; }

.check input { width: 16px; height: 16px; flex: none; margin: 0; accent-color: var(--accent); }

.field-key { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; overflow-wrap: anywhere; }

.field-name {
  margin-left: auto;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}


.order-row .grow { flex: 1; }
.order-row .field-key.grow + .field-name { margin-left: 0; }
.order-row > .field-key:not(.grow) { color: var(--muted); }

.rank {
  min-width: 22px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: none;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  color: var(--ink);
}

.icon-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover:not(:disabled) { border-color: var(--line-strong); background: #f3f4f6; }
.icon-btn:disabled { opacity: 0.35; cursor: default; }

.add-row { display: flex; gap: 8px; margin-top: 12px; }
.add-row select { flex: 1; height: 36px; }

.add-row button {
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 500;
}

.add-row button:hover { background: #f3f4f6; }

.order-row .ghost {
  min-height: 32px;
  margin-left: 4px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 13px;
}

.order-row .ghost:hover { background: #fef2f2; }

.savebar {
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  bottom: 0;
  margin: 16px -22px 0;
  padding: 12px 22px;
  background: var(--bg);
  border-top: 1px solid var(--line);
  z-index: 2;
}

.savebar button, .syn-form button {
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  padding: 0 14px;
  font-weight: 600;
}

.savebar button:disabled, .syn-form button:disabled { opacity: 0.45; cursor: default; }

.savebar .secondary-btn {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  font-weight: 500;
}

.savebar .secondary-btn:hover:not(:disabled) { background: #f3f4f6; }

.status { font-size: 13px; color: var(--muted); }
.status.ok { color: var(--ok); }
.status.err { color: var(--danger); }

.syn-form {
  display: grid;
  grid-template-columns: 180px 1fr auto auto;
  gap: 8px;
  margin-bottom: 12px;
}

.both { display: flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; }

.syn-search { margin-bottom: 10px; }

.syn-list { display: flex; flex-direction: column; gap: 6px; }

.syn-row {
  display: grid;
  grid-template-columns: 180px 1fr auto;
  gap: 10px;
  align-items: start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}

.syn-row strong { font-weight: 650; }
.syn-row p { margin: 0; color: #374151; }
.ghost {
  border: 0;
  background: transparent;
  color: var(--danger);
  padding: 0;
}

body.is-loading .split { opacity: 0.72; }

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .nav {
    display: flex;
    flex-direction: row;
    gap: 6px;
    align-items: center;
    overflow: auto;
    padding: 10px;
    position: sticky;
    top: 0;
    z-index: 3;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .nav .brand, .index-card, .nav-label, .session-user { display: none; }
  .nav-menu { display: flex; gap: 6px; }
  .nav-btn, .logout-btn { width: auto; min-height: 44px; white-space: nowrap; }
  .nav-btn.active::before { top: auto; bottom: 0; left: 10px; right: 10px; width: auto; height: 3px; }
  .session { margin: 0 0 0 auto; padding: 0; border: 0; }
  .logout-btn { width: 44px; padding: 0; }
  .logout-btn span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .split, .config-grid, .syn-form { grid-template-columns: 1fr; }
  .facets-panel { position: static; max-height: none; }
  .toolbar, .subbar { flex-direction: column; align-items: stretch; }
  .subbar-actions { margin-left: 0; }
}
