/* ---------- палитра ---------- */
:root {
  --bg: #0b0f14;
  --bg-2: #0f1620;
  --bg-3: #141d29;
  --line: #1e2a38;
  --line-2: #27364a;
  --fg: #d6e2f0;
  --fg-2: #8fa3ba;
  --fg-3: #5c6f85;
  --accent: #00e58a;
  --accent-2: #2dd4ff;
  --danger: #ff5c7a;
  --warn: #ffb547;
  --me: #0f2a21;
  --me-line: #15563f;
  --them: #141d29;
  --radius: 10px;
  --mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(1200px 600px at 10% -10%, rgba(0, 229, 138, .08), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(45, 212, 255, .07), transparent 60%);
  background-attachment: fixed;
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--fg-2); }
.center { text-align: center; }
.accent { color: var(--accent); }
.grow { flex: 1; min-width: 0; }
.inline { display: inline; }
[hidden] { display: none !important; }

/* ---------- бренд ---------- */
.brand {
  font-family: var(--mono);
  font-weight: 600;
  letter-spacing: .02em;
  display: flex; align-items: center; gap: .5em;
}
.brand .prompt { color: var(--accent); }
.brand.big { font-size: 48px; opacity: .3; justify-content: center; }
.brand .tag {
  font-size: 11px; font-weight: 500;
  padding: 2px 6px; border: 1px solid var(--line-2); border-radius: 4px; color: var(--fg-2);
}
.cursor {
  display: inline-block; width: .55em; height: 1.1em; background: var(--accent);
  animation: blink 1.1s steps(1) infinite; vertical-align: text-bottom;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- кнопки и инпуты ---------- */
.btn {
  font: inherit; cursor: pointer;
  padding: 10px 16px; border-radius: 8px;
  border: 1px solid var(--line-2); background: var(--bg-3); color: var(--fg);
  transition: .15s background, .15s border-color, .15s transform;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); color: #04140d; border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { background: #22ff9f; }
.btn-ghost { background: transparent; }
a.btn { display: inline-block; color: var(--fg); text-decoration: none; }
a.btn:hover { text-decoration: none; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }

input, textarea {
  font: inherit; color: var(--fg);
  background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 10px 12px; width: 100%; outline: none;
  transition: .15s border-color, .15s box-shadow;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0, 229, 138, .12); }
input::placeholder, textarea::placeholder { color: var(--fg-3); }
textarea { resize: none; line-height: 1.4; max-height: 160px; }

/* ---------- страницы входа ---------- */
.page-auth { display: flex; align-items: center; justify-content: center; min-height: 100%; padding: 20px; }
.auth-card {
  width: 100%; max-width: 420px;
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  border: 1px solid var(--line); border-radius: 14px; padding: 28px 28px 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
}
.auth-card h1 { margin: 18px 0 4px; font-size: 24px; font-weight: 600; }
.auth-card .muted { margin: 0 0 18px; font-family: var(--mono); font-size: 13px; }
.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 6px; font-size: 13px; color: var(--fg-2); }
.form .hint { color: var(--fg-3); font-size: 12px; }
.form .btn { margin-top: 6px; }
.captcha-row { display: flex; gap: 10px; align-items: center; }
.captcha-row img {
  height: 64px; width: 200px; border-radius: 8px; border: 1px solid var(--line-2);
  background: var(--bg); cursor: pointer; flex: none;
}
.captcha-input { font-family: var(--mono); letter-spacing: .2em; text-transform: lowercase; }
.alert {
  border: 1px solid rgba(255, 92, 122, .4); background: rgba(255, 92, 122, .08);
  color: #ffb3c1; padding: 10px 12px; border-radius: 8px; margin-bottom: 14px; font-size: 14px;
}
.alert.ok {
  border-color: rgba(0, 229, 138, .4); background: rgba(0, 229, 138, .08); color: #9df5cf;
}
.auth-card .center { margin: 18px 0 0; }

/* ---------- каркас приложения ---------- */
.shell { height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  height: 54px; flex: none;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; border-bottom: 1px solid var(--line);
  background: rgba(11, 15, 20, .85); backdrop-filter: blur(8px);
}
.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 13px; color: var(--fg-2); }
.topbar .who { font-family: var(--mono); color: var(--fg); }
.topbar .stat { font-family: var(--mono); }
.topbar .stat b { color: var(--fg); font-weight: 600; }
.status { display: flex; align-items: center; gap: 6px; }

.dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--fg-3); box-shadow: 0 0 0 0 transparent;
}
.dot.on { background: var(--accent); box-shadow: 0 0 10px var(--accent); }

