:root {
  --background: #f4f7f9;
  --surface: #ffffff;
  --surface-hover: #f0fafa;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --foreground: #1e293b;
  --muted: #64748b;
  --navy: #1a3a5c;
  --accent: #2ab1b3;
  --accent-hover: #239a9c;
  --accent-light: #e6f7f7;
  --danger: #ef4444;
  --success: #16a34a;
  --shadow: 0 10px 40px rgba(26, 58, 92, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  background: var(--background);
  color: var(--foreground);
}
#app { height: 100%; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

.center {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
}
.card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
}

.wordmark { font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }
.wordmark .der { color: var(--navy); }
.wordmark .secur { color: var(--accent); }
.server-hint, .instance {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  word-break: break-all;
}
.subtitle {
  margin: 6px 0 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}
.card .subtitle { margin-bottom: 24px; }

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin: 14px 0 6px;
}
input, select, textarea, button { font-family: inherit; }
input, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  background: var(--surface);
  color: var(--foreground);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(42, 177, 179, 0.15);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  padding: 10px 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  width: auto;
  margin: 0;
}
.card .btn { width: 100%; margin-top: 18px; }
.btn:hover { background: var(--accent-hover); }
.btn.secondary, .btn.ghost {
  background: var(--surface);
  color: var(--navy);
  border: 1px solid var(--border);
}
.btn.secondary:hover, .btn.ghost:hover { background: var(--surface-hover); border-color: var(--accent); }
.card .btn.secondary { margin-top: 8px; }
.btn.small { padding: 6px 10px; font-size: 12px; }
.btn.danger { background: var(--danger); color: #fff; border: 0; }
.btn.danger:hover { filter: brightness(0.95); }

.error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }
.row { display: flex; gap: 8px; align-items: center; }
.lang { display: flex; gap: 6px; }
.lang button {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.lang button.active { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
.card .lang { justify-content: flex-end; margin-bottom: 8px; }

.shell { display: flex; height: 100%; background: var(--background); }
.sidebar {
  width: 300px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.side-head { padding: 20px 18px 16px; }
.sidebar .wordmark { font-size: 22px; }
.who { display: flex; align-items: center; gap: 10px; margin-top: 16px; }
.who-text { min-width: 0; }
.who-text strong { display: block; font-size: 14px; color: var(--navy); }
.who-mail { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.side-nav { padding: 0 12px 8px; }
.nav-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 14px 10px 6px;
}
.nav-item {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--foreground);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.nav-item:hover { background: var(--surface-hover); }
.nav-item.active {
  background: var(--accent-light);
  color: var(--navy);
  box-shadow: inset 3px 0 0 var(--accent);
  font-weight: 600;
}
.nav-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 2px 4px; }
.nav-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--navy);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.nav-chip:hover { border-color: var(--accent); background: var(--accent-light); }

.side-foot {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.side-foot .lang { padding: 4px 10px 8px; }

.list { flex: 1; overflow: auto; }
.item {
  padding: 12px 16px;
  cursor: pointer;
  display: flex;
  gap: 12px;
  align-items: center;
}
.item-text { min-width: 0; flex: 1; }
.item:hover { background: var(--surface-hover); }
.item.active { background: var(--accent-light); box-shadow: inset 3px 0 0 var(--accent); }
.item .title { font-weight: 600; font-size: 14px; color: var(--navy); }
.item .preview { color: var(--muted); font-size: 12px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.face {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600; position: relative; flex-shrink: 0;
  overflow: hidden;
}
.face.sm { width: 28px; height: 28px; font-size: 12px; }
.face img { width: 100%; height: 100%; object-fit: cover; }
.face.on::after {
  content: ""; position: absolute; right: 1px; bottom: 1px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--success); border: 2px solid var(--surface);
}
.face-edit { cursor: pointer; display: inline-flex; }
.ticks { letter-spacing: -2px; }
.ticks.read { color: var(--accent); }

.search-box { padding: 8px 12px 12px; }
.search-box input { width: 100%; background: var(--background); }
.search-hits { max-height: 180px; overflow: auto; background: var(--accent-light); }

.thread { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.thread-head {
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.thread-head h1 { margin: 0; font-size: 16px; font-weight: 600; color: var(--navy); display: flex; align-items: center; gap: 8px; }
.thread-head .head-link { color: var(--navy); font-size: 16px; font-weight: 600; text-decoration: none; }
.thread-head .head-link:hover { color: var(--accent); }
.head-who { min-width: 0; flex: 1; }
.seen-line { font-size: 12px; font-weight: 400; color: var(--muted); margin-top: 2px; }
.thread-head .call-actions { display: flex; gap: 8px; }
.thread-head #back { display: none; }

.msgs { flex: 1; overflow: auto; padding: 22px 24px; display: flex; flex-direction: column; gap: 10px; }
.bubble {
  max-width: 68%;
  padding: 10px 14px 8px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.bubble.me { align-self: flex-end; background: var(--accent-light); color: var(--navy); border-bottom-right-radius: 6px; }
.bubble.them { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.quote {
  font-size: 12px; color: var(--muted); border-left: 3px solid var(--accent);
  padding: 2px 8px; margin-bottom: 6px;
}
.msg-acts { display: none; gap: 8px; margin-top: 4px; }
.bubble:hover .msg-acts { display: flex; }
.bubble.deleted { opacity: 0.7; font-style: italic; }
.typing, .reply-bar {
  padding: 8px 20px; font-size: 12px; color: var(--muted);
  background: var(--surface); border-top: 1px solid var(--border);
}
.unread {
  display: inline-block;
  min-width: 18px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
}

.compose {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 12px 16px 16px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.compose textarea {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 14px;
  background: var(--background);
}
.compose.recording { background: var(--accent-light); }
.voice-bubble { min-width: 180px; }
.wave {
  display: flex; align-items: flex-end; gap: 2px;
  height: 28px; margin: 6px 0;
}
.wave i {
  display: block; width: 3px; min-height: 3px;
  background: var(--accent); border-radius: 2px; opacity: 0.85;
}
.bubble.system {
  align-self: center; background: transparent; border: 0;
  color: var(--muted); font-size: 12px; text-align: center;
}
.chat-img { max-width: 240px; max-height: 240px; border-radius: 10px; display: block; }
.linkish {
  background: none; border: 0; color: var(--navy); font-weight: 600;
  cursor: pointer; padding: 0; text-decoration: none;
}
.linkish:hover { color: var(--accent); }

.call-overlay {
  position: fixed; inset: 0; z-index: 20;
  background: #12263d;
  color: #fff;
  display: flex; flex-direction: column;
}
.call-overlay header {
  padding: 16px 20px;
  background: var(--navy);
  display: flex; justify-content: space-between; align-items: center;
}
.call-stage {
  flex: 1; display: flex; flex-wrap: wrap; gap: 8px; padding: 12px;
  align-content: center; justify-content: center;
}
.call-tile {
  background: #1a3a5c; border-radius: 10px; overflow: hidden;
  min-width: 160px; min-height: 120px; flex: 1 1 220px; max-width: 480px;
  position: relative;
}
.call-tile video { width: 100%; height: 100%; object-fit: cover; background: #0f172a; }
.call-tile .name {
  position: absolute; left: 8px; bottom: 8px;
  font-size: 12px; background: rgba(0,0,0,.45); padding: 2px 8px; border-radius: 999px;
}
.call-bar {
  padding: 16px; display: flex; justify-content: center; gap: 10px; flex-wrap: wrap;
}
.call-bar .btn { min-width: 96px; }

.admin-main { background: var(--background); }
.admin-body { flex: 1; overflow: auto; padding: 24px 28px 40px; }
.admin-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px 22px; max-width: 880px; margin-bottom: 16px;
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.03);
}
.admin-card h3 { margin: 0 0 14px; font-size: 15px; color: var(--navy); }
.admin-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.admin-create { margin-top: 16px; }
.admin-toggles { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.toggle-row { font-weight: 500; color: var(--foreground); display: flex; align-items: center; gap: 8px; margin: 0; }
.toggle-row input { width: auto; accent-color: var(--accent); }
.admin-card-row {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.admin-card-row:last-child { border-bottom: 0; }
.admin-card-row code { font-size: 11px; word-break: break-all; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.admin-edit { margin-top: 10px; max-width: 320px; }
.admin-notice {
  max-width: 880px; margin-bottom: 16px; padding: 12px 14px;
  background: var(--accent-light); border-radius: 10px; color: var(--navy);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: 13px; word-break: break-all;
}
.admin-row {
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.circle-members {
  display: flex; flex-direction: column; gap: 6px;
  margin-top: 12px; max-height: 240px; overflow: auto;
  padding-top: 8px; border-top: 1px solid var(--border);
}

.incoming {
  position: fixed; right: 16px; bottom: 16px; z-index: 21;
  background: var(--navy); color: #fff; border-radius: 14px; padding: 16px 18px;
  box-shadow: var(--shadow); max-width: 320px;
}
.incoming .row { margin-top: 10px; }
.empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-align: center;
}
.empty-title { font-size: 18px; font-weight: 600; color: var(--navy); margin-bottom: 6px; }

.modal-back {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.4);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 24px; width: 100%; max-width: 440px; box-shadow: var(--shadow); }
.people { max-height: 220px; overflow: auto; margin: 8px 0; }
.people label { font-weight: 500; color: var(--foreground); }

@media (max-width: 720px) {
  .sidebar { width: 100%; }
  .shell.chat-open .sidebar { display: none; }
  .shell:not(.chat-open) .thread { display: none; }
  .thread-head #back { display: inline-flex; }
  .admin-form { grid-template-columns: 1fr; }
  .admin-card-row { flex-direction: column; }
}
