: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);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  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-x: hidden;
}

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;
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(330px, 410px) minmax(0, 1fr);
}

.ticket-sidebar {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  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 {
  min-height: 0;
  overflow: auto;
  display: grid;
  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;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: rgba(5, 10, 24, .30);
}
.ticket-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 24px 26px;
  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 {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 13px;
  padding: 24px 26px;
}
.message {
  max-width: min(760px, 92%);
  padding: 13px 14px;
  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-end;
  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;
}
.reply-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  padding: 18px 26px;
  border-top: 1px solid var(--line);
  background: rgba(4,10,24,.72);
}
.reply-panel .primary-btn { min-width: 132px; }
.empty-workspace {
  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: 360px minmax(0, 1fr); }
  .stat-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 840px) {
  .desk-shell {
    grid-template-columns: 1fr;
    min-height: 100vh;
  }
  .ticket-sidebar {
    min-height: auto;
    max-height: 50vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .ticket-workspace { min-height: 50vh; }
  .ticket-header { flex-direction: column; }
  .reply-panel { 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)); }
}