:root {
  --tg-bg-color: #17212b;
  --tg-secondary-bg-color: #1f2c39;
  --tg-tertiary-bg-color: #22303d;
  --tg-surface-color: #182533;
  --tg-surface-elevated: #1c2b3a;
  --tg-text-color: #e6edf3;
  --tg-hint-color: #7f91a4;
  --tg-link-color: #64a8e8;
  --tg-button-color: #4ea4f6;
  --tg-button-text-color: #ffffff;
  --tg-border-color: rgba(255, 255, 255, 0.06);
  --tg-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
  --tg-user-bubble: #2b5278;
  --tg-peer-bubble: #223242;
  --tg-chat-fill: rgba(255, 255, 255, 0.02);
  --tg-success: #55a6f7;
  --tg-danger: #d96c7b;
  --app-height: 100vh;
  --keyboard-gap: 0px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

@supports (padding-top: constant(safe-area-inset-top)) {
  :root {
    --safe-top: constant(safe-area-inset-top);
    --safe-bottom: constant(safe-area-inset-bottom);
    --safe-left: constant(safe-area-inset-left);
    --safe-right: constant(safe-area-inset-right);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  color: var(--tg-text-color);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 13px;
  background: var(--tg-bg-color);
  overscroll-behavior: none;
  touch-action: manipulation;
}

html {
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }
input, textarea, select, button { font: inherit; color: inherit; }

input, textarea, select {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 999px;
  background: #243447;
  color: var(--tg-text-color);
  padding: 10px 14px;
  transition: background 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

textarea {
  resize: none;
  border-radius: 18px;
}

input::placeholder,
textarea::placeholder {
  color: var(--tg-hint-color);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: rgba(100, 168, 232, 0.42);
  box-shadow: 0 0 0 1px rgba(100, 168, 232, 0.32);
}

button {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 10px 16px;
  background: var(--tg-button-color);
  color: var(--tg-button-text-color);
  cursor: pointer;
  transition: filter 160ms ease, transform 120ms ease, background 160ms ease;
  box-shadow: none;
}

button:hover { filter: brightness(1.04); }
button:active { transform: translateY(1px); }

.card {
  background: linear-gradient(180deg, #1c2a38, #182533);
  border: 1px solid var(--tg-border-color);
  border-radius: 22px;
  box-shadow: var(--tg-shadow);
}

.card-soft {
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--tg-border-color);
  border-radius: 16px;
}

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

.login-card {
  width: min(400px, 100%);
  padding: 20px;
  border-radius: 22px;
  border: 1px solid var(--tg-border-color);
  background: linear-gradient(180deg, #1f2d3a, #192733);
  box-shadow: var(--tg-shadow);
}

.login-card h1 {
  margin: 0;
  font-size: 18px;
}

.login-card p {
  margin: 4px 0 14px;
  color: var(--tg-hint-color);
}

.login-card form {
  display: grid;
  gap: 8px;
}

.app-shell {
  min-height: var(--app-height);
  padding: calc(var(--safe-top) + 12px) calc(var(--safe-right) + 12px) calc(var(--safe-bottom) + 12px) calc(var(--safe-left) + 12px);
  display: grid;
  gap: 10px;
  grid-template-rows: auto 1fr;
}

.app-shell.route-loading {
  visibility: hidden;
}

.topbar {
  min-height: 58px;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  background: linear-gradient(180deg, #253546, #213140);
}

.topbar-copy {
  min-width: 0;
}

.topbar h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.topbar p {
  margin: 2px 0 0;
  color: var(--tg-hint-color);
  font-size: 12px;
}

.topbar-refresh-btn {
  justify-self: end;
}

.topbar-refresh-btn.is-loading {
  animation: refresh-spin 0.8s linear infinite;
}

@keyframes refresh-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.icon-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--tg-border-color);
  color: var(--tg-text-color);
}

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

.pill {
  min-width: 88px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--tg-border-color);
}

.pill span {
  display: block;
  color: var(--tg-hint-color);
  font-size: 11px;
}

.pill b {
  font-size: 15px;
  font-weight: 700;
}

.board {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

.board.board-single {
  grid-template-columns: minmax(0, 1fr);
}

.lane {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto 1fr;
  padding: 10px;
  background: linear-gradient(180deg, #14202c, #13202b);
  align-content: start;
}

.lane h3 {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 700;
}

.lane.drag-over {
  border-color: rgba(100, 168, 232, 0.35);
}

.folders-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--tg-border-color);
}

.folder-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 0 10px;
  border: none;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--tg-hint-color);
  font-size: 15px;
  font-weight: 700;
}

