:root {
  --bg: #07070a;
  --card: #121218;
  --card2: #18181f;
  --red: #e11d2e;
  --red-dim: #8b1220;
  --purple: #7c3aed;
  --text: #ececf1;
  --muted: #8b8b9a;
  --line: #24242e;
  --ok: #22c55e;
  --warn: #f59e0b;
  --sidebar: 220px;
  --radius: 8px;
  --font: 'Outfit', system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; }
#app { min-height: 100vh; }

.layout { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, #0c0c12 0%, #09090e 100%);
  border-right: 1px solid var(--line);
  padding: 1.1rem 0.85rem;
  display: flex; flex-direction: column; gap: 1rem;
  position: sticky; top: 0; height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.35rem 0.5rem 0.85rem; border-bottom: 1px solid var(--line);
}
.brand-logo {
  width: 36px; height: 36px; border-radius: 10px; object-fit: cover;
  box-shadow: 0 0 22px color-mix(in srgb, var(--purple) 35%, transparent);
}
.brand strong { display: block; font-size: 0.92rem; letter-spacing: 0.04em; }
.brand span { color: var(--muted); font-size: 0.75rem; }
.gate-brand { margin-bottom: 1rem; }
.gate-brand .brand { border: 0; padding: 0; }
.gate-card code { font-size: 0.78rem; color: #c4b5fd; }
.nav { display: flex; flex-direction: column; gap: 0.25rem; flex: 1; }
.nav button {
  appearance: none; border: 0; background: transparent; text-align: left;
  padding: 0.55rem 0.7rem; border-radius: 6px; color: var(--muted); cursor: pointer;
}
.nav button:hover { background: var(--card2); color: var(--text); }
.nav button.active { background: color-mix(in srgb, var(--red) 18%, transparent); color: #fff; border-left: 2px solid var(--red); }
.user-chip { font-size: 0.78rem; color: var(--muted); padding: 0.5rem; border-top: 1px solid var(--line); }
.main { padding: 1.15rem 1.35rem 2rem; max-width: 1100px; }

.gate {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background:
    radial-gradient(ellipse 60% 40% at 50% -10%, color-mix(in srgb, var(--red) 22%, transparent), transparent),
    var(--bg);
}
.gate-card {
  width: min(380px, 100%); background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 1.5rem; box-shadow: 0 20px 50px rgba(0,0,0,.45);
}
.gate-card h1 { margin: 0 0 0.35rem; font-size: 1.35rem; }
.gate-card p { margin: 0 0 1rem; color: var(--muted); font-size: 0.9rem; }

.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem 1.1rem; margin-bottom: 1rem;
}
.panel h2 { margin: 0 0 0.75rem; font-size: 1.05rem; font-weight: 600; }
.panel h3 { margin: 0 0 0.6rem; font-size: 0.95rem; color: var(--muted); font-weight: 500; }
.muted { color: var(--muted); }
.fine { font-size: 0.8rem; color: var(--muted); }
.error-line { color: #f87171; }

.toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 0.85rem; }
.split { display: grid; grid-template-columns: minmax(240px, 320px) 1fr; gap: 0.85rem; min-height: 420px; }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .split { grid-template-columns: 1fr; }
}

.ticket-list, .msg-list, .user-list, .code-list { display: flex; flex-direction: column; gap: 0.4rem; max-height: 70vh; overflow: auto; }
.ticket-item, .msg-item, .user-card, .code-row {
  background: var(--card2); border: 1px solid var(--line); border-radius: 6px;
  padding: 0.65rem 0.75rem; cursor: pointer;
}
.ticket-item:hover, .msg-item:hover { border-color: #333342; }
.ticket-item.active { border-color: var(--red); box-shadow: inset 3px 0 0 var(--red); }
.ticket-item .subj { font-weight: 600; font-size: 0.92rem; }
.ticket-item .meta, .msg-item .meta { font-size: 0.75rem; color: var(--muted); margin-top: 0.2rem; }
.msg-item.unread { border-color: color-mix(in srgb, var(--warn) 50%, var(--line)); }
.msg-item p { margin: 0.4rem 0; white-space: pre-wrap; word-break: break-word; }
.user-card { cursor: default; }
.user-card form { display: grid; gap: 0.45rem; margin-top: 0.55rem; }
.user-card .row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.45rem; }

