:root {
  --bg: #0b0e14;
  --card: #121722;
  --card2: #1a1f2b;
  --in: #0b0e14;
  --line: #222938;
  --line2: #2e3648;
  --fg: #e6e9ef;
  --fg2: #c9cfdb;
  --mut: #8b93a7;
  --acc: #5b8cff;
  --acc-fg: #08142e;
  --acc-bg: #5b8cff1f;
  --acc-text: #7aa2ff;
  --ok: #3ddc97;
  --ok-fg: #06281a;
  --ok-bg: #0f2a1e;
  --ok-line: #1f4d36;
  --ok-text: #8ce99a;
  --bad: #ff6b6b;
  --bad-solid: #d5373c;
  --bad-bg: #2a1215;
  --bad-line: #5c1f1f;
  --bad-text: #ffb3b3;
  --warn: #fcc419;
  --warn-bg: #2a230b;
  --warn-line: #5c4a12;
  --warn-text: #f5d58a;
  --ph: #7d879b;
  --acc-line: #5b8cff55;
  --ring: #5b8cff66;
  --scrim: #000b;
  --shadow: #0008;
  --top-bg: #0b0e14e6;
  --hover: #ffffff0d;
  --chart-1: #3987e5;
  --chart-2: #d95926;
  color-scheme: dark;
  --r: 12px;
  --r-sm: 8px;
  --sw: 224px;
  --top: 56px;
}
/* Light theme: chosen in the sidebar, remembered per browser (public/theme.js sets data-theme before first paint). */
:root[data-theme='light'] {
  --bg: #f4f6fa;
  --card: #ffffff;
  --card2: #eef1f6;
  --in: #ffffff;
  --line: #dfe3ec;
  --line2: #c5ccd9;
  --fg: #161b26;
  --fg2: #3a4354;
  --mut: #5b6577;
  --acc: #2f66e0;
  --acc-fg: #fff;
  --acc-bg: #2f66e01a;
  --acc-text: #2456c9;
  --ok: #0c7d4d;
  --ok-fg: #fff;
  --ok-bg: #e3f6ec;
  --ok-line: #a9dfc2;
  --ok-text: #0b6b42;
  --bad: #c9302f;
  --bad-solid: #cf2f35;
  --bad-bg: #fdecec;
  --bad-line: #f2b8b8;
  --bad-text: #a52626;
  --warn: #8a5d00;
  --warn-bg: #fff4d6;
  --warn-line: #ecd28a;
  --warn-text: #7a5200;
  --ph: #6b7588;
  --acc-line: #2f66e055;
  --ring: #2f66e066;
  --scrim: #0f172a80;
  --shadow: #0f172a26;
  --top-bg: #f4f6fae6;
  --hover: #0f172a0d;
  --chart-1: #2a78d6;
  --chart-2: #eb6834;
  color-scheme: light;
}
* {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  padding-left: var(--sw);
  font:
    14px/1.5 system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    sans-serif;
  background: var(--bg);
  color: var(--fg);
}
body.plain {
  padding-left: 0;
}
a {
  color: var(--acc-text);
}
h1 {
  font-size: 1rem;
  margin: 0;
  font-weight: 650;
  letter-spacing: 0.2px;
}
h2 {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 650;
}

