:root {
  --bg: #0f1420;
  --panel: #171d2b;
  --panel-2: #1e2536;
  --line: #2a3346;
  --text: #e6ebf5;
  --muted: #8a94a8;
  --accent: #4c8dff;
  --accent-2: #2f6fe0;
  --user: #223049;
  --op: #1f3d2e;
  --warn: #f0b429;
  --tg: #29a0da;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
.muted { color: var(--muted); font-size: 13px; }
button { cursor: pointer; font: inherit; }
a { color: var(--accent); }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; }
.login-card {
  width: 340px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 28px 24px; display: flex; flex-direction: column; gap: 12px; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.login-card h1 { margin: 0; font-size: 22px; }
.tg-btn {
  display: inline-block; background: var(--tg); color: #fff; border: 0; border-radius: 10px;
  padding: 12px; font-weight: 600; text-decoration: none;
}
.tg-btn:hover { filter: brightness(1.08); }
.hint { margin-top: 8px; }
.error { color: #ff6b6b; font-size: 13px; min-height: 16px; }

/* ---------- topbar ---------- */
.topbar { display: flex; align-items: center; gap: 18px; padding: 12px 18px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.badge { background: var(--warn); color: #1a1200; font-size: 12px; font-weight: 700; border-radius: 20px; padding: 1px 8px; min-width: 20px; text-align: center; }
.tabs { display: flex; gap: 6px; }
.tabs button { background: transparent; color: var(--muted); border: 1px solid transparent; padding: 6px 12px; border-radius: 8px; }
.tabs button.active { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.me { margin-left: auto; color: var(--muted); font-size: 13px; }
.logout { background: transparent; color: var(--muted); border: 1px solid var(--line); padding: 6px 12px; border-radius: 8px; }
.logout:hover { color: var(--text); }

/* ---------- tickets layout ---------- */
.layout { display: grid; grid-template-columns: 340px 1fr; height: calc(100vh - 57px); }
.sidebar { border-right: 1px solid var(--line); display: flex; flex-direction: column; background: var(--panel); min-height: 0; }
.filters { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line); }
.filters button { flex: 1; background: transparent; color: var(--muted); border: 1px solid var(--line); padding: 6px; border-radius: 8px; }
.filters button.active { background: var(--panel-2); color: var(--text); }
.list { overflow-y: auto; flex: 1; }

.ticket { padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.ticket:hover { background: var(--panel-2); }
.ticket.selected { background: var(--panel-2); box-shadow: inset 3px 0 0 var(--accent); }
.ticket.waiting .ticket-name::after { content: "●"; color: var(--warn); font-size: 10px; margin-left: 6px; vertical-align: middle; }
.ticket-top { display: flex; justify-content: space-between; align-items: baseline; }
.ticket-name { font-weight: 600; }
.ticket-id { color: var(--muted); font-size: 12px; }
.ticket-last { color: var(--muted); font-size: 13px; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ticket-time { color: var(--muted); font-size: 11px; margin-top: 3px; }
.chip { display: inline-block; font-size: 11px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); border-radius: 20px; padding: 1px 9px; margin-top: 5px; }

/* ---------- thread ---------- */
.thread { position: relative; display: flex; flex-direction: column; min-height: 0; }
.empty { margin: auto; color: var(--muted); }
.thread-inner { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.thread-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.thread-name { font-weight: 700; font-size: 16px; }
.thread-actions button { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 7px 14px; }
.thread-actions button:hover { border-color: var(--accent); }
.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 72%; padding: 9px 13px; border-radius: 12px; }
.msg-text { white-space: pre-wrap; word-wrap: break-word; }
.msg-meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.from-user { align-self: flex-start; background: var(--user); border-bottom-left-radius: 4px; }
.from-op { align-self: flex-end; background: var(--op); border-bottom-right-radius: 4px; }
.reply { display: flex; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--panel); }
.reply textarea { flex: 1; resize: none; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 10px 12px; font: inherit; outline: none; }
.reply textarea:focus { border-color: var(--accent); }
.reply button { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 0 22px; font-weight: 600; }
.reply button:hover { background: var(--accent-2); }

/* ---------- pages (admins / cats) ---------- */
.page { padding: 22px 26px; max-width: 900px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.page-head h2 { margin: 0; }
.primary { background: var(--accent); color: #fff; border: 0; border-radius: 9px; padding: 9px 16px; font-weight: 600; }
.primary:hover { background: var(--accent-2); }
.inline-form { display: flex; gap: 8px; }
.inline-form input { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 9px; padding: 9px 12px; outline: none; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.card.off { opacity: .55; }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.tag { font-size: 11px; background: var(--accent); color: #fff; border-radius: 20px; padding: 1px 9px; }
.muted-tag { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.scope { font-size: 13px; color: var(--muted); margin-top: 8px; }
.card-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.card-actions button { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; font-size: 13px; }
.card-actions button:hover { border-color: var(--accent); }

.invite-result { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; margin-bottom: 16px; word-break: break-all; }
.invite-result .copy { margin-left: 10px; background: var(--accent); color: #fff; border: 0; border-radius: 7px; padding: 5px 12px; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 20; }
.modal-card { width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px; }
.modal-card h3 { margin: 0 0 14px; }
.row { display: flex; align-items: center; gap: 8px; padding: 5px 0; }
.cat-picker { max-height: 240px; overflow-y: auto; border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; margin: 8px 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.modal-actions button { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 9px; padding: 9px 16px; }
.modal-actions .primary { background: var(--accent); border: 0; }
