:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --panel: #121820;
  --panel-2: #18212b;
  --text: #edf3f8;
  --muted: #8da0b3;
  --line: #263544;
  --accent: #36d399;
  --accent-2: #45a3ff;
  --danger: #ff6b6b;
  --warn: #ffd166;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea,
input {
  font: inherit;
}

button,
input,
textarea {
  outline: none;
}

button {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  transition: transform .12s ease, border-color .12s ease, background .12s ease, opacity .12s ease;
}

button:hover {
  border-color: rgba(69, 163, 255, .72);
  background: #1b2834;
}

button:active {
  transform: translateY(1px);
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(69, 163, 255, .16);
}

button.primary,
#sendBtn {
  background: var(--accent);
  border-color: var(--accent);
  color: #06110d;
  font-weight: 700;
}

button.primary:hover,
#sendBtn:hover {
  background: #41e3a8;
}

button.danger {
  color: #fff;
  border-color: rgba(255, 107, 107, .55);
  background: rgba(255, 107, 107, .18);
}

button.danger:hover {
  border-color: rgba(255, 107, 107, .9);
  background: rgba(255, 107, 107, .28);
}

button:disabled {
  opacity: .48;
  cursor: not-allowed;
  transform: none;
}

.shell {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 16px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0 16px;
  background: rgba(11, 15, 20, .92);
  backdrop-filter: blur(14px);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  letter-spacing: 0;
}

h2 {
  font-size: 17px;
  letter-spacing: 0;
}

#profile,
.thread-head p,
.muted {
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(15, 21, 28, .8);
}

.tabs button {
  min-width: 76px;
  border-color: transparent;
  padding: 8px 10px;
}

.tabs button.active {
  background: var(--accent-2);
  color: #04111f;
  font-weight: 700;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 14px;
  min-height: calc(100vh - 96px);
}

.panel {
  min-width: 0;
  border: 1px solid rgba(38, 53, 68, .92);
  border-radius: 8px;
  background: rgba(18, 24, 32, .86);
  backdrop-filter: blur(16px);
}

.list-panel {
  overflow: hidden;
}

.panel-head,
.thread-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.thread-head {
  position: sticky;
  top: 72px;
  z-index: 4;
  background: rgba(18, 24, 32, .94);
  backdrop-filter: blur(14px);
}

.icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 18px;
}

.ticket-list {
  display: grid;
  gap: 8px;
  padding: 10px;
  max-height: calc(100vh - 170px);
  overflow: auto;
}

.ticket {
  width: 100%;
  display: grid;
  gap: 6px;
  text-align: left;
  border-color: rgba(38, 53, 68, .45);
  background: rgba(15, 21, 28, .9);
}

.ticket:hover {
  transform: translateY(-1px);
}

.ticket.active {
  border-color: var(--accent-2);
  background: rgba(69, 163, 255, .11);
}

.ticket.new-ticket {
  border-color: rgba(54, 211, 153, .38);
}

.ticket strong {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.ticket-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 10px;
  color: var(--muted);
  font-size: 12px;
}

.ticket-warning,
.hint {
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
}

