:root {
  color-scheme: dark;
  --bg: #101418;
  --panel: #171d23;
  --panel-soft: #202832;
  --text: #edf2f7;
  --muted: #9aa8b7;
  --line: #2b3541;
  --field: #11171d;
  --field-line: #3a4654;
  --accent: #20b8a6;
  --accent-dark: #65d8ca;
  --danger: #ff8a7a;
  --danger-bg: #3a1d1c;
  --success: #6ee7a8;
  --success-bg: #123225;
  --warning-bg: #352914;
  --warning: #f6c768;
  --button: #263240;
  --button-text: #e8eef5;
  --shadow: 0 14px 35px rgba(0, 0, 0, 0.34);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f9fafb;
  --text: #17202a;
  --muted: #697586;
  --line: #dde3ea;
  --field: #ffffff;
  --field-line: #cfd8e3;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --danger: #b42318;
  --danger-bg: #fff1f0;
  --success: #067647;
  --success-bg: #ecfdf3;
  --warning-bg: #fff7e6;
  --warning: #a15c07;
  --button: #e8eef5;
  --button-text: #243547;
  --shadow: 0 14px 35px rgba(23, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

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

button {
  border: 0;
}

body.login-body {
  overflow: auto;
}

.app-shell {
  min-height: 100vh;
}

.login-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.theme-toggle.login-theme {
  position: fixed;
  top: 18px;
  right: 18px;
}

.login-panel {
  width: min(430px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 28px;
}

.login-panel h1,
.section-title h1,
.section-title h2 {
  margin: 0;
  letter-spacing: 0;
}

.login-panel h1 {
  font-size: 28px;
  line-height: 1.15;
}

.login-panel p {
  margin: 8px 0 24px;
  color: var(--muted);
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 16px;
}

.field span {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--field-line);
  border-radius: 6px;
  background: var(--field);
  color: var(--text);
  padding: 9px 11px;
  outline: none;
}

.field textarea {
  min-height: 78px;
  resize: vertical;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 16px;
  color: var(--text);
  font-weight: 600;
}

.checkbox-field input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 20px;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
  font-size: 18px;
  font-weight: 750;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
}

.user-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 12px;
  margin-bottom: 18px;
}

.user-box strong {
  display: block;
  overflow-wrap: anywhere;
}

.user-box span {
  color: var(--muted);
  font-size: 13px;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-button {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 10px 12px;
  text-align: left;
}

.nav-button.active,
.nav-button:hover {
  background: var(--panel-soft);
  color: var(--accent-dark);
}

.content {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100vh;
  overflow: hidden;
  padding: 26px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex: 0 0 auto;
}

.section-title h1 {
  font-size: 26px;
  line-height: 1.2;
}

.section-title p {
  margin: 5px 0 0;
  color: var(--muted);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.btn {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 6px;
  background: var(--button);
  color: var(--button-text);
  cursor: pointer;
  font-weight: 650;
  padding: 9px 13px;
  text-decoration: none;
}

.btn:hover {
  filter: brightness(0.97);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.danger {
  background: var(--danger-bg);
  color: var(--danger);
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
}

.theme-toggle {
  min-width: 42px;
}

.theme-toggle::before {
  content: "☾";
}

:root[data-theme="light"] .theme-toggle::before {
  content: "☼";
}

.grid {
  display: grid;
  gap: 16px;
  min-height: 0;
}

.dashboard-grid {
  grid-template-columns: minmax(260px, 360px) minmax(0, 1fr);
  align-items: stretch;
  flex: 1 1 auto;
  overflow: hidden;
}

.panel {
  display: flex;
  min-height: 0;
  max-height: 100%;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 14px 16px;
  flex: 0 0 auto;
}

.panel-header h2 {
  margin: 0;
  font-size: 17px;
}

.panel-body {
  padding: 16px;
  min-height: 0;
  overflow: auto;
}

.search {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--field-line);
  border-radius: 6px;
  background: var(--field);
  color: var(--text);
  padding: 8px 10px;
}

.bot-list {
  display: grid;
  align-content: start;
  gap: 8px;
}

.bots-body {
  display: grid;
  align-content: start;
  gap: 12px;
}

.bot-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  padding: 12px;
  text-align: left;
}

.bot-item.active {
  border-color: var(--accent);
  background: var(--panel-soft);
}

.bot-item strong {
  display: block;
  overflow-wrap: anywhere;
}

.bot-item span,
.meta {
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: auto;
  overflow-y: auto;
}

.bots-panel .panel-body,
.users-panel .table-wrap {
  flex: 1 1 auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 12px;
  text-align: left;
  vertical-align: middle;
}

th {
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
  position: sticky;
  top: 0;
  z-index: 1;
}

td {
  font-size: 14px;
}

td code {
  display: inline-block;
  max-width: 260px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 750;
  line-height: 1;
  padding: 6px 9px;
}

.status.ok {
  background: var(--success-bg);
  color: var(--success);
}

.status.blocked {
  background: var(--danger-bg);
  color: var(--danger);
}

.status.warning {
  background: var(--warning-bg);
  color: var(--warning);
}

.empty,
.error {
  border: 1px dashed #cfd8e3;
  border-radius: 8px;
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.error {
  border-color: #f1a7a0;
  background: var(--danger-bg);
  color: var(--danger);
  text-align: left;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(16, 24, 40, 0.45);
  padding: 18px;
  z-index: 20;
}

.modal {
  width: min(460px, 100%);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.modal header {
  border-bottom: 1px solid var(--line);
  padding: 16px 18px;
}

.modal header h2 {
  margin: 0;
  font-size: 18px;
}

.modal form {
  padding: 18px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(460px, calc(100vw - 36px));
  border-radius: 8px;
  background: #17202a;
  color: #fff;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  z-index: 30;
}

.hidden {
  display: none !important;
}

@media (max-width: 860px) {
  body {
    overflow: auto;
  }

  .layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow: visible;
  }

  .content {
    height: auto;
    overflow: visible;
    padding: 18px;
  }

  .topbar,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-grid {
    overflow: visible;
  }

  .topbar {
    display: grid;
  }

  .toolbar {
    width: 100%;
  }

  .toolbar .btn {
    flex: 1 1 auto;
  }
}
