:root {
  --page: #dcebf1;
  --shell: #f8f8f6;
  --sidebar: #fbfbfa;
  --surface: #ffffff;
  --surface-soft: #f3f3f1;
  --text: #171717;
  --muted: #7a7f87;
  --soft: #a6abb2;
  --line: #ececea;
  --line-strong: #deded9;
  --black: #202020;
  --purple: #8d6cf7;
  --purple-2: #7354dc;
  --green: #8ef0a0;
  --cyan: #8de1ef;
  --yellow: #ffd36b;
  --danger: #dc4c3f;
  --warn: #a86d16;
  --ok: #16804a;
  --shadow: 0 22px 60px rgba(34, 42, 48, 0.12);
  --shadow-soft: 0 10px 28px rgba(36, 39, 44, 0.07);
  --radius: 24px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-size: 14px;
}

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

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  padding: 0 14px;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(20, 20, 20, 0.03);
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

button:hover {
  background: #f8f8f7;
  border-color: var(--line-strong);
  box-shadow: 0 8px 20px rgba(20, 20, 20, 0.06);
}

button:active {
  transform: translateY(1px);
}

button.primary {
  background: var(--purple);
  color: #fff;
  border-color: var(--purple);
  box-shadow: 0 12px 24px rgba(141, 108, 247, 0.28);
}

button.primary:hover {
  background: var(--purple-2);
  border-color: var(--purple-2);
}

button.danger {
  color: var(--danger);
  border-color: #f3c3be;
  background: #fff6f5;
}

button.ghost {
  background: #f4f4f1;
  color: var(--muted);
  border-color: transparent;
  box-shadow: none;
}

button.ghost:hover {
  color: var(--text);
  background: #ebebe7;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: #fff;
  color: var(--text);
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(141, 108, 247, 0.7);
  box-shadow: 0 0 0 4px rgba(141, 108, 247, 0.14);
}

textarea {
  min-height: 110px;
  resize: vertical;
}

label {
  display: grid;
  gap: 8px;
  color: #68707b;
  font-size: 12px;
  font-weight: 800;
}

.checkline input {
  width: auto;
  min-height: auto;
  justify-self: start;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background: var(--page);
}

.login-box {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 30px;
  box-shadow: var(--shadow);
  padding: 34px;
}

.login-title {
  margin: 0 0 22px;
  font-size: 24px;
  letter-spacing: 0;
}

.login-form {
  display: grid;
  gap: 16px;
}

.app-shell {
  min-height: calc(100vh - 56px);
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  margin: 28px;
  overflow: hidden;
  border-radius: 34px;
  background: var(--shell);
  box-shadow: var(--shadow);
}

.sidebar {
  min-height: calc(100vh - 56px);
  background: var(--sidebar);
  color: var(--text);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  border-right: 1px solid var(--line);
}

.brand {
  padding: 0 8px 16px;
  border-bottom: 1px solid var(--line);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: linear-gradient(135deg, #111, #303030);
  color: #fff;
  font-weight: 900;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.12);
}

.brand-name {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.nav {
  display: grid;
  gap: 7px;
}

.nav button {
  justify-content: flex-start;
  text-align: left;
  min-height: 46px;
  width: 100%;
  border: 0;
  border-radius: 16px;
  color: #545b64;
  background: transparent;
  padding: 0 14px;
  box-shadow: none;
}

.nav button::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d6d6d0;
  margin-right: 11px;
}

.nav button.active {
  color: #fff;
  background: var(--black);
  box-shadow: 0 12px 26px rgba(23, 23, 23, 0.22);
}

.nav button.active::before {
  background: var(--purple);
}

.nav button:hover:not(.active) {
  color: var(--text);
  background: #f0f0ed;
  box-shadow: none;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 8px;
  padding: 0 8px;
}

.content {
  min-width: 0;
  padding: 28px;
}