.folder-tab span {
  min-width: 28px;
  height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  background: rgba(100, 168, 232, 0.9);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.folder-tab.active {
  color: var(--tg-text-color);
  border-bottom-color: var(--tg-link-color);
}

.folder-tab.active span {
  background: var(--tg-link-color);
}

.folder-tab:hover {
  filter: none;
  color: var(--tg-text-color);
}

.conversation-list {
  overflow: auto;
  min-height: 140px;
  display: grid;
  gap: 2px;
  align-content: start;
  grid-auto-rows: max-content;
}

.conversation-item {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  width: 100%;
  padding: 10px 10px;
  border-radius: 16px;
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}

.conversation-item:hover {
  background: rgba(255, 255, 255, 0.03);
}

.conversation-item.active {
  background: rgba(100, 168, 232, 0.14);
  border-color: rgba(100, 168, 232, 0.12);
}

.conversation-item.new {
  background: rgba(47, 79, 110, 0.28);
}

.conv-avatar,
.conv-avatar-img,
.conv-avatar-fallback {
  width: 52px;
  height: 52px;
  border-radius: 50%;
}

.conv-avatar {
  overflow: hidden;
  background: #35506c;
  border: 1px solid rgba(255, 255, 255, 0.05);
  display: grid;
  place-items: center;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
}

.conv-avatar img,
.conv-avatar-img {
  object-fit: cover;
  display: block;
  width: 100%;
  height: 100%;
}

.conv-avatar-fallback {
  display: grid;
  place-items: center;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, #ef7f5a, #e2644d);
}

.conv-main {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.conv-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
}

.conv-name {
  min-width: 0;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-assignee,
.conv-preview,
.conv-rating {
  min-width: 0;
  color: var(--tg-hint-color);
  font-size: 12px;
  line-height: 1.35;
}

.conv-preview {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-preview.new-text {
  color: #7fc3ff;
  font-weight: 600;
}

.conv-rating {
  color: #f3d27c;
}

.conv-tag {
  align-self: start;
  min-width: 28px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #4b84b8;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.history-page {
  width: 100%;
  min-height: 0;
  padding: 12px;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 10px;
  background: linear-gradient(180deg, #14202c, #13202b);
  border: 1px solid var(--tg-border-color);
  border-radius: 22px;
  box-shadow: var(--tg-shadow);
}

#users-view.history-page {
  grid-template-rows: auto auto auto auto 1fr;
  align-content: start;
}

#broadcast-view.history-page {
  grid-template-rows: auto 1fr;
  align-content: start;
}

#quick-replies-view.history-page {
  grid-template-rows: auto 1fr;
  align-content: start;
}

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

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

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
  padding: 4px 2px 0;
}

.history-head strong {
  font-size: 16px;
  font-weight: 700;
}

.history-results {
  overflow: auto;
  display: grid;
  gap: 6px;
  align-content: start;
}

.history-search {
  margin-bottom: 4px;
}

.board-empty {
  padding: 18px 10px;
}

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.44);
  z-index: 60;
}

.drawer {
  position: fixed;
  left: calc(var(--safe-left) + 12px);
  top: calc(var(--safe-top) + 12px);
  bottom: calc(var(--safe-bottom) + 12px);
  width: min(360px, calc(100vw - 24px));
  z-index: 70;
  padding: 0;
  overflow: auto;
  background: linear-gradient(180deg, #1f2d3a, #182633);
  transform: translateX(-110%);
  transition: transform 220ms ease;
}

.drawer.open { transform: translateX(0); }

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.drawer-title {
  font-size: 16px;
  font-weight: 700;
}

.profile {
  padding: 16px;
  margin: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.drawer-profile {
  border-radius: 0;
}

.notify-box {
  margin-top: 12px;
  padding: 12px;
  display: grid;
  gap: 8px;
  background: rgba(255, 255, 255, 0.03);
}

.notify-btn {
  min-height: 38px;
}

.notify-help {
  line-height: 1.35;
}

.profile-top {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, #60a9ef, #3d8dd8);
}

.name {
  font-size: 14px;
  font-weight: 700;
}

.hint {
  font-size: 12px;
  color: var(--tg-hint-color);
}

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 10px 0 8px;
}

.drawer-menu {
  display: grid;
  padding: 10px 8px;
  gap: 2px;
}

.drawer-item {
  width: 100%;
  min-height: 48px;
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--tg-text-color);
  text-align: left;
  box-shadow: none;
}

