/* Geen externe fonts en geen externe stylesheets: het CSP-beleid staat geen
   enkele andere origin toe, en dat is hier het hele punt. */

:root {
  --bg: #12141a;
  --panel: #191c24;
  --panel-2: #20242e;
  --line: #2a2f3a;
  --text: #e6e8ee;
  --muted: #8b93a7;
  --accent: #7c5cff;
  --accent-soft: #2a2450;
  --danger: #ff6b6b;
  --ok: #4ade80;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

/* Het `hidden`-attribuut zet display op none, maar elke eigen display-regel
   wint daarvan. Zonder deze regel blijven de placeholder, het gespreksvenster
   en de composer zichtbaar terwijl de code denkt dat ze verborgen zijn. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 var(--font);
  -webkit-text-size-adjust: 100%;
}

h1, h2 { font-weight: 600; line-height: 1.25; }
h1 { font-size: 1.5rem; margin: 0 0 .5rem; }
h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1.25rem 0 .5rem; }
a { color: var(--accent); }
p { margin: 0 0 .75rem; }

.lead { color: var(--muted); }
.error { color: var(--danger); font-weight: 500; }
.empty { color: var(--muted); font-size: .9rem; }

/* Losse schermen: setup, login, fout. */
.sheet {
  max-width: 34rem;
  margin: 0 auto;
  padding: 3rem 1.25rem 4rem;
}

.note {
  margin-top: 2rem;
  padding: 1rem 1.1rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: .9rem;
  color: var(--muted);
}
.note h2 { margin-top: 0; }

label {
  display: block;
  margin: 1rem 0 .3rem;
  font-size: .85rem;
  color: var(--muted);
}

input[type="text"], input[type="password"], textarea {
  width: 100%;
  padding: .6rem .7rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
}
input:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  margin-top: 1rem;
  padding: .55rem 1rem;
  background: var(--accent);
  border: 0;
  border-radius: var(--radius);
  color: #fff;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
button:hover { filter: brightness(1.1); }
button[disabled] { opacity: .5; cursor: not-allowed; }

/* De app zelf. */
.app {
  display: grid;
  grid-template-columns: minmax(15rem, 20rem) 1fr;
  height: 100dvh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 1rem;
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
}

.me {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0 .5rem;
  padding-bottom: .75rem;
  border-bottom: 1px solid var(--line);
}
.me-name { font-weight: 600; }
.me-handle { grid-column: 1; font-size: .8rem; color: var(--muted); }
.conn {
  grid-row: 1 / span 2;
  width: .55rem;
  height: .55rem;
  border-radius: 50%;
  background: var(--muted);
}
.conn.live { background: var(--ok); }
.conn.down { background: var(--danger); }

.add-contact button { width: 100%; }

.contacts ul, .requests ul { list-style: none; margin: 0; padding: 0; }

.contact-item, .request-item {
  padding: .55rem .6rem;
  border-radius: var(--radius);
  cursor: pointer;
}
.contact-item:hover { background: var(--panel-2); }
.contact-item.active { background: var(--accent-soft); }
.contact-item .name { display: block; font-weight: 500; }
.contact-item .handle { display: block; font-size: .78rem; color: var(--muted); }
.contact-item .badge {
  float: right;
  min-width: 1.3rem;
  padding: 0 .35rem;
  border-radius: 999px;
  background: var(--accent);
  font-size: .72rem;
  text-align: center;
}

.request-item { background: var(--panel-2); margin-bottom: .5rem; }
.request-item button { margin: .5rem .4rem 0 0; padding: .3rem .7rem; font-size: .82rem; }
.request-item button.secondary { background: transparent; border: 1px solid var(--line); color: var(--muted); }

.sidebar-foot {
  display: flex;
  gap: .5rem;
  margin-top: auto;
  padding-top: 1rem;
}
.sidebar-foot button {
  margin: 0;
  padding: .4rem .7rem;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: .85rem;
}

.conversation { display: flex; flex-direction: column; min-height: 0; }

.placeholder {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--muted);
}

.thread-wrap { display: flex; flex-direction: column; min-height: 0; height: 100%; }

.thread-head {
  display: flex;
  align-items: baseline;
  gap: .6rem;
  padding: .9rem 1.25rem;
  border-bottom: 1px solid var(--line);
}
.thread-name { font-weight: 600; }
.thread-handle { color: var(--muted); font-size: .82rem; }
.thread-head button {
  margin: 0 0 0 auto;
  padding: .3rem .7rem;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: .82rem;
}

.key-warning {
  margin: 1rem 1.25rem 0;
  padding: .9rem 1rem;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  background: rgba(255, 107, 107, .08);
  font-size: .9rem;
}
.key-warning button { margin-top: .5rem; background: var(--danger); }

.thread {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 1.25rem;
  list-style: none;
  overflow-y: auto;
}

.msg { max-width: 42rem; margin-bottom: .7rem; }
.msg .bubble {
  display: inline-block;
  padding: .5rem .75rem;
  border-radius: var(--radius);
  background: var(--panel-2);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.out { margin-left: auto; text-align: right; }
.msg.out .bubble { background: var(--accent-soft); text-align: left; }
.msg .meta { display: block; margin-top: .2rem; font-size: .72rem; color: var(--muted); }
.msg.undecryptable .bubble { border: 1px dashed var(--danger); color: var(--muted); font-style: italic; }

.composer {
  display: flex;
  gap: .6rem;
  align-items: flex-end;
  padding: .9rem 1.25rem 1.1rem;
  border-top: 1px solid var(--line);
}
.composer textarea { resize: none; max-height: 9rem; }
.composer button { margin: 0; }

.composer-blocked {
  margin: 0;
  padding: .9rem 1.25rem 1.1rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .9rem;
}

dialog {
  max-width: 32rem;
  padding: 1.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
/* Koppen in een dialoog zijn gewone koppen, geen sectielabels. */
dialog h2 { margin-top: 0; font-size: 1.25rem; text-transform: none; letter-spacing: 0; color: var(--text); }
dialog .note h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
dialog pre {
  padding: .9rem;
  border-radius: var(--radius);
  background: var(--panel-2);
  font-size: 1.05rem;
  letter-spacing: .08em;
  line-height: 1.9;
  white-space: pre-wrap;
}

@media (max-width: 46rem) {
  .app { grid-template-columns: 1fr; }
  .app.viewing-thread .sidebar { display: none; }
  .app:not(.viewing-thread) .conversation { display: none; }
}
