:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --border: #2d3748;
  --success: #22c55e;
  --danger: #ef4444;
  --user-msg: #1e3a5f;
  --operator-msg: #1f2937;
  --system-msg: #374151;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

header {
  margin-bottom: 24px;
}

header h1 {
  margin: 0 0 8px;
  font-size: 1.5rem;
}

header p {
  margin: 0;
  color: var(--muted);
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}

.hidden { display: none !important; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

button, .btn {
  appearance: none;
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 0.95rem;
  cursor: pointer;
  background: var(--accent);
  color: white;
  transition: background 0.15s;
}

button:hover { background: var(--accent-hover); }
button.secondary { background: #334155; }
button.secondary:hover { background: #475569; }
button.danger { background: var(--danger); }
button.danger:hover { background: #dc2626; }

label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

input, select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #111827;
  color: var(--text);
  margin-bottom: 12px;
}

#chat-layout {
  display: grid;
  grid-template-rows: 1fr auto;
  height: calc(100vh - 120px);
  min-height: 480px;
  position: relative;
}

#screen-chat {
  position: relative;
}

#screen-chat.drop-active > *:not(.drop-overlay) {
  pointer-events: none;
}

.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(59, 130, 246, 0.14);
  border: 2px dashed var(--accent);
  border-radius: 12px;
  pointer-events: none;
}

.drop-overlay.hidden {
  display: none;
}

.drop-overlay p {
  margin: 0;
  padding: 16px 24px;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(15, 20, 25, 0.85);
  border-radius: 10px;
}

#messages {
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.user { align-self: flex-end; background: var(--user-msg); }
.msg.operator { align-self: flex-start; background: var(--operator-msg); }
.msg.system {
  align-self: center;
  background: var(--system-msg);
  color: var(--muted);
  font-size: 0.85rem;
  max-width: 95%;
  text-align: center;
}

.msg-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
}

#composer {
  display: flex;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

#composer.disabled {
  opacity: 0.55;
  pointer-events: none;
}

#composer input {
  margin: 0;
  flex: 1;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: #334155;
  color: var(--muted);
}

.badge-success {
  background: rgba(34, 197, 94, 0.18);
  color: var(--success);
  font-weight: 600;
}

.badge-danger {
  background: rgba(239, 68, 68, 0.18);
  color: var(--danger);
  font-weight: 600;
}

.badge-warning {
  background: rgba(234, 179, 8, 0.22);
  color: #facc15;
  font-weight: 600;
}

.ticket-card-head .badge-warning {
  font-size: 0.7rem;
  line-height: 1.25;
  max-width: 55%;
  text-align: right;
}

.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.confirm-summary {
  font-size: 1.05rem;
  line-height: 1.5;
  margin: 16px 0 8px;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}

.menu-btn {
  width: 100%;
  text-align: left;
}

.menu-btn.selected {
  outline: 2px solid var(--accent);
}

.menu-btn:disabled,
.menu-btn.menu-btn-locked {
  opacity: 0.45;
  cursor: not-allowed;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.chat-header > div:last-child {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ticket-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0;
}

.ticket-tabs {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.ticket-tab {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.ticket-tab.active {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(59, 130, 246, 0.12);
}

.ticket-card.closed {
  opacity: 0.92;
}

#cash-link-wait-notice {
  margin: 20px 0;
}

#btn-cash-link-wait-main {
  margin-top: 8px;
}

.ticket-card {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.ticket-card:hover {
  border-color: var(--accent);
  background: #1e293b;
}

.ticket-card.ticket-card-warning {
  border-color: rgba(234, 179, 8, 0.55);
  background: rgba(234, 179, 8, 0.1);
  box-shadow: inset 0 0 0 1px rgba(234, 179, 8, 0.12);
}

.ticket-card.ticket-card-warning:hover {
  border-color: #eab308;
  background: rgba(234, 179, 8, 0.16);
}

.ticket-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 6px;
}

.ticket-card-title {
  font-weight: 600;
}

.ticket-card-meta {
  font-size: 0.85rem;
  color: var(--muted);
}

.banner {
  margin-top: 12px;
  padding: 12px;
  background: #1e3a5f;
  border-radius: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.card.inner {
  margin-top: 12px;
  background: #111827;
}

.code-value {
  font-size: 1.25rem;
  margin: 8px 0;
  word-break: break-all;
}

.msg-media {
  max-width: min(280px, 100%);
  max-height: 220px;
  border-radius: 8px;
  margin: 6px 0;
  cursor: zoom-in;
  object-fit: cover;
  display: block;
  transition: opacity 0.15s;
}

.msg-media:hover {
  opacity: 0.92;
}

.msg-sticker {
  max-width: 160px;
  max-height: 160px;
  object-fit: contain;
  cursor: default;
  background: transparent;
}

.msg-sticker:hover {
  opacity: 1;
}

.msg-sticker-fallback {
  font-size: 4rem;
  line-height: 1;
  margin: 6px 0;
}

.msg-sticker-hint {
  font-size: 0.8rem;
  opacity: 0.7;
  margin-bottom: 4px;
}

.msg-video-note {
  width: 180px;
  height: 180px;
  max-width: 180px;
  max-height: 180px;
  border-radius: 50%;
  object-fit: cover;
  cursor: pointer;
  background: #111;
}

.msg-voice-player {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 6px 0;
  max-width: min(320px, 100%);
}

.msg-voice-icon {
  display: none;
}

.msg-voice-label {
  font-size: 0.85rem;
  opacity: 0.75;
}

.msg-audio {
  display: block;
  width: 100%;
  height: 36px;
}

.photo-lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-lightbox.hidden {
  display: none;
}

.photo-lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  cursor: zoom-out;
}

.photo-lightbox-content {
  position: relative;
  z-index: 1;
  max-width: min(96vw, 1200px);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 16px 24px;
  pointer-events: none;
}

.photo-lightbox-content img {
  max-width: 100%;
  max-height: calc(92vh - 60px);
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  pointer-events: auto;
  cursor: zoom-out;
}

.photo-lightbox-close {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 2;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.photo-lightbox-close:hover {
  background: rgba(255, 255, 255, 0.22);
}

.photo-lightbox-caption {
  margin: 12px 0 0;
  color: rgba(255, 255, 255, 0.85);
  text-align: center;
  max-width: 90vw;
  font-size: 0.9rem;
  pointer-events: auto;
}

.photo-lightbox-caption.hidden {
  display: none;
}

.msg-file {
  color: var(--accent);
  display: block;
  margin: 4px 0;
}

#composer {
  display: flex;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  align-items: center;
}

#composer input[type="text"] {
  margin: 0;
  flex: 1;
}

