/* ============================================================
   MepxDev Chat — "Engineered" theme
   Tokens, type scale and component language mirror mepxdev.com:
   editor-dark, monospace-first, restrained. Syne is display-only.
   ============================================================ */

:root {
  --bg: #0A0C10;
  --bg-2: #0D1117;
  --surface: #11161F;
  --panel: #0F141C;
  --border: #1C2430;
  --border-light: #2A3543;

  --text: #E6EDF3;
  --muted: #8B949E;
  --muted-dim: #6E7681;

  --accent: #22D3EE;
  --accent-2: #A78BFA;
  --green: #4ADE80;
  --amber: #FBBF24;
  --red: #F87171;

  --font-display: 'Syne', system-ui, sans-serif;
  --font-mono: 'DM Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --ease: cubic-bezier(.4, 0, .2, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
}

/* ---------- RESET ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-weight: 300;
  font-size: 13.5px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

button { font-family: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, textarea { font-family: inherit; color: inherit; }
ul { list-style: none; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
::selection { background: rgba(34, 211, 238, .26); color: #fff; }

::-webkit-scrollbar { width: 10px; }
::-webkit-scrollbar-track { background: var(--bg-2); }
::-webkit-scrollbar-thumb { background: var(--border-light); border: 2px solid var(--bg-2); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #3A4759; }

kbd {
  font-family: inherit;
  font-size: 10.5px;
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--panel);
  color: var(--muted-dim);
}

/* ---------- ATMOSPHERE — deliberately quiet ---------- */
.grain {
  position: fixed; inset: 0; z-index: 250; pointer-events: none;
  opacity: .03; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 160px 160px;
}
.aurora { position: absolute; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.blob { position: absolute; display: block; border-radius: 50%; filter: blur(100px); opacity: .26; }
.blob-1 { width: 46vw; height: 46vw; top: -14vw; left: -10vw; background: radial-gradient(circle, rgba(34, 211, 238, .22), transparent 68%); animation: drift1 34s var(--ease) infinite alternate; }
.blob-2 { width: 42vw; height: 42vw; bottom: -16vw; right: -12vw; background: radial-gradient(circle, rgba(167, 139, 250, .20), transparent 68%); animation: drift2 42s var(--ease) infinite alternate; }
@keyframes drift1 { to { transform: translate3d(8vw, 6vh, 0) scale(1.14); } }
@keyframes drift2 { to { transform: translate3d(-10vw, -8vh, 0) scale(.9); } }

/* ---------- VIEW SWITCHING ---------- */
#boot, #gate, #app { display: none; }
body[data-view="loading"] #boot { display: grid; }
body[data-view="gate"] #gate { display: flex; }
body[data-view="chat"] #app { display: grid; }

.boot { place-items: center; height: 100%; }
.boot-log { font-size: 12.5px; color: var(--muted-dim); letter-spacing: .04em; }
.caret { display: inline-block; width: 7px; height: 14px; margin-left: 4px; background: var(--accent); vertical-align: -2px; animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- SHARED ---------- */
.nl-prompt { color: var(--accent); }
.nl-dim { color: var(--muted-dim); }

.accent {
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted-dim);
  display: inline-block; flex: none;
}
.dot.is-online { background: var(--green); box-shadow: 0 0 8px var(--green); animation: pulse 2.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  background: var(--accent); color: #04141A; border: 1px solid var(--accent);
  font-size: 12.5px; font-weight: 500; letter-spacing: .04em;
  padding: 13px 24px; border-radius: 6px;
  transition: background .2s, box-shadow .25s, transform .2s var(--ease-out), opacity .2s;
}
.btn-primary:hover:not(:disabled) { background: #67E8F9; box-shadow: 0 8px 28px rgba(34, 211, 238, .24); transform: translateY(-2px); }
.btn-primary span { transition: transform .22s var(--ease-out); }
.btn-primary:hover:not(:disabled) span { transform: translateX(3px); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }

.btn-secondary {
  display: inline-flex; align-items: center; gap: 9px; color: var(--text);
  border: 1px solid var(--border-light); border-radius: 6px;
  font-size: 12.5px; padding: 9px 18px; background: var(--panel);
  transition: border-color .2s, color .2s, background .2s, transform .2s var(--ease-out);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); background: rgba(34, 211, 238, .06); transform: translateY(-2px); }
.btn-secondary span { transition: transform .22s var(--ease-out); }
.btn-secondary:hover span { transform: translateX(3px); }

.btn-block { width: 100%; }

.btn-link {
  display: block; width: 100%; margin-top: 12px;
  font-size: 12px; color: var(--muted-dim); text-align: center;
  padding: 6px; transition: color .2s;
}
.btn-link:hover { color: var(--accent); }

.icon-btn {
  border: 1px solid var(--border); background: var(--panel); color: var(--muted);
  border-radius: 5px; padding: 5px 11px; font-size: 11.5px; line-height: 1.5;
  transition: color .2s, border-color .2s;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }
.icon-btn.danger:hover { color: var(--red); border-color: var(--red); }
.site-link { text-decoration: none; white-space: nowrap; }

.pill {
  font-size: 11px; color: var(--muted-dim);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 1px 8px;
}

.badge-role {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .14em;
  padding: 3px 9px; border-radius: 4px;
  color: var(--accent); border: 1px solid rgba(34, 211, 238, .3);
  background: rgba(34, 211, 238, .07);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px;
}
.badge-role.is-admin { color: var(--amber); border-color: rgba(251, 191, 36, .3); background: rgba(251, 191, 36, .07); }

/* ---------- FORM LANGUAGE ---------- */
.form-group { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.form-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .14em; color: var(--muted-dim); }
.form-input {
  width: 100%;
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; font-weight: 300; font-size: 12.5px; padding: 13px 15px;
  outline: none; transition: border-color .2s, box-shadow .2s;
}
.form-input::placeholder { color: var(--muted-dim); }
.form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34, 211, 238, .10); }

