* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--tg-theme-bg-color, #f2f2f7);
  color: var(--tg-theme-text-color, #000000);
  overscroll-behavior-y: none;
}

#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.screen.hidden {
  display: none;
}

/* ---------- Top bar ---------- */

.topbar {
  flex: 0 0 auto;
  padding: 10px 12px 8px;
  background: var(--tg-theme-secondary-bg-color, #ffffff);
  border-bottom: 1px solid rgba(0,0,0,0.06);
}

.topbar h1 {
  font-size: 18px;
  margin: 0 0 8px;
  font-weight: 600;
}

.search-row {
  margin-bottom: 8px;
}

#search-input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  border: none;
  background: var(--tg-theme-bg-color, #f2f2f7);
  color: var(--tg-theme-text-color, #000);
  font-size: 15px;
}

#search-input:focus {
  outline: 2px solid var(--tg-theme-button-color, #3390ec);
}

.tabs {
  display: flex;
  gap: 6px;
}

.tab {
  flex: 1;
  padding: 7px 8px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--tg-theme-hint-color, #8e8e93);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.tab.active {
  background: var(--tg-theme-button-color, #3390ec);
  color: var(--tg-theme-button-text-color, #ffffff);
}

/* ---------- Ticket list ---------- */

.list-status {
  padding: 10px 14px 0;
  font-size: 13px;
  color: var(--tg-theme-hint-color, #8e8e93);
}

.ticket-list {
  list-style: none;
  margin: 0;
  padding: 6px 8px 90px;
  overflow-y: auto;
  flex: 1 1 auto;
}

.ticket-card {
  background: var(--tg-theme-secondary-bg-color, #ffffff);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 6px 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ticket-card:active {
  opacity: 0.7;
}

.ticket-card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.ticket-name {
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ticket-time {
  font-size: 11px;
  color: var(--tg-theme-hint-color, #8e8e93);
  flex: 0 0 auto;
}

.ticket-question {
  font-size: 13px;
  color: var(--tg-theme-hint-color, #8e8e93);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ticket-badges {
  display: flex;
  gap: 6px;
  margin-top: 2px;
}

.badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 6px;
  font-weight: 600;
}

.badge-open {
  background: #ffe4b8;
  color: #a35b00;
}

.badge-answered {
  background: #d4f0dc;
  color: #197b3a;
}

.badge-closed {
  background: #e5e5ea;
  color: #6b6b70;
}

.badge-vip {
  background: #fde3f0;
  color: #b0197f;
}

.load-more {
  margin: 4px 16px 16px;
  padding: 10px;
  border-radius: 10px;
  border: none;
  background: var(--tg-theme-secondary-bg-color, #ffffff);
  color: var(--tg-theme-link-color, #3390ec);
  font-size: 14px;
}

.load-more.hidden {
  display: none;
}

.empty-state {
  text-align: center;
  color: var(--tg-theme-hint-color, #8e8e93);
  padding: 40px 20px;
  font-size: 14px;
}

/* ---------- Dialog screen ---------- */

.dialog-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.back-btn {
  border: none;
  background: none;
  font-size: 20px;
  color: var(--tg-theme-link-color, #3390ec);
  padding: 2px 4px;
  cursor: pointer;
}

.dialog-title {
  min-width: 0;
  flex: 1;
}

#dialog-name {
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dialog-sub {
  font-size: 12px;
  color: var(--tg-theme-hint-color, #8e8e93);
}

.thread {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble-row {
  display: flex;
  flex-direction: column;
}

.bubble-row.from-user {
  align-items: flex-start;
}

.bubble-row.from-admin {
  align-items: flex-end;
}

.bubble {
  max-width: 82%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}

.from-user .bubble {
  background: var(--tg-theme-secondary-bg-color, #ffffff);
  border-bottom-left-radius: 4px;
}

.from-admin .bubble {
  background: var(--tg-theme-button-color, #3390ec);
  color: var(--tg-theme-button-text-color, #ffffff);
  border-bottom-right-radius: 4px;
}

.bubble-meta {
  font-size: 10px;
  color: var(--tg-theme-hint-color, #8e8e93);
  margin: 3px 4px 0;
}

.bubble-meta.awaiting {
  color: #c47a00;
}

.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: var(--tg-theme-secondary-bg-color, #ffffff);
  border-top: 1px solid rgba(0,0,0,0.06);
}

#reply-text {
  flex: 1 1 auto;
  resize: none;
  max-height: 120px;
  padding: 9px 12px;
  border-radius: 14px;
  border: none;
  background: var(--tg-theme-bg-color, #f2f2f7);
  color: var(--tg-theme-text-color, #000);
  font-size: 15px;
  font-family: inherit;
}

.send-btn, .close-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  font-size: 16px;
  cursor: pointer;
}

.send-btn {
  background: var(--tg-theme-button-color, #3390ec);
  color: var(--tg-theme-button-text-color, #ffffff);
}

.send-btn:disabled {
  opacity: 0.5;
}

.close-btn {
  background: #ffe0e0;
  color: #c0392b;
}

.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.85);
  color: #fff;
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 1000;
  transition: opacity 0.3s;
}
