:root {
  color-scheme: dark;
  --bg: #080a0f;
  --panel: #10141d;
  --panel-2: #151b25;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f6f8fb;
  --muted: #9aa5b5;
  --soft: #cbd3df;
  --accent: #4fb8ff;
  --accent-2: #78e0c2;
  --danger: #ff6b7a;
  --warn: #ffd166;
  --radius: 8px;
  --tg-safe-top: env(safe-area-inset-top, 0px);
  --tg-safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body {
  overflow-x: hidden;
}

button,
textarea,
input {
  font: inherit;
}

.app-shell {
  width: min(100%, 520px);
  min-height: 100dvh;
  margin: 0 auto;
  background:
    radial-gradient(circle at 20% 0%, rgba(79, 184, 255, 0.12), transparent 32%),
    linear-gradient(180deg, #0b0e14 0%, #080a0f 54%, #090c12 100%);
}

.screen {
  min-height: 100dvh;
  padding: calc(12px + var(--tg-safe-top)) 14px calc(84px + var(--tg-safe-bottom));
}

.screen.admin {
  max-width: 880px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  margin-bottom: 12px;
}

.title-block h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
  font-weight: 750;
}

.title-block p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.icon-button,
.button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border-radius: var(--radius);
  min-height: 38px;
  cursor: pointer;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  padding: 0;
  font-size: 18px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 12px;
  font-size: 14px;
  font-weight: 650;
  text-decoration: none;
}

.button.primary {
  border-color: rgba(79, 184, 255, 0.35);
  background: linear-gradient(135deg, #2f92ff, #44d0b1);
  color: #061016;
}

.button.ghost {
  background: transparent;
}

.button.danger {
  border-color: rgba(255, 107, 122, 0.35);
  color: #ffd7dc;
}

.button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.stack {
  display: grid;
  gap: 10px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(16, 20, 29, 0.82);
  padding: 12px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
}

.panel.tight {
  padding: 10px;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.row.start {
  align-items: flex-start;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12px;
  line-height: 1.35;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid rgba(79, 184, 255, 0.22);
  border-radius: 999px;
  background: rgba(79, 184, 255, 0.08);
  color: #ccecff;
  font-size: 12px;
  white-space: nowrap;
}

.status.closed {
  border-color: rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
}

.status.waiting_user {
  border-color: rgba(255, 209, 102, 0.26);
  background: rgba(255, 209, 102, 0.1);
  color: #ffe2a3;
}

.status.in_progress {
  border-color: rgba(120, 224, 194, 0.28);
  background: rgba(120, 224, 194, 0.09);
  color: #c9f7ea;
}

.hint {
  color: var(--soft);
  background: rgba(79, 184, 255, 0.07);
  border: 1px solid rgba(79, 184, 255, 0.12);
}

.message-list {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.message {
  max-width: 86%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  font-size: 14px;
  line-height: 1.42;
}

.message.user {
  justify-self: end;
  background: rgba(79, 184, 255, 0.12);
  border-color: rgba(79, 184, 255, 0.2);
}

.message.operator,
.message.admin {
  justify-self: start;
  background: rgba(120, 224, 194, 0.09);
  border-color: rgba(120, 224, 194, 0.17);
}

.message.system,
.message.bot {
  justify-self: center;
  max-width: 92%;
  text-align: center;
  color: var(--muted);
  background: transparent;
}

.attachment {
  display: grid;
  gap: 6px;
  margin-top: 6px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.04);
  padding: 9px;
}

.composer {
  position: fixed;
  left: 50%;
  bottom: calc(56px + var(--tg-safe-bottom));
  z-index: 10;
  display: flex;
  gap: 8px;
  width: min(100% - 24px, 496px);
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(16, 20, 29, 0.96);
  padding: 8px;
  backdrop-filter: blur(14px);
}

.composer textarea {
  min-height: 38px;
  max-height: 116px;
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  padding: 9px 10px;
  outline: none;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 11;
  display: grid;
  width: min(100%, 520px);
  min-height: calc(54px + var(--tg-safe-bottom));
  transform: translateX(-50%);
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line);
  background: rgba(8, 10, 15, 0.96);
  padding: 5px 8px var(--tg-safe-bottom);
  backdrop-filter: blur(14px);
}

.bottom-nav.admin {
  grid-template-columns: repeat(4, 1fr);
}

.bottom-nav button {
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.bottom-nav button.active {
  background: rgba(79, 184, 255, 0.1);
  color: var(--text);
}

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.tabs button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  padding: 7px 10px;
  white-space: nowrap;
}

.tabs button.active {
  border-color: rgba(79, 184, 255, 0.28);
  color: var(--text);
  background: rgba(79, 184, 255, 0.1);
}

.field-grid {
  display: grid;
  gap: 8px;
}

.field {
  display: grid;
  grid-template-columns: minmax(92px, 0.55fr) 1fr;
  gap: 8px;
  font-size: 13px;
}

.error {
  border-color: rgba(255, 107, 122, 0.24);
  background: rgba(255, 107, 122, 0.08);
  color: #ffe1e5;
}

.skeleton-line,
.skeleton-card {
  background: linear-gradient(90deg, rgba(255,255,255,0.05), rgba(255,255,255,0.1), rgba(255,255,255,0.05));
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite linear;
}

.skeleton-line {
  width: 48%;
  height: 22px;
  border-radius: 999px;
  margin: 16px 0;
}

.skeleton-line.wide {
  width: 70%;
}

.skeleton-card {
  height: 116px;
  border-radius: var(--radius);
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

@media (min-width: 720px) {
  .app-shell {
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pending-bar {
  position: fixed;
  left: 50%;
  bottom: calc(112px + var(--tg-safe-bottom));
  transform: translateX(-50%);
  z-index: 20;
  min-width: 220px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--text);
  text-align: center;
  font-size: 13px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.24);
}
