:root {
  color-scheme: light;
  --bg: #f3f6f8;
  --bar-bg: rgba(243, 246, 248, 0.94);
  --thread-bar-bg: rgba(243, 246, 248, 0.96);
  --nav-bg: rgba(255, 255, 255, 0.96);
  --control-bg: rgba(255, 255, 255, 0.72);
  --surface: #ffffff;
  --surface-soft: #eef4f7;
  --text: #111820;
  --muted: #6b7785;
  --line: #d8e1e8;
  --primary: #1677aa;
  --primary-soft: #e8f3f8;
  --primary-faint: rgba(22, 119, 170, 0.07);
  --primary-line: #b8d9e8;
  --avatar-a: #1677aa;
  --avatar-b: #2f9ac7;
  --performer: #7b4de8;
  --client: #0d8a72;
  --danger: #c8485b;
  --shadow: 0 -10px 24px rgba(22, 33, 43, 0.08);
  --tg-safe-top: 0px;
  --tg-chrome-top: 0px;
  --tg-chrome-bottom: 0px;
  --topbar-base-height: 60px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f141a;
  --bar-bg: rgba(15, 20, 26, 0.94);
  --thread-bar-bg: rgba(15, 20, 26, 0.96);
  --nav-bg: rgba(21, 27, 34, 0.96);
  --control-bg: rgba(27, 35, 44, 0.92);
  --surface: #151b22;
  --surface-soft: #1d2630;
  --text: #eef4f8;
  --muted: #9aa8b5;
  --line: #2a3541;
  --primary: #62b7e8;
  --primary-soft: #172b36;
  --primary-faint: rgba(98, 183, 232, 0.08);
  --primary-line: #315b70;
  --avatar-a: #2b8fc3;
  --avatar-b: #5269d9;
  --danger: #ed6b7e;
  --shadow: 0 -12px 26px rgba(0, 0, 0, 0.36);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

input {
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  outline: none;
}

.loading {
  min-height: 100vh;
  display: grid;
  place-items: center;
  color: var(--muted);
}

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

.has-bottom-nav {
  padding-bottom: 72px;
}

.performer-app {
  --primary: var(--performer);
  --primary-soft: #f0edff;
  --primary-faint: rgba(123, 77, 232, 0.07);
  --primary-line: #d7ccff;
  --avatar-a: #7b4de8;
  --avatar-b: #b65bd8;
}

[data-theme="dark"] .performer-app {
  --primary: #a78bfa;
  --primary-soft: #251f3e;
  --primary-faint: rgba(167, 139, 250, 0.08);
  --primary-line: #5e4a92;
  --avatar-a: #8b5cf6;
  --avatar-b: #cf5fd4;
}

.client-app {
  --primary: var(--client);
  --primary-soft: #e6f5f1;
  --primary-faint: rgba(13, 138, 114, 0.07);
  --primary-line: #b7ded6;
  --avatar-a: #0d8a72;
  --avatar-b: #33a9b0;
}

[data-theme="dark"] .client-app {
  --primary: #4fd1b5;
  --primary-soft: #17342f;
  --primary-faint: rgba(79, 209, 181, 0.08);
  --primary-line: #326b60;
  --avatar-a: #0d9488;
  --avatar-b: #38bdf8;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: calc(var(--topbar-base-height) + var(--tg-chrome-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bar-bg);
  backdrop-filter: blur(18px);
  padding: calc(9px + var(--tg-chrome-top)) 14px 9px;
}

.top-title {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.topbar em,
.topbar small,
.list-head span,
.row-side small,
.thread-head em,
.thread-head small,
.message-line span,
.metric-row em,
.notice,
.error {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.topbar strong {
  overflow: hidden;
  font-size: 18px;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar small {
  flex: 0 0 auto;
}

.icon {
  width: 20px;
  height: 20px;
  display: block;
}

.settings-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: var(--control-bg);
  color: var(--muted);
  padding: 0;
}

.settings-button.active,
.settings-button:hover {
  background: var(--primary-soft);
  color: var(--primary);
}

.content {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 0 14px;
}

.notice,
.error {
  margin: 10px 0;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.notice {
  color: #17613a;
}

.error {
  color: #922437;
}

.list-head {
  min-height: 62px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.list-head h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0;
}

.message-list {
  display: grid;
}

.message-row,
.plain-row,
.metric-row {
  width: 100%;
  min-height: 72px;
  display: grid;
  align-items: center;
  gap: 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  padding: 12px 0;
  text-align: left;
}

.message-row,
.plain-row.with-icon {
  grid-template-columns: 42px minmax(0, 1fr) auto;
}

.plain-row,
.metric-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.message-row:hover,
.message-row.unread,
.package-row:hover,
.text-action:hover {
  color: var(--primary);
}

.message-row.unread .row-main strong {
  font-weight: 850;
}

.avatar,
.row-icon {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: linear-gradient(145deg, var(--avatar-a), var(--avatar-b));
  color: #fff;
  font-size: 13px;
  font-weight: 900;
}

.row-icon {
  background: var(--primary-soft);
  color: var(--primary);
}

.row-icon .icon {
  width: 20px;
  height: 20px;
}

.row-main {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.row-main strong,
.row-main em,
.metric-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-main em {
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
  font-weight: 500;
}

.row-side {
  display: grid;
  justify-items: end;
  gap: 5px;
  flex: 0 0 auto;
}

.row-side b {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 12px;
}

.tab-view {
  padding-bottom: 12px;
}

.plain-list,
.metric-list {
  display: grid;
}

.metric-row {
  min-height: 62px;
  background: linear-gradient(90deg, var(--primary-faint), transparent 52%);
}

.metric-row strong {
  font-size: 19px;
}

.sub-head {
  min-height: 46px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.sub-head h2 {
  margin: 0;
  font-size: 15px;
}

.sub-head button,
.list-head button,
.text-action {
  min-height: 34px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--primary);
  padding: 0;
  font-weight: 800;
}

.theme-section {
  min-height: 72px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
}

.theme-section > span:first-child {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.theme-section em {
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
}

.theme-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(62px, 1fr));
  border: 1px solid var(--line);
  background: var(--control-bg);
}

.theme-toggle button {
  min-height: 36px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: 0 10px;
  font-size: 13px;
  font-weight: 850;
}

.theme-toggle button + button {
  border-left: 1px solid var(--line);
}

.theme-toggle button.active {
  background: var(--primary);
  color: #fff;
}

.package-row {
  cursor: pointer;
}

.thread-view {
  min-height: calc(100vh - var(--topbar-base-height) - var(--tg-chrome-top));
  display: flex;
  flex-direction: column;
}

.thread-head {
  position: sticky;
  top: calc(var(--topbar-base-height) + var(--tg-chrome-top));
  z-index: 5;
  min-height: 58px;
  display: grid;
  grid-template-columns: auto 42px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--thread-bar-bg);
  backdrop-filter: blur(18px);
}

.thread-head span {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.thread-head strong,
.thread-head em {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.back-button {
  min-height: 38px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--primary);
  padding: 0;
  font-weight: 800;
}

.thread-avatar {
  width: 38px;
  height: 38px;
}

.history {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 0;
}

.message-line {
  align-self: flex-start;
  max-width: min(560px, 88%);
  border-left: 2px solid var(--primary-line);
  padding: 2px 0 2px 10px;
}

.message-line.me {
  align-self: flex-end;
  border-right: 2px solid var(--primary);
  border-left: 0;
  padding: 2px 10px 2px 0;
  text-align: right;
}

.message-line p {
  margin: 2px 0 0;
  line-height: 1.36;
  overflow-wrap: anywhere;
}

.message-line.me p {
  color: var(--primary);
}

.composer {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  border-top: 1px solid var(--line);
  background: var(--bar-bg);
  backdrop-filter: blur(18px);
  padding: 9px 0 calc(9px + env(safe-area-inset-bottom) + var(--tg-chrome-bottom));
}

.composer input {
  min-height: 38px;
  padding: 0;
}

.composer button {
  min-height: 38px;
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  padding: 0 14px;
  font-weight: 800;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 20;
  width: min(760px, 100%);
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 0;
  transform: translateX(-50%);
  border-top: 1px solid var(--line);
  background: var(--nav-bg);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  padding: 6px 12px calc(7px + env(safe-area-inset-bottom) + var(--tg-chrome-bottom));
}

.bottom-nav button {
  min-width: 0;
  min-height: 52px;
  display: grid;
  place-items: center;
  gap: 3px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  position: relative;
  padding: 4px 4px 2px;
  font-size: 11px;
  font-weight: 800;
}

.bottom-nav button + button {
  border-left: 1px solid var(--line);
}

.bottom-nav .icon {
  width: 19px;
  height: 19px;
}

.bottom-nav button.active {
  color: var(--primary);
}

.bottom-nav button.active::before {
  content: "";
  position: absolute;
  top: -6px;
  left: 28%;
  right: 28%;
  height: 3px;
  border-radius: 999px;
  background: var(--primary);
}

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

  .topbar {
    padding-inline: 12px;
  }

  .message-row {
    min-height: 64px;
  }

  .thread-head {
    top: calc(55px + var(--tg-chrome-top));
    gap: 10px;
  }
}

.telegram-mini .topbar {
  padding-top: calc(10px + var(--tg-safe-top));
}

.telegram-mini .thread-head {
  top: calc(60px + var(--tg-safe-top));
}
