:root {
  --bg: #040711;
  --panel: rgba(8, 17, 36, 0.82);
  --panel-strong: #081225;
  --panel-soft: rgba(255, 255, 255, 0.045);
  --line: rgba(126, 169, 255, 0.18);
  --line-strong: rgba(95, 169, 255, 0.42);
  --text: #edf4ff;
  --muted: #91a4c5;
  --blue: #2f7cff;
  --cyan: #00b8ff;
  --violet: #8b5cf6;
  --danger: #ff4d6d;
  --warning: #ffc857;
  --success: #32d583;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
  --sidebar-width: 390px;
  --chat-width: 820px;
}

* { box-sizing: border-box; }
html {
  min-height: 100%;
  height: 100%;
  background: #020611;
}
body {
  margin: 0;
  min-height: 100vh;
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(8, 18, 39, 0.96) 0%, rgba(3, 7, 19, 1) 100%),
    var(--bg);
  overflow: hidden;
}

* {
  scrollbar-width: thin;
  scrollbar-color: rgba(95, 169, 255, .48) rgba(4, 10, 24, .42);
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: rgba(4, 10, 24, .42);
  border-left: 1px solid rgba(126, 169, 255, .10);
}

*::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(47,124,255,.74), rgba(0,184,255,.54));
  border: 2px solid rgba(4, 10, 24, .72);
  border-radius: 999px;
}

*::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(180deg, rgba(47,124,255,.96), rgba(0,184,255,.72));
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 16% 18%, rgba(230, 243, 255, .48) 0 1px, transparent 1.6px),
    radial-gradient(circle at 31% 72%, rgba(170, 210, 255, .30) 0 1px, transparent 1.7px),
    radial-gradient(circle at 52% 27%, rgba(255, 255, 255, .24) 0 1px, transparent 1.5px),
    radial-gradient(circle at 73% 61%, rgba(118, 184, 255, .28) 0 1px, transparent 1.6px),
    radial-gradient(circle at 89% 21%, rgba(255, 255, 255, .22) 0 1px, transparent 1.5px),
    linear-gradient(130deg, rgba(47, 124, 255, .16), transparent 36%, rgba(139, 92, 246, .10) 66%, transparent);
  opacity: .78;
  z-index: 0;
}

button, input, select, textarea { font: inherit; }
button { border: 0; cursor: pointer; }
button:disabled,
textarea:disabled,
input:disabled,
select:disabled {
  opacity: .58;
  cursor: not-allowed;
}

input, select, textarea {
  width: 100%;
  color: var(--text);
  background: rgba(4, 10, 24, .88);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 13px;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--line-strong);
  box-shadow: 0 0 0 3px rgba(47, 124, 255, .16);
}

select option { background: #081225; color: var(--text); }
textarea { min-height: 92px; resize: vertical; }

.login {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 12px;
  padding: 26px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.login-brand,
.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.login-brand { margin-bottom: 6px; }
.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: white;
  font-size: 22px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--blue), var(--cyan) 52%, var(--violet));
  box-shadow: 0 14px 34px rgba(47, 124, 255, .34);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .13em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.05;
  letter-spacing: 0;
}
h2 {
  margin: 0;
  font-size: clamp(22px, 2.6vw, 34px);
  line-height: 1.1;
  letter-spacing: 0;
}
p { color: var(--muted); }

.field-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.danger-btn {
  min-height: 42px;
  border-radius: 8px;
  padding: 11px 15px;
  color: var(--text);
  font-weight: 800;
}
.primary-btn {
  background: linear-gradient(135deg, var(--blue), var(--cyan));
  box-shadow: 0 15px 35px rgba(47, 124, 255, .30);
}
.secondary-btn,
.ghost-btn {
  background: rgba(255,255,255,.065);
  border: 1px solid var(--line);
}
.danger-btn {
  background: rgba(255,77,109,.14);
  color: #ff9aac;
  border: 1px solid rgba(255,77,109,.32);
}
.primary-btn:hover,
.secondary-btn:hover,
.ghost-btn:hover,
.danger-btn:hover { transform: translateY(-1px); }
.error { color: #ff9aac; margin: 4px 0 0; }

.desk-shell {
  position: relative;
  z-index: 1;
  width: 100vw;
  max-width: none;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(330px, var(--sidebar-width)) minmax(0, 1fr);
}

.ticket-sidebar {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: rgba(3, 8, 20, 0.68);
  backdrop-filter: blur(18px);
}

.brand-row { margin-bottom: 24px; }
.sidebar-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  color: var(--muted);
  font-weight: 800;
}

