:root {
  --canvas: #eef0f4;
  --surface: #ffffff;
  --surface-soft: #f7f8fa;
  --sidebar: #171b35;
  --sidebar-soft: #252b4a;
  --ink: #171a24;
  --muted: #7c8191;
  --line: #e6e8ed;
  --green: #55cd78;
  --green-dark: #35a85a;
  --purple: #6d68ef;
  --danger: #b75b49;
  --shadow: 0 24px 70px rgba(28, 34, 53, .14);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.icon-sprite { display: none; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
html { background: var(--canvas); }
body {
  margin: 0;
  min-height: 100vh;
  padding: 22px;
  color: var(--ink);
  background: radial-gradient(circle at 50% -20%, #fff 0, var(--canvas) 48%);
  font: 14px/1.5 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}
button, input, select, textarea { font: inherit; }
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 18px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: var(--green);
  box-shadow: 0 6px 18px rgba(74, 196, 111, .22);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: transform .16s ease, filter .16s ease, background .16s ease;
}
button:hover, .button:hover { filter: brightness(.97); transform: translateY(-1px); }
button:disabled { opacity: .55; cursor: wait; transform: none; }
#sync.cancel { background: #c46755; box-shadow: 0 6px 18px rgba(196, 103, 85, .2); }
input, select, textarea {
  width: auto;
  max-width: 100%;
  padding: 10px 13px;
  border: 1px solid #dfe2e8;
  border-radius: 9px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 1px 2px rgba(20, 23, 38, .02);
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 3px solid rgba(109, 104, 239, .2);
  border-color: var(--purple);
  outline-offset: 1px;
}

#workspace {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  width: min(1760px, 100%);
  min-height: calc(100vh - 44px);
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .9);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

aside {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 44px);
  padding: 26px 18px 20px;
  color: #d9dced;
  background: linear-gradient(180deg, #181c38 0%, #14182f 100%);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  font-weight: 800;
}
.brand b {
  display: grid;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 13px;
  color: #fff;
  background: linear-gradient(145deg, #807aff, #5652d9);
  box-shadow: 0 8px 22px rgba(91, 86, 225, .42);
  font-size: 13px;
  letter-spacing: -.4px;
}
.brand > span { font-size: 14px; letter-spacing: .7px; line-height: 1.25; }
.brand small { display: block; margin-top: 4px; color: #969dbd; font-size: 10px; font-weight: 500; letter-spacing: .2px; }
.nav-label { margin: 43px 12px 13px; color: #747c9e; font-size: 9px; font-weight: 700; letter-spacing: 1.6px; }
nav { display: grid; gap: 7px; }
nav button {
  justify-content: flex-start;
  width: 100%;
  min-height: 46px;
  padding: 11px 13px;
  color: #b9bfd7;
  background: transparent;
  box-shadow: none;
  font-size: 12px;
  font-weight: 550;
  text-align: left;
}
nav button:hover { color: #fff; background: rgba(255, 255, 255, .055); transform: none; }
nav button.active { color: #fff; background: #343b60; box-shadow: inset 3px 0 0 #7772f1; }
nav button svg { flex: 0 0 19px; width: 19px; height: 19px; margin-right: 5px; color: #9ca4c7; }
nav button.active svg { color: #fff; }
.aside-bottom {
  margin-top: auto;
  padding: 18px 11px 0;
  border-top: 1px solid rgba(255, 255, 255, .08);
  color: #8f97b8;
  font-size: 11px;
}
.dot { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(85, 205, 120, .1); }
.aside-bottom button { display: flex; gap: 8px; min-height: 0; margin-top: 17px; padding: 0; color: #b3bad2; background: transparent; box-shadow: none; font-size: 11px; }
.aside-bottom button svg { width: 16px; height: 16px; }

main { min-width: 0; padding: 0 34px 30px; background: #fff; }
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 74px;
  border-bottom: 1px solid var(--line);
}
.breadcrumb { color: #777d8c; font-size: 12px; }
.breadcrumb span { margin: 0 13px; color: #c7cad1; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: #737989;
  background: #fafbfc;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .5px;
}
.badge i { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.titlebar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin: 32px 0 24px; }
.eyebrow { margin: 0 0 5px; color: var(--purple); font-size: 10px; font-weight: 800; letter-spacing: 1.6px; }
h1 { margin: 0 0 7px; font-size: 30px; line-height: 1.22; letter-spacing: -.75px; }
h2 { margin: 0 0 5px; font-size: 17px; letter-spacing: -.2px; }
p { margin: 5px 0 15px; color: var(--muted); }
#freshness { margin: 0; font-size: 11px; }
.actions { display: flex; gap: 10px; }
.actions svg { width: 17px; height: 17px; margin-right: 8px; }
.secondary { color: #464b59; background: #fff; border: 1px solid #e0e3e8; box-shadow: 0 4px 15px rgba(23, 26, 36, .05); }
main.knowledge-mode .filters, main.knowledge-mode .actions { display: none; }

.filters {
  display: flex;
  align-items: flex-end;
  gap: 15px;
  margin-bottom: 24px;
  padding: 17px 18px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface-soft);
}
.filters label { display: grid; gap: 6px; color: #787e8c; font-size: 10px; font-weight: 650; }
.filters select { min-width: 240px; }
.filter-note { margin-left: auto; color: #9297a3; font-size: 10px; text-align: right; }
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.metrics article {
  position: relative;
  overflow: hidden;
  min-width: 0;
  padding: 20px 21px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 5px 18px rgba(34, 39, 58, .045);
}
.metrics article::before { content: ""; position: absolute; top: 0; left: 0; width: 4px; height: 100%; background: #d9dce4; }
.metrics article:nth-child(1)::before { background: var(--purple); }
.metrics article:nth-child(2)::before { background: #ffb154; }
.metrics article.accent::before { background: var(--green); }
.metrics span { color: #727888; font-size: 11px; font-weight: 650; }
.metrics strong { display: block; margin: 10px 0 9px; overflow: hidden; font-size: clamp(20px, 2vw, 28px); line-height: 1.2; letter-spacing: -1px; text-overflow: ellipsis; white-space: nowrap; }
.metrics small { color: #999eaa; font-size: 9px; }
.metrics .accent { background: linear-gradient(140deg, #f3fbf5, #fff); border-color: #dceddf; }
.metrics .accent strong { color: #278a49; }

.content-card, .cash-card {
  margin-bottom: 18px;
  padding: 21px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 5px 18px rgba(34, 39, 58, .04);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin-bottom: 13px; }
.card-head p { margin: 3px 0; font-size: 10px; }
.pill { padding: 6px 10px; border-radius: 999px; color: #906d24; background: #fff5dc; font-size: 10px; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th { padding: 11px 10px; color: #8d92a0; background: #fafbfc; font-size: 9px; font-weight: 750; letter-spacing: .6px; text-transform: uppercase; }
td { padding: 12px 10px; border-top: 1px solid #eff0f3; font-size: 11px; }
th:not(:first-child), td:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.group td { color: #545a6a; background: #f4f5f8; font-size: 10px; font-weight: 750; }
.clickable { cursor: pointer; transition: background .12s ease; }
.clickable:hover { background: #f8f9fc; }
.quiet { min-height: 0; padding: 8px 0; color: #7e8492; background: transparent; box-shadow: none; font-size: 11px; font-weight: 500; }
.info, .notice { margin: 0 0 18px; padding: 14px 17px; border: 1px solid #e2e4fb; border-radius: 11px; color: #555c75; background: #f5f5ff; font-size: 11px; }
.notice { border-color: #f0dfb8; color: #7f6328; background: #fff7e4; white-space: pre-line; }
.empty { padding: 75px 15px; text-align: center; }
.mapping-row, .simple-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.mapping-row > span { max-width: 48%; font-size: 11px; }
.mapping-controls { display: flex; align-items: center; gap: 8px; }
.mapping-controls select { width: 290px; font-size: 11px; }
.mapping-controls input { width: 88px; font-size: 11px; }
#articleSearch { width: 100%; margin-top: 14px; }
.simple-row button { min-height: 34px; padding: 7px 12px; font-size: 10px; }
.sync-card { margin-bottom: 11px; padding: 17px 18px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.sync-card.running { border-color: #dddffc; background: #fcfcff; }
.sync-card.queued { border-color: #dbe6f4; background: #f8fbff; }
.sync-card.error { border-color: #f0d4cd; background: #fffafa; }
.sync-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; }
.sync-head strong { display: block; font-size: 12px; }
.sync-head small { display: block; margin-top: 3px; color: #9499a7; font-size: 9px; }
.sync-status { padding: 5px 9px; border-radius: 999px; font-size: 9px; font-weight: 750; }
.sync-status.running { color: #5751d3; background: #efefff; }
.sync-status.queued { color: #3f6f9f; background: #eaf3fc; }
.sync-status.success { color: #2e8b4b; background: #edf8f0; }
.sync-status.error { color: #aa503d; background: #fff0ec; }
.sync-status.interrupted { color: #80682f; background: #fff7df; }
.sync-stage { display: grid; gap: 7px; margin-top: 14px; }
.sync-stage > strong { font-size: 12px; }
.sync-stage > span, .sync-stage > small { color: #858a98; font-size: 9px; }
.sync-progress { height: 7px; overflow: hidden; border-radius: 999px; background: #e9eaf0; }
.sync-progress i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--purple), #8b86ff); transition: width .3s ease; }
.sync-card > p { margin: 12px 0 0; font-size: 10px; }
.sync-error { color: var(--danger) !important; font-weight: 650; }
.large { font-size: 28px; }
.cash-card .review { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.cash-card input { flex: 1; min-width: 160px; }
.status { color: var(--green-dark); font-size: 10px; font-weight: 700; }
.bad { color: var(--danger); }
footer { display: flex; justify-content: space-between; padding: 24px 0 0; color: #a0a4af; font-size: 9px; }

dialog { width: min(1060px, 92vw); max-height: 88vh; padding: 24px; border: 0; border-radius: 17px; color: var(--ink); box-shadow: 0 30px 80px rgba(20, 23, 38, .28); }
dialog::backdrop { background: rgba(17, 20, 38, .55); backdrop-filter: blur(3px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
pre { white-space: pre-wrap; word-break: break-word; font-size: 11px; }
form { display: flex; flex-wrap: wrap; gap: 12px; }
textarea { min-height: 90px; resize: vertical; }
.review-form { display: grid; gap: 14px; }
.split-lines { display: grid; gap: 11px; }
.split-line { display: flex; gap: 9px; }
.split-line select { flex: 1; min-width: 0; }
.split-line input { width: 180px; }
.review-form > button { justify-self: start; }
.review-form p { margin: 0; }

.kb-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
  padding: 24px;
  border: 1px solid #e2e4fb;
  border-radius: 15px;
  background: linear-gradient(135deg, #f5f5ff 0%, #fbfbff 62%, #f2fbf5 100%);
}
.kb-hero h2 { margin-top: 5px; font-size: 22px; }
.kb-hero p { margin-bottom: 0; }
.kb-label { color: var(--purple); font-size: 9px; font-weight: 800; letter-spacing: 1.5px; }
.kb-search { position: relative; display: block; flex: 0 0 min(360px, 38%); }
.kb-search svg { position: absolute; top: 50%; left: 13px; width: 17px; height: 17px; color: #8b90a0; transform: translateY(-50%); pointer-events: none; }
.kb-search input { width: 100%; padding-left: 40px; background: rgba(255, 255, 255, .92); }
.kb-list { display: grid; gap: 10px; }
.kb-item { overflow: hidden; border: 1px solid var(--line); border-radius: 13px; background: #fff; box-shadow: 0 4px 14px rgba(34, 39, 58, .035); }
.kb-item summary { display: flex; align-items: center; gap: 15px; padding: 17px 19px; list-style: none; cursor: pointer; user-select: none; }
.kb-item summary::-webkit-details-marker { display: none; }
.kb-item summary::after { content: "+"; margin-left: auto; color: #9297a5; font-size: 21px; font-weight: 300; }
.kb-item[open] summary::after { content: "−"; }
.kb-item[open] summary { border-bottom: 1px solid var(--line); background: #fafbfc; }
.kb-number { display: grid; flex: 0 0 36px; width: 36px; height: 36px; place-items: center; border-radius: 10px; color: #5c57d8; background: #efefff; font-size: 10px; font-weight: 800; }
.kb-item summary b { display: block; font-size: 13px; }
.kb-item summary small { display: block; margin-top: 2px; color: #959aa7; font-size: 10px; }
.kb-body { padding: 18px 22px 21px 70px; color: #555b69; font-size: 12px; }
.kb-body p { color: #686e7c; }
.kb-body strong { color: #303541; }
.kb-body ol, .kb-body ul { display: grid; gap: 7px; margin: 10px 0 15px; padding-left: 20px; }
.kb-body table { margin: 13px 0; }
.kb-note { display: flex; align-items: flex-start; gap: 9px; margin-top: 13px; padding: 12px 14px; border-radius: 10px; color: #514fa0; background: #f2f2ff; }
.kb-note svg { flex: 0 0 17px; width: 17px; height: 17px; }
.kb-formula { display: inline-block; padding: 10px 14px; border-radius: 9px; color: #267d45 !important; background: #eef9f1; font-size: 14px; font-weight: 750; font-variant-numeric: tabular-nums; }
.empty.compact { padding: 35px 15px; }

.login {
  width: min(460px, calc(100vw - 34px));
  margin: 8vh auto;
  padding: 36px;
  border: 1px solid rgba(255, 255, 255, .95);
  border-radius: 20px;
  background: #fff;
  box-shadow: var(--shadow);
}
.login .brand { margin-bottom: 42px; color: var(--ink); }
.login .brand small { color: #999eaa; }
.login h1 { font-size: 32px; }
.login form { display: grid; margin-top: 26px; }
.login label { display: grid; gap: 7px; color: #777d8d; font-size: 11px; }
.login input { width: 100%; }
.login p[role="alert"] { color: var(--danger); }

@media (max-width: 1150px) {
  body { padding: 0; }
  #workspace { grid-template-columns: 230px minmax(0, 1fr); min-height: 100vh; border: 0; border-radius: 0; }
  aside { min-height: 100vh; }
  main { padding: 0 23px 25px; }
  .metrics strong { font-size: 20px; }
  .titlebar { align-items: flex-start; }
}

@media (max-width: 780px) {
  #workspace { display: block; }
  aside { min-height: auto; padding: 16px; }
  .brand b { flex-basis: 36px; width: 36px; height: 36px; border-radius: 10px; }
  .nav-label, .aside-bottom { display: none; }
  nav { display: flex; gap: 7px; margin-top: 16px; overflow-x: auto; }
  nav button { flex: 0 0 auto; width: auto; min-height: 39px; white-space: nowrap; }
  main { padding: 0 15px 24px; }
  header { height: 58px; }
  .badge { display: none; }
  .titlebar { flex-direction: column; margin: 22px 0 17px; }
  .actions { width: 100%; }
  .actions > * { flex: 1; }
  .filters { flex-wrap: wrap; align-items: center; padding: 14px; }
  .filters select { width: 100%; min-width: 0; }
  .filter-note { display: none; }
  .metrics { grid-template-columns: 1fr; gap: 10px; }
  .metrics article { padding: 16px 18px; }
  .metrics strong { margin: 6px 0; font-size: 24px; }
  .card-head { align-items: flex-start; flex-direction: column; }
  .content-card { padding: 15px; }
  .mapping-row { align-items: flex-start; flex-direction: column; }
  .mapping-row > span { max-width: 100%; }
  .mapping-controls { width: 100%; flex-wrap: wrap; }
  .mapping-controls select { width: 100%; }
  .mapping-controls input { width: 110px; }
  .split-line { flex-wrap: wrap; }
  .split-line select { flex-basis: 100%; }
  .split-line input { flex: 1; }
  h1 { font-size: 26px; }
  th, td { padding: 9px 6px; }
  footer span { display: none; }
  .kb-hero { align-items: stretch; flex-direction: column; padding: 18px; }
  .kb-search { flex-basis: auto; width: 100%; }
  .kb-body { padding: 16px; }
}
