:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-alt: #eef2ff;
  --text: #172033;
  --muted: #5c6780;
  --line: #d9dfec;
  --accent: #245cff;
  --accent-hover: #1947d1;
  --accent-soft: rgba(36, 92, 255, 0.08);
  --radius-lg: 20px;
  --radius-md: 14px;
  --shadow: 0 18px 40px rgba(20, 35, 80, 0.08);
  --page-width: 1200px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(36, 92, 255, 0.12), transparent 28%),
    linear-gradient(180deg, #f8faff 0%, var(--bg) 100%);
  color: var(--text);
  font-family: "Segoe UI", "Inter", sans-serif;
}

body {
  padding: 32px 16px 48px;
}

body.app-body {
  min-height: 100vh;
  padding: 0;
  background: #f4f6fa;
}

.page-shell {
  width: min(100%, var(--page-width));
  margin: 0 auto;
}

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

.page-header-left {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.page-brand {
  color: var(--text);
  text-decoration: none;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

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

.page-nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 600;
}

.page-nav-link:hover {
  background: var(--accent-soft);
  border-color: rgba(36, 92, 255, 0.25);
}

.page-content {
  display: grid;
  gap: 16px;
}

.home-panel {
  display: grid;
  align-items: center;
  min-height: min(680px, calc(100vh - 140px));
  padding: 56px 0;
}

.home-panel-content {
  display: grid;
  gap: 18px;
  max-width: 680px;
}

.home-title {
  margin: 0;
  color: var(--text);
  font-size: clamp(3rem, 8vw, 6.5rem);
  line-height: 0.95;
  font-weight: 800;
}

.home-copy {
  max-width: 520px;
  margin: 0;
  color: var(--muted);
  font-size: 1.15rem;
  line-height: 1.55;
}

.app-frame {
  min-height: 100vh;
  height: 100vh;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  background: #f4f6fa;
}

.tool-sidebar {
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  border-right: 1px solid var(--line);
  background: #ffffff;
  padding: 18px 12px;
}

.tool-brand {
  display: flex;
  align-items: center;
  min-height: 42px;
  padding: 0 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 800;
}

.tool-nav {
  display: grid;
  gap: 10px;
}

.tool-group {
  position: relative;
  min-width: 0;
  display: grid;
  gap: 6px;
}

.tool-group-trigger {
  width: 100%;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
  list-style: none;
}

.tool-group-trigger span:not(.tool-icon) {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-group-trigger::-webkit-details-marker {
  display: none;
}

.tool-group-trigger::after {
  content: "v";
  flex: 0 0 auto;
  margin-left: auto;
  color: var(--muted);
  font-size: 0.82rem;
  transition: transform 0.18s ease;
}

.tool-group[open] .tool-group-trigger {
  border-color: rgba(36, 92, 255, 0.28);
  background: rgba(36, 92, 255, 0.06);
}

.tool-group[open] .tool-group-trigger::after {
  transform: rotate(180deg);
}

.tool-icon {
  flex: 0 0 24px;
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: var(--accent-soft);
  color: var(--accent-hover);
  font-size: 0.82rem;
  font-weight: 900;
}

.tool-group-menu {
  min-width: 0;
  display: grid;
  gap: 6px;
  padding-left: 8px;
  border-left: 2px solid rgba(36, 92, 255, 0.12);
  transform-origin: top;
  animation: tool-menu-in 0.18s ease both;
}

.tool-group:not([open]) .tool-group-menu {
  display: none;
}

@keyframes tool-menu-in {
  from {
    opacity: 0;
    transform: translateY(-4px) scaleY(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scaleY(1);
  }
}

.tool-link {
  min-width: 0;
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-decoration: none;
}

.tool-link strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-link:hover,
.tool-link.is-active {
  border-color: rgba(36, 92, 255, 0.36);
  background: var(--accent-soft);
}

.tool-link.is-disabled {
  color: var(--muted);
  cursor: default;
  opacity: 0.72;
}

.tool-kicker {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
}

.work-shell {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr);
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
  padding: 0 18px;
}

.top-bar-title {
  display: grid;
  gap: 2px;
}

.top-bar-title .eyebrow {
  margin: 0;
}

.top-bar-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.balance-pill {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  min-height: 40px;
  padding: 7px 11px;
  border: 1px solid rgba(37, 99, 235, 0.18);
  border-radius: 8px;
  background: rgba(37, 99, 235, 0.06);
  color: #0f172a;
  white-space: nowrap;
}

.balance-label {
  color: #64748b;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.balance-pill strong {
  font-size: 15px;
}

.profile-menu {
  position: relative;
}

.profile-trigger {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 58px;
  min-height: 40px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  list-style: none;
}

.profile-trigger::-webkit-details-marker {
  display: none;
}

.profile-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 800;
}

.profile-label {
  font-weight: 700;
}

.profile-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 10;
  width: 220px;
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.profile-dropdown a {
  color: var(--text);
  text-decoration: none;
  font-weight: 700;
}

.profile-dropdown a:hover {
  color: var(--accent-hover);
}

.profile-logout-form {
  margin: 0;
}

.profile-logout-button {
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.profile-logout-button:hover {
  color: var(--accent-hover);
}

.work-area {
  min-width: 0;
  min-height: 0;
  padding: 18px;
  overflow: hidden;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 24px;
}

.profile-page {
  height: 100%;
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 16px;
  overflow-y: auto;
  padding-right: 4px;
}

.profile-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.profile-identity {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.profile-avatar-large {
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 76px;
  height: 76px;
  border-radius: 18px;
  background: #0f766e;
  color: #fff;
  font-size: 1.45rem;
  font-weight: 900;
}

.profile-avatar-image {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
}

.profile-metrics {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.profile-metric {
  min-width: 0;
  display: grid;
  align-content: space-between;
  gap: 14px;
  min-height: 118px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.profile-metric span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.profile-metric strong {
  min-width: 0;
  color: var(--text);
  font-size: clamp(1.8rem, 4vw, 2.55rem);
  line-height: 1;
  overflow-wrap: anywhere;
}

.profile-metric-primary {
  border-color: rgba(15, 118, 110, 0.24);
  background: #ecfdf5;
}

.profile-metric-primary span,
.profile-metric-primary strong {
  color: #0f766e;
}

.profile-details {
  display: grid;
  gap: 18px;
}

.profile-detail-list {
  margin: 0;
  display: grid;
  border-top: 1px solid var(--line);
}

.profile-detail-row {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(140px, 0.35fr) minmax(0, 1fr);
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.profile-detail-row dt {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.profile-detail-row dd {
  min-width: 0;
  margin: 0;
  color: var(--text);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.profile-copy-value {
  position: relative;
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 8px;
  border: 1px solid rgba(36, 92, 255, 0.18);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-hover);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.profile-copy-value:hover,
.profile-copy-value.is-copied {
  border-color: rgba(36, 92, 255, 0.34);
  background: rgba(36, 92, 255, 0.14);
}

.profile-copy-value:disabled {
  cursor: default;
  opacity: 0.68;
}

.profile-copy-value::after {
  content: "Скопировано";
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(-50%);
  pointer-events: none;
  opacity: 0;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--text);
  color: var(--surface);
  font-size: 0.72rem;
  font-weight: 800;
  white-space: nowrap;
}

.profile-copy-value.is-copied::after {
  opacity: 1;
}

.profile-email-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.profile-email-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid rgba(36, 92, 255, 0.2);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-hover);
  text-decoration: none;
}

.profile-payments {
  display: grid;
  gap: 18px;
}

.profile-payment-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
}

.profile-payment-form {
  display: grid;
  gap: 8px;
}

.profile-email-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.profile-email-row input {
  min-width: 0;
  flex: 1;
}

.profile-payment-packages {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.profile-payment-package {
  min-width: 0;
  min-height: 92px;
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 16px;
  border: 1px solid rgba(36, 92, 255, 0.18);
  border-radius: var(--radius-md);
  background: #fff;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: 0.18s ease;
}

.profile-payment-package:hover {
  border-color: rgba(36, 92, 255, 0.36);
  background: var(--accent-soft);
}

.profile-payment-package:disabled {
  cursor: wait;
  opacity: 0.68;
}

.profile-payment-package strong,
.profile-payment-package span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.profile-payment-package strong {
  font-size: 1rem;
}

.profile-payment-package span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.page-title,
.section-title {
  margin: 0;
  line-height: 1.15;
}

.page-title {
  font-size: clamp(1.9rem, 3vw, 2.6rem);
}

.section-title {
  font-size: 1.35rem;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.muted {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.stack-gap-lg > * + * {
  margin-top: 20px;
}

.stack-gap-md > * + * {
  margin-top: 14px;
}

.stack-gap-sm > * + * {
  margin-top: 8px;
}

.field-label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
}

input,
textarea,
select {
  width: 100%;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fff;
  color: var(--text);
  font: inherit;
}

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid rgba(36, 92, 255, 0.16);
  border-color: var(--accent);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 999px;
  text-decoration: none;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: 0.18s ease;
}

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

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

.button-ghost {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

.button-ghost:hover {
  background: var(--accent-soft);
  border-color: rgba(36, 92, 255, 0.25);
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.note-block {
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--surface-alt);
  border: 1px solid rgba(36, 92, 255, 0.12);
}

.note-block summary {
  cursor: pointer;
  font-weight: 700;
}

.login-code-form {
  margin-top: 14px;
}

.app-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.app-sidebar {
  display: grid;
  gap: 10px;
}

.app-tab {
  display: grid;
  gap: 4px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  text-decoration: none;
}

.app-tab:hover,
.app-tab.is-active {
  border-color: rgba(36, 92, 255, 0.28);
  background: var(--accent-soft);
}

.app-tab-kicker {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.app-main {
  min-width: 0;
}

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

.chat-workspace {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 380px);
  gap: 14px;
  align-items: stretch;
}

.chat-surface {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(220px, 1fr) auto;
  gap: 14px;
  overflow: hidden;
}

.dialog-selector-panel {
  min-width: 0;
  min-height: 0;
  max-height: 100%;
}

.conversation-selector-mount {
  display: grid;
  gap: 10px;
}

.conversation-selector-card {
  display: grid;
  grid-template-rows: auto auto auto auto minmax(0, 1fr);
  gap: 10px;
  height: 100%;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
  box-shadow: none;
  padding: 16px;
}

.selector-header {
  display: grid;
  gap: 12px;
}

.selector-scope-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.selector-scope-tab {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
  text-decoration: none;
}

.selector-scope-tab:hover,
.selector-scope-tab.is-active {
  border-color: rgba(36, 92, 255, 0.28);
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.dialog-create-button-form {
  display: grid;
}

.dialog-create-button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-alt);
  color: var(--accent-hover);
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
}

.dialog-create-button:hover {
  border-color: rgba(36, 92, 255, 0.28);
  background: var(--accent-soft);
}

.dialogs-list {
  display: grid;
  align-content: start;
  gap: 6px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}

.dialog-list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.dialog-list-item.is-active {
  border-color: rgba(36, 92, 255, 0.28);
  background: #f8faff;
}

.dialog-select-button {
  display: grid;
  min-width: 0;
  padding: 4px 2px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.dialog-select-button:disabled {
  cursor: default;
}

.dialog-row-actions {
  display: flex;
  gap: 6px;
}

.dialog-icon-button {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 800;
  cursor: pointer;
}

.dialog-icon-button:hover {
  border-color: rgba(36, 92, 255, 0.28);
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.dialog-list-main,
.dialog-title,
.dialog-meta {
  min-width: 0;
}

.dialog-state-label {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.dialog-list-item.is-active .dialog-state-label {
  color: var(--accent-hover);
}

.dialog-title {
  overflow: hidden;
  color: var(--text);
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dialog-meta {
  color: var(--muted);
  font-size: 0.84rem;
}

.dialog-rename-form {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
}

.dialog-rename-input {
  min-height: 38px;
  padding: 9px 11px;
}

.dialog-delete-confirm {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid rgba(220, 38, 38, 0.18);
  border-radius: var(--radius-md);
  background: rgba(220, 38, 38, 0.06);
}

.dialog-delete-confirm p {
  margin: 0;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
}

.dialog-list-item .button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.88rem;
}

.chat-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.chat-header-controls {
  display: grid;
  justify-items: end;
  gap: 8px;
  min-width: min(260px, 42%);
}

.chat-model-label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.chat-model-select {
  min-height: 38px;
  padding: 8px 34px 8px 12px;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 700;
}

.chat-active-title {
  max-width: 220px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-messages {
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 10px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px;
  border: 1px dashed rgba(36, 92, 255, 0.3);
  border-radius: var(--radius-md);
  background: #f8faff;
}

.chat-empty-state {
  align-self: center;
  justify-self: center;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.chat-compose {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
}

.chat-compose-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.chat-compose textarea {
  min-height: 44px;
  max-height: min(180px, 30vh);
  padding: 10px 4px;
  border: 0;
  border-radius: 0;
  line-height: 1.45;
  overflow-y: hidden;
  resize: none;
}

.chat-compose textarea.is-scrollable {
  overflow-y: auto;
}

.chat-compose textarea:focus {
  outline: 0;
  border-color: transparent;
}

.chat-attach-button {
  width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--accent-hover);
  font-size: 1.4rem;
  font-weight: 800;
  cursor: pointer;
}

.chat-attach-button input {
  display: none;
}

.chat-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chat-attachment-chip {
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--text);
  font: inherit;
  font-size: 0.84rem;
  cursor: pointer;
}

.chat-status {
  padding: 10px 12px;
  font-size: 0.9rem;
}

.chat-placeholder {
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px dashed rgba(36, 92, 255, 0.3);
  border-radius: var(--radius-md);
  background: #f8faff;
}

.chat-bubble {
  max-width: 70%;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  line-height: 1.45;
  white-space: pre-wrap;
}

.chat-bubble-time {
  display: block;
  margin-bottom: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.1;
  opacity: 0.68;
}

.chat-bubble.is-pending {
  opacity: 0.68;
}

.chat-bubble.is-error {
  border-color: rgba(220, 38, 38, 0.25);
  background: rgba(220, 38, 38, 0.08);
  color: #991b1b;
}

.chat-bubble-label {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.chat-bubble-user {
  justify-self: end;
  background: var(--accent);
  color: #fff;
}

.chat-bubble-assistant {
  justify-self: start;
  background: var(--surface);
  border: 1px solid var(--line);
}

.chat-rich-text {
  display: grid;
  gap: 10px;
  white-space: normal;
}

.chat-rich-text :first-child {
  margin-top: 0;
}

.chat-rich-text :last-child {
  margin-bottom: 0;
}

.chat-rich-text p {
  margin: 0;
}

.chat-rich-text h1,
.chat-rich-text h2,
.chat-rich-text h3,
.chat-rich-text h4,
.chat-rich-text h5,
.chat-rich-text h6 {
  margin: 8px 0 0;
  color: var(--text);
  line-height: 1.25;
}

.chat-rich-text h1 {
  font-size: 1.28rem;
}

.chat-rich-text h2 {
  font-size: 1.18rem;
}

.chat-rich-text h3 {
  font-size: 1.08rem;
}

.chat-rich-text h4,
.chat-rich-text h5,
.chat-rich-text h6 {
  font-size: 1rem;
}

.chat-rich-text ul,
.chat-rich-text ol {
  margin: 0;
  padding-left: 22px;
}

.chat-rich-text li + li {
  margin-top: 4px;
}

.chat-rich-text strong {
  font-weight: 800;
}

.chat-rich-text a {
  color: var(--accent-hover);
  font-weight: 700;
}

.chat-rich-text code {
  padding: 2px 5px;
  border-radius: 6px;
  background: var(--surface-alt);
  color: var(--accent-hover);
  font-size: 0.92em;
}

.chat-rich-text pre {
  max-width: 100%;
  margin: 0;
  padding: 12px;
  overflow: auto;
  border-radius: 10px;
  background: #111827;
  color: #e5eefc;
  font-size: 0.9rem;
}

.chat-rich-text pre code {
  padding: 0;
  background: transparent;
  color: inherit;
}

.chat-rich-text hr {
  width: 100%;
  margin: 4px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.chat-rich-text blockquote {
  margin: 0;
  padding: 10px 12px;
  border-left: 3px solid rgba(36, 92, 255, 0.34);
  border-radius: 0 8px 8px 0;
  background: var(--surface-alt);
  color: var(--text);
}

.chat-rich-text details {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.chat-rich-text summary {
  cursor: pointer;
  font-weight: 800;
}

.chat-rich-text table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  border-spacing: 0;
  font-size: 0.92rem;
}

.chat-rich-text th,
.chat-rich-text td {
  padding: 8px 10px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.chat-rich-text th {
  background: var(--surface-alt);
  font-weight: 800;
}

.chat-bubble-image {
  display: block;
  max-width: min(320px, 100%);
  max-height: 260px;
  margin-top: 8px;
  border-radius: 10px;
  object-fit: contain;
}

code,
pre {
  font-family: "Cascadia Code", "Consolas", monospace;
}

code {
  color: var(--accent-hover);
}

pre {
  margin: 0;
  padding: 16px;
  overflow: auto;
  border-radius: var(--radius-md);
  background: #111827;
  color: #e5eefc;
  font-size: 0.92rem;
  line-height: 1.55;
}

@media (max-width: 820px) {
  body {
    padding: 18px 12px 28px;
  }

  body.app-body {
    padding: 0;
  }

  .app-frame {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
  }

  .tool-sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    overflow: visible;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
  }

  .tool-nav {
    display: flex;
    gap: 8px;
    min-width: 0;
    overflow: visible;
  }

  .tool-group {
    flex: 1 1 0;
    min-width: 0;
  }

  .tool-group-trigger {
    min-height: 40px;
    padding: 0 8px;
  }

  .tool-group-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 30;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow);
  }

  .tool-link {
    min-height: 38px;
  }

  .work-shell {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .top-bar {
    align-items: stretch;
    flex-direction: column;
    padding: 12px;
  }

  .profile-dropdown {
    left: 0;
    right: auto;
    width: min(100vw - 24px, 260px);
  }

  .work-area {
    padding: 12px;
    overflow: visible;
  }

  .page-header {
    align-items: stretch;
    flex-direction: column;
  }

  .page-header-left {
    align-items: stretch;
    flex-direction: column;
  }

  .card {
    padding: 18px;
  }

  .profile-page {
    height: auto;
    overflow: visible;
    padding-right: 0;
  }

  .profile-hero {
    align-items: flex-start;
    flex-direction: column;
  }

  .profile-avatar-large {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    font-size: 1.2rem;
  }

  .profile-metrics,
  .profile-detail-row,
  .profile-payment-packages {
    grid-template-columns: 1fr;
  }

  .profile-metric {
    min-height: 104px;
  }

  .profile-payment-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .profile-email-row {
    align-items: stretch;
    flex-direction: column;
  }

  .button {
    width: 100%;
  }

  .app-layout,
  .chat-workspace,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .chat-surface {
    min-height: auto;
  }

  .dialog-selector-panel,
  .conversation-selector-card {
    height: auto;
    max-height: none;
  }

  .dialogs-list {
    max-height: min(55vh, 520px);
  }

  .chat-compose {
    grid-template-columns: 1fr;
  }

  .chat-header,
  .chat-compose-row {
    grid-template-columns: 1fr;
  }

  .chat-header {
    display: grid;
  }

  .chat-header-controls {
    justify-items: stretch;
    min-width: 0;
  }

  .chat-active-title {
    max-width: none;
  }

  .dialog-rename-form,
  .dialog-delete-confirm {
    grid-template-columns: 1fr;
  }

  .dialog-delete-confirm .button {
    width: 100%;
  }

  .chat-bubble {
    max-width: 100%;
  }
}