.field-wrap { position: relative; display: block; }
.field-wrap .form-input { padding-right: 64px; }
.reveal {
  position: absolute; right: 7px; top: 50%; transform: translateY(-50%);
  background: var(--surface); border: 1px solid var(--border); color: var(--muted-dim);
  border-radius: 4px; padding: 4px 9px; font-size: 11px;
  transition: color .2s, border-color .2s;
}
.reveal:hover { color: var(--accent); border-color: var(--accent); }

.field-hint { font-size: 10.5px; color: var(--muted-dim); letter-spacing: .02em; margin-top: -2px; }

/* Two-mode visitor gate: register vs. log back in. */
.seg {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 6px; padding: 4px; margin-bottom: 22px;
}
.seg-btn {
  padding: 8px 10px; border-radius: 4px;
  font-size: 11.5px; letter-spacing: .04em; color: var(--muted-dim);
  transition: background .18s, color .18s;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.is-active { background: rgba(34, 211, 238, .1); color: var(--accent); box-shadow: inset 0 0 0 1px rgba(34, 211, 238, .28); }

.form-feedback {
  font-size: 12px; padding: 11px 14px; border-radius: 6px;
  border-left: 2px solid; margin-bottom: 16px;
}
.form-feedback.error { color: var(--red); border-color: var(--red); background: rgba(248, 113, 113, .07); }

/* ---------- GATE ---------- */
.gate {
  position: relative; height: 100%; flex-direction: column;
  overflow-y: auto; overflow-x: hidden;
}
.gate-grid {
  position: absolute; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(rgba(34, 211, 238, .04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(34, 211, 238, .04) 1px, transparent 1px);
  background-size: 52px 52px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 40%, #000, transparent);
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 40%, #000, transparent);
}

.nav {
  position: relative; z-index: 3; flex: none;
  height: 64px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 clamp(16px, 4vw, 32px);
  border-bottom: 1px solid var(--border);
  background: rgba(10, 12, 16, .72);
  backdrop-filter: blur(14px);
}
.nav-logo { font-size: 13.5px; font-weight: 400; letter-spacing: .04em; text-decoration: none; display: inline-flex; gap: 8px; }
.nav-right { display: flex; align-items: center; gap: clamp(12px, 3vw, 26px); }
.nav-site { font-size: 12.5px; color: var(--muted); text-decoration: none; white-space: nowrap; transition: color .2s; }
.nav-site:hover { color: var(--accent); }

.gate-body { position: relative; z-index: 2; flex: 1; display: grid; place-items: center; padding: clamp(24px, 6vw, 56px) clamp(16px, 4vw, 32px); }
.gate-foot { position: relative; z-index: 2; flex: none; text-align: center; font-size: 11px; color: var(--muted-dim); letter-spacing: .06em; padding: 18px; }
.foot-sep { margin: 0 8px; color: var(--border-light); }
.foot-link { color: var(--muted-dim); text-decoration: none; border-bottom: 1px solid var(--border-light); padding-bottom: 1px; transition: color .2s, border-color .2s; }
.foot-link:hover { color: var(--accent); border-color: var(--accent); }

.gate-card {
  width: min(460px, 100%);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: clamp(24px, 4vw, 34px);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .45);
}

.section-header { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.section-num { font-size: 11px; letter-spacing: .16em; color: var(--accent); }
.section-eyebrow { font-size: 10.5px; text-transform: uppercase; letter-spacing: .14em; color: var(--muted-dim); white-space: nowrap; }
.section-line { flex: 1; height: 1px; background: var(--border); }

.gate-title {
  font-family: var(--font-display); font-weight: 800;
  font-size: clamp(26px, 4.4vw, 38px); letter-spacing: -.03em; line-height: 1.1;
  margin-bottom: 14px;
}

.gate-status { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted); margin-bottom: 18px; }

.lede { font-size: 13px; color: var(--muted); line-height: 1.85; margin-bottom: 26px; }

.spec { margin-top: 22px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); overflow: hidden; }
.spec > div { display: flex; justify-content: space-between; gap: 16px; padding: 10px 14px; font-size: 11.5px; border-bottom: 1px solid var(--border); }
.spec > div:last-child { border-bottom: 0; }
.spec dt { color: var(--muted-dim); }
.spec dd { color: var(--text); }
.spec dd.ok { color: var(--green); }