.drawer-item:hover {
  filter: none;
  background: rgba(255,255,255,0.04);
}

.drawer-item-icon {
  font-size: 18px;
  line-height: 1;
  opacity: 0.9;
}

.drawer-item-danger {
  color: #f0b7bf;
}

.drawer-item-danger .drawer-item-icon {
  color: #f0b7bf;
}

.ios-switch {
  position: relative;
  width: 48px;
  height: 28px;
  display: inline-block;
}

.ios-switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.ios-slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  transition: background 180ms ease;
}

.ios-slider::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: #fff;
  transition: transform 180ms ease;
}

.ios-switch input:checked + .ios-slider {
  background: #34c759;
}

.ios-switch input:checked + .ios-slider::before {
  transform: translateX(20px);
}

.ghost-btn {
  width: 100%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--tg-border-color);
  color: var(--tg-text-color);
}

.danger-btn {
  background: rgba(217, 108, 123, 0.12);
  border-color: rgba(217, 108, 123, 0.32);
  color: #f6c2cb;
}

.success-btn {
  background: rgba(46, 160, 103, 0.16);
  border-color: rgba(77, 201, 128, 0.34);
  color: #8df0ad;
}

#admin-section h4 {
  margin: 0 0 8px;
  font-size: 16px;
}

#metrics,
#staff-list {
  display: grid;
  gap: 6px;
}

#admin-section {
  margin: 8px 12px 12px;
  padding: 12px;
  border-radius: 16px;
  background: rgba(255,255,255,0.025);
  border: 1px solid rgba(255,255,255,0.04);
}

.admin-create-form {
  padding: 8px;
  display: grid;
  gap: 6px;
  margin-bottom: 8px;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  align-items: center;
}

.users-toolbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-bottom: 2px;
}

.broadcast-card {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 4px 0 0;
  display: grid;
  gap: 16px;
  align-content: start;
}

.quick-replies-card {
  gap: 14px;
}

.quick-reply-form {
  display: grid;
  gap: 12px;
}

.quick-reply-form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.quick-reply-fields {
  display: grid;
  gap: 10px;
}

.quick-reply-fields input,
.quick-reply-fields textarea {
  background: #223247;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 18px;
  padding: 14px 16px;
}

.quick-reply-fields textarea {
  min-height: 132px;
  resize: vertical;
}

.quick-replies-list {
  display: grid;
  gap: 8px;
}

.quick-reply-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  background: rgba(255, 255, 255, 0.03);
}

