:root {
  --bg: #0b141a; --panel: #111b21; --panel2: #202c33; --hover: #2a3942;
  --accent: #00a884; --accent2: #005c4b; --in: #202c33;
  --text: #e9edef; --muted: #8696a0; --danger: #f15c6d; --line: #222d34;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); overflow: hidden; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.msg { font-size: 13px; min-height: 16px; }
.msg.ok { color: var(--accent); } .msg.err { color: var(--danger); }
code { background: #0b141a; padding: 1px 5px; border-radius: 4px; }
input, textarea, select { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; }
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
.icon-btn { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 6px; border-radius: 50%; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.btn-primary { background: var(--accent); color: #04231b; border: none; border-radius: 8px; padding: 10px 16px; font-weight: 600; cursor: pointer; }
.btn-primary.sm { padding: 7px 12px; font-size: 14px; }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); border-radius: 8px; padding: 6px 12px; cursor: pointer; }
.link { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 13px; }
.row { display: flex; gap: 8px; margin: 10px 0; } .row input { flex: 1; }

/* AUTH */
.auth { height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(180deg,#0b141a,#111b21); }
.auth-card { background: var(--panel); padding: 28px; border-radius: 14px; width: 100%; max-width: 360px; }
.auth-card h1 { font-size: 20px; margin: 0 0 18px; text-align: center; }
.auth-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.auth-tabs button { flex: 1; background: var(--panel2); color: var(--muted); border: none; padding: 9px; border-radius: 8px; cursor: pointer; }
.auth-tabs button.active { background: var(--accent); color: #04231b; font-weight: 600; }
#auth-form { display: flex; flex-direction: column; gap: 10px; }

/* APP SHELL */
.wa { height: 100dvh; display: grid; grid-template-columns: minmax(300px, 30%) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
@media (min-width: 1300px){ .wa { grid-template-columns: 400px minmax(0, 1fr); } }

/* SIDEBAR */
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.side-head { display: flex; align-items: center; gap: 8px; padding: 9px 12px; background: var(--panel2); flex: 0 0 auto; }
.me, .peer-avatar, .avatar { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; color: #04231b; flex: 0 0 auto; }
.side-head select { flex: 1; min-width: 0; }
.chat-list { flex: 1; overflow-y: auto; min-height: 0; }
.chat-item { display: flex; gap: 12px; padding: 11px 14px; cursor: pointer; border-bottom: 1px solid var(--line); align-items: center; }
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--panel2); }
.chat-item .ci-body { flex: 1; min-width: 0; }
.chat-item .ci-top { display: flex; justify-content: space-between; gap: 8px; }
.chat-item .ci-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item .ci-time { color: var(--muted); font-size: 12px; flex: 0 0 auto; }
.chat-item .ci-last { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.chat-item .ci-badge { background: var(--accent); color: #04231b; font-size: 11px; font-weight: 700; border-radius: 10px; padding: 1px 7px; flex: 0 0 auto; }
.chat-empty { padding: 24px; text-align: center; color: var(--muted); }

/* CHAT PANE */
.chat-pane { background: #0b141a; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); gap: 10px; }
.empty-logo { font-size: 56px; opacity: .5; }
.chat-open-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 9px 14px; background: var(--panel2); border-left: 1px solid var(--line); flex: 0 0 auto; }
.back-btn { display: none; }
.peer-info { min-width: 0; } .peer-name { font-weight: 600; cursor: pointer; } .peer-name:hover { text-decoration: underline; } .peer-sub { font-size: 12px; color: var(--muted); }
.messages { flex: 1; overflow-y: auto; min-height: 0; padding: 16px 8%; display: flex; flex-direction: column; gap: 4px; }
.bubble { max-width: 70%; padding: 6px 9px 8px; border-radius: 8px; font-size: 14.5px; line-height: 1.35; position: relative; word-wrap: break-word; white-space: pre-wrap; }
.bubble .t { font-size: 11px; color: var(--muted); float: right; margin: 6px 0 -4px 10px; }
.bubble.in { background: var(--in); align-self: flex-start; border-top-left-radius: 2px; }
.bubble.out { background: var(--accent2); align-self: flex-end; border-top-right-radius: 2px; }
.day-sep { align-self: center; background: var(--panel2); color: var(--muted); font-size: 12px; padding: 4px 12px; border-radius: 8px; margin: 8px 0; }

/* COMPOSER */
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 12px; background: var(--panel2); flex: 0 0 auto; }
.composer textarea { flex: 1; resize: none; max-height: 140px; border-radius: 20px; padding: 10px 14px; }
.send-btn { background: var(--accent); color: #04231b; border: none; width: 44px; height: 44px; border-radius: 50%; font-size: 18px; cursor: pointer; flex: 0 0 auto; }
.tone-wrap { position: relative; }
.tone-menu { position: absolute; bottom: 48px; left: 0; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 6px; display: flex; flex-direction: column; min-width: 190px; box-shadow: 0 6px 24px rgba(0,0,0,.5); z-index: 20; }
.tone-menu button { background: none; border: none; color: var(--text); text-align: left; padding: 9px 10px; border-radius: 7px; cursor: pointer; font-size: 14px; }
.tone-menu button:hover { background: var(--hover); }
.tone-loading { position: absolute; bottom: 52px; left: 0; background: var(--panel2); padding: 8px 12px; border-radius: 8px; font-size: 13px; color: var(--muted); }

/* MODALS */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal-card { background: var(--panel); border-radius: 14px; padding: 18px; width: 100%; max-width: 360px; }
.modal-card.wide { max-width: 480px; }
.modal-card img { width: 250px; height: 250px; background: #fff; border-radius: 8px; margin: 10px auto; display: block; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.modal-head h3 { margin: 0; }
.modal-foot { margin-top: 14px; text-align: center; }
.settings-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.settings-tabs button { flex: 1; background: var(--panel2); color: var(--muted); border: none; padding: 8px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.settings-tabs button.active { background: var(--accent); color: #04231b; font-weight: 600; }
.card { background: var(--panel2); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.card .actions { display: flex; gap: 8px; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 10px; background: var(--hover); color: var(--muted); }
.badge.on { color: var(--accent); } .badge.off { color: var(--danger); }

/* MOBILE */
@media (max-width: 820px) {
  .wa { grid-template-columns: 1fr; }
  .chat-pane { display: none; }
  body.chat-open .sidebar { display: none; }
  body.chat-open .chat-pane { display: flex; }
  .back-btn { display: inline-block; }
  .messages { padding: 14px 14px; }
  .bubble { max-width: 82%; }
}
