:root {
  --bg: #0f1218;
  --surface: #171b24;
  --surface-2: #1e2430;
  --border: #2a3140;
  --text: #e7ecf3;
  --muted: #8b96a8;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.14);
  --ok: #35c46a;
  --warn: #f0a92b;
  --danger: #ef5a5a;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: radial-gradient(1200px 600px at 20% -10%, #1b2333 0%, var(--bg) 60%);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--accent); }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: .95rem; }
p { margin: 0 0 .75rem; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.row { display: flex; gap: .6rem; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }

/* ---------- form controls ---------- */

input, textarea, select, button {
  font: inherit;
  color: inherit;
}

input[type="text"], input[type="password"], textarea, select {
  width: 100%;
  padding: .6rem .75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

label { display: block; margin-bottom: .8rem; }
label > span { display: block; margin-bottom: .3rem; font-size: .85rem; color: var(--muted); }

button {
  padding: .6rem 1rem;
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: 10px;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: filter .15s, background .15s, opacity .15s;
}
button:hover:not(:disabled) { filter: brightness(1.1); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.ghost { background: transparent; border-color: var(--border); color: var(--text); font-weight: 500; }
button.ghost:hover:not(:disabled) { background: var(--surface-2); }
button.ok { background: var(--ok); }
button.warn { background: var(--warn); color: #241a04; }
button.danger { background: var(--danger); }
button.sm { padding: .35rem .7rem; font-size: .85rem; }

/* ---------- layout ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem .75rem;
  padding: .7rem 1.1rem;
  flex: none;
  background: rgba(23, 27, 36, .85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand { font-weight: 700; letter-spacing: .2px; white-space: nowrap; }
.topbar .brand span { color: var(--accent); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .18rem .55rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-2);
  white-space: nowrap;
}
.badge.ok { color: var(--ok); border-color: rgba(53,196,106,.35); background: rgba(53,196,106,.12); }
.badge.warn { color: var(--warn); border-color: rgba(240,169,43,.35); background: rgba(240,169,43,.12); }
.badge.danger { color: var(--danger); border-color: rgba(239,90,90,.35); background: rgba(239,90,90,.12); }
.badge.info { color: var(--accent); border-color: rgba(79,140,255,.35); background: var(--accent-soft); }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.online { background: var(--ok); box-shadow: 0 0 0 3px rgba(53,196,106,.18); }

.alert {
  padding: .6rem .8rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: .9rem;
  margin-bottom: .8rem;
}
.alert.error { color: #ffb4b4; border-color: rgba(239,90,90,.4); background: rgba(239,90,90,.12); }
.alert.ok { color: #b6f0cb; border-color: rgba(53,196,106,.4); background: rgba(53,196,106,.12); }
.alert.warn { color: #ffdca5; border-color: rgba(240,169,43,.4); background: rgba(240,169,43,.12); }

/* ---------- chat ---------- */

.chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.msg { max-width: 78%; padding: .5rem .75rem; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); }
.msg .meta { font-size: .72rem; color: var(--muted); margin-bottom: .15rem; }
.msg .text { white-space: pre-wrap; word-break: break-word; }
.msg.mine { align-self: flex-end; background: var(--accent); border-color: transparent; }
.msg.mine .meta { color: rgba(255,255,255,.75); }
.msg.system {
  align-self: center;
  max-width: 90%;
  text-align: center;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: .82rem;
}
.chat-form {
  display: flex;
  gap: .5rem;
  padding: .75rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.chat-form textarea { resize: none; height: 42px; max-height: 120px; }
.typing { height: 1rem; padding: 0 1rem; font-size: .78rem; color: var(--muted); }

/* ---------- photo ---------- */

.photo-frame {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 160px;
}
.photo-frame img { width: 100%; display: block; object-fit: contain; max-height: 340px; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  background: var(--surface-2);
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .icon { font-size: 2rem; }

.progress {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  border: 1px solid var(--border);
}
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s linear; }

.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- small screens ---------- */

@media (max-width: 640px) {
  .topbar { padding: .5rem .7rem; gap: .35rem .5rem; }
  /* The connection badge carries its meaning in the colour — drop the word. */
  #conn { font-size: 0; gap: 0; padding: .38rem; }
  .topbar .brand { font-size: .95rem; }
  .topbar .badge { font-size: .72rem; padding: .15rem .45rem; }
  .topbar button.sm { padding: .28rem .55rem; font-size: .8rem; }
  .card { padding: 1rem; }
  .msg { max-width: 88%; }
}
