:root {
  --app-bg: var(--tg-theme-bg-color, #f5f6f7);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --surface-soft: var(--tg-theme-section-bg-color, #f7f8fa);
  --surface-strong: #f1f3f6;
  --sidebar: #0f172a;
  --sidebar-active: rgba(255, 255, 255, 0.12);
  --text: var(--tg-theme-text-color, #2d2d2d);
  --muted: var(--tg-theme-hint-color, #6b6b6b);
  --subtle: #a7a7a7;
  --border: #e4e4e4;
  --primary: var(--tg-theme-button-color, #2d2d2d);
  --green: #039855;
  --green-bg: #ecfdf3;
  --amber: #e66b00;
  --amber-bg: #fff7e8;
  --red: #d92d20;
  --red-bg: #fff1f0;
  --blue: #175cd3;
  --blue-bg: #eff6ff;
  --radius-sm: 9px;
  --radius-md: 12px;
  --radius-lg: 14px;
  --sidebar-width: 240px;
}

* {
  box-sizing: border-box;
}

.hidden {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--app-bg);
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--app-bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
  text-decoration: none;
}

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

.app-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  display: flex;
  width: var(--sidebar-width);
  flex-direction: column;
  background: var(--sidebar);
  padding: 26px 10px 14px;
}

.app-brand {
  padding: 0 10px 26px;
}

.app-brand__name {
  color: #fff;
  font-size: 15px;
  font-weight: 700;
}

.app-brand__caption {
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.4);
  font-size: 12px;
}

.app-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.app-nav__link {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 10px;
  border-radius: 10px;
  padding: 10px;
  color: rgba(255, 255, 255, 0.42);
  font-weight: 500;
  transition: background-color 0.16s ease, color 0.16s ease;
}

.app-nav__link:hover {
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.78);
}

.app-nav__link.is-active {
  background: var(--sidebar-active);
  color: #fff;
  font-weight: 600;
}

.app-nav__icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.app-user {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: auto;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding: 16px 10px 2px;
  color: rgba(255, 255, 255, 0.62);
}