.hint {
  padding: 10px 12px;
  color: var(--warn);
  border: 1px solid rgba(255, 209, 102, .26);
  border-radius: 8px;
  background: rgba(255, 209, 102, .08);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 2px 8px;
  color: #081019;
  background: var(--accent);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.closed {
  background: #8c98a6;
}

.badge.pending {
  background: var(--warn);
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.stat {
  display: grid;
  gap: 3px;
  min-height: 78px;
  padding: 10px;
  text-align: left;
  border-color: rgba(38, 53, 68, .55);
  background: rgba(15, 21, 28, .88);
}

.stat.active {
  border-color: var(--accent-2);
  background: rgba(69, 163, 255, .12);
}

.stat strong {
  font-size: 22px;
}

.stat span {
  color: var(--muted);
  font-size: 12px;
}

.stat-icon {
  color: var(--text) !important;
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.search-row input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f151c;
  color: var(--text);
  padding: 11px;
}

.blocked-card,
.ticket-info,
.occupied-warning {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(15, 21, 28, .9);
}

.blocked-card {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.blocked-card div {
  display: grid;
  gap: 3px;
}

.ticket-info {
  width: min(720px, 100%);
  color: var(--muted);
}

.ticket-info strong {
  color: var(--text);
  font-size: 16px;
}

.occupied-warning {
  width: min(720px, 100%);
  border-color: rgba(255, 107, 107, .55);
  background: rgba(255, 107, 107, .1);
  color: #ffdede;
}

.thread-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 560px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  overflow: auto;
}

.message {
  width: min(680px, 92%);
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0e141b;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.admin {
  align-self: flex-end;
  border-color: rgba(54, 211, 153, .35);
  background: rgba(54, 211, 153, .08);
}

.message .meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.attachment-btn {
  margin-top: 8px;
  color: var(--accent-2);
  background: transparent;
}

.composer {
  position: sticky;
  bottom: 0;
  display: grid;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: rgba(18, 24, 32, .96);
  backdrop-filter: blur(14px);
}

textarea {
  resize: vertical;
  min-height: 88px;
  max-height: 180px;
}

.composer-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

input[type="file"] {
  width: 100%;
  min-width: 0;
  color: var(--muted);
}

.banner,
.empty {
  margin: 12px 0;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid rgba(255, 209, 102, .5);
  background: rgba(255, 209, 102, .12);
}

.empty {
  border-color: var(--line);
  background: var(--panel);
  color: var(--muted);
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .shell {
    padding: 12px;
  }

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

  .layout {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .ticket-list {
    max-height: 320px;
  }

  .thread-panel {
    min-height: 540px;
  }

  .thread-head {
    top: 118px;
    align-items: stretch;
    flex-direction: column;
  }

  .stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .search-row,
  .composer-row,
  .blocked-card {
    grid-template-columns: 1fr;
  }

  .actions {
    justify-content: flex-start;
  }

  .actions button,
  .composer-row button,
  .search-row button {
    min-height: 44px;
  }
}


/* Mini App UI fixes: wider chat, compact composer, preview, block sheet. */
.shell {
  width: min(1480px, 100%);
  padding: 16px 20px;
}

.layout {
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 16px;
}

.thread-panel {
  min-width: 0;
}

.messages {
  align-items: stretch;
  padding: 16px 20px;
}

.message {
  width: min(1040px, 96%);
}

.ticket-info,
.occupied-warning {
  width: min(1040px, 100%);
}

.search-row {
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
}

.attachment-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.attachment-btn {
  margin-top: 0;
  color: var(--accent-2);
  background: transparent;
}

textarea {
  resize: none;
  min-height: 46px;
  max-height: 176px;
  overflow-y: hidden;
  line-height: 1.35;
}

.composer {
  gap: 8px;
}

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

.preview-overlay,
.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 18px;
  background: rgba(0, 0, 0, .58);
}

.preview-overlay {
  align-items: center;
}

.preview-modal,
.bottom-sheet {
  width: min(1040px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 60px rgba(0, 0, 0, .42);
}

.preview-modal {
  max-height: min(82vh, 780px);
  display: grid;
  grid-template-rows: auto 1fr;
}

.preview-head,
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.preview-head div {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.preview-body {
  min-height: 220px;
  overflow: auto;
  padding: 14px;
}

.preview-image {
  display: block;
  max-width: 100%;
  max-height: 70vh;
  margin: 0 auto;
  border-radius: 8px;
}

.preview-frame {
  width: 100%;
  height: min(70vh, 680px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f151c;
}

.preview-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text);
}

.preview-fallback {
  display: grid;
  place-items: center;
  min-height: 180px;
  color: var(--muted);
}

.bottom-sheet {
  padding-bottom: env(safe-area-inset-bottom);
}

.block-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 360px);
  gap: 14px;
  padding: 14px;
}

.block-user-card,
.block-controls {
  display: grid;
  gap: 10px;
}

.block-user-card {
  align-content: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(15, 21, 28, .9);
}

.block-controls label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.block-controls input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f151c;
  color: var(--text);
  padding: 11px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  z-index: 60;
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  padding: 10px 14px;
  border: 1px solid rgba(54, 211, 153, .5);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  transition: opacity .16s ease, transform .16s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 900px) {
  .shell {
    width: 100%;
    padding: 12px;
  }

  .layout {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .messages {
    padding: 12px;
  }

  .message,
  .ticket-info,
  .occupied-warning {
    width: 100%;
  }

  .search-row {
    grid-template-columns: 1fr 1fr;
  }

  .search-row input {
    grid-column: 1 / -1;
  }

  .composer-row {
    grid-template-columns: 1fr;
  }

  .preview-overlay,
  .sheet-overlay {
    padding: 10px;
  }

  .block-layout {
    grid-template-columns: 1fr;
  }

  .block-controls button {
    min-height: 46px;
  }
}