/* app shell */
.side {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sw);
  background: var(--card);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 10px;
  z-index: 30;
  overflow: auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 16px;
  font-weight: 700;
  font-size: 15px;
  color: var(--fg);
  text-decoration: none;
}
.brand i {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--acc);
  color: var(--acc-fg);
  font-style: normal;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.03em;
}
.nsec {
  padding: 14px 10px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--mut);
}
.nl {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  color: var(--mut);
  text-decoration: none;
  font-weight: 500;
}
.nl svg {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.nl:hover {
  background: var(--card2);
  color: var(--fg);
}
.nl.on {
  background: var(--acc-bg);
  color: var(--fg);
}
.nl.on svg {
  color: var(--acc-text);
}
.nl:focus-visible {
  outline: 2px solid var(--acc);
  outline-offset: -2px;
}
.sfoot {
  margin-top: auto;
  padding: 12px 10px 2px;
  border-top: 1px solid var(--line);
}
.sfoot .who {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sopts {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}
.sfoot .sopts button {
  flex: 1;
  width: auto;
  padding: 6px 4px;
}
kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  border: 1px solid var(--line2);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--card2);
  color: var(--fg);
  font:
    600 12px ui-monospace,
    monospace;
  text-align: center;
}
.sfoot form {
  margin: 10px 0 0;
}
.sfoot button {
  width: 100%;
}
.role {
  display: inline-block;
  margin-top: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--line2);
  color: var(--fg2);
  background: var(--card2);
}
.role.super_admin {
  color: var(--acc-text);
  border-color: var(--acc-line);
  background: var(--acc-bg);
}
header.top {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--top);
  padding: 8px 20px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--top-bg);
  backdrop-filter: blur(8px);
  z-index: 20;
}
header.top h1 {
  font-size: 1.05rem;
}
.topx {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.burger {
  display: none;
  padding: 0;
  width: 38px;
  min-height: 38px;
  font-size: 18px;
}
.scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--scrim);
  z-index: 25;
}
main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 20px;
}

/* components */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px;
  margin-bottom: 14px;
}
.grid {
  display: grid;
  gap: 12px;
}
.g2 {
  grid-template-columns: 1fr 1fr;
}
.g3 {
  grid-template-columns: repeat(3, 1fr);
}
.g4 {
  grid-template-columns: 1fr 1.3fr 1.3fr 1fr;
}
label {
  display: block;
  font-size: 12px;
  color: var(--mut);
  margin-bottom: 4px;
  font-weight: 500;
}
input,
select,
button,
textarea {
  font: inherit;
}
input,
select,
textarea {
  width: 100%;
  background: var(--in);
  border: 1px solid var(--line2);
  color: var(--fg);
  border-radius: var(--r-sm);
  padding: 9px 12px;
  min-height: 40px;
}
input::placeholder {
  color: var(--ph);
}
input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--ring);
  border-color: var(--acc);
}
button {
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 9px 14px;
  min-height: 40px;
  background: var(--acc);
  color: var(--acc-fg);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}