.stat-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}
.mini-stat {
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,.045);
}
.mini-stat span {
  display: block;
  min-height: 28px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
}
.mini-stat strong {
  display: block;
  margin-top: 6px;
  font-size: 24px;
  line-height: 1;
}
.mini-stat.open strong { color: var(--cyan); }
.mini-stat.answered strong { color: var(--success); }
.mini-stat.closed strong { color: var(--text); }

.folder-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}
.tab {
  min-height: 40px;
  color: var(--muted);
  background: rgba(255,255,255,.045);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 800;
}
.tab.active,
.tab:hover {
  color: var(--text);
  border-color: var(--line-strong);
  background: rgba(47,124,255,.16);
}

.filters {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px;
  gap: 8px;
  margin-bottom: 14px;
}

.ticket-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 9px;
  padding-right: 2px;
}
.ticket-card {
  width: 100%;
  display: grid;
  gap: 7px;
  text-align: left;
  color: var(--text);
  padding: 14px;
  background: rgba(4,10,24,.74);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.ticket-card:hover,
.ticket-card.active {
  border-color: var(--line-strong);
  background: rgba(47,124,255,.12);
}
.ticket-card-head,
.ticket-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.ticket-card-head b,
.ticket-subject {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ticket-subject { font-weight: 850; }
.ticket-preview {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}
.ticket-meta {
  justify-content: flex-start;
  color: var(--muted);
  font-size: 12px;
}
.source-pill {
  flex: 0 0 auto;
  padding: 5px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-style: normal;
  font-weight: 850;
  background: rgba(255,255,255,.07);
  border: 1px solid var(--line);
}
.source-pill.telegram { color: #8fd5ff; }
.source-pill.discord { color: #b8b8ff; }
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.status-dot.open { background: var(--cyan); }
.status-dot.answered { background: var(--success); }
.status-dot.closed { background: var(--text); }
.empty-list {
  padding: 18px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  text-align: center;
}

.ticket-workspace {
  min-width: 0;
  width: 100%;
  max-width: none;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  background: transparent;
}
.ticket-header {
  width: 100%;
  align-self: flex-start;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(4,10,24,.52);
  backdrop-filter: blur(14px);
}
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.meta-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}
.meta-grid span {
  display: grid;
  gap: 2px;
  min-width: 150px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,.045);
  color: var(--muted);
  font-size: 12px;
}
.meta-grid b {
  color: var(--text);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.messages {
  width: 100%;
  align-self: flex-start;
  flex: 0 1 auto;
  min-height: 0;
  max-height: min(48vh, 500px);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 20px 22px;
}
.message {
  max-width: min(1040px, 86%);
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.055);
  box-shadow: 0 14px 34px rgba(0,0,0,.18);
}
.message.outbound {
  align-self: flex-start;
  margin-left: 28px;
  border-color: rgba(47,124,255,.36);
  background: linear-gradient(135deg, rgba(47,124,255,.22), rgba(0,184,255,.10));
}
.message-author {
  font-weight: 850;
  margin-bottom: 8px;
}
.message p {
  margin: 0 0 9px;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message time {
  color: var(--muted);
  font-size: 12px;
}
.attachments {
  display: grid;
  gap: 9px;
  margin: 9px 0;
}
.attachment-card {
  display: grid;
  gap: 7px;
  max-width: 520px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(4,10,24,.46);
}
.attachment-card strong {
  color: var(--text);
  overflow-wrap: anywhere;
}
.attachment-card span,
.attachment-payload summary {
  color: var(--muted);
  font-size: 12px;
}
.attachment-card img,
.selected-gif img,
.gif-tile img {
  display: block;
  max-width: 100%;
  border-radius: 8px;
}
.attachment-card img {
  max-height: 280px;
  object-fit: contain;
}
.attachment-card video {
  width: min(520px, 100%);
  max-height: 320px;
  border-radius: 8px;
}
.attachment-card audio {
  width: min(420px, 100%);
}
.attachment-link,
.attachment-card a {
  color: #aee7ff;
  font-weight: 800;
  text-decoration: none;
}
.attachment-link.disabled {
  color: rgba(145, 164, 197, .72);
  cursor: not-allowed;
  font-weight: 750;
}
.attachment-link:hover,
.attachment-card a:hover {
  text-decoration: underline;
}
.attachment-link.disabled:hover {
  text-decoration: none;
}
.attachment-payload pre {
  max-width: 100%;
  max-height: 220px;
  overflow: auto;
  padding: 9px;
  color: var(--text);
  background: rgba(0,0,0,.24);
  border-radius: 8px;
  white-space: pre-wrap;
}
.reply-panel {
  width: 100%;
  align-self: flex-start;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  background: rgba(4,10,24,.72);
}
.reply-panel .primary-btn { min-width: 132px; }
.reply-panel textarea {
  min-height: 64px;
}
.reply-compose {
  display: grid;
  gap: 9px;
  min-width: 0;
}
.reply-tools {
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr) auto minmax(120px, 1fr) auto;
  gap: 8px;
  align-items: center;
}
.file-picker {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
  color: var(--text);
  background: rgba(255,255,255,.065);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 800;
  cursor: pointer;
}
.reply-panel.closed .file-picker,
.file-picker.disabled {
  opacity: .58;
  cursor: not-allowed;
  pointer-events: none;
}
.reply-panel.closed .reply-tools input,
.reply-panel.closed .reply-tools button {
  pointer-events: none;
}
.file-picker input {
  display: none;
}
.selected-gif {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 84px auto;
  gap: 10px;
  align-items: center;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,.045);
}
.selected-gif[hidden],
.gif-results[hidden] {
  display: none;
}
.selected-gif span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}
.selected-gif img {
  width: 84px;
  height: 64px;
  object-fit: cover;
}
.gif-results {
  width: min(760px, 100%);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
  max-height: min(360px, 42vh);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(4,10,24,.72);
}
.gif-tile {
  min-height: 82px;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,.045);
}
.gif-tile img {
  width: 100%;
  height: 82px;
  object-fit: cover;
}
.gif-status {
  grid-column: 1 / -1;
  color: var(--muted);
  padding: 9px;
}
.gif-status.error {
  color: #ff9aac;
}
.empty-workspace {
  width: 100%;
  height: 100%;
  display: grid;
  place-content: center;
  text-align: center;
  padding: 24px;
}
.empty-workspace p { margin-bottom: 0; }

