:root {
  color-scheme: dark;
  --bg: #07090d;
  --panel: #10141b;
  --panel-soft: #151b24;
  --line: #242c38;
  --text: #f5f7fb;
  --muted: #93a0b4;
  --accent: #00d4a6;
  --accent-strong: #48f2c2;
  --danger: #ff5c7a;
  --warning: #f6c45f;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(0, 212, 166, 0.12), transparent 34rem),
    linear-gradient(135deg, #07090d 0%, #0b1017 45%, #090b10 100%);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 17rem minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  height: 100vh;
  padding: 1.25rem;
  background: rgba(9, 12, 17, 0.86);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.brand,
.sidebar-footer,
.nav-item,
.topbar,
.topbar-actions,
.primary-button,
.secondary-button,
.icon-button,
.panel-header,
.search-box,
.table-row,
.form-footer,
.modal-header,
.modal-actions,
.toggle-row,
.steps {
  display: flex;
  align-items: center;
}

.brand {
  gap: 0.8rem;
}

.brand-mark {
  display: grid;
  width: 2.8rem;
  height: 2.8rem;
  place-items: center;
  border: 1px solid rgba(72, 242, 194, 0.42);
  border-radius: 0.5rem;
  background: linear-gradient(145deg, rgba(0, 212, 166, 0.24), rgba(245, 247, 251, 0.06));
  color: var(--accent-strong);
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.eyebrow,
.panel-header p,
.section-copy,
.metric span,
.save-state,
.review-box span,
.review-box p {
  color: var(--muted);
}

.nav-list {
  display: grid;
  gap: 0.45rem;
}

.nav-item {
  width: 100%;
  gap: 0.7rem;
  padding: 0.8rem;
  border: 1px solid transparent;
  border-radius: 0.5rem;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.nav-item.is-active,
.nav-item:hover {
  border-color: rgba(72, 242, 194, 0.28);
  background: rgba(0, 212, 166, 0.1);
  color: var(--text);
}

.sidebar-footer {
  gap: 0.5rem;
  margin-top: auto;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 0.9rem;
}

.status-dot {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 1rem rgba(0, 212, 166, 0.8);
}

.workspace {
  min-width: 0;
  padding: 2rem;
}

.topbar {
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.eyebrow {
  margin: 0 0 0.35rem;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 1;
}

h2 {
  margin-bottom: 0.45rem;
  font-size: 1.35rem;
}

h3 {
  margin-bottom: 0.5rem;
}

.topbar-actions {
  gap: 0.7rem;
}

.primary-button,
.secondary-button,
.icon-button {
  justify-content: center;
  gap: 0.45rem;
  min-height: 2.55rem;
  border-radius: 0.5rem;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.primary-button {
  padding: 0 1rem;
  border: 1px solid rgba(72, 242, 194, 0.55);
  background: linear-gradient(180deg, var(--accent-strong), var(--accent));
  color: #04110e;
  font-weight: 800;
}

.secondary-button {
  padding: 0 0.9rem;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.icon-button {
  width: 2.55rem;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.primary-button:hover,
.secondary-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.section {
  display: none;
}

.section.is-visible {
  display: block;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.metric,
.settings-card,
.bot-table,
.empty-state,
.review-box {
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: rgba(16, 20, 27, 0.82);
  box-shadow: var(--shadow);
}

.metric {
  padding: 1rem;
}

.metric span,
.metric strong {
  display: block;
}

.metric strong {
  margin-top: 0.35rem;
  font-size: 2rem;
}

.panel-header {
  justify-content: space-between;
  gap: 1rem;
  margin: 1.4rem 0 0.8rem;
}

.panel-header p {
  margin-bottom: 0;
}

.search-box {
  gap: 0.45rem;
  width: min(100%, 22rem);
  min-height: 2.6rem;
  padding: 0 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.04);
}

.search-box input,
label input,
label select {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

label select option {
  background: #111722;
  color: var(--text);
}

.bot-table {
  overflow: hidden;
}

.table-row {
  display: grid;
  grid-template-columns: 1.15fr 1.25fr 1.1fr 0.8fr 3rem;
  gap: 0.8rem;
  min-height: 4rem;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--line);
}

.table-row:last-child {
  border-bottom: 0;
}

.table-head {
  min-height: 2.8rem;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.bot-name {
  min-width: 0;
}

.bot-name strong,
.bot-name small,
.masked {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bot-name small,
.masked {
  color: var(--muted);
}

.pill {
  width: fit-content;
  padding: 0.35rem 0.55rem;
  border-radius: 999px;
  background: rgba(0, 212, 166, 0.12);
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 700;
}

.pill.is-off {
  background: rgba(255, 92, 122, 0.12);
  color: var(--danger);
}

.empty-state {
  display: none;
  margin-top: 1rem;
  padding: 2rem;
  text-align: center;
}

.empty-state.is-visible {
  display: block;
}

.empty-state svg {
  width: 3rem;
  height: 3rem;
  margin-bottom: 0.8rem;
  color: var(--accent);
}

.settings-layout {
  display: grid;
  grid-template-columns: minmax(15rem, 0.8fr) minmax(18rem, 1fr);
  gap: 1.2rem;
  align-items: start;
  max-width: 62rem;
}

.section-copy {
  line-height: 1.6;
}

.settings-card {
  display: grid;
  gap: 1rem;
  padding: 1.1rem;
}

label {
  display: grid;
  gap: 0.45rem;
}

label span {
  color: #cad3e3;
  font-size: 0.88rem;
  font-weight: 700;
}

label input,
label select {
  height: 2.9rem;
  padding: 0 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.04);
}

.form-footer {
  justify-content: space-between;
  gap: 1rem;
}

.modal {
  width: min(92vw, 34rem);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  background: transparent;
  color: var(--text);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.68);
  backdrop-filter: blur(8px);
}

.modal-content {
  display: grid;
  gap: 1rem;
  padding: 1.2rem;
  background: #0f141d;
}

.modal-header,
.modal-actions,
.panel-header {
  justify-content: space-between;
}

.steps {
  gap: 0.6rem;
}

.step {
  display: grid;
  width: 2rem;
  height: 2rem;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.step.is-active,
.step.is-done {
  border-color: rgba(72, 242, 194, 0.7);
  background: rgba(0, 212, 166, 0.14);
  color: var(--accent-strong);
}

.step-line {
  flex: 1;
  height: 1px;
  background: var(--line);
}

.step-screen {
  display: none;
  gap: 1rem;
}

.step-screen.is-visible {
  display: grid;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.toggle-row input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
}

.review-box {
  padding: 1rem;
}

.review-box strong {
  display: block;
  margin: 0.3rem 0;
}

.form-error {
  min-height: 1.2rem;
  margin-bottom: 0;
  color: var(--danger);
  font-weight: 700;
}

.is-hidden {
  display: none;
}

.topbar.is-compact-hidden {
  display: none;
}

svg {
  width: 1.1rem;
  height: 1.1rem;
  flex: 0 0 auto;
}

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

  .sidebar {
    position: static;
    height: auto;
    padding: 1rem;
  }

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

  .nav-item {
    justify-content: center;
  }

  .sidebar-footer {
    display: none;
  }

  .workspace {
    padding: 1rem;
  }

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

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

  .topbar-actions,
  .search-box {
    width: 100%;
  }

  .topbar-actions .primary-button {
    flex: 1;
  }

  .table-head {
    display: none;
  }

  .table-row {
    grid-template-columns: 1fr auto;
    gap: 0.55rem;
  }

  .table-row > span:nth-child(2),
  .table-row > span:nth-child(3),
  .table-row > span:nth-child(4) {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .brand {
    justify-content: center;
  }

  .nav-item span {
    display: none;
  }

  .nav-list {
    grid-template-columns: repeat(3, 1fr);
  }

  .modal-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
}

.dialogs-shell {
  display: grid;
  grid-template-columns: 22rem minmax(0, 1fr);
  height: calc(100vh - 4rem);
  min-height: 38rem;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: rgba(8, 12, 18, 0.86);
  box-shadow: var(--shadow);
}

.dialogs-list-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 0.8rem;
  min-width: 0;
  padding: 1rem;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
}

.dialog-search {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.7rem;
  padding: 0 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.04);
}

.dialog-search input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.dialog-tabs {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
}

.dialog-tabs button {
  min-height: 2.3rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-weight: 700;
}

.dialog-tabs button.is-active {
  border-color: rgba(72, 242, 194, 0.5);
  color: var(--text);
}

.dialogs-list {
  display: grid;
  align-content: start;
  gap: 0.45rem;
  min-height: 0;
  overflow: auto;
}

.dialog-user {
  display: grid;
  grid-template-columns: 2.4rem minmax(0, 1fr);
  gap: 0.7rem;
  width: 100%;
  min-height: 4.8rem;
  padding: 0.72rem;
  border: 1px solid transparent;
  border-radius: 0.5rem;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.dialog-user.is-active,
.dialog-user:hover {
  border-color: rgba(72, 242, 194, 0.32);
  background: rgba(0, 212, 166, 0.09);
}

.dialog-avatar {
  display: grid;
  width: 2.4rem;
  height: 2.4rem;
  place-items: center;
  border-radius: 50%;
  background: rgba(72, 242, 194, 0.16);
  color: var(--accent-strong);
  font-weight: 800;
  text-transform: uppercase;
  overflow: hidden;
}

.dialog-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dialog-user strong,
.dialog-user small,
.dialog-user span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dialog-user small,
.dialog-user span {
  color: var(--muted);
  font-size: 0.82rem;
}

.dialog-chat-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 17rem;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  background: #0b1017;
}

.dialog-chat-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 1rem;
  min-height: 4.25rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--line);
  background: rgba(10, 14, 20, 0.88);
}

.dialog-chat-header .secondary-button {
  margin-left: auto;
}

.dialog-profile-avatar {
  display: grid;
  width: 2.45rem;
  height: 2.45rem;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  border-radius: 50%;
  background: rgba(72, 242, 194, 0.16);
  border: 1px solid rgba(72, 242, 194, 0.34);
  box-shadow: 0 0 0 3px rgba(72, 242, 194, 0.08);
  color: var(--accent-strong);
  font-weight: 800;
  text-transform: uppercase;
}

.dialog-profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dialog-chat-header p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.dialog-chat-header h2 {
  margin-bottom: 0.18rem;
  font-size: 1.18rem;
  line-height: 1.05;
}

#dialogSubtitle {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

#dialogSubtitle code {
  padding: 0.12rem 0.38rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 0.76rem;
}

.dialog-messages {
  grid-column: 1;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  gap: 0.38rem;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  padding: 0.8rem 1rem;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.dialog-placeholder {
  margin: auto;
  color: var(--muted);
}

.message-bubble {
  position: relative;
  width: fit-content;
  max-width: min(34rem, 66%);
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 0.42rem;
  background: transparent;
  box-shadow: none;
  white-space: pre-wrap;
}

.message-bubble.is-out {
  align-self: flex-end;
  background: transparent;
}

.message-bubble:not(.is-out) {
  align-self: flex-start;
}

.message-text {
  display: inline-block;
  width: auto;
  max-width: 100%;
  padding: 0.28rem 0.46rem;
  border-radius: 0.36rem;
  background: #171d26;
  font-size: 0.88rem;
  line-height: 1.22;
  overflow-wrap: anywhere;
}

.message-bubble.is-out .message-text {
  background: #082d29;
}

.message-text:empty::before {
  content: "пустое сообщение";
  color: var(--muted);
  font-style: italic;
}

.message-bubble small {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.18rem;
  padding: 0 0.12rem 0.18rem;
  color: var(--muted);
  font-size: 0.68rem;
}

.message-kind {
  padding: 0.12rem 0.34rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--accent-strong);
  font-weight: 800;
}

.dialog-reply {
  grid-column: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.8rem;
  padding: 1rem;
  border-top: 1px solid var(--line);
  background: rgba(10, 14, 20, 0.9);
}

.dialog-user-panel {
  grid-column: 2;
  grid-row: 2 / 4;
  min-height: 0;
  overflow-y: auto;
  padding: 1rem;
  border-left: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.018);
}

.dialog-user-card {
  display: grid;
  justify-items: center;
  gap: 0.7rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: rgba(16, 20, 27, 0.8);
}

.dialog-user-card-avatar {
  display: grid;
  width: 5rem;
  height: 5rem;
  place-items: center;
  overflow: hidden;
  border-radius: 50%;
  border: 1px solid rgba(72, 242, 194, 0.38);
  background: rgba(72, 242, 194, 0.14);
  color: var(--accent-strong);
  font-size: 1.5rem;
  font-weight: 800;
}

.dialog-user-card-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.dialog-user-card > strong {
  font-size: 1.05rem;
}

.dialog-user-card > span,
.delete-state {
  color: var(--muted);
  font-size: 0.86rem;
}

.dialog-user-card dl {
  display: grid;
  gap: 0.55rem;
  width: 100%;
  margin: 0.4rem 0;
}

.dialog-user-card dl div {
  display: grid;
  gap: 0.15rem;
  padding: 0.55rem;
  border-radius: 0.45rem;
  background: rgba(255, 255, 255, 0.04);
}

.dialog-user-card dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.dialog-user-card dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.danger-button {
  width: 100%;
  min-height: 2.5rem;
  border: 1px solid rgba(255, 92, 122, 0.5);
  border-radius: 0.5rem;
  background: rgba(255, 92, 122, 0.13);
  color: #ff8da0;
  font-weight: 800;
}

.download-dialog-button {
  width: 100%;
  min-height: 2.5rem;
  border: 1px solid rgba(72, 242, 194, 0.5);
  border-radius: 0.5rem;
  background: rgba(0, 212, 166, 0.13);
  color: var(--accent-strong);
  font-weight: 800;
}

.toast {
  position: fixed;
  right: 1.2rem;
  bottom: 1.2rem;
  z-index: 50;
  max-width: min(28rem, calc(100vw - 2.4rem));
  padding: 0.85rem 1rem;
  border: 1px solid rgba(72, 242, 194, 0.45);
  border-radius: 0.5rem;
  background: rgba(4, 17, 14, 0.94);
  color: var(--accent-strong);
  font-weight: 800;
  opacity: 0;
  transform: translateY(0.5rem);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.dialog-reply textarea {
  min-height: 3rem;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.dialog-reply.is-disabled {
  opacity: 0.55;
  pointer-events: none;
}

@media (max-width: 980px) {
  .dialogs-shell {
    grid-template-columns: minmax(15rem, 18rem) minmax(43rem, 1fr);
    overflow-x: auto;
  }

  .dialogs-list-panel {
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }
}