#attach-btn {
  padding: 10px 12px;
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  min-width: 0;
}

#user-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  max-width: 100%;
  min-width: 0;
}

#user-bar .badge,
#user-bar a.secondary,
#user-bar button {
  flex: 0 1 auto;
  max-width: 100%;
}

@media (max-width: 640px) {
  .header-row {
    flex-direction: column;
    align-items: stretch;
  }

  #user-bar {
    justify-content: flex-start;
    width: 100%;
  }

  #user-bar a.secondary,
  #user-bar button {
    padding: 10px 12px;
    font-size: 0.875rem;
  }

  #user-bar .badge {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

#user-bar a.secondary {
  display: inline-block;
  text-decoration: none;
  appearance: none;
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 0.95rem;
  cursor: pointer;
  background: #334155;
  color: white;
  transition: background 0.15s;
}

#user-bar a.secondary:hover {
  background: #475569;
}

#user-bar a.admin-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

@keyframes support-btn-shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-4px) rotate(-3deg); }
  30% { transform: translateX(4px) rotate(3deg); }
  45% { transform: translateX(-4px) rotate(-3deg); }
  60% { transform: translateX(4px) rotate(3deg); }
  75% { transform: translateX(-2px); }
}

#btn-admin.support-btn-shake {
  animation: support-btn-shake 0.5s ease-in-out;
}

#user-bar .support-badge,
#admin-badge-urgent.support-badge,
#admin-badge-followup.support-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #dc2626 !important;
  color: #fff !important;
  font-weight: 700;
  font-size: 0.75rem;
  min-width: 1.35rem;
  padding: 2px 7px;
  text-align: center;
  line-height: 1.25;
  border-radius: 999px;
  cursor: help;
}

#admin-badge-followup.support-badge-followup {
  background: #ca8a04 !important;
}

.support-codes-alert {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.85rem;
  line-height: 1;
  flex-shrink: 0;
  cursor: help;
}

.support-codes-alert.codes-critical {
  background: #dc2626;
  color: #fff;
}

.support-codes-alert.codes-warning {
  background: #ca8a04;
  color: #111;
}

.codes-alert-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
}

.codes-alert-popup {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  min-width: 200px;
  max-width: min(280px, 80vw);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0b1220;
  color: var(--text);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: normal;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.15s ease, visibility 0.15s ease;
}

.codes-alert-popup::before {
  content: "";
  position: absolute;
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 6px solid #0b1220;
}

.codes-alert-wrap:hover .codes-alert-popup,
.codes-alert-wrap:focus-within .codes-alert-popup {
  opacity: 1;
  visibility: visible;
}

.codes-alert-popup strong {
  display: block;
  margin-bottom: 6px;
  font-size: 0.88rem;
}

.codes-alert-popup .codes-alert-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.codes-alert-popup .codes-alert-hint {
  margin-top: 8px;
  color: var(--muted);
  white-space: normal;
}

.auth-block {
  margin: 12px 0;
}

.telegram-login-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  background: #2aabee;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.telegram-login-btn:hover {
  background: #229ed9;
}

.telegram-login-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.telegram-login-icon {
  font-size: 1.2rem;
  line-height: 1;
}

.auth-block iframe {
  display: none;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.setup-user {
  margin-bottom: 12px;
  line-height: 1.8;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  font: inherit;
  text-decoration: underline;
}

.link-btn:hover {
  background: none;
  opacity: 0.85;
}