.quick-reply-copy {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.quick-reply-key {
  font-size: 14px;
  font-weight: 700;
  color: #8cc9ff;
}

.quick-reply-preview {
  color: var(--tg-text-color);
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.quick-reply-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.quick-reply-action-btn {
  width: auto;
  min-width: 112px;
  min-height: 38px;
  padding-inline: 14px;
}

.broadcast-copy {
  display: grid;
  gap: 6px;
}

.broadcast-copy strong {
  font-size: 16px;
}

#notice-current {
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  line-height: 1.4;
}

.broadcast-form {
  display: grid;
  gap: 12px;
  padding: 16px 0 0;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.notice-actions {
  justify-content: space-between;
}

.notice-delete-btn {
  width: auto;
  min-width: 120px;
}

.broadcast-form textarea {
  min-height: 180px;
  background: #223247;
  border: 1px solid rgba(255, 255, 255, 0.06);
  resize: vertical;
  padding: 14px 16px;
  border-radius: 18px;
  line-height: 1.45;
}

.broadcast-actions {
  display: flex;
  justify-content: flex-end;
}

.broadcast-submit-btn {
  width: auto;
  min-width: 160px;
  min-height: 44px;
  padding-inline: 22px;
  background: linear-gradient(180deg, #5ca9f3, #4792df);
}

#broadcast-result {
  margin-top: 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.users-create-btn {
  width: auto;
  min-height: 38px;
  padding-inline: 18px;
  background: linear-gradient(180deg, #29425a, #22384c);
  border-color: rgba(115, 167, 216, 0.18);
}

.staff-editor {
  padding: 12px;
  display: grid;
  gap: 10px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(39, 58, 78, 0.82), rgba(24, 37, 51, 0.92));
  border-color: rgba(113, 150, 187, 0.14);
}

.staff-editor-head,
.staff-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.staff-summary-btn {
  width: 100%;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
  color: inherit;
  text-align: left;
}

.staff-summary-btn:hover {
  filter: none;
}

.staff-summary-main {
  min-width: 0;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.staff-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, #5fa9ef, #3c88cf);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.staff-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.staff-copy-top {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.staff-copy-top strong {
  min-width: 0;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.staff-copy-sub,
.staff-copy-meta {
  min-width: 0;
  color: var(--tg-hint-color);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.staff-copy-meta {
  display: flex;
  align-items: center;
  gap: 6px;
}

.staff-expand-icon {
  flex: 0 0 auto;
  color: var(--tg-hint-color);
  font-size: 14px;
}

.staff-editor-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.staff-settings-btn {
  width: 34px;
  height: 34px;
}

.admin-create-form input,
.admin-create-form select,
.staff-editor input,
.staff-editor select {
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 12px;
  font-size: 12px;
}

.admin-create-form button,
.staff-editor button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 600;
}

.staff-card,
.metric-card,
.profile-stat,
.profile-line {
  border-radius: 14px;
  border: 1px solid var(--tg-border-color);
  background: rgba(255, 255, 255, 0.03);
  padding: 8px;
}

.admin-stat-card {
  min-height: 88px;
  padding: 14px;
  background: linear-gradient(180deg, rgba(35, 53, 72, 0.94), rgba(27, 42, 56, 0.94));
  border-color: rgba(113, 150, 187, 0.14);
}

.admin-stat-value {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.05;
  color: #f4f8fc;
}

.admin-stat-label {
  margin-top: 6px;
  color: var(--tg-hint-color);
  font-size: 12px;
  line-height: 1.25;
}

.presence-badge {
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 11px;
  color: #dfefff;
  background: rgba(100, 168, 232, 0.18);
  border: 1px solid rgba(100, 168, 232, 0.14);
}

.presence-badge.online {
  color: #c7ffd8;
  background: rgba(52, 199, 89, 0.14);
  border-color: rgba(52, 199, 89, 0.2);
}

.presence-badge.offline {
  color: #dce7f3;
  background: rgba(128, 145, 164, 0.16);
  border-color: rgba(128, 145, 164, 0.16);
}

.modal-shell {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.48);
}

.modal-card {
  position: relative;
  width: min(560px, 100%);
  padding: 14px;
  z-index: 1;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.modal-form {
  grid-template-columns: 1fr;
  margin-bottom: 0;
}

.staff-metrics {
  padding-top: 2px;
}

.staff-metrics .metric-card {
  min-height: 72px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.028);
}

.staff-metrics .metric-card strong {
  display: block;
  font-size: 16px;
  margin-bottom: 4px;
}

.chat-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.42);
  display: grid;
  place-items: center;
  padding: calc(var(--safe-top) + 18px) calc(var(--safe-right) + 18px) calc(var(--safe-bottom) + 18px) calc(var(--safe-left) + 18px);
}

.chat-window {
  width: min(980px, 100%);
  height: min(94vh, 920px);
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  background: #101923;
  border-radius: 26px;
}

.chat-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 70px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--tg-border-color);
  background: linear-gradient(180deg, #223242, #1d2b38);
}

#mark-resolved {
  width: auto;
  min-width: 108px;
  justify-self: end;
}

#chat-profile-trigger.chat-user-btn {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  text-align: left;
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
}

#chat-profile-trigger.chat-user-btn:hover {
  filter: none;
}

.chat-header-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(180deg, #ef7f5a, #e2644d);
}

.chat-header-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.chat-header-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}

#chat-header-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
  font-weight: 700;
}