button:hover:not(:disabled) {
  filter: brightness(1.1);
}
button:focus-visible {
  outline: 2px solid var(--acc);
  outline-offset: 2px;
}
button.sec {
  background: var(--card2);
  color: var(--fg);
  border-color: var(--line2);
}
button.ok {
  background: var(--ok);
  color: var(--ok-fg);
}
button.bad {
  background: var(--bad-solid);
  color: #fff;
}
button.sm {
  padding: 6px 10px;
  min-height: 32px;
  font-size: 12px;
}
button.lg {
  min-height: 46px;
  padding: 10px 22px;
  font-size: 15px;
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
button.loading::before {
  content: '';
  width: 13px;
  height: 13px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.sp {
  flex: 1;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--line2);
  background: var(--card2);
  white-space: nowrap;
}
.pill.ok {
  color: var(--ok);
  background: var(--ok-bg);
  border-color: var(--ok-line);
}
.pill.warn {
  color: var(--warn);
  background: var(--warn-bg);
  border-color: var(--warn-line);
}
.pill.bad {
  color: var(--bad);
  background: var(--bad-bg);
  border-color: var(--bad-line);
}
.pill.mut {
  color: var(--mut);
}
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.num {
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}
.tbl {
  overflow: auto;
  max-height: 60vh;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  -webkit-overflow-scrolling: touch;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th,
td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
thead th {
  position: sticky;
  top: 0;
  background: var(--card2);
  z-index: 1;
}
tbody tr:last-child td {
  border-bottom: 0;
}
th {
  color: var(--mut);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.muted {
  color: var(--mut);
}
.err {
  color: var(--bad);
}
.okt {
  color: var(--ok);
}
.small {
  font-size: 12px;
}
code {
  background: var(--in);
  border: 1px solid var(--line);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.92em;
}
.note {
  margin: 10px 0 0;
  padding: 8px 12px;
  border-radius: var(--r-sm);
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  color: var(--warn-text);
  font-size: 13px;
}
.msg {
  padding: 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--bad-line);
  background: var(--bad-bg);
  color: var(--bad-text);
  white-space: pre-line;
  margin-bottom: 14px;
}
.msg.info {
  border-color: var(--line2);
  background: var(--card);
  color: var(--fg2);
}
.msg.ok {
  border-color: var(--ok-line);
  background: var(--ok-bg);
  color: var(--ok-text);
}
.empty {
  padding: 22px 12px;
  text-align: center;
  color: var(--mut);
  font-size: 13px;
}
.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  margin: 8px 0;
}
.kv > div:nth-child(odd) {
  color: var(--mut);
}
.stat {
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  background: var(--in);
}
.stat .k {
  color: var(--mut);
  font-size: 12px;
}
.stat .v {
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.chip {
  padding: 5px 12px;
  min-height: 32px;
  border-radius: 999px;
  background: var(--card2);
  color: var(--fg2);
  border-color: var(--line2);
  font-size: 13px;
  font-weight: 500;
}
#toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
  max-width: min(420px, calc(100vw - 32px));
}
.toast {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 12px 12px 14px;
  border-radius: var(--r);
  background: var(--card2);
  border: 1px solid var(--line2);
  border-left: 4px solid var(--acc);
  box-shadow: 0 8px 24px var(--shadow);
  animation: tin 0.18s ease-out;
  color: var(--fg);
}
.toast.ok {
  border-left-color: var(--ok);
}
.toast.err {
  border-left-color: var(--bad);
  background: var(--bad-bg);
}
.toast .tmsg {
  flex: 1;
  word-break: break-word;
  white-space: pre-line;
}
.toast .tx {
  background: none;
  border: 0;
  color: var(--mut);
  min-height: 0;
  padding: 0 4px;
  font-size: 18px;
  line-height: 1;
}
@keyframes tin {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
}
.modal {
  position: fixed;
  inset: 0;
  background: var(--scrim);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 40;
}
.modal.open {
  display: flex;
}
.modal .box {
  background: var(--card);
  border: 1px solid var(--line2);
  border-radius: 16px;
  padding: 18px;
  max-width: 440px;
  width: 100%;
  max-height: calc(100vh - 32px);
  overflow: auto;
  box-shadow: 0 20px 60px var(--shadow);
}
.modal .box.wide {
  max-width: 560px;
}
.modal .acts {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 16px;
}
.captcha {
  height: 48px;
  border-radius: 8px;
  border: 1px solid var(--line);
  cursor: pointer;
  background: #fff;
  display: block;
}
.stack > * + * {
  margin-top: 12px;
}
.bals {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
  gap: 8px;
}
.bal {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--in);
  cursor: pointer;
  font-size: 13px;
}
.bal {
  min-width: 0;
}
.bal:hover {
  border-color: var(--acc);
}
.bal .n {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.bal .n span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bal .v {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  text-align: right;
}
.bal .v small {
  display: block;
  font-weight: 400;
  color: var(--mut);
  font-size: 10px;
}
.bal.ok .dot {
  color: var(--ok);
}
.bal.warn .dot {
  color: var(--warn);
}
.bal.bad .dot {
  color: var(--bad);
}
.bal.warn .v {
  color: var(--warn);
}
.gname {
  font-size: 12px;
  color: var(--mut);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 10px 0 6px;
}
.acts-main {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.sw {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 12px;
  color: var(--mut);
  margin: 0;
  user-select: none;
}
.sw input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.sw .tr {
  width: 36px;
  height: 20px;
  border-radius: 999px;
  background: var(--line2);
  position: relative;
  transition: 0.15s;
  flex: none;
}
.sw .tr::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: 0.15s;
}
.sw input:checked + .tr {
  background: var(--ok);
}
.sw input:checked + .tr::after {
  left: 18px;
}
.sw input:focus-visible + .tr {
  outline: 2px solid var(--acc);
}
.sw input:disabled + .tr {
  opacity: 0.4;
}
.cellsw {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
input[type='checkbox'] {
  width: auto;
  min-height: 0;
  accent-color: var(--acc);
}
td .row {
  flex-wrap: nowrap;
}
.bal.warn .v {
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.chip.on {
  background: var(--acc-bg);
  border-color: var(--acc);
  color: var(--fg);
}
.chip .cnt {
  color: var(--mut);
  font-variant-numeric: tabular-nums;
}
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--line);
  margin: 0 0 16px;
  overflow-x: auto;
}
.tab {
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--mut);
  padding: 10px 14px;
  min-height: 0;
  font-weight: 600;
}
.tab:hover:not(:disabled) {
  color: var(--fg);
  filter: none;
}
.tab.on {
  color: var(--fg);
  border-bottom-color: var(--acc);
}
.tab .cnt {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--acc);
  color: var(--acc-fg);
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}
details.help {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--mut);
}
details.help summary {
  cursor: pointer;
  color: var(--acc-text);
  font-weight: 500;
  width: fit-content;
}
details.help[open] summary {
  margin-bottom: 6px;
}
details.help p {
  margin: 0 0 6px;
}
.savebar {
  position: sticky;
  bottom: 12px;
  display: none;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 14px;
  margin-top: 14px;
  background: var(--card2);
  border: 1px solid var(--acc);
  border-radius: var(--r);
  box-shadow: 0 8px 24px var(--shadow);
  z-index: 15;
}
.savebar.on {
  display: flex;
}
body:has(.savebar.on) #toasts {
  bottom: 84px;
}
tr.dirty td:first-child {
  box-shadow: inset 3px 0 0 var(--acc);
}
.tbl.full {
  max-height: none;
}
th[data-sort] {
  cursor: pointer;
  user-select: none;
}
th[data-sort]:hover {
  color: var(--fg);
}
th[data-sort].asc::after {
  content: ' \2191';
}
th[data-sort].desc::after {
  content: ' \2193';
}
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login .card {
  width: 100%;
  max-width: 400px;
  padding: 24px;
}
.login h1 {
  font-size: 1.25rem;
}
@media (max-width: 900px) {
  body {
    padding-left: 0;
  }
  .side {
    transform: translateX(-100%);
    transition: transform 0.18s ease-out;
    width: 260px;
    box-shadow: 0 0 40px var(--shadow);
  }
  body.nav-open .side {
    transform: none;
  }
  body.nav-open .scrim {
    display: block;
  }
  .burger {
    display: inline-flex;
  }
  header.top {
    padding: 8px 12px;
  }
}
@media (max-width: 760px) {
  .g2,
  .g3,
  .g4 {
    grid-template-columns: 1fr;
  }
  main {
    padding: 12px;
  }
  .card {
    padding: 14px;
  }
  .acts-main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }
  .acts-main button {
    width: 100%;
  }
  .bals {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .bal {
    min-width: 0;
    padding: 8px;
  }
  #toasts {
    left: 12px;
    right: 12px;
    bottom: 12px;
    max-width: none;
  }
  .hide-sm {
    display: none;
  }
}
@media (max-width: 760px) {
  .tbl:has(table.stack) {
    max-height: none;
  }
  table.stack thead {
    display: none;
  }
  table.stack,
  table.stack tbody,
  table.stack tr {
    display: block;
    width: 100%;
  }
  table.stack tr {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
  }
  table.stack tbody tr:last-child {
    border-bottom: 0;
  }
  table.stack td {
    display: flex;
    gap: 12px;
    justify-content: space-between;
    align-items: baseline;
    border: 0;
    padding: 3px 0;
    text-align: right;
    white-space: normal;
    min-width: 0 !important;
    max-width: none !important;
    word-break: break-word;
  }
  table.stack td::before {
    content: attr(data-l);
    flex: none;
    color: var(--mut);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    text-align: left;
  }
  table.stack td:not([data-l])::before,
  table.stack td[data-l='']::before {
    display: none;
  }
  table.stack td:empty,
  table.stack td.hide-sm {
    display: none;
  }
  table.stack td:not([data-l]),
  table.stack td[data-l=''] {
    justify-content: flex-start;
    text-align: left;
  }
  table.stack td > input,
  table.stack td > select {
    min-width: 0 !important;
    width: auto !important;
    flex: 1;
    max-width: 65%;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

td .row button {
  padding: 6px 10px;
  min-height: 32px;
  font-size: 12px;
}
