* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
:root {
  --bg:#0f1419; --panel:#1a2029; --accent:#3b82f6; --accent2:#2563eb;
  --mine:#3b82f6; --theirs:#2d3540; --text:#e6e9ee; --muted:#8a93a0;
  --line:#2d3540; --ok:#34d399; --danger:#f87171;
}
html, body { height: 100%; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
input { font: inherit; }

button { font: inherit; cursor: pointer; border: none; border-radius: 12px; }
.primary-btn { background: var(--accent); color:#fff; padding: 14px 18px; border-radius: 12px; font-size: 16px; }
.primary-btn:active { background: var(--accent2); }
.secondary-btn { background: #2d3540; color: var(--text); padding: 12px 16px; border-radius: 12px; font-size: 15px; }
.secondary-btn.full { width: 100%; margin-bottom: 14px; }
.link-btn { background: transparent; color: var(--muted); padding: 8px; font-size: 15px; }
.icon-btn { background: transparent; color: var(--text); font-size: 20px; padding: 6px 10px; }

.screen { min-height: 100vh; min-height: 100dvh; }
.error { color: var(--danger); font-size: 14px; min-height: 18px; text-align: center; margin: 6px 0; }
.subtitle { color: var(--muted); text-align: center; font-size: 15px; }
h1 { text-align: center; font-size: 24px; margin-bottom: 6px; }

/* ===== PIN screen ===== */
#screen-pin, #screen-newname { display: flex; align-items: center; justify-content: center; padding: 20px; }
.pin-box { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.pin-box h1 { margin-top: 6px; }
.pin-box input, .modal-box input {
  width: 100%; padding: 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-size: 18px; text-align: center;
}
.pin-dots { display: flex; gap: 14px; height: 22px; align-items: center; margin: 6px 0; }
.pin-dots .dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots .dot.filled { background: var(--accent); border-color: var(--accent); }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; width: 100%; margin-top: 8px; }
.keypad button {
  background: var(--panel); color: var(--text); font-size: 26px; padding: 18px 0;
  border-radius: 16px; border: 1px solid var(--line);
}
.keypad button:active { background: #232b35; }
.keypad button.ok { background: var(--accent); color:#fff; font-size: 18px; }
.keypad button.ok:disabled { opacity: .4; }
.keypad button.wide { font-size: 20px; }

/* ===== Users tiles ===== */
#screen-users { display: flex; align-items: center; justify-content: center; padding: 20px; }
.users-box { width: 100%; max-width: 480px; display: flex; flex-direction: column; gap: 12px; align-items: center; }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; width: 100%; margin-top: 8px; }
.tile {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 22px 12px; text-align: center; font-size: 18px; color: var(--text);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
}
.tile:active { background: #232b35; }
.tile .avatar { width: 48px; height: 48px; border-radius: 50%; background: var(--accent);
  display: flex; align-items: center; justify-content: center; font-size: 22px; color:#fff; }
.tile.add { border-style: dashed; color: var(--muted); }
.tile.add .avatar { background: #2d3540; }

/* ===== Chat ===== */
#screen-chat, .container { height: 100vh; height: 100dvh; }
.container { display: flex; }
.sidebar { width: 300px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.sidebar-header { display: flex; justify-content: space-between; align-items: center; padding: 14px; border-bottom: 1px solid var(--line); }
.me-name { font-weight: 600; font-size: 16px; }
.header-actions { display: flex; gap: 2px; }

.contact-list { list-style: none; overflow-y: auto; flex: 1; }
.contact { padding: 14px; border-bottom: 1px solid #232b35; cursor: pointer; display: flex; align-items: center; gap: 12px; }
.contact:active, .contact.active { background: #232b35; }
.contact .avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--accent);
  display: flex; align-items: center; justify-content: center; color:#fff; font-size: 18px; flex-shrink: 0; }
.contact .c-info { display: flex; flex-direction: column; min-width: 0; }
.contact .c-name { font-size: 16px; }
.contact .c-status { font-size: 12px; color: var(--muted); }
.online-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); display: inline-block; margin-right: 5px; }

.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-header { padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--panel); display: flex; align-items: center; gap: 10px; }
.chat-header-info { display: flex; flex-direction: column; }
#peer-name { font-weight: 600; font-size: 16px; }
.peer-status { font-size: 12px; color: var(--muted); }
.back-btn { display: none; background: transparent; color: var(--text); padding: 4px 8px; font-size: 22px; }

.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.date-sep { align-self: center; background: #232b35; color: var(--muted); font-size: 12px; padding: 4px 12px; border-radius: 12px; margin: 10px 0 4px; }
.msg { max-width: 78%; padding: 8px 12px; border-radius: 16px; word-wrap: break-word; position: relative; }
.msg.mine { align-self: flex-end; background: var(--mine); border-bottom-right-radius: 5px; }
.msg.theirs { align-self: flex-start; background: var(--theirs); border-bottom-left-radius: 5px; }
.msg.deleted { font-style: italic; color: rgba(255,255,255,.7); background: #232b35; }
.msg img, .msg video { max-width: 100%; max-height: 320px; border-radius: 10px; display: block; cursor: pointer; }
.media-wrap { position: relative; display: inline-block; }
.play-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 44px; color: #fff; text-shadow: 0 0 8px rgba(0,0,0,.7); pointer-events: none; }
.msg .meta { font-size: 11px; color: rgba(255,255,255,.65); display: flex; gap: 5px; justify-content: flex-end; align-items: center; margin-top: 3px; }
.msg .check { font-size: 12px; }
.msg .check.read { color: #bfe3ff; }
.msg .del-btn { background: transparent; color: rgba(255,255,255,.7); font-size: 12px; padding: 0 2px; margin-right: auto; }

.typing-row { padding: 4px 18px; color: var(--muted); font-size: 13px; font-style: italic; }

.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); background: var(--panel); align-items: center; }
.composer input[type=text] { flex: 1; padding: 13px 16px; border-radius: 22px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 16px; }
.file-btn { font-size: 24px; cursor: pointer; user-select: none; padding: 0 4px; }
.send-btn { background: var(--accent); color:#fff; border-radius: 50%; width: 46px; height: 46px; font-size: 18px; flex-shrink: 0; }

/* ===== Modals ===== */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal-box { background: var(--panel); border-radius: 18px; padding: 22px; width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-box h2 { font-size: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }
.admin-users { display: flex; flex-direction: column; gap: 8px; }
.admin-user { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px; background: var(--bg); border-radius: 10px; }
.admin-user .au-name { font-size: 15px; }
.admin-user .au-sub { font-size: 12px; color: var(--muted); }

/* ===== Mobile ===== */
@media (max-width: 720px) {
  .sidebar { width: 100%; }
  .chat { display: none; }
  .container.chat-open .sidebar { display: none; }
  .container.chat-open .chat { display: flex; }
  .back-btn { display: inline-block; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
}