.topbar {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.page-title {
  margin: 0;
  font-size: 28px;
  line-height: 1.08;
  letter-spacing: 0;
}

.title-stack {
  display: grid;
  gap: 7px;
}

.topbar-date {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.grid {
  display: grid;
  gap: 18px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 14px;
}

.metric {
  position: relative;
  min-height: 128px;
  border: 0;
  border-radius: 26px;
  padding: 18px;
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  background: #fff;
}

.metric::after {
  content: "";
  position: absolute;
  right: -22px;
  top: -22px;
  width: 88px;
  height: 88px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.36);
  transform: rotate(18deg);
}

.metric:nth-child(1) {
  background: linear-gradient(135deg, #f4f0ff, #d8fbff);
}

.metric:nth-child(2) {
  background: linear-gradient(135deg, #f0ffe7, #baf7c4);
}

.metric:nth-child(3) {
  background: linear-gradient(135deg, #fff4d7, #ffd878);
}

.metric:nth-child(4) {
  background: linear-gradient(135deg, #eff4ff, #b9d6ff);
}

.metric:nth-child(5) {
  background: linear-gradient(135deg, #f3eeff, #a891ff);
  color: #fff;
}

.metric:nth-child(5) .metric-label {
  color: rgba(255, 255, 255, 0.82);
}

.metric:nth-child(6) {
  background: linear-gradient(135deg, #eefdf1, #9cf0ab);
}

.metric:nth-child(7) {
  background: linear-gradient(135deg, #fff0ea, #ffc1ad);
}

.metric:nth-child(8) {
  background: linear-gradient(135deg, #eef9ff, #99e3ee);
}

.metric:nth-child(9),
.metric:nth-child(10) {
  background: #fff;
}

.metric-label {
  position: relative;
  z-index: 1;
  color: rgba(23, 23, 23, 0.62);
  font-size: 12px;
  font-weight: 900;
}

.metric-value {
  position: relative;
  z-index: 1;
  margin-top: 18px;
  font-size: 25px;
  line-height: 1.12;
  font-weight: 900;
  letter-spacing: 0;
  word-break: break-word;
}

.panel {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 28px;
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.panel-head {
  min-height: 62px;
  padding: 18px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.panel-title {
  margin: 0;
  font-size: 17px;
  font-weight: 900;
  letter-spacing: 0;
}

.panel-body {
  padding: 18px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 8px;
  min-width: 780px;
}

th,
td {
  padding: 12px 14px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  background: transparent;
}

td {
  background: #f7f7f5;
  border-top: 1px solid #f0f0ed;
  border-bottom: 1px solid #f0f0ed;
}

td:first-child {
  border-left: 1px solid #f0f0ed;
  border-radius: 16px 0 0 16px;
}

td:last-child {
  border-right: 1px solid #f0f0ed;
  border-radius: 0 16px 16px 0;
}

tbody tr:hover td {
  background: #f1f1ee;
}

td.actions {
  white-space: nowrap;
  width: 160px;
}

td.actions button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: 12px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.toolbar input {
  max-width: 320px;
  background: #f7f7f5;
  border-color: transparent;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  color: #5e6470;
  background: #ecece8;
}

.status.ok {
  color: var(--ok);
  background: #e8f8ec;
}

.status.warn {
  color: var(--warn);
  background: #fff4d8;
}

.status.danger {
  color: var(--danger);
  background: #fff0ef;
}

.empty {
  color: var(--muted);
  padding: 24px 0;
  text-align: center;
  font-weight: 800;
}

.notice {
  min-height: 40px;
  display: none;
  align-items: center;
  border-radius: 16px;
  padding: 9px 12px;
  color: var(--danger);
  background: #fff0ef;
}

.notice.show {
  display: flex;
}

.danger-zone {
  margin-top: 18px;
  border-color: #ffe0dc;
}

.danger-zone .panel-head {
  background: #fff9f8;
}

.muted {
  color: var(--muted);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.form-grid label.full {
  grid-column: 1 / -1;
}

dialog {
  width: min(820px, calc(100vw - 24px));
  border: 0;
  border-radius: 28px;
  padding: 0;
  box-shadow: var(--shadow);
  overflow: hidden;
}

dialog::backdrop {
  background: rgba(33, 39, 44, 0.45);
}

.dialog-head,
.dialog-foot {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.dialog-head strong {
  font-size: 19px;
  font-weight: 900;
}

.dialog-foot {
  border-top: 1px solid var(--line);
  border-bottom: 0;
  justify-content: flex-end;
}

.dialog-body {
  padding: 20px;
  background: #fbfbfa;
}

.bot-preview {
  white-space: pre-wrap;
  line-height: 1.78;
  background: #202020;
  color: #f5f5f2;
  border-radius: 24px;
  padding: 18px;
  min-height: 240px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.split {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
}

.settings-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  max-width: 780px;
}

.settings-form label.full {
  grid-column: 1 / -1;
}

.telegram-actions {
  margin-top: 16px;
}

.mobile-top {
  display: none;
}

@media (max-width: 1280px) {
  .metrics {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }
}

@media (max-width: 1080px) {
  .app-shell {
    margin: 16px;
    min-height: calc(100vh - 32px);
    grid-template-columns: 226px minmax(0, 1fr);
  }

  .sidebar {
    min-height: calc(100vh - 32px);
  }

  .grid.two,
  .grid.three,
  .split {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 780px) {
  .app-shell {
    margin: 0;
    min-height: 100vh;
    grid-template-columns: 1fr;
    border-radius: 0;
  }

  .sidebar {
    min-height: auto;
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 10px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand,
  .sidebar-footer {
    display: none;
  }

  .nav {
    display: flex;
    overflow-x: auto;
    gap: 8px;
    padding-bottom: 2px;
  }

  .nav button {
    min-width: max-content;
    width: auto;
    min-height: 42px;
  }

  .nav button::before {
    display: none;
  }

  .content {
    padding: 16px;
  }

  .topbar {
    align-items: flex-start;
    min-height: auto;
    flex-direction: column;
  }

  .page-actions {
    justify-content: flex-start;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(135px, 1fr));
  }

  .form-grid,
  .settings-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 500px) {
  .content {
    padding: 12px;
  }

  .metrics {
    grid-template-columns: 1fr;
  }

  .login-box {
    padding: 24px;
  }
}