/* ---------- чат ---------- */
.chat { flex: 1; min-height: 0; display: flex; flex-direction: column; width: 100%; }
.page-app .chat {
  max-width: 900px; margin: 0 auto;
  border-left: 1px solid var(--line); border-right: 1px solid var(--line);
  background: rgba(15, 22, 32, .35);
}
.chat-inner { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat-head {
  flex: none; display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
}
.chat-title { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.chat-sub { font-size: 12px; color: var(--fg-2); font-family: var(--mono); min-height: 16px; }
.chat-badge {
  font-family: var(--mono); font-size: 12px;
  padding: 3px 8px; border-radius: 6px; border: 1px solid var(--line-2); color: var(--fg-2);
}
.chat-badge.closed { color: var(--warn); border-color: rgba(255, 181, 71, .4); }
.chat-actions { display: flex; gap: 8px; }
.back { display: none; }

.messages {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 16px; display: flex; flex-direction: column; gap: 6px;
  scroll-behavior: smooth;
}
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 4px; }
.load-more { align-self: center; margin-bottom: 8px; }
.day-sep {
  align-self: center; font-family: var(--mono); font-size: 12px; color: var(--fg-3);
  padding: 4px 10px; margin: 6px 0;
}

.msg {
  max-width: min(78%, 640px); padding: 9px 12px 6px;
  border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--them); word-wrap: break-word; white-space: pre-wrap;
  animation: pop .15s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(4px); } }
.msg.me { align-self: flex-end; background: var(--me); border-color: var(--me-line); }
.msg.them { align-self: flex-start; }
.msg.system {
  align-self: center; background: transparent; border: 1px dashed var(--line-2);
  color: var(--fg-2); font-size: 13px; font-family: var(--mono); max-width: 90%;
}
.msg .meta {
  display: flex; justify-content: flex-end; gap: 6px; align-items: center;
  font-family: var(--mono); font-size: 11px; color: var(--fg-3); margin-top: 4px;
}
.msg.me .meta .ticks { color: var(--fg-3); }
.msg.me .meta .ticks.read { color: var(--accent); }
.msg .file {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; margin: 2px 0 4px; border-radius: 8px;
  background: rgba(0, 0, 0, .25); border: 1px solid var(--line);
  color: var(--fg); white-space: normal;
}
.msg .file:hover { border-color: var(--accent); text-decoration: none; }
.msg .file .fname { font-family: var(--mono); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .file .fsize { font-size: 11px; color: var(--fg-3); }
.msg img.preview { display: block; max-width: 100%; max-height: 320px; border-radius: 8px; margin: 2px 0 4px; cursor: zoom-in; }

.composer {
  flex: none; display: flex; gap: 10px; align-items: flex-end;
  padding: 12px 16px; border-top: 1px solid var(--line);
  background: rgba(15, 22, 32, .7);
}
.composer textarea { flex: 1; }
.attach {
  display: flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; border-radius: 8px; cursor: pointer; flex: none;
  border: 1px solid var(--line-2); color: var(--fg-2); background: var(--bg-3);
}
.attach:hover { color: var(--accent); border-color: var(--accent); }
.attach.busy { opacity: .5; pointer-events: none; }
.composer-error {
  font-family: var(--mono); font-size: 12px; color: var(--danger);
  padding: 0 16px; min-height: 18px; margin-bottom: 4px;
}

/* ---------- админ ---------- */
.admin-body { flex: 1; min-height: 0; display: flex; }
.sidebar {
  width: 340px; flex: none; display: flex; flex-direction: column;
  border-right: 1px solid var(--line); background: var(--bg-2);
}
.sidebar-tools { padding: 12px; display: grid; gap: 10px; border-bottom: 1px solid var(--line); }
.seg { display: flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.seg button {
  flex: 1; font: inherit; font-size: 12px; font-family: var(--mono);
  padding: 6px; background: transparent; color: var(--fg-2); border: 0; cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button.active { background: var(--bg-3); color: var(--accent); }

.conv-list { flex: 1; overflow-y: auto; }
.conv-list .empty { padding: 20px; font-family: var(--mono); font-size: 13px; }
.conv {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px;
  padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer;
  transition: background .12s;
}
.conv:hover { background: var(--bg-3); }
.conv.active { background: var(--bg-3); box-shadow: inset 3px 0 0 var(--accent); }
.conv .login { font-family: var(--mono); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.conv .login .dot { width: 7px; height: 7px; }
.conv .time { font-size: 11px; color: var(--fg-3); font-family: var(--mono); align-self: start; }
.conv .last { grid-column: 1; font-size: 13px; color: var(--fg-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .badge {
  grid-column: 2; justify-self: end;
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--accent); color: #04140d; font-size: 12px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; font-family: var(--mono);
}
.conv .flags { grid-column: 1 / -1; display: flex; gap: 6px; }
.conv .flag {
  font-size: 10px; font-family: var(--mono); padding: 1px 6px; border-radius: 4px;
  border: 1px solid var(--line-2); color: var(--fg-3); text-transform: uppercase;
}
.conv .flag.closed { color: var(--warn); border-color: rgba(255, 181, 71, .4); }
.conv .flag.blocked { color: var(--danger); border-color: rgba(255, 92, 122, .4); }

.chat-placeholder {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
}

/* ---------- мобильные ---------- */
@media (max-width: 760px) {
  .topbar { padding: 0 12px; }
  .topbar .stat, .topbar .who { display: none; }
  .msg { max-width: 88%; }
  .composer { padding: 10px 12px; }
  .composer .btn-primary { padding: 10px 12px; }
  .messages { padding: 12px; }

  .admin-body { position: relative; }
  .sidebar { width: 100%; border-right: 0; }
  .admin .chat { position: absolute; inset: 0; background: var(--bg); display: none; }
  .admin.chat-open .sidebar { display: none; }
  .admin.chat-open .chat { display: flex; }
  .back { display: inline-block; }
  .chat-actions .btn { padding: 6px 8px; font-size: 12px; }
}