.chat-header-subtitle {
  font-size: 12px;
  color: #7f94a8;
}

.chat-body {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.messages {
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px 16px;
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 255, 255, 0.018), transparent 18%),
    radial-gradient(circle at 72% 76%, rgba(255, 255, 255, 0.018), transparent 22%),
    linear-gradient(180deg, rgba(11, 22, 34, 0.98), rgba(13, 22, 33, 0.98));
}

.messages::before {
  content: "";
  margin-top: auto;
}

.user-detail-view {
  position: absolute;
  inset: 0;
  z-index: 96;
  display: grid;
  grid-template-rows: auto 1fr;
  background:
    radial-gradient(circle at top left, rgba(100, 168, 232, 0.08), transparent 24%),
    linear-gradient(180deg, #16212c, #111b24);
  transition: transform 180ms ease;
  border-radius: inherit;
  overflow: hidden;
}

.user-detail-view.is-dragging {
  transition: none;
}

.user-detail-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  min-height: 68px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--tg-border-color);
  background: linear-gradient(180deg, #223242, #1c2a38);
}

.user-detail-header-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.user-detail-header-copy strong {
  min-width: 0;
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-detail-content {
  overflow: auto;
  display: grid;
  gap: 12px;
  align-content: start;
  padding: 0 0 20px;
}

.tg-profile-hero {
  position: relative;
  min-height: 220px;
  padding: 24px 18px 18px;
  background: linear-gradient(180deg, #8a5b3d, #b97244);
  overflow: hidden;
}

.tg-profile-backdrop {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 18%, rgba(255,255,255,0.08), transparent 10%),
    radial-gradient(circle at 70% 14%, rgba(255,255,255,0.08), transparent 10%),
    radial-gradient(circle at 80% 40%, rgba(255,255,255,0.06), transparent 14%);
  opacity: 0.55;
  pointer-events: none;
}

.tg-profile-top {
  position: relative;
  min-height: 178px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.tg-profile-avatar-wrap {
  width: 104px;
  height: 104px;
}

.user-card-avatar,
.user-card-avatar-fallback {
  width: 104px;
  height: 104px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.12);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.16);
}

.user-card-avatar {
  object-fit: cover;
}

.user-card-avatar-fallback {
  display: grid;
  place-items: center;
  font-size: 36px;
  font-weight: 700;
  color: #fff;
}

.tg-profile-name {
  font-size: 28px;
  font-weight: 700;
  color: #fff;
  line-height: 1.1;
}

.tg-profile-status {
  font-size: 14px;
  color: rgba(255,255,255,0.8);
}

.tg-profile-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.profile-actions-row {
  display: flex;
  padding: 0 10px;
}

.profile-action-btn {
  min-height: 42px;
}

.tg-profile-section {
  margin: 0 10px;
  padding: 10px 12px;
  border-radius: 16px;
  background: #1f2c39;
  border: 1px solid rgba(255,255,255,0.04);
}

.tg-profile-stat {
  border-radius: 14px;
  background: #22303d;
  border: 1px solid rgba(255,255,255,0.04);
  padding: 10px;
}

.tg-profile-stat strong {
  display: block;
  font-size: 15px;
  margin-top: 2px;
  color: #fff;
}

.tg-profile-section-title {
  margin-bottom: 8px;
  font-size: 11px;
  color: var(--tg-hint-color);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.tg-profile-row {
  display: grid;
  gap: 3px;
  padding: 8px 0;
  border-top: 1px solid rgba(255,255,255,0.04);
}

.tg-profile-copy-row {
  width: 100%;
  border: none;
  border-top: 1px solid rgba(255,255,255,0.04);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  text-align: left;
  padding: 10px 0;
}

.tg-profile-copy-row:hover {
  filter: none;
  background: rgba(255, 255, 255, 0.02);
}

.tg-profile-row:first-of-type {
  border-top: none;
  padding-top: 0;
}

.tg-profile-row span {
  font-size: 11px;
  color: var(--tg-hint-color);
}

.tg-profile-row b {
  font-size: 13px;
  color: #fff;
  word-break: break-word;
}

.profile-error {
  color: #f0b7bf;
}

.msg {
  width: fit-content;
  max-width: min(74%, 560px);
  position: relative;
  padding: 9px 14px 7px;
  border-radius: 18px;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid rgba(255, 255, 255, 0.03);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.14);
}

