:root {
  --bg: #0d1418;
  --panel: #111b21;
  --panel-2: #182229;
  --line: #22303a;
  --text: #e9edef;
  --muted: #8696a0;
  --accent: #21c063;
  --bubble-in: #202c33;
  --bubble-out: #005c4b;
  --danger: #f15c6d;
  --warn: #f0b232;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: .5rem 0 0; font-size: .85rem; }

button { font: inherit; cursor: pointer; }

.link-btn {
  background: none; border: 0; color: var(--muted);
  padding: .25rem .4rem; border-radius: 6px;
}
.link-btn:hover { color: var(--text); background: var(--panel-2); }

/* ------------------------------------------------------------------ login */

.login {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.login-card {
  width: min(360px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 2rem;
}
.login-card h1 { margin: 0; font-size: 1.35rem; }
.login-card p { margin: .25rem 0 1.5rem; font-size: .9rem; }
.login-card input, .login-card button {
  width: 100%;
  padding: .75rem .9rem;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
}
.login-card button {
  margin-top: .75rem;
  background: var(--accent);
  border-color: var(--accent);
  color: #06231a;
  font-weight: 600;
}
.login-card button:disabled { opacity: .6; cursor: progress; }

/* -------------------------------------------------------------- app shell */

.app {
  height: 100%;
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .9rem 1rem;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .55rem; }
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--muted); transition: background .3s;
}
.dot.live { background: var(--accent); box-shadow: 0 0 8px rgba(33,192,99,.6); }

.search {
  margin: .75rem 1rem;
  padding: .55rem .8rem;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
}

.conversations { list-style: none; margin: 0; padding: 0 0 1rem; overflow-y: auto; flex: 1; }
.conversations li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .15rem .5rem;
  padding: .7rem 1rem;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.conversations li:hover { background: var(--panel-2); }
.conversations li.active { background: var(--panel-2); border-left-color: var(--accent); }
.conv-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { color: var(--muted); font-size: .75rem; white-space: nowrap; }
.conv-preview {
  color: var(--muted); font-size: .85rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.badge {
  justify-self: end;
  background: var(--accent); color: #06231a;
  font-size: .72rem; font-weight: 700;
  border-radius: 999px; padding: .05rem .45rem;
}

.empty { color: var(--muted); font-size: .88rem; padding: 1rem; text-align: center; }

/* ----------------------------------------------------------------- thread */

.thread { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.placeholder { flex: 1; display: grid; place-items: center; color: var(--muted); }
.thread-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.thread-head {
  display: flex; align-items: center; gap: .75rem;
  padding: .8rem 1.1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.thread-name { font-weight: 600; }
.thread-meta { color: var(--muted); font-size: .78rem; }
.back { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 1.1rem; min-height: 0; }
.load-older {
  display: block; margin: 0 auto 1rem;
  background: var(--panel-2); color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px;
  padding: .35rem 1rem; font-size: .82rem;
}

.day-sep {
  text-align: center; margin: 1.1rem 0 .8rem;
  color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .05em;
}

.msg { display: flex; margin-bottom: .45rem; }
.msg.out { justify-content: flex-end; }
.bubble {
  max-width: min(72ch, 78%);
  background: var(--bubble-in);
  padding: .5rem .7rem .35rem;
  border-radius: 10px;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.msg.out .bubble { background: var(--bubble-out); }
.bubble img, .bubble video {
  max-width: 100%; max-height: 340px;
  border-radius: 7px; display: block; margin-bottom: .35rem;
}
.bubble audio { width: 260px; max-width: 100%; margin-bottom: .35rem; }
.bubble a { color: #8fd6ff; }
.doc {
  display: inline-flex; align-items: center; gap: .5rem;
  background: rgba(255,255,255,.06);
  padding: .5rem .7rem; border-radius: 7px;
  text-decoration: none; color: var(--text); margin-bottom: .35rem;
}
.pending { color: var(--muted); font-style: italic; font-size: .85rem; }

.meta {
  display: block; text-align: right;
  color: rgba(233,237,239,.55);
  font-size: .68rem; margin-top: .15rem;
  white-space: nowrap;
}
.meta .tick.read { color: #53bdeb; }
.meta .failed { color: var(--danger); font-style: normal; }

/* --------------------------------------------------------------- composer */

.composer { border-top: 1px solid var(--line); background: var(--panel); padding: .7rem 1rem 1rem; }
.composer form { display: flex; gap: .6rem; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; max-height: 160px;
  padding: .65rem .85rem;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text);
  font: inherit;
}
.composer textarea:disabled { opacity: .5; }
.composer button {
  padding: .65rem 1.3rem;
  border-radius: 10px; border: 0;
  background: var(--accent); color: #06231a; font-weight: 600;
}
.composer button:disabled { opacity: .45; cursor: not-allowed; }

.window-warning {
  background: rgba(240,178,50,.12);
  border: 1px solid rgba(240,178,50,.35);
  color: var(--warn);
  border-radius: 9px;
  padding: .55rem .8rem;
  font-size: .83rem;
  margin-bottom: .6rem;
}

/* ---------------------------------------------------------------- mobile */

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; }
  .app.viewing .sidebar { display: none; }
  .app:not(.viewing) .thread { display: none; }
  .back { display: inline-block; }
  .bubble { max-width: 86%; }
}
