* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0f172a; --panel: #ffffff; --panel2: #f1f5f9; --ink: #0f172a; --muted: #64748b;
  --accent: #0e7490; --accent2: #0891b2; --mine: #d9fdd3; --theirs: #ffffff; --line: #e2e8f0;
}
html, body { height: 100%; }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
.hidden { display: none !important; }
button { cursor: pointer; border: none; font: inherit; }
input { font: inherit; }
.error { color: #dc2626; font-size: 0.9rem; min-height: 1.2em; }
.error.pad { padding: 0 12px 8px; background: #ece5dd; }
.hint { color: var(--muted); padding: 16px; font-size: 0.92rem; }

/* Auth */
.auth-wrap { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card { background: var(--panel); border-radius: 16px; padding: 28px 24px; width: 100%; max-width: 360px; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.auth-card .logo { font-size: 44px; }
.auth-card h1 { font-size: 1.4rem; margin: 8px 0 4px; }
.auth-card .sub { color: var(--muted); font-size: 0.92rem; margin-bottom: 18px; }
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tab { flex: 1; padding: 9px; border-radius: 10px; background: var(--panel2); color: var(--muted); font-weight: 600; }
.tab.active { background: var(--accent); color: #fff; }
#authForm { display: flex; flex-direction: column; gap: 10px; }
#authForm input { padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; }
#authSubmit { padding: 11px; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 700; }
#authSubmit:hover { background: var(--accent2); }

/* Chat layout */
.chat-wrap { display: flex; height: 100dvh; background: var(--panel); }
.sidebar { width: 340px; max-width: 100%; border-right: 1px solid var(--line); display: flex; flex-direction: column; background: var(--panel); }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; background: var(--panel2); }
.small-btn { background: transparent; color: var(--accent); font-weight: 600; padding: 6px 8px; border-radius: 8px; }
.small-btn:hover { background: var(--line); }
.search-box { padding: 10px 12px; position: relative; }
.search-box input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel2); }
.search-results { position: absolute; left: 12px; right: 12px; top: 56px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 30px rgba(0,0,0,.15); z-index: 5; overflow: hidden; }
.search-results button { display: flex; justify-content: space-between; width: 100%; padding: 11px 12px; background: #fff; text-align: left; }
.search-results button:hover { background: var(--panel2); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #cbd5e1; display: inline-block; }
.dot.on { background: #22c55e; }
.chat-list { overflow-y: auto; flex: 1; }
.chat-item { display: flex; gap: 10px; width: 100%; padding: 12px 14px; background: #fff; text-align: left; border-bottom: 1px solid var(--panel2); align-items: center; }
.chat-item:hover, .chat-item.active { background: var(--panel2); }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; position: relative; }
.avatar .dot { position: absolute; right: 0; bottom: 0; border: 2px solid #fff; }
.chat-item .meta { flex: 1; min-width: 0; }
.chat-item .name { font-weight: 600; }
.chat-item .last { color: var(--muted); font-size: 0.86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unread { background: #22c55e; color: #fff; font-size: 0.75rem; font-weight: 700; border-radius: 999px; min-width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; padding: 0 6px; }

.main-pane { flex: 1; display: flex; flex-direction: column; background: #ece5dd; min-width: 0; }
.full { display: flex; flex-direction: column; height: 100%; }
.empty-pane { margin: auto; text-align: center; color: var(--muted); padding: 20px; }
.empty-pane .logo { font-size: 52px; margin-bottom: 10px; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--panel2); border-bottom: 1px solid var(--line); }
.chat-head .status { font-size: 0.8rem; color: var(--muted); }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 72%; padding: 8px 11px; border-radius: 12px; font-size: 0.96rem; line-height: 1.35; word-wrap: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.08); }
.msg.mine { align-self: flex-end; background: var(--mine); border-bottom-right-radius: 4px; }
.msg.theirs { align-self: flex-start; background: var(--theirs); border-bottom-left-radius: 4px; }
.msg .time { display: block; font-size: 0.7rem; color: var(--muted); text-align: right; margin-top: 3px; }
.msg a.file { color: var(--accent); font-weight: 600; text-decoration: none; }
.msg .fsize { color: var(--muted); font-size: 0.8rem; }
.send-bar { display: flex; gap: 8px; padding: 10px 12px; background: var(--panel2); align-items: center; }
.send-bar input[type="text"] { flex: 1; padding: 11px 14px; border: 1px solid var(--line); border-radius: 999px; background: #fff; }
.attach-btn { font-size: 20px; cursor: pointer; padding: 6px; }
.send-btn { width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 17px; }
.mobile-only { display: none; }

@media (max-width: 760px) {
  .sidebar { width: 100%; }
  .main-pane { display: none; }
  .chat-wrap.in-chat .sidebar { display: none; }
  .chat-wrap.in-chat .main-pane { display: flex; width: 100%; }
  .mobile-only { display: inline-block; }
  .msg { max-width: 85%; }
}