.fine { font-size: 11px; color: var(--muted-dim); line-height: 1.75; margin-top: 16px; }

/* ---------- APP SHELL ---------- */
.app { height: 100%; grid-template-columns: 296px 1fr; }
body[data-role="user"] .app { grid-template-columns: 1fr; }
body[data-role="user"] .sidebar { display: none; }

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--bg-2);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar-head {
  flex: none; height: 64px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; border-bottom: 1px solid var(--border);
}
.sidebar-title { font-size: 12.5px; letter-spacing: .04em; color: var(--text); }
.sidebar-search { flex: none; padding: 12px; border-bottom: 1px solid var(--border); }
.sidebar-search input {
  width: 100%; background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 5px; padding: 8px 11px; font-size: 12px; font-weight: 300; outline: none;
  transition: border-color .2s;
}
.sidebar-search input::placeholder { color: var(--muted-dim); }
.sidebar-search input:focus { border-color: var(--accent); }

.conv-list { padding: 6px; overflow-y: auto; flex: 1; min-height: 0; }
.conv-empty { color: var(--muted-dim); font-size: 11.5px; line-height: 1.8; padding: 16px; }

.conv {
  display: grid; grid-template-columns: 30px 1fr auto; gap: 11px; align-items: center;
  padding: 9px 10px; border-radius: 6px; cursor: pointer;
  border: 1px solid transparent; border-left: 2px solid transparent;
  transition: background .16s, border-color .16s;
}
.conv:hover { background: var(--surface); }
.conv.is-active { background: var(--surface); border-color: var(--border-light); border-left-color: var(--accent); }
.conv-name { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text); }
.conv-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-last { color: var(--muted-dim); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.conv-time { color: var(--muted-dim); font-size: 10.5px; white-space: nowrap; }
.unread {
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--accent); color: #04141A;
  border-radius: 4px; font-size: 10.5px; font-weight: 500;
  display: grid; place-items: center;
}

.avatar {
  width: 30px; height: 30px; border-radius: 6px;
  display: grid; place-items: center;
  background: var(--panel); border: 1px solid var(--border-light);
  font-size: 12px; color: var(--accent); text-transform: lowercase;
}

/* ---------- CHAT PANE ---------- */
.chat { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }

.chat-head {
  flex: none; height: 64px; display: flex; align-items: center; gap: 12px;
  padding: 0 clamp(12px, 3vw, 20px);
  border-bottom: 1px solid var(--border);
  background: rgba(13, 17, 23, .8); backdrop-filter: blur(14px);
}
.peer { display: flex; align-items: center; gap: 11px; min-width: 0; flex: 1; }
.peer-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.45; }
.peer-text strong { font-size: 13.5px; font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.peer-text small { font-size: 10.5px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted-dim); }
.peer-text small.is-online { color: var(--green); }
.chat-actions { display: flex; align-items: center; gap: 8px; }

.messages {
  flex: 1; overflow-y: auto; min-height: 0;
  padding: 22px clamp(12px, 4vw, 30px);
  display: flex; flex-direction: column;
  scroll-behavior: smooth;
}

.day-sep {
  align-self: center; margin: 18px 0 12px;
  font-size: 10px; text-transform: uppercase; letter-spacing: .16em; color: var(--muted-dim);
  border: 1px solid var(--border); border-radius: 4px; padding: 2px 12px; background: var(--panel);
}