.msg.user {
  align-self: flex-start;
  margin-right: auto;
  background: #182734;
  border-top-left-radius: 8px;
}

.msg.support,
.msg.admin {
  align-self: flex-end;
  margin-left: auto;
  background: #2f5f8b;
  border-top-right-radius: 8px;
}

.msg.system {
  align-self: center;
  max-width: 100%;
  background: rgba(33, 49, 65, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.04);
  color: #dfe7ef;
  font-size: 12px;
  padding: 5px 12px;
  box-shadow: none;
}

.msg img {
  display: block;
  width: 100%;
  max-width: 280px;
  margin-top: 6px;
  border-radius: 12px;
  object-fit: cover;
}

.file-link {
  display: inline-block;
  margin-top: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #8ac7ff;
  text-decoration: none;
}

.msg small {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 5px;
  font-size: 11px;
  color: rgba(230, 237, 243, 0.66);
}

.msg-delivery {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  color: #8fd0ff;
  transform: translateY(-0.5px);
}

.reply-form {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--tg-border-color);
  background: #182533;
}

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

.reply-form textarea {
  min-height: 44px;
  max-height: 108px;
  padding: 11px 16px;
  line-height: 1.35;
  background: #243447;
  border-radius: 22px;
}

.reply-form button {
  height: 44px;
  min-width: 96px;
  padding: 0 18px;
  background: var(--tg-button-color);
}

.reply-form button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: none;
}

.clip-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--tg-border-color);
  background: #243447;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--tg-hint-color);
}

.reply-attachment-meta {
  padding: 0 8px;
  color: #9fb4c8;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.quick-reply-suggestions {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 8px);
  display: grid;
  gap: 4px;
  padding: 8px;
  border-radius: 16px;
  background: rgba(22, 35, 49, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.38);
  max-height: 220px;
  overflow: auto;
  z-index: 24;
}

.quick-reply-suggestion {
  width: 100%;
  min-width: 0;
  min-height: 54px;
  display: grid;
  grid-template-columns: minmax(96px, 120px) minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px 14px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.015);
  box-shadow: none;
  text-align: left;
  color: var(--tg-text-color);
  overflow: hidden;
  isolation: isolate;
  cursor: pointer;
}

.quick-reply-suggestion:hover {
  filter: none;
  background: rgba(255, 255, 255, 0.015);
  border-color: rgba(255, 255, 255, 0.07);
}

.quick-reply-suggestion.active {
  filter: none;
  background: rgba(255, 255, 255, 0.015);
  border-color: rgba(88, 155, 221, 0.98);
  box-shadow: inset 0 0 0 1px rgba(88, 155, 221, 0.42);
}

.quick-reply-suggestion-key {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: #8cc9ff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.quick-reply-suggestion-text {
  display: block;
  font-size: 12px;
  color: var(--tg-hint-color);
  line-height: 1.35;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  pointer-events: none;
}

.reply-upload-progress {
  display: none !important;
}

.reply-upload-progress-bar {
  width: 0%;
  height: 100%;
}

.clip-btn input { display: none; }

