:root {
  color-scheme: dark;
  --ink: #edf0fc;
  --muted: #b4bad3;
  --line: #343853;
  --paper: #1c2034;
  --canvas: #131625;
  --accent: #bdb5ff;
  --accent-tint: #34305b;
  --button: #6254cf;
  --button-hover: #5345bb;
  --focus: #a69aff;
  --control: #161a2a;
  --control-line: #5c627f;
  --table-head: #242941;
  --row-hover: #272b44;
  --neutral: #30334d;
  --neutral-text: #d0cde9;
  --good: #1e403c;
  --good-text: #a0e6cc;
  --bad: #482b3a;
  --bad-text: #ffb5c3;
  --warn: #473a29;
  --warn-text: #ffda9e;
  --info: #253b57;
  --info-text: #a9d2ff;
  --sidebar: 216px;
  --top-height: 64px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --ink: #20233a;
  --muted: #60667d;
  --line: #e1e4ef;
  --paper: #fff;
  --canvas: #f5f6fb;
  --accent: #5143c8;
  --accent-tint: #efedff;
  --button: #5143c8;
  --button-hover: #4135aa;
  --focus: #7467e8;
  --control: #fff;
  --control-line: #c9cede;
  --table-head: #f8f8fd;
  --row-hover: #fafaff;
  --neutral: #edecf6;
  --neutral-text: #555177;
  --good: #e6f6ee;
  --good-text: #16604b;
  --bad: #fcebed;
  --bad-text: #9d303d;
  --warn: #fff1dc;
  --warn-text: #815516;
  --info: #e9f2ff;
  --info-text: #2c66a2;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink);
  font: 1rem/1.5 var(--font);
}