.app-user__avatar {
  display: grid;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.app-user__name {
  min-width: 0;
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-user__identity {
  min-width: 0;
  flex: 1;
}

.app-user__hint {
  margin-top: 1px;
  color: rgba(255, 255, 255, 0.35);
  font-size: 9px;
}

.account-switcher {
  position: relative;
  width: 100%;
}

.account-switcher__summary {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 9px;
  border-radius: 9px;
  cursor: pointer;
  list-style: none;
}

.account-switcher__summary::-webkit-details-marker {
  display: none;
}

.account-switcher__summary:hover {
  color: #fff;
}

.account-switcher__chevron {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  transition: transform 0.16s ease;
}

.account-switcher[open] .account-switcher__chevron {
  transform: rotate(180deg);
}

.account-switcher__menu {
  position: absolute;
  bottom: calc(100% + 12px);
  left: -2px;
  z-index: 120;
  width: 260px;
  max-height: min(380px, 70vh);
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: #fff;
  padding: 7px;
  color: var(--text);
  box-shadow: 0 16px 42px rgba(15, 23, 42, 0.2);
}

.account-switcher__title {
  padding: 7px 9px 8px;
  color: var(--subtle);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.account-switcher__menu form {
  margin: 0;
}

.account-option {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 9px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  padding: 9px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.account-option:hover {
  background: var(--surface-strong);
}

.account-option.is-current {
  background: var(--surface-soft);
  cursor: default;
}

.account-option__avatar {
  display: grid;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.account-option__copy {
  min-width: 0;
  flex: 1;
}

.account-option__copy strong,
.account-option__copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-option__copy strong {
  font-size: 11px;
  font-weight: 650;
}

.account-option__copy small {
  margin-top: 1px;
  color: var(--subtle);
  font-size: 9px;
}

.account-option__check {
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
}

.account-switcher__empty {
  padding: 12px 9px;
  color: var(--muted);
  font-size: 11px;
}

.app-main {
  min-height: 100vh;
  margin-left: var(--sidebar-width);
}

.app-content {
  width: 100%;
  max-width: 1500px;
  padding: 28px 32px 42px;
}

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

.page-header__title {
  margin: 0;
  color: var(--text);
  font-size: 24px;
  font-weight: 750;
  letter-spacing: -0.025em;
  line-height: 1.3;
}

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

.page-header__eyebrow {
  margin-bottom: 4px;
  color: var(--subtle);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.065em;
  text-transform: uppercase;
}

.page-header__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.btn {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

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

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

.btn-primary:hover {
  background: #171717;
}

.btn-secondary {
  border-color: var(--border);
  background: #fff;
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--surface-soft);
}

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

.btn-ghost:hover {
  background: var(--surface-strong);
  color: var(--text);
}

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

.btn-danger:hover {
  background: #ffe4e1;
}

.btn-sm {
  min-height: 30px;
  padding: 6px 10px;
  font-size: 12px;
}

.btn-icon {
  width: 18px;
  height: 18px;
}

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.panel + .panel {
  margin-top: 16px;
}

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

.panel__title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.panel__subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.panel__body {
  padding: 20px;
}

.panel__body--flush {
  padding: 0;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  min-height: 102px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: 18px 20px;
}

.stat-card__label {
  color: var(--subtle);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.055em;
  text-transform: uppercase;
}

.stat-card__value {
  margin-top: 8px;
  color: var(--text);
  font-size: 27px;
  font-weight: 750;
  letter-spacing: -0.03em;
}

.stat-card__value--green {
  color: var(--green);
}

.stat-card__value--red {
  color: var(--red);
}

.quick-stats {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.quick-stats__value {
  margin-top: 2px;
  font-size: 20px;
  font-weight: 750;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.65fr);
  gap: 16px;
}

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

.toolbar__group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.segmented__item,
.chip {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--surface-strong);
  padding: 7px 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.segmented__item:hover {
  color: var(--text);
}

.segmented__item.is-active {
  background: var(--primary);
  color: #fff;
}

.chip {
  min-height: 26px;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 11px;
}

.chip--green {
  background: var(--green-bg);
  color: var(--green);
}

.chip--amber {
  background: var(--amber-bg);
  color: var(--amber);
}

.chip--red {
  background: var(--red-bg);
  color: var(--red);
}

.chip--blue {
  background: var(--blue-bg);
  color: var(--blue);
}

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

.entity-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: #fff;
  padding: 15px 16px;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.entity-card:hover {
  border-color: #d2d2d2;
}

.entity-card__content {
  min-width: 0;
  flex: 1;
}

.entity-card__title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.entity-card__title {
  min-width: 0;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

.entity-card__title a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.entity-card__description {
  display: -webkit-box;
  overflow: hidden;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.entity-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 14px;
  margin-top: 10px;
  color: var(--subtle);
  font-size: 11px;
}

.entity-card__actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.meta-danger {
  color: var(--red) !important;
}

.status {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.025em;
  text-transform: uppercase;
}

.status--new {
  background: var(--surface-strong);
  color: var(--muted);
}

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

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

.empty-state {
  border: 1px dashed #d7d7d7;
  border-radius: var(--radius-md);
  background: var(--surface-soft);
  padding: 28px 18px;
  color: var(--muted);
  text-align: center;
}

.empty-state--compact {
  padding: 15px;
}

.project-card__mark {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--sidebar);
}

.project-card--compact {
  padding: 13px 14px;
}

.project-card--compact .entity-card__meta {
  margin-top: 6px;
}

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

.project-main,
.project-aside {
  min-width: 0;
}

.stage-list {
  display: grid;
  gap: 12px;
}

.stage-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  overflow: hidden;
}

.stage-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.stage-card__tasks {
  padding: 14px 16px 16px;
  background: var(--surface-soft);
}

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

.stage-number {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 7px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}

.section-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.045em;
  text-transform: uppercase;
}

.project-settings {
  display: grid;
  gap: 16px;
}

.project-settings .btn {
  justify-self: start;
}

.member-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}

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

.member-row__identity {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.member-row__avatar {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.member-row__name {
  overflow: hidden;
  font-size: 12px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.member-row__role {
  color: var(--subtle);
  font-size: 11px;
}

.member-row__copy {
  min-width: 0;
}

.member-row__actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 4px;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.6fr);
  align-items: start;
  gap: 16px;
}

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

.definition-item {
  border-radius: var(--radius-md);
  background: var(--surface-soft);
  padding: 14px;
}

.definition-item__label {
  color: var(--subtle);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.definition-item__value {
  margin-top: 5px;
  font-size: 13px;
  font-weight: 600;
}

.detail-description {
  color: var(--text);
  font-size: 14px;
  line-height: 1.7;
}

.detail-description--muted {
  color: var(--subtle);
}

.detail-definitions {
  margin-top: 20px;
}

.comment-list {
  padding: 4px 20px;
}

.comment {
  display: flex;
  gap: 11px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.comment:last-child {
  border-bottom: 0;
}

.comment__avatar {
  display: grid;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.comment__content {
  min-width: 0;
  flex: 1;
}

.comment__header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}

.comment__header time {
  color: var(--subtle);
  font-size: 10px;
}

.comment__text {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

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

.discussion-link {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding: 15px 18px;
}

.discussion-link:last-child {
  border-bottom: 0;
}

.discussion-link:hover {
  background: var(--surface-soft);
}

.discussion-link__title {
  margin: 0;
  font-weight: 650;
  font-size: 13px;
}

.discussion-link__avatar {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 11px;
  background: var(--surface-strong);
  color: var(--muted);
  font-weight: 750;
}

.discussion-link__content {
  min-width: 0;
  flex: 1;
}

.discussion-link__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.discussion-link__top time {
  flex: 0 0 auto;
  color: var(--subtle);
  font-size: 10px;
}

.discussion-link__preview {
  overflow: hidden;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.discussion-link__meta {
  margin-top: 5px;
  color: var(--subtle);
  font-size: 11px;
}

.discussion-list-panel {
  max-width: 960px;
}

.discussion-empty {
  margin: 20px;
}

.chat {
  display: flex;
  min-height: calc(100vh - 112px);
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: #fff;
}

.chat__header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.chat__back {
  display: grid;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 16px;
}

.chat__back:hover {
  background: var(--surface-soft);
}

.chat__messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding: 20px;
  background: var(--surface-soft);
}

.chat__composer {
  padding: 14px;
  border-top: 1px solid var(--border);
  background: #fff;
}

.chat__composer form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.chat__composer textarea {
  min-height: 42px;
  max-height: 120px;
}

.chat__empty {
  margin: auto;
  color: var(--subtle);
  text-align: center;
}

.message {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.message--mine {
  flex-direction: row-reverse;
}

.message__avatar {
  display: grid;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  background: #e2e5e9;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.message__body {
  max-width: min(72%, 540px);
}

.message__bubble {
  border: 1px solid var(--border);
  border-radius: 13px 13px 13px 4px;
  background: #fff;
  padding: 9px 11px;
  font-size: 13px;
}

.message--mine .message__bubble {
  border-color: var(--primary);
  border-radius: 13px 13px 4px;
  background: var(--primary);
  color: #fff;
}

.message__meta {
  margin-top: 3px;
  color: var(--subtle);
  font-size: 10px;
}

.message--mine .message__meta {
  text-align: right;
}

.form-card {
  max-width: 760px;
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: #fff;
  padding: 24px;
}

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

.form-grid__contents {
  display: contents;
}

.form-field {
  min-width: 0;
}

.form-field--full {
  grid-column: 1 / -1;
}

.form-label {
  display: block;
  margin-bottom: 6px;
  color: var(--subtle);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.055em;
  text-transform: uppercase;
}

.form-field input:not([type="checkbox"]),
.form-field select,
.form-field textarea,
.modal-panel input:not([type="checkbox"]),
.modal-panel select,
.modal-panel textarea,
.chat__composer textarea {
  width: 100%;
  border: 1px solid var(--border) !important;
  border-radius: 10px !important;
  outline: none;
  background: #fff !important;
  color: var(--text) !important;
  box-shadow: none !important;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-field input:not([type="checkbox"]),
.form-field select,
.modal-panel input:not([type="checkbox"]),
.modal-panel select {
  min-height: 44px;
  padding: 9px 12px !important;
}

.form-field textarea,
.modal-panel textarea,
.chat__composer textarea {
  padding: 10px 12px !important;
  resize: vertical;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus,
.modal-panel input:focus,
.modal-panel select:focus,
.modal-panel textarea:focus,
.chat__composer textarea:focus {
  border-color: #9e9e9e !important;
  box-shadow: 0 0 0 3px rgba(45, 45, 45, 0.07) !important;
}

.form-error {
  margin-top: 5px;
  color: var(--red);
  font-size: 11px;
}

.form-hint {
  margin-top: 5px;
  color: var(--subtle);
  font-size: 10px;
}

.checkbox-list {
  max-height: 250px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 12px;
}

.checkbox-list > div > div {
  border-bottom: 1px solid var(--border);
  padding: 9px 0;
}

.checkbox-list > div > div:last-child {
  border-bottom: 0;
}

.checkbox-list label {
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
}

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

.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.38);
  padding: 22px;
  backdrop-filter: blur(1px);
}

.modal-panel {
  width: min(720px, 100%);
  max-height: calc(100vh - 44px);
  overflow-y: auto;
  border-radius: 18px;
  background: #fff;
  padding: 26px 30px;
  box-shadow: 0 18px 55px rgba(15, 23, 42, 0.18);
}

.modal-panel--sm {
  width: min(520px, 100%);
}

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

.modal-title {
  margin: 0;
  font-size: 19px;
  font-weight: 750;
}

.modal-copy {
  margin: -10px 0 18px;
  color: var(--muted);
  font-size: 12px;
}

.modal-close {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--subtle);
  cursor: pointer;
  font-size: 22px;
}

.modal-close:hover {
  background: var(--surface-strong);
  color: var(--text);
}

.auth-layout {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 0%, rgba(15, 23, 42, 0.08), transparent 32%),
    var(--app-bg);
}

.auth-card {
  width: min(420px, 100%);
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #fff;
  padding: 32px;
}

.auth-logo {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 13px;
  background: var(--sidebar);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
}

.auth-title {
  margin: 22px 0 4px;
  font-size: 24px;
  font-weight: 750;
}

.auth-copy {
  margin: 0 0 22px;
  color: var(--muted);
}

.tg-theme-active .btn-primary {
  color: var(--tg-theme-button-text-color, #fff);
}

.tg-theme-active .btn-primary:hover {
  background: var(--primary);
  filter: brightness(0.94);
}

.telegram-auth-overlay {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--app-bg);
}

.telegram-auth-overlay__card {
  width: min(360px, 100%);
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  padding: 32px;
  text-align: center;
}

.telegram-auth-overlay__spinner {
  width: 32px;
  height: 32px;
  margin: 0 auto 16px;
  border: 3px solid var(--surface-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: telegram-auth-spin 0.75s linear infinite;
}

.telegram-auth-overlay__message,
.telegram-auth-overlay__error {
  margin: 0;
  color: var(--text);
}

.telegram-auth-overlay__error {
  color: var(--red);
}

@keyframes telegram-auth-spin {
  to { transform: rotate(360deg); }
}

.scroll-area {
  overflow: auto;
  scrollbar-color: #929292 transparent;
  scrollbar-width: thin;
}

.scroll-area::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.scroll-area::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #929292;
}

.scroll-area::-webkit-scrollbar-track {
  background: transparent;
}

.mobile-only {
  display: none;
}

@media (max-width: 1000px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-grid,
  .project-layout,
  .detail-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  body {
    font-size: 13px;
  }

  .app-sidebar {
    inset: auto 0 0;
    width: auto;
    height: calc(68px + env(safe-area-inset-bottom, 0px));
    flex-direction: row;
    align-items: stretch;
    overflow-x: auto;
    padding: 6px 10px calc(8px + env(safe-area-inset-bottom, 0px));
  }

  .app-brand {
    display: none;
  }

  .app-nav {
    min-width: 272px;
    flex: 1;
    flex-direction: row;
    justify-content: space-around;
    gap: 2px;
  }

  .app-nav__link {
    min-width: 68px;
    min-height: 54px;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    padding: 6px 8px;
    font-size: 9px;
  }

  .app-nav__icon {
    width: 19px;
    height: 19px;
  }

  .app-user {
    display: flex;
    width: 66px;
    flex: 0 0 66px;
    margin: 0;
    border: 0;
    padding: 0;
  }

  .account-switcher__summary {
    min-height: 54px;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    padding: 6px 5px;
    color: rgba(255, 255, 255, 0.42);
  }

  .account-switcher__summary .app-user__avatar {
    width: 19px;
    height: 19px;
    font-size: 8px;
  }

  .account-switcher__summary .app-user__name,
  .account-switcher__summary .account-switcher__chevron {
    display: none;
  }

  .account-switcher__summary .app-user__hint {
    margin: 0;
    color: inherit;
    font-size: 9px;
    font-weight: 500;
    white-space: nowrap;
  }

  .account-switcher[open] .account-switcher__summary {
    background: var(--sidebar-active);
    color: #fff;
  }

  .account-switcher__menu {
    right: 0;
    bottom: calc(100% + 8px);
    left: auto;
    width: min(280px, calc(100vw - 28px));
  }

  .app-main {
    margin-left: 0;
    padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px));
  }

  .app-content {
    padding: calc(18px + env(safe-area-inset-top, 0px)) 14px 30px;
  }

  .page-header {
    gap: 12px;
    margin-bottom: 20px;
  }

  .page-header__title {
    font-size: 21px;
  }

  .page-header__actions {
    align-items: stretch;
  }

  .page-header__actions .btn {
    min-width: 38px;
    padding-inline: 10px;
  }

  .stats-grid {
    display: flex;
    margin-right: -14px;
    overflow-x: auto;
    padding-right: 14px;
    scroll-snap-type: x mandatory;
  }

  .stat-card {
    min-width: 128px;
    min-height: 114px;
    flex: 0 0 128px;
    scroll-snap-align: start;
  }

  .stat-card__value {
    margin-top: 12px;
    font-size: 24px;
  }

  .panel__header,
  .toolbar {
    align-items: flex-start;
    padding: 14px;
  }

  .panel__body {
    padding: 14px;
  }

  .entity-card {
    flex-direction: column;
    gap: 12px;
    padding: 14px;
  }

  .entity-card__actions {
    width: 100%;
    justify-content: flex-start;
  }

  .entity-card__actions .btn {
    flex: 1;
  }

  .stage-card__header {
    flex-direction: column;
    padding: 14px;
  }

  .stage-card__tasks {
    padding: 12px;
  }

  .definition-list,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .discussion-grid {
    grid-template-columns: 1fr;
  }

  .chat {
    min-height: calc(100vh - 118px - env(safe-area-inset-top, 0px));
  }

  .chat__messages {
    padding: 14px;
  }

  .message__body {
    max-width: 84%;
  }

  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .modal-panel,
  .modal-panel--sm {
    width: 100%;
    max-height: calc(92vh - env(safe-area-inset-top, 0px));
    border-radius: 18px 18px 0 0;
    padding: 22px 18px calc(20px + env(safe-area-inset-bottom, 0px));
  }

  .form-actions {
    position: sticky;
    bottom: 0;
    padding-top: 12px;
    background: #fff;
  }

  .mobile-only {
    display: initial;
  }
}

@media (max-width: 420px) {
  .page-header {
    flex-direction: column;
  }

  .page-header__actions {
    width: 100%;
    justify-content: flex-start;
  }
}
