:root {
  --bg: #0e0f12;
  --bg-2: #16181d;
  --bg-3: #1d2026;
  --bg-hover: #232730;
  --border: #262a33;
  --text: #e6e8ec;
  --text-dim: #9097a3;
  --text-faint: #5a616e;
  --accent: #6aa9ff;
  --accent-2: #8a7dff;
  --danger: #ff6a6a;
  --good: #4ade80;
  --radius: 0;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", system-ui, sans-serif;
  --mono: "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { height: 100%; overflow: hidden; }
body {
  position: fixed; inset: 0; margin: 0; overflow: hidden;
}
.app {
  position: fixed;
  top: var(--vv-y, 0);
  left: var(--vv-x, 0);
  width: var(--vv-w, 100%);
  height: var(--vv-h, 100%);
}
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { cursor: pointer; font-family: inherit; }
input, textarea, button { font-family: inherit; font-size: 14px; }

/* ---- auth ---- */
.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at top, #1a1d26 0%, var(--bg) 60%);
}
.auth-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 28px;
  width: 360px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.4);
}
.auth-card h1 {
  margin: 0 0 20px;
  font-size: 22px;
  letter-spacing: 0.5px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tabs { display: flex; gap: 4px; margin-bottom: 16px; }
.tab {
  flex: 1; padding: 8px; background: transparent;
  color: var(--text-dim); border: 1px solid var(--border);
  border-radius: 0;
}
.tab.active { background: var(--bg-3); color: var(--text); border-color: var(--accent); }
.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-form input {
  padding: 10px 12px; background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 0; color: var(--text); outline: none;
}
.auth-form input:focus { border-color: var(--accent); }
.auth-form button {
  margin-top: 6px; padding: 10px 12px;
  background: var(--accent); color: #0a0c10; border: none;
  border-radius: 0; font-weight: 600;
}
.auth-form button:hover { filter: brightness(1.08); }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 10px 0 0; }
.hint { color: var(--text-dim); font-size: 12px; margin: 4px 0 0; }

/* ---- app ---- */
.app { display: grid; grid-template-columns: 240px 1fr; }
.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.brand {
  font-weight: 700; letter-spacing: 0.4px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
#logout-btn {
  background: transparent; border: none; color: var(--text-dim);
  font-size: 16px; padding: 4px 8px; border-radius: 0;
}
#logout-btn:hover { color: var(--danger); background: var(--bg-hover); }

.section { padding: 12px 8px; flex-shrink: 0; }
.section-title {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px 6px; color: var(--text-faint);
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.8px;
}
.add-btn {
  background: transparent; border: none; color: var(--text-faint);
  font-size: 16px; line-height: 1; padding: 0 4px; border-radius: 0;
}
.add-btn:hover { color: var(--text); background: var(--bg-hover); }
.list { list-style: none; padding: 0; margin: 0; }
.list li {
  padding: 6px 10px; border-radius: 0; cursor: pointer;
  color: var(--text-dim); display: flex; align-items: center; gap: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.list li:hover { background: var(--bg-hover); color: var(--text); }
.list li.active { background: var(--bg-3); color: var(--text); }
.list li .prefix { color: var(--text-faint); }
.list.small li { font-family: var(--mono); font-size: 12px; padding: 4px 8px; }
.list.small li.used { color: var(--text-faint); text-decoration: line-through; }

.me {
  margin-top: auto; padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-dim);
  display: flex; align-items: center; gap: 8px;
}
.me .dot { width: 8px; height: 8px; background: var(--good); border-radius: 0; }
.admin-section { border-top: 1px solid var(--border); padding-top: 10px; max-height: 200px; overflow-y: auto; }

