:root {
  color-scheme: light;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #eef3f7;
  --panel: #ffffff;
  --panel-muted: #f5f8fb;
  --line: #d8e1ea;
  --text: #12202f;
  --muted: #718094;
  --blue: #2aabee;
  --blue-dark: #168acd;
  --green: #40b76a;
  --red: #db5967;
  --vk: #4c75a3;
  --max: #7961ff;
  --web: #f49b32;
  --shadow: 0 18px 55px rgba(30, 45, 70, 0.14);
}

.max-personal-fields { display: grid; gap: 14px; }
.max-personal-warning { padding: 12px 14px; border: 1px solid #f2c66d; border-radius: 12px; background: #fff8e7; color: #74510a; font-size: 13px; line-height: 1.45; }
.max-personal-qr { display: grid; justify-items: center; gap: 12px; padding: 16px; border: 1px solid #d9e3ee; border-radius: 14px; background: #f8fbfe; text-align: center; }
.max-personal-qr img { width: min(280px, 100%); aspect-ratio: 1; object-fit: contain; border-radius: 10px; background: #fff; }
.hidden { display: none !important; }

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(42, 171, 238, 0.12), transparent 34rem),
    linear-gradient(135deg, #e7f0f6, #f8fbfd 50%, #e9f3ef);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.admin-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
  padding: 18px;
  gap: 14px;
}

.admin-sidebar,
.admin-content,
.panel {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(216, 225, 234, 0.9);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.admin-sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.brand-block {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 21px;
}

h3 {
  font-size: 16px;
}

.back-link {
  display: inline-flex;
  margin-top: 14px;
  color: var(--blue-dark);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}

.section-nav {
  display: grid;
  gap: 8px;
  padding: 14px;
}

.section-link {
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 800;
  text-align: left;
  background: transparent;
}

.section-link:hover,
.section-link.active {
  color: var(--blue-dark);
  background: #e3f4fd;
}

.admin-content {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.topbar-status {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.backend-health {
  display: grid;
  gap: 2px;
  min-width: 250px;
  max-width: 340px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 12px;
  background: var(--panel-muted);
}

.backend-health strong {
  font-size: 12px;
}

.backend-health span,
.backend-health small {
  color: var(--muted);
  line-height: 1.25;
}

.backend-health.ready {
  border-color: #bfe6cd;
  background: #eaf8ef;
}

.backend-health.warning {
  border-color: #f1d69a;
  background: #fff7df;
}

.backend-health.error {
  border-color: #f4bdc5;
  background: #fff0f2;
}

.save-state {
  min-height: 32px;
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  background: var(--panel-muted);
}

.section-panel {
  display: none;
  min-height: 0;
  overflow: auto;
  padding: 18px;
}

.section-panel.active {
  display: block;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1.1fr) minmax(280px, 0.9fr);
  gap: 14px;
}

.channels-grid {
  align-items: start;
  grid-template-columns: minmax(0, 1fr);
}

.ai-manager-grid {
  align-items: start;
}

.settings-form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  resize: vertical;
  color: var(--text);
  background: #ffffff;
  font: inherit;
}

.settings-form textarea:focus {
  border-color: rgba(42, 171, 238, 0.75);
  box-shadow: 0 0 0 3px rgba(42, 171, 238, 0.14);
}

.settings-fieldset {
  display: grid;
  gap: 14px;
  min-width: 0;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f8fbfe;
}

.settings-fieldset legend {
  padding: 0 6px;
  color: var(--text);
  font-weight: 800;
}

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

.channel-checkbox-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #ffffff;
}

.channel-checkbox-grid input {
  width: 18px;
  min-height: 18px;
}

.status-pill {
  padding: 7px 10px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  background: var(--panel-muted);
}

.status-pill.connected {
  color: #19713d;
  background: #e3f7ea;
}

.ai-knowledge-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.ai-knowledge-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f8fbfe;
}

.ai-knowledge-item p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.ai-knowledge-item button {
  align-self: start;
}

.panel {
  padding: 16px;
  box-shadow: none;
}

.wide-panel {
  max-width: 980px;
}

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

.status-pill,
.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  background: var(--panel-muted);
}

.status-pill.connected,
.status-badge.connected {
  color: #1f7a45;
  background: #e0f5e7;
}

.status-pill.error,
.status-badge.error {
  color: #ad3342;
  background: #ffe7ea;
}

.channel-list {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  margin-bottom: 16px;
  padding: 0 2px 6px;
  border-bottom: 1px solid var(--line);
  scrollbar-width: thin;
  scroll-snap-type: inline proximity;
}

.channel-option {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 8px;
  min-width: 142px;
  min-height: 50px;
  padding: 7px 10px;
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 8px 8px 0 0;
  color: var(--text);
  text-align: left;
  background: transparent;
  scroll-snap-align: start;
}

.channel-option.active {
  border-bottom-color: var(--blue);
  background: #eef8fe;
}

.channel-option:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: -2px;
}

.channel-status-check {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  margin-left: auto;
  border-radius: 50%;
  color: #ffffff;
  background: #aeb9c6;
  font-size: 13px;
  font-weight: 900;
}

.channel-option.connected .channel-status-check {
  background: var(--green);
}

.channel-option small,
.toggle-row small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.channel-mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: #ffffff;
  font-size: 12px;
  font-weight: 900;
}

.channel-settings-panel {
  min-width: 0;
}

.channel-mark.vk {
  background: var(--vk);
}

.channel-mark.max {
  background: var(--max);
}

.channel-mark.telegram {
  background: #229ed9;
}