h1, h2, p { margin: 0; }
a { color: var(--accent); font-weight: 650; text-underline-offset: .18em; }
button, input, select { font: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.workspace {
  display: grid;
  grid-template: var(--top-height) 1fr / var(--sidebar) minmax(0, 1fr);
}

.top {
  position: sticky;
  top: 0;
  z-index: 2;
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  min-height: var(--top-height);
  padding: 0 clamp(16px, 3vw, 36px);
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.brand, .identity { display: flex; align-items: center; gap: 11px; }
.brand { color: var(--ink); text-decoration: none; }
.brand strong { font-weight: 790; letter-spacing: .035em; }
.brand > span:last-child { color: var(--muted); font-size: .88rem; font-weight: 550; }

.brand-mark {
  display: inline-flex;
  flex: 0 0 33px;
  width: 33px;
  height: 33px;
  align-items: end;
  justify-content: center;
  gap: 3px;
  padding: 8px 0;
  border-radius: 9px;
  background: var(--button);
}

.brand-mark i { width: 3px; height: 8px; border-radius: 2px; background: white; }
.brand-mark i:nth-child(2) { height: 13px; }
.brand-mark i:nth-child(3) { height: 17px; }

.identity { color: var(--ink); font-size: .875rem; font-weight: 650; }
.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 30px;
  height: 30px;
  width: 30px;
  border-radius: 50%;
  background: var(--accent-tint);
  color: var(--accent);
}

.quiet {
  min-height: 34px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  color: var(--muted);
}

.theme-toggle {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, 30px);
  place-items: center;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 100px;
  background: var(--accent-tint);
  color: var(--muted);
}
.theme-toggle[hidden] { display: none; }
.theme-toggle::before {
  content: "";
  position: absolute;
  inset: 2px auto 2px 2px;
  width: 30px;
  border-radius: inherit;
  background: var(--button);
  box-shadow: 0 1px 3px #17113033;
}
.theme-toggle[aria-pressed="true"]::before { transform: translateX(30px); }
.theme-toggle svg {
  position: relative;
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.theme-toggle[aria-pressed="false"] svg:first-child,
.theme-toggle[aria-pressed="true"] svg:last-child { color: white; }
.theme-toggle:hover { border-color: var(--accent); }
@media (prefers-reduced-motion: no-preference) {
  .theme-toggle::before { transition: transform .18s ease-out; }
  .theme-toggle svg { transition: color .18s ease-out; }
}

.quiet:hover { color: var(--accent); background: var(--accent-tint); }

.sidebar {
  position: sticky;
  top: var(--top-height);
  align-self: start;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 24px;
  min-height: calc(100vh - var(--top-height));
  padding: 24px 13px 17px;
  background: var(--paper);
  border-right: 1px solid var(--line);
}

.nav-heading {
  margin: 0 10px 6px;
  color: var(--muted);
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .055em;
  text-transform: uppercase;
}

.nav-heading:not(:first-child) { margin-top: 24px; }
.sidebar a {
  display: flex;
  min-height: 39px;
  align-items: center;
  gap: 10px;
  margin: 3px 0;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
  font-size: .875rem;
  white-space: normal;
  overflow-wrap: anywhere;
  min-width: 0;
  max-width: 100%;
  line-height: 1.35;
}

.icon-library { position: absolute; width: 0; height: 0; overflow: hidden; }
.ui-icon { flex: none; vertical-align: -.15em; }
.sidebar a .ui-icon { color: var(--accent); }
.metric-icon .ui-icon { width: 18px; height: 18px; }
.quiet .ui-icon { margin-inline-end: .2em; }

.sidebar a:hover, .sidebar a[aria-current] { color: var(--accent); background: var(--accent-tint); }
.sidebar-foot { padding: 12px 10px 0; border-top: 1px solid var(--line); color: var(--muted); font-size: .8rem; }
.sidebar-foot .ui-icon { margin-right: 4px; }

.nav-dot {
  display: inline-block;
  flex: 0 0 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #7467e8;
}

.nav-dot.amo { background: #3280dc; }
.nav-dot.mk { background: #087b68; }
.source { display: inline-flex; align-items: center; gap: 7px; }

.shell {
  width: 100%;
  max-width: 1510px;
  min-width: 0;
  margin: 0 auto;
  padding: 0 clamp(16px, 3vw, 38px);
}

.heading { padding-top: 29px; margin-bottom: 21px; }
.heading h1, .login h1 {
  font-size: clamp(1.7rem, 4vw, 2.35rem);
  line-height: 1.15;
  font-weight: 770;
  letter-spacing: -.04em;
  overflow-wrap: anywhere;
}

.heading p, .login p { margin-top: 7px; color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 21px; }

.metric, .panel, .login {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 13px;
  box-shadow: 0 2px 6px #24223d06;
}

.metric { min-width: 0; padding: 16px 18px 17px; }
.metric-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin-bottom: 10px;
  border-radius: 8px;
  background: var(--accent-tint);
  color: var(--accent);
  font-size: 1.1rem;
  font-weight: 720;
}

.records .metric-icon { background: var(--good); color: var(--good-text); }
.errors .metric-icon { background: var(--bad); color: var(--bad-text); }
.speed .metric-icon { background: var(--info); color: var(--info-text); }
.metric span { display: block; color: var(--muted); font-size: .86rem; }
.metric strong { display: block; margin-top: 4px; font-size: clamp(1.45rem, 3vw, 2rem); font-weight: 740; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.panel { margin-bottom: 28px; }
.panel-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 12px;
}
.panel-heading h2 { font-size: 1.12rem; }
.panel-heading > span { color: var(--muted); font-size: .8rem; white-space: nowrap; }

.filters { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; padding: 2px 18px 16px; }
.filters label { display: grid; gap: 4px; color: var(--muted); font-size: .79rem; font-weight: 650; }
.filters .query { flex: 1 1 155px; }
input, select {
  width: 100%;
  min-width: 0;
  min-height: 39px;
  padding: 6px 9px;
  border: 1px solid var(--control-line);
  border-radius: 7px;
  background: var(--control);
  color: var(--ink);
  font-size: .86rem;
}

select {
  appearance: none;
  padding-right: 23px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 12px) 16px, calc(100% - 8px) 16px;
  background-size: 4px 4px;
  background-repeat: no-repeat;
}

.filter-actions { display: flex; align-items: center; gap: 10px; font-size: .85rem; }
.button {
  display: inline-flex;
  align-items: center;
  min-height: 39px;
  padding: 7px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--button);
  color: white;
  font-weight: 660;
  text-decoration: none;
}

