:root {
  --bg: #1e1f22;
  --bg-2: #2b2d31;
  --bg-3: #313338;
  --bg-hover: #393c41;
  --text: #dbdee1;
  --text-muted: #949ba4;
  --brand: #5865f2;
  --green: #23a55a;
  --red: #f23f43;
  --yellow: #f0b232;
  --border: #1f2023;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "gg sans", system-ui, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-3);
  color: var(--text);
  font-size: 15px;
}
.hidden { display: none !important; }
.muted { color: var(--text-muted); font-size: 13px; }

/* ---------- Login ---------- */
.login-body { display: grid; place-items: center; height: 100vh; background: var(--bg); }
.login-card {
  background: var(--bg-2);
  padding: 40px;
  border-radius: 14px;
  text-align: center;
  max-width: 420px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}
.login-logo { font-size: 52px; }
.login-card h1 { margin: 8px 0 6px; }
.discord-btn {
  display: inline-flex; align-items: center; gap: 10px;
  margin-top: 22px; background: var(--brand); color: #fff;
  text-decoration: none; padding: 12px 22px; border-radius: 8px; font-weight: 600;
}
.discord-btn:hover { background: #4752c4; }

/* ---------- Topbar ---------- */
.topbar {
  height: 52px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: var(--bg); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; }
.brand span { vertical-align: middle; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.me-name { font-weight: 600; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--bg-3); }
.conn { color: var(--text-muted); font-size: 12px; }
.conn.online { color: var(--green); }
.conn.offline { color: var(--red); }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 52px); }
.sidebar { background: var(--bg-2); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.content { display: flex; flex-direction: column; min-height: 0; }

/* ---------- Filters ---------- */
.filters { padding: 12px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--border); }
.input {
  width: 100%; padding: 8px 10px; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; outline: none;
}
.input:focus { border-color: var(--brand); }
.pill-row { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  border: none; background: var(--bg-3); color: var(--text-muted);
  padding: 5px 11px; border-radius: 999px; cursor: pointer; font-size: 13px;
}
.pill:hover { background: var(--bg-hover); color: var(--text); }
.pill.active { background: var(--brand); color: #fff; }

/* ---------- Ticket list ---------- */
.ticket-list { overflow-y: auto; flex: 1; min-height: 0; }
.ticket-item {
  padding: 11px 14px; border-bottom: 1px solid var(--border); cursor: pointer; display: flex; flex-direction: column; gap: 3px;
}
.ticket-item:hover { background: var(--bg-3); }
.ticket-item.selected { background: var(--bg-hover); box-shadow: inset 3px 0 0 var(--brand); }
.ticket-item .row1 { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.ticket-item .num { font-weight: 700; }
.ticket-item .subject { font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ticket-item .preview { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Badges / chips ---------- */
.badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: .03em; }
.badge.open { background: rgba(35,165,90,.18); color: #4ed684; }
.badge.claimed { background: rgba(240,178,50,.18); color: #f0b232; }
.badge.closed { background: rgba(148,155,164,.18); color: #b5bac1; }
.badge.deleted { background: rgba(242,63,67,.18); color: #f98a8c; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--bg-3); color: var(--text-muted); }

/* ---------- Ticket view ---------- */
.empty { flex: 1; display: grid; place-items: center; color: var(--text-muted); }
.empty-icon { font-size: 48px; text-align: center; }
.ticket-view { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.ticket-header {
  padding: 12px 18px; border-bottom: 1px solid var(--border); display: flex;
  justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--bg);
}
.ticket-title h2 { margin: 0 0 4px; font-size: 17px; }
.ticket-sub { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ticket-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.assign { width: auto; min-width: 150px; padding: 6px 8px; }

/* ---------- Messages ---------- */
.messages { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.msg { display: flex; gap: 12px; }
.msg .m-avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--bg-2); flex-shrink: 0; }
.msg .m-body { min-width: 0; }
.msg .m-head { display: flex; align-items: baseline; gap: 8px; }
.msg .m-name { font-weight: 600; }
.msg.staff .m-name { color: #8b9bff; }
.msg .m-time { font-size: 11px; color: var(--text-muted); }
.msg .m-text { white-space: pre-wrap; word-break: break-word; margin-top: 2px; }
.msg .m-attach a { color: #00a8fc; font-size: 13px; display: inline-block; margin-top: 4px; }
.msg .m-img { display: inline-block; margin-top: 6px; }
.msg .m-img img { max-width: 320px; max-height: 260px; border-radius: 8px; display: block; }
.reply-icon { font-size: 18px; padding: 8px 10px; }
.translate-btn {
  margin-top: 4px; font-size: 12px; background: none; border: none; color: var(--text-muted);
  cursor: pointer; padding: 0; text-decoration: underline dotted;
}
.translate-btn:hover { color: var(--brand); }
.translation {
  margin-top: 6px; padding: 8px 10px; border-left: 3px solid var(--brand);
  background: var(--bg-2); border-radius: 0 6px 6px 0; font-size: 14px;
}
.translation .t-meta { font-size: 11px; color: var(--text-muted); margin-bottom: 3px; }

/* system event lines (close / claim / assign / delete) */
.msg-system { text-align: center; color: var(--text-muted); font-size: 12px; margin: 2px 0; }
.msg-system .sys-text { background: var(--bg-2); padding: 3px 12px; border-radius: 999px; }
.msg-system .sys-time { font-size: 10px; opacity: .65; margin-left: 4px; }

/* ---------- Reply bar ---------- */
.reply-bar { display: flex; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--border); background: var(--bg); align-items: flex-end; }
.reply-input {
  flex: 1; resize: none; max-height: 160px; padding: 10px 12px; border-radius: 8px;
  background: var(--bg-3); color: var(--text); border: 1px solid var(--border); outline: none; font-family: inherit; font-size: 15px;
}
.reply-input:focus { border-color: var(--brand); }
.reply-bar.disabled { opacity: .5; pointer-events: none; }
.staged-file {
  display: flex; align-items: center; gap: 8px; margin: 0 18px; padding: 6px 10px;
  background: var(--bg-2); border: 1px solid var(--brand); border-radius: 8px 8px 0 0;
  font-size: 13px; color: var(--text);
}
.staged-file button { margin-left: auto; background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 13px; }
.staged-file button:hover { color: var(--red); }

/* ---------- AI tools ---------- */
.ai-tools { display: flex; align-items: center; gap: 8px; padding: 6px 18px 0; flex-wrap: wrap; }
.btn-ai { background: linear-gradient(135deg, #5865f2, #8b5cf6); color: #fff; font-size: 13px; padding: 6px 12px; }
.btn-ai:hover { filter: brightness(1.1); }
.lang-indicator { font-size: 12px; color: var(--text-muted); }
.rewrite-preview {
  margin: 8px 18px 0; padding: 10px 12px; background: var(--bg-2);
  border: 1px solid var(--brand); border-radius: 8px;
}
.rewrite-preview .rp-head { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin-bottom: 6px; }
.rewrite-preview .rp-text { white-space: pre-wrap; word-break: break-word; font-size: 14px; margin-bottom: 8px; }
.rewrite-preview .rp-actions { display: flex; gap: 8px; }

/* ---------- Settings modal ---------- */
.settings-body { display: flex; flex-direction: column; gap: 6px; }
.s-label { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.s-row { display: flex; gap: 8px; }
.s-row .input { flex: 1; }
.s-check { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 14px; }
.s-actions { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.u-lang-row { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.u-lang-row .input { width: auto; min-width: 160px; }

/* ---------- Departments manager ---------- */
.s-sep { border: none; border-top: 1px solid var(--border); margin: 18px 0 12px; }
.s-head { margin: 0 0 4px; font-size: 14px; }
.dept-note { font-size: 12px; margin: 0 0 10px; }
.dept-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.dept-row { display: flex; gap: 6px; align-items: center; }
.dept-emoji { width: 54px; text-align: center; flex: 0 0 auto; }
.dept-row .d-label { flex: 1; min-width: 80px; }
.dept-row .d-desc { flex: 1.4; min-width: 80px; }
.dept-row .btn { padding: 7px 9px; }
.dept-add { display: flex; gap: 6px; margin-top: 6px; }
.dept-add .input { flex: 1; }
.dept-desc-add { margin-top: 6px; }

/* ---------- Buttons ---------- */
.btn {
  border: none; background: var(--bg-hover); color: var(--text); padding: 8px 13px;
  border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 500;
}
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--bg); color: var(--text); padding: 10px 16px; border-radius: 8px;
  border: 1px solid var(--border); box-shadow: 0 6px 24px rgba(0,0,0,.4); z-index: 50; font-size: 14px;
}
.toast.err { border-color: var(--red); }

/* clickable user names */
.m-name.clickable, .user-link { cursor: pointer; }
.m-name.clickable:hover, .user-link:hover { text-decoration: underline; }

/* ---------- User profile modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 100;
}
.modal-card {
  background: var(--bg-2); width: min(560px, 94vw); max-height: 86vh; border-radius: 12px;
  display: flex; flex-direction: column; box-shadow: 0 12px 50px rgba(0,0,0,.5); overflow: hidden;
}
.modal-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head .u-id { flex: 1; min-width: 0; }
.modal-head h3 { margin: 0; font-size: 17px; }
.avatar-lg { width: 44px; height: 44px; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-body h4 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }

.note-form { display: flex; gap: 8px; margin-bottom: 10px; }
.notes-list { display: flex; flex-direction: column; gap: 8px; }
.note {
  background: var(--bg-3); border-radius: 8px; padding: 8px 10px; font-size: 14px;
  border-left: 3px solid var(--yellow);
}
.note .note-meta { font-size: 11px; color: var(--text-muted); display: flex; justify-content: space-between; gap: 8px; margin-bottom: 3px; }
.note .note-del { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 12px; }
.note .note-del:hover { color: var(--red); }
.note-text { white-space: pre-wrap; word-break: break-word; }
.empty-note { color: var(--text-muted); font-size: 13px; padding: 4px 0; }

.user-tickets { display: flex; flex-direction: column; gap: 6px; }
.uticket {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--bg-3);
  border-radius: 8px; cursor: pointer;
}
.uticket:hover { background: var(--bg-hover); }
.uticket .ut-subj { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- per-message delete (admin) ---------- */
.msg { position: relative; }
.msg-del-btn {
  position: absolute; top: 0; right: 0; background: var(--bg-2); border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer; border-radius: 6px; font-size: 12px; padding: 2px 6px;
  opacity: 0; transition: opacity .1s;
}
.msg:hover .msg-del-btn { opacity: 1; }
.msg-del-btn:hover { color: var(--red); }

/* ---------- Setup overlay ---------- */
.setup-overlay {
  position: fixed; inset: 0; background: var(--bg); display: grid; place-items: center; z-index: 200; padding: 20px;
}
.setup-card {
  background: var(--bg-2); border-radius: 14px; padding: 32px 36px; max-width: 480px; text-align: center;
  box-shadow: 0 12px 50px rgba(0,0,0,.5);
}
.setup-card h2 { margin: 10px 0 6px; }
.setup-cmd {
  display: inline-block; font-family: monospace; font-size: 20px; background: var(--bg);
  padding: 8px 18px; border-radius: 8px; margin: 12px 0; color: #8b9bff; border: 1px solid var(--border);
}
.setup-steps { text-align: left; margin: 14px auto; max-width: 380px; color: var(--text); line-height: 1.7; }
.setup-steps code { background: var(--bg); padding: 1px 6px; border-radius: 4px; }
.setup-spinner {
  width: 42px; height: 42px; border: 4px solid var(--bg-3); border-top-color: var(--brand);
  border-radius: 50%; margin: 0 auto; animation: spin 0.9s linear infinite;
}
.waiting { color: var(--text-muted); font-size: 14px; margin-top: 16px; }
.waiting .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--green); margin-right: 6px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%,100% { opacity: .3; } 50% { opacity: 1; } }

/* ---------- Mobile ---------- */
.mobile-only { display: none; }
@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: flex; border-right: none; }
  .content { display: none; }
  body.viewing .sidebar { display: none; }
  body.viewing .content { display: flex; }
  .mobile-only { display: inline-flex; }
  .me-name { display: none; }
  .brand span { display: none; }
  .ticket-header { gap: 8px; padding: 10px 12px; }
  .ticket-title h2 { font-size: 15px; }
  .ticket-controls { gap: 6px; }
  .assign { min-width: 110px; }
  .messages { padding: 12px; }
  .reply-bar { padding: 10px 12px; }
  .modal-card { width: 96vw; max-height: 90vh; }
  .sidebar .filters { padding: 10px; }
}

/* scrollbars */
::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-thumb { background: #202225; border-radius: 6px; }