.msg { max-width: min(620px, 84%); display: flex; flex-direction: column; gap: 4px; margin-top: 14px; }
.msg.same { margin-top: 4px; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.msg.in { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  white-space: pre-wrap; overflow-wrap: anywhere;
  font-size: 13px; line-height: 1.75;
  animation: rise .18s var(--ease-out);
}
@keyframes rise { from { opacity: 0; transform: translateY(4px); } }
.msg.in .bubble { border-top-left-radius: 2px; }
.msg.out .bubble {
  background: rgba(34, 211, 238, .07);
  border-color: rgba(34, 211, 238, .32);
  border-top-right-radius: 2px;
}
.msg.same.in .bubble { border-top-left-radius: 8px; }
.msg.same.out .bubble { border-top-right-radius: 8px; }
.bubble a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }

.meta { font-size: 10px; color: var(--muted-dim); letter-spacing: .06em; padding: 0 3px; display: flex; gap: 7px; align-items: center; }
.msg.same .meta { display: none; }
.msg:last-child .meta, .msg:hover .meta { display: flex; }
.tick { color: var(--muted-dim); }
.tick.is-read { color: var(--accent); }

.empty-thread { margin: auto; text-align: center; color: var(--muted-dim); font-size: 12px; max-width: 340px; line-height: 1.9; }
.empty-thread strong { display: block; color: var(--muted); font-size: 13.5px; font-weight: 400; margin-bottom: 8px; }

.typing { flex: none; display: flex; align-items: center; gap: 9px; padding: 0 clamp(12px, 4vw, 30px) 8px; color: var(--muted-dim); font-size: 11.5px; }
.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--accent); animation: tblink 1.2s infinite; }
.typing-dots i:nth-child(2) { animation-delay: .18s; }
.typing-dots i:nth-child(3) { animation-delay: .36s; }
@keyframes tblink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

.composer { flex: none; padding: 12px clamp(12px, 4vw, 30px) 14px; border-top: 1px solid var(--border); background: var(--bg-2); }
.composer-inner {
  display: flex; gap: 10px; align-items: flex-end;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 8px 8px 14px;
  transition: border-color .2s, box-shadow .2s;
}
.composer-inner:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34, 211, 238, .10); }
.composer-prompt { color: var(--green); font-size: 13px; line-height: 30px; flex: none; }
.composer textarea {
  flex: 1; background: none; border: 0; outline: none; resize: none;
  color: var(--text); font-weight: 300; font-size: 13px; line-height: 1.7;
  padding: 5px 0; max-height: 168px; caret-color: var(--accent); min-width: 0;
}
.composer textarea::placeholder { color: var(--muted-dim); }
.send {
  width: 34px; height: 34px; flex: none;
  border: 1px solid var(--accent); border-radius: 6px;
  background: var(--accent); color: #04141A;
  display: grid; place-items: center;
  transition: background .2s, box-shadow .25s, opacity .2s;
}
.send:hover:not(:disabled) { background: #67E8F9; box-shadow: 0 6px 20px rgba(34, 211, 238, .24); }
.send:disabled { opacity: .35; cursor: not-allowed; }
.composer-hint { margin: 8px 2px 0; font-size: 10.5px; color: var(--muted-dim); letter-spacing: .04em; }

.chat-placeholder { position: absolute; inset: 0; display: none; place-items: center; background: var(--bg); text-align: center; color: var(--muted-dim); }
.chat-placeholder p { margin-top: 12px; font-size: 12px; letter-spacing: .04em; }
.placeholder-mark { font-size: 26px; color: var(--border-light); }
body[data-thread="none"] .chat-placeholder { display: grid; }

.only-mobile { display: none; }

/* ---------- TOAST ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border-light);
  border-left: 2px solid var(--accent);
  color: var(--text); padding: 10px 16px; border-radius: 6px;
  font-size: 12px; box-shadow: 0 18px 50px rgba(0, 0, 0, .5); z-index: 300;
  animation: toastin .2s var(--ease-out);
  max-width: min(420px, calc(100vw - 32px));
}
.toast.is-error { border-left-color: var(--red); color: #FCA5A5; }
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  body[data-role="admin"] .sidebar { grid-column: 1; }
  body[data-role="admin"][data-pane="thread"] .sidebar { display: none; }
  body[data-role="admin"][data-pane="list"] .chat { display: none; }
  body[data-role="admin"][data-pane="thread"] .only-mobile { display: block; }
  .msg { max-width: 90%; }
  .composer-hint { display: none; }
  .badge-role { display: none; }
  /* The admin header already carries back / rm -rf / logout on a 375px row;
     the owner hardly needs a link to their own site. Visitors keep theirs. */
  body[data-role="admin"] .site-link { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