@media (max-width: 1060px) {
  .desk-shell { grid-template-columns: minmax(330px, 360px) minmax(0, 1fr); }
  .stat-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 840px) {
  .desk-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(220px, 45vh) minmax(0, 1fr);
    height: 100vh;
    min-height: 0;
  }
  .ticket-sidebar {
    height: auto;
    min-height: 0;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .ticket-workspace {
    width: 100%;
    height: auto;
    min-height: 0;
  }
  .messages {
    max-height: 34vh;
  }
  .ticket-header { flex-direction: column; }
  .reply-panel,
  .reply-tools,
  .selected-gif { grid-template-columns: 1fr; }
  .reply-panel .primary-btn { width: 100%; }
}

@media (max-width: 560px) {
  .login { padding: 16px; }
  .login-card,
  .ticket-sidebar,
  .ticket-header,
  .messages,
  .reply-panel { padding: 16px; }
  .filters { grid-template-columns: 1fr; }
  .folder-tabs { grid-template-columns: 1fr; }
  .meta-grid span { min-width: 100%; }
  h1 { font-size: 24px; }
}
/* Ticket status and ownership polish */
.mini-stat {
  display: grid;
  align-content: center;
  justify-items: center;
  text-align: center;
}
.mini-stat span { min-height: 0; }
.mini-stat strong { margin-top: 8px; }
.mini-stat.open { background: linear-gradient(180deg, rgba(0, 184, 255, .11), rgba(255,255,255,.035)); }
.mini-stat.answered { background: linear-gradient(180deg, rgba(50, 213, 131, .11), rgba(255,255,255,.035)); }
.mini-stat.closed { background: linear-gradient(180deg, rgba(237, 244, 255, .10), rgba(255,255,255,.035)); }
.ticket-header-main { min-width: 0; flex: 1; }
.assignment-panel {
  margin-top: 16px;
  display: grid;
  gap: 10px;
  max-width: 760px;
  padding: 12px;
  border: 1px solid rgba(95, 169, 255, .30);
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(47,124,255,.12), rgba(0,184,255,.06));
}
.assignment-copy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
.assignment-copy strong {
  color: var(--text);
  font-size: 14px;
}
.assignment-copy strong.free { color: var(--muted); }
.operator-slider {
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  min-height: 42px;
  padding: 4px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(4,10,24,.72);
}
.operator-thumb {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 4px;
  width: calc((100% - 8px) / 5);
  border-radius: 7px;
  background: linear-gradient(135deg, rgba(47,124,255,.88), rgba(0,184,255,.62));
  box-shadow: 0 10px 24px rgba(47,124,255,.24);
  transition: transform .18s ease;
}
.operator-slider.selected-0 .operator-thumb { transform: translateX(0); }
.operator-slider.selected-1 .operator-thumb { transform: translateX(100%); }
.operator-slider.selected-2 .operator-thumb { transform: translateX(200%); }
.operator-slider.selected-3 .operator-thumb { transform: translateX(300%); }
.operator-slider.selected-4 .operator-thumb { transform: translateX(400%); }
.operator-pill {
  position: relative;
  z-index: 1;
  min-width: 0;
  min-height: 34px;
  padding: 7px 9px;
  color: var(--muted);
  background: transparent;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.operator-pill.active { color: white; }
.operator-pill:hover { color: var(--text); background: rgba(255,255,255,.055); }
.assignment-mini {
  justify-self: start;
  max-width: 100%;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255,255,255,.045);
  font-size: 12px;
  font-weight: 850;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.assignment-mini.amnezis { color: #8fd5ff; border-color: rgba(0,184,255,.34); }
.assignment-mini.xaikq { color: #b8b8ff; border-color: rgba(139,92,246,.36); }
.assignment-mini.natsunagi { color: #7df0b2; border-color: rgba(50,213,131,.34); }
.assignment-mini.citation { color: #f5f7ff; border-color: rgba(237,244,255,.34); }

@media (max-width: 560px) {
  .stat-strip,
  .folder-tabs,
  .operator-slider { grid-template-columns: 1fr; }
  .operator-thumb { display: none; }
  .operator-pill.active { background: linear-gradient(135deg, rgba(47,124,255,.88), rgba(0,184,255,.62)); }
}

/* Final layout lock: keep the ticket panel compact on desktop. */
@media (min-width: 841px) {
  .desk-shell {
    width: 100vw !important;
    max-width: none !important;
    grid-template-columns: minmax(330px, var(--sidebar-width)) minmax(0, 1fr) !important;
  }

  .ticket-workspace {
    justify-self: start !important;
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    background: transparent !important;
  }

  .ticket-header,
  .messages,
  .reply-panel {
    width: 100% !important;
    max-width: none !important;
  }

  .messages {
    flex: 0 1 auto !important;
    max-height: min(48vh, 500px) !important;
    overflow-y: auto !important;
  }

  .message.outbound {
    align-self: flex-start !important;
    margin-left: 28px !important;
  }
}

.reply-panel.closed .file-picker,
.reply-panel.closed .reply-tools input,
.reply-panel.closed .reply-tools button {
  pointer-events: none !important;
}

.reply-panel.closed .file-picker {
  opacity: .46 !important;
  cursor: not-allowed !important;
}