/* ---- main ---- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; position: relative; }
.main-header {
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 600;
}
.conn { font-size: 10px; color: var(--good); }
.conn.bad { color: var(--danger); }

.messages {
  flex: 1; min-height: 0; overflow-y: auto; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 2px;
}
.msg {
  padding: 4px 0; display: grid;
  grid-template-columns: 44px 1fr; gap: 6px;
}
.msg-grouped { padding: 1px 0; }
.msg-grouped .msg-meta { color: transparent; }
.msg-grouped:hover .msg-meta { color: var(--text-faint); }
.msg-meta { color: var(--text-faint); font-size: 11px; padding-top: 4px; text-align: right; font-variant-numeric: tabular-nums; }
.msg-body { min-width: 0; }
.msg-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 1px; }
.msg-author { font-weight: 600; color: var(--text); }
.msg-time { font-size: 11px; color: var(--text-faint); }
.msg-content { white-space: pre-wrap; word-wrap: break-word; }
.msg-content a { color: var(--accent); }
.day-divider {
  text-align: center; color: var(--text-faint); font-size: 11px;
  margin: 14px 0 6px; position: relative;
}
.day-divider::before, .day-divider::after {
  content: ''; position: absolute; top: 50%;
  width: 40%; height: 1px; background: var(--border);
}
.day-divider::before { left: 0; }
.day-divider::after { right: 0; }

.composer-wrap {
  border-top: 1px solid var(--border);
  padding: 6px 0;
  background: var(--bg-3);
}
.composer-wrap:focus-within { border-top-color: var(--accent); }
.composer {
  display: flex; align-items: stretch;
  background: var(--bg-3); border: none;
}
.composer textarea {
  flex: 1; min-width: 0;
  resize: none; padding: 14px 12px;
  background: var(--bg); color: var(--text);
  border: none; outline: none;
  min-height: 48px; max-height: 200px; line-height: 1.4;
  font-family: inherit;
}
.attach-btn {
  width: 42px; padding: 0;
  background: transparent; border: none; color: var(--text-dim);
  font-size: 20px; line-height: 1;
  flex-shrink: 0;
}
.attach-btn:hover { color: var(--text); background: var(--bg-hover); }
.composer button[type="submit"] {
  padding: 0 18px;
  background: transparent; color: var(--accent);
  border: none; font-weight: 600;
  flex-shrink: 0;
}
.composer button[type="submit"]:hover { background: var(--bg-hover); }
.composer button[type="submit"]:disabled { opacity: 0.4; cursor: not-allowed; }

.staged {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 0;
}
.staged:not(:empty) { padding: 6px 8px; }
.staged-item {
  position: relative; background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 0; padding: 6px 28px 6px 8px;
  font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 6px;
  max-width: 260px;
}
.staged-item img {
  width: 32px; height: 32px; object-fit: cover; border-radius: 0;
}
.staged-item .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.staged-item .remove {
  position: absolute; top: 2px; right: 4px;
  background: transparent; border: none; color: var(--text-faint);
  cursor: pointer; font-size: 14px; padding: 2px 4px;
}
.staged-item .remove:hover { color: var(--danger); }
.staged-item.uploading { opacity: 0.6; }

.attachments {
  margin-top: 6px; display: flex; flex-direction: column; gap: 6px;
}
.attachments img, .attachments video {
  max-width: 420px; max-height: 360px; border-radius: 0; cursor: zoom-in;
  background: var(--bg-3); display: block;
}
.attachments video { cursor: default; }
.attachments audio { width: 360px; max-width: 100%; }
.attachments a.file {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 0; color: var(--text); text-decoration: none;
  max-width: 360px;
}
.attachments a.file:hover { border-color: var(--accent); }
.attachments a.file .fname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attachments a.file .fsize { color: var(--text-faint); font-size: 11px; flex-shrink: 0; }

.drop-overlay {
  position: absolute; inset: 60px 0 100px 240px;
  background: rgba(106, 169, 255, 0.08);
  border: 2px dashed var(--accent);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent); font-size: 18px; pointer-events: none;
  z-index: 10;
}

/* ---- modal ---- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: grid; place-items: center; z-index: 50;
}
.modal-card {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 0; padding: 22px; min-width: 320px; max-width: 420px;
}
.modal-card h3 { margin: 0 0 14px; }
.modal-card input, .modal-card select {
  width: 100%; padding: 9px 11px; background: var(--bg-3);
  border: 1px solid var(--border); border-radius: 0;
  color: var(--text); outline: none;
}
.modal-card input:focus, .modal-card select:focus { border-color: var(--accent); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal-actions button {
  padding: 8px 14px; border-radius: 0; border: none;
  background: var(--accent); color: #0a0c10; font-weight: 600;
}
.modal-actions .ghost {
  background: transparent; color: var(--text-dim); border: 1px solid var(--border);
}
.code-display {
  font-family: var(--mono); background: var(--bg-3);
  padding: 10px; border-radius: 0; border: 1px solid var(--border);
  word-break: break-all; user-select: all;
}

/* scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 0; }
::-webkit-scrollbar-thumb:hover { background: var(--bg-hover); }

@media (max-width: 700px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}