.button:hover { background: var(--button-hover); }
.table-wrap { overflow: auto; }
table { width: 100%; min-width: 750px; border-collapse: collapse; font-size: .88rem; text-align: left; }
th, td { padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: middle; }
th { background: var(--table-head); color: var(--muted); font-size: .78rem; font-weight: 690; white-space: nowrap; }
tr:hover td { background: var(--row-hover); }
.fixed, .number { white-space: nowrap; }
.number { text-align: right; font-variant-numeric: tabular-nums; }
.who { max-width: 200px; overflow-wrap: anywhere; }
small { display: block; color: var(--muted); font-size: .78rem; }
.operation { font: 650 .83rem ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; }
.error-text, .alert { color: var(--bad-text); }

.chip { display: inline-block; padding: 3px 8px; border-radius: 6px; background: var(--neutral); color: var(--neutral-text); font-size: .79rem; font-weight: 650; white-space: nowrap; }
.success { background: var(--good); color: var(--good-text); }
.failed { background: var(--bad); color: var(--bad-text); }
.denied { background: var(--warn); color: var(--warn-text); }

.empty, .pagination, .alert { padding: 15px 18px; }
.empty, .pagination { border-top: 1px solid var(--line); color: var(--muted); }
.pagination { display: flex; justify-content: flex-end; align-items: center; gap: 17px; font-size: .88rem; }
.login { width: min(100%, 560px); margin: clamp(40px, 12vh, 125px) auto; padding: clamp(22px, 5vw, 42px); }
.login .button { margin-top: 20px; }
.login .alert { padding: 0; }
.detail-heading a { display: inline-block; margin-bottom: 9px; }
.timeline .panel-heading { border-bottom: 1px solid var(--line); }
.timeline article { margin: 0 18px; padding: 15px 0; }
.timeline article + article { border-top: 1px solid var(--line); }
.event-title { display: flex; justify-content: space-between; gap: 15px; }
.event-title h2 { font-size: 1rem; }
.event-title time, .timeline dt { color: var(--muted); font-size: .85rem; }
dl { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 175px), 1fr)); gap: 12px; margin: 12px 0 0; }
dd { margin: 0; overflow-wrap: anywhere; }

@media (max-width: 1080px) {
  :root { --sidebar: 175px; }
}

@media (max-width: 900px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters label { flex: 1 1 130px; }
  .filters .query { flex-basis: 100%; }
}

@media (max-width: 780px) {
  .workspace { display: block; }
  .sidebar { position: static; min-height: 0; padding: 8px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: 4px 6px; }
  .sidebar a { min-height: 34px; margin: 0; }
  .sidebar .nav-heading, .sidebar-foot { display: none; }
  .heading { padding-top: 20px; margin-bottom: 16px; }
  .table-wrap { overflow: visible; }
  table, tbody { display: block; min-width: 0; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  tbody tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; padding: 12px 16px; border-top: 1px solid var(--line); }
  td { min-width: 0; padding: 0; border: 0; white-space: normal !important; }
  td:nth-child(4) { grid-column: 1 / -1; grid-row: 1; }
  td:nth-child(1) { grid-row: 2; grid-column: 1 / -1; color: var(--muted); }
  td:nth-child(5) { grid-column: 1 / -1; }
  td:nth-child(6), td:nth-child(7) { text-align: left; }
  td:nth-child(6)::before, td:nth-child(7)::before { display: block; color: var(--muted); font-size: .8rem; }
  td:nth-child(6)::before { content: "Записей"; }
  td:nth-child(7)::before { content: "Время ответа"; }
  tr:hover td { background: transparent; }
}

@media (max-width: 440px) {
  .brand > span:last-child, .identity-name, .avatar { display: none; }
  .identity { gap: 6px; }
  .cards { gap: 9px; }
  .metric { padding: 12px; }
  .event-title { flex-direction: column; gap: 3px; }
}

.audit-tools { display: flex; align-items: center; gap: clamp(6px, 1vw, 14px); }
.audit-clock { display: grid; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; line-height: 1.3; }
.audit-clock b { color: var(--ink); font-size: .78rem; font-weight: 650; }
.audit-clock small { color: var(--muted); font-size: .72rem; font-weight: 500; }

@media (max-width: 380px) {
  .top { padding-inline: 8px; gap: 4px; }
  .brand { gap: 5px; }
}