.channel-mark.site {
  background: var(--web);
}

.public-url-field {
  display: grid;
  gap: 7px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.public-url-field input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  color: var(--text);
  background: #ffffff;
}

.setup-guide {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.setup-guide-header {
  display: grid;
  gap: 2px;
}

.setup-steps {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
  color: #3c4d62;
  font-size: 13px;
  line-height: 1.38;
}

.settings-form {
  display: grid;
  gap: 14px;
}

.proxy-form {
  max-width: 760px;
}

.proxy-panel {
  min-height: 100%;
}

.proxy-help {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.proxy-save-button {
  justify-self: start;
}

.settings-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.settings-form .checkbox-field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #f8fbfe;
}

.settings-form .checkbox-field input {
  width: 18px;
  min-height: 18px;
  margin: 0;
}

.proxy-channel-toggle:has(input:checked) {
  border-color: rgba(42, 171, 238, 0.65);
  background: #e9f7fe;
}

.settings-form label.hidden {
  display: none;
}

.settings-form input,
.settings-form select {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
  color: var(--text);
  background: #ffffff;
}

.settings-form input:focus,
.settings-form select:focus {
  border-color: rgba(42, 171, 238, 0.75);
  box-shadow: 0 0 0 3px rgba(42, 171, 238, 0.14);
}

.copy-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

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

.primary-button,
.secondary-button,
.ghost-button {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button {
  border: 0;
  color: #ffffff;
  background: var(--blue);
}

.primary-button:hover {
  background: var(--blue-dark);
}

.secondary-button {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel-muted);
  text-decoration: none;
}

.ghost-button {
  border: 1px solid var(--line);
  color: var(--blue-dark);
  background: #ffffff;
}

.connection-status-list,
.diagnostics-list,
.audit-list,
.users-table {
  display: grid;
  gap: 10px;
}

.connection-overview {
  display: grid;
  gap: 4px;
  margin-bottom: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #ffffff;
}

.connection-overview strong {
  font-size: 15px;
}

.connection-overview span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.connection-overview.ready {
  border-color: rgba(54, 188, 121, 0.45);
}

.connection-overview.error {
  border-color: rgba(212, 76, 92, 0.45);
}

.overview-action {
  justify-self: start;
  margin-top: 2px;
  border: 0;
  color: var(--blue-dark);
  background: transparent;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.overview-action:hover,
.overview-action:focus-visible {
  text-decoration: underline;
}

.progress-last-action {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.status-card,
.diagnostic-item,
.audit-item,
.user-row {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-muted);
}

.status-card {
  width: 100%;
  color: inherit;
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.status-card:hover,
.status-card.active {
  border-color: rgba(42, 161, 216, 0.45);
  background: #ffffff;
}

.status-card:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.diagnostics-block {
  display: grid;
  gap: 10px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.diagnostics-header {
  display: grid;
  gap: 2px;
}

.connection-progress {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.progress-row span {
  color: var(--muted);
  font-size: 12px;
}

.progress-track {
  overflow: hidden;
  height: 8px;
  border-radius: 999px;
  background: var(--panel-muted);
}

.progress-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
}

.progress-next-action {
  color: #3c4d62;
  font-size: 13px;
  line-height: 1.35;
}

.connection-progress.ready .progress-track span {
  background: var(--green);
}

.connection-progress.error .progress-track span {
  background: var(--red);
}

.diagnostic-item {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  background: #ffffff;
}

.diagnostic-dot {
  width: 10px;
  height: 10px;
  margin-top: 4px;
  border-radius: 50%;
  background: var(--muted);
}

.diagnostic-item.ready .diagnostic-dot {
  background: var(--green);
}

.diagnostic-item.warning .diagnostic-dot {
  background: var(--red);
}

.diagnostic-item.pending .diagnostic-dot {
  background: var(--web);
}

.diagnostic-item p {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.status-card-header,
.user-row {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.status-card-header {
  display: grid;
  gap: 10px;
}

.status-card p,
.audit-item p {
  color: var(--muted);
  font-size: 13px;
}

.split-form {
  grid-template-columns: repeat(2, minmax(220px, 1fr));
}

.user-create-form {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-muted);
}

.management-status {
  min-height: 20px;
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.user-row.inactive {
  opacity: 0.68;
}

.user-meta {
  color: var(--muted);
  font-size: 12px;
}

.user-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.user-actions select,
.user-actions button {
  min-height: 34px;
}

.danger-button {
  border: 1px solid rgba(212, 76, 92, 0.35);
  border-radius: 8px;
  color: var(--red);
  background: #ffffff;
  font-weight: 800;
}

.management-dialog {
  width: min(460px, calc(100vw - 32px));
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 24px 70px rgba(20, 38, 55, 0.24);
}

.management-dialog::backdrop {
  background: rgba(20, 38, 55, 0.45);
}

.dialog-description {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.form-action {
  justify-self: start;
}

.toggle-list {
  display: grid;
  gap: 10px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-muted);
}

.toggle-row input {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
}

.role-select {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

@media (max-width: 920px) {
  .admin-shell {
    grid-template-columns: 1fr;
  }

  .admin-sidebar {
    min-height: auto;
  }

  .section-nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .content-grid,
  .split-form,
  .user-create-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .admin-shell {
    padding: 10px;
  }

  .topbar,
  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .section-nav {
    grid-template-columns: 1fr 1fr;
  }

  .copy-row {
    grid-template-columns: 1fr;
  }

  .user-row {
    grid-template-columns: 1fr;
  }

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