@media (max-width: 920px) {
  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .stats {
    grid-column: 1 / -1;
  }

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

  .chat-modal {
    display: block;
    padding: 0;
    background: #101923;
  }

  .chat-window {
    width: 100%;
    height: var(--app-height);
    border-radius: 0;
    max-height: none;
  }

  .user-detail-view {
    border-radius: 0;
  }

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

  .admin-create-form {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 620px) {
  #users-view.history-page {
    grid-template-rows: auto auto auto auto 1fr;
  }

  .app-shell {
    padding: calc(var(--safe-top) + 8px) calc(var(--safe-right) + 8px) calc(var(--safe-bottom) + 8px) calc(var(--safe-left) + 8px);
  }

  .drawer {
    left: calc(var(--safe-left) + 8px);
    right: calc(var(--safe-right) + 8px);
    top: calc(var(--safe-top) + 8px);
    bottom: calc(var(--safe-bottom) + 8px);
    width: auto;
    border-radius: 20px;
  }

  .drawer-head {
    position: sticky;
    top: 0;
    z-index: 2;
    background: linear-gradient(180deg, #1f2d3a, #1a2834);
  }

  .topbar {
    padding: 10px 12px;
    grid-template-columns: 38px minmax(0, 1fr) 38px;
    gap: 10px;
  }

  .pill {
    min-width: 78px;
  }

  .conversation-item {
    grid-template-columns: 46px minmax(0, 1fr);
    gap: 10px;
    padding: 9px 8px;
  }

  .conv-avatar,
  .conv-avatar-img,
  .conv-avatar-fallback {
    width: 46px;
    height: 46px;
  }

  .msg {
    max-width: 88%;
  }

  .chat-modal {
    inset: 0;
    padding: 0;
    place-items: stretch;
  }

  .user-detail-header {
    padding: 10px 12px;
  }

  .tg-profile-hero {
    min-height: 200px;
    padding: 22px 14px 16px;
  }

  .tg-profile-avatar-wrap,
  .user-card-avatar,
  .user-card-avatar-fallback {
    width: 88px;
    height: 88px;
  }

  .tg-profile-name {
    font-size: 24px;
  }

  .chat-window {
    width: 100%;
    height: var(--app-height);
    border-radius: 0;
    grid-template-rows: auto minmax(0, 1fr) auto;
  }

  .chat-header {
    min-height: calc(62px + var(--safe-top));
    padding: calc(var(--safe-top) + 8px) 12px 10px;
    gap: 10px;
  }

  #chat-profile-trigger.chat-user-btn {
    grid-template-columns: 40px minmax(0, 1fr);
    gap: 10px;
  }

  .chat-header-avatar {
    width: 40px;
    height: 40px;
    font-size: 16px;
  }

  #chat-header-title {
    font-size: 15px;
  }

  .chat-header-subtitle {
    font-size: 11px;
  }

  #mark-resolved {
    min-width: 92px;
    min-height: 40px;
    padding: 0 14px;
    font-size: 14px;
  }

  .messages {
    padding: 12px 12px calc(16px + var(--keyboard-gap));
    scroll-padding-bottom: calc(16px + var(--keyboard-gap));
  }

  .reply-form {
    grid-template-columns: 40px minmax(0, 1fr) 40px;
    align-items: end;
    gap: 8px;
    padding: 8px 10px calc(var(--safe-bottom) + 8px) 10px;
  }

  .reply-form textarea {
    min-height: 40px;
    max-height: 96px;
    padding: 9px 14px;
    border-radius: 20px;
  }

  .reply-form button {
    grid-column: auto;
    width: 40px;
    min-width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    font-size: 0;
    position: relative;
    justify-self: end;
    background: linear-gradient(180deg, #56a8f4, #3f95e4);
  }

  .reply-form button::before {
    content: "➤";
    font-size: 16px;
    line-height: 1;
    color: #fff;
    transform: translateX(1px) translateY(-1px);
    display: inline-block;
  }

  .clip-btn {
    width: 40px;
    height: 40px;
  }

  .quick-reply-suggestions {
    left: 0;
    right: 0;
    bottom: calc(100% + 6px);
    padding: 6px;
    max-height: 180px;
  }

  .quick-reply-suggestion {
    min-height: 46px;
    grid-template-columns: 92px minmax(0, 1fr);
    padding: 8px 12px;
  }

  .quick-reply-suggestion-key {
    font-size: 13px;
  }

  .quick-reply-suggestion-text {
    font-size: 11px;
  }

  .dashboard-grid,
  .dashboard-grid.compact,
  .profile-grid,
  .admin-create-form {
    grid-template-columns: 1fr;
  }

  .users-toolbar {
    justify-content: stretch;
  }

  .users-create-btn {
    width: 100%;
    justify-content: center;
  }

  .staff-summary-main {
    grid-template-columns: 40px minmax(0, 1fr);
    gap: 10px;
  }

  .quick-reply-item {
    grid-template-columns: 1fr;
  }

  .quick-reply-actions {
    width: 100%;
  }

  .quick-reply-action-btn {
    flex: 1 1 0;
  }

  .staff-avatar {
    width: 40px;
    height: 40px;
    font-size: 14px;
  }

  .staff-copy-top {
    flex-wrap: wrap;
  }

  .staff-copy-meta {
    white-space: normal;
  }
}