.thread { display: flex; flex-direction: column; gap: 0.55rem; min-height: 280px; max-height: 52vh; overflow: auto; padding: 0.4rem; background: #0a0a0e; border-radius: 6px; border: 1px solid var(--line); }
.bubble { max-width: 85%; padding: 0.55rem 0.7rem; border-radius: 8px; background: var(--card2); border: 1px solid var(--line); }
.bubble.admin { align-self: flex-end; background: color-mix(in srgb, var(--red) 14%, var(--card)); border-color: var(--red-dim); }
.bubble .who { font-size: 0.72rem; color: var(--muted); margin-bottom: 0.2rem; }
.bubble .body { white-space: pre-wrap; word-break: break-word; }

.badge {
  display: inline-block; font-size: 0.68rem; font-weight: 600; letter-spacing: 0.03em;
  text-transform: uppercase; padding: 0.12rem 0.4rem; border-radius: 4px; vertical-align: middle;
}
.badge-mcbot { background: color-mix(in srgb, var(--red) 25%, transparent); color: #ff8a95; }
.badge-turkbot { background: color-mix(in srgb, var(--purple) 28%, transparent); color: #c4b5fd; }
.badge-plugin { background: color-mix(in srgb, #0ea5e9 25%, transparent); color: #7dd3fc; }
.status {
  display: inline-block; font-size: 0.7rem; padding: 0.1rem 0.35rem; border-radius: 4px;
  background: #1f1f28; color: var(--muted);
}
.status-open { color: #86efac; background: #14532d44; }
.status-answered { color: #fde68a; background: #78350f44; }
.status-closed { color: var(--muted); }

form.stack { display: grid; gap: 0.55rem; }
label { display: grid; gap: 0.25rem; font-size: 0.82rem; color: var(--muted); }
input, select, textarea {
  background: #0b0b10; border: 1px solid var(--line); border-radius: 6px;
  padding: 0.5rem 0.6rem; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--red-dim); }
textarea { min-height: 72px; resize: vertical; }
.chk { display: flex; align-items: center; gap: 0.45rem; color: var(--text); font-size: 0.88rem; }
.chk input { width: auto; }
.actions { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin-top: 0.35rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.55rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.55rem; }
@media (max-width: 700px) { .grid-3, .grid-2, .user-card .row-2 { grid-template-columns: 1fr; } }

button.btn, .actions button, form button {
  appearance: none; border: 0; border-radius: 6px; padding: 0.45rem 0.85rem;
  background: var(--red); color: #fff; font-weight: 600; cursor: pointer;
}
button.btn:hover, .actions button:hover, form button:hover { filter: brightness(1.08); }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); font-weight: 500; }
button.danger { background: #3f1218; color: #fda4af; }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.empty { padding: 1.5rem; text-align: center; color: var(--muted); }

.dropzone {
  border: 1px dashed #3a3a48;
  border-radius: 10px;
  padding: 1.1rem;
  text-align: center;
  background: #0b0b10;
  display: grid;
  gap: 0.35rem;
  justify-items: center;
}
.dropzone strong { color: var(--text); }
.dropzone span { color: var(--muted); font-size: 0.82rem; }
.img-drafts { display: grid; gap: 0.65rem; }
.img-draft {
  display: grid;
  grid-template-columns: 88px 1fr auto;
  gap: 0.65rem;
  align-items: center;
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem;
}
.img-draft img {
  width: 88px; height: 64px; object-fit: cover; border-radius: 6px; background: #000;
}
@media (max-width: 700px) {
  .img-draft { grid-template-columns: 1fr; }
}

.toast {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 50;
  background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--ok);
  padding: 0.7rem 0.95rem; border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.4);
  max-width: min(360px, calc(100vw - 2rem)); animation: toast-in .2s ease;
}
.toast.err { border-left-color: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
