:root {
  --bg: #eef1f0;
  --panel: #ffffff;
  --panel-2: #eef2f1;
  --header: #f5f7f6;
  --text: #16211d;
  --text-soft: #6b7a75;
  --accent: #14a17c;
  --accent-2: #0c8a90;
  --accent-dark: #0f7d61;
  --out-bubble: #d6ece2;
  --in-bubble: #ffffff;
  --border: #e6ebe9;
  --danger: #e5484d;
  --tick-read: #14a17c;
  --shadow: 0 1px 2px rgba(16,32,26,.07);
  --chat-bg: #e8ecea;
}
:root[data-theme="dark"] {
  --bg: #0d1512;
  --panel: #131d19;
  --panel-2: #1d2a25;
  --header: #1a251f;
  --text: #e7edea;
  --text-soft: #8ba39a;
  --accent: #1ec592;
  --accent-2: #17a2b0;
  --accent-dark: #12a074;
  --out-bubble: #0f5e4c;
  --in-bubble: #1d2a25;
  --border: #223029;
  --danger: #f0666b;
  --tick-read: #52e0b0;
  --shadow: 0 1px 2px rgba(0,0,0,.3);
  --chat-bg: #0d1512;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; }
.hidden { display: none !important; }

.brand-gradient { background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%); }

/* ---------- Přihlašovací obrazovka ---------- */
.auth {
  height: 100%;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(150deg, var(--accent) 0%, var(--accent-2) 60%, #0a5f73 100%);
  padding: 16px;
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--panel);
  border-radius: 22px;
  padding: 34px 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,.28);
}
.auth-logo {
  width: 76px; height: 76px; margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
}
.auth-logo svg { width: 76px; height: 76px; }
.auth h1 { text-align: center; font-size: 27px; margin-bottom: 3px; letter-spacing: -.5px; }
.auth h1 b { color: var(--accent); }
.auth .tagline { text-align: center; color: var(--text-soft); margin-bottom: 22px; font-size: 14px; }
.auth label { display: block; font-size: 13px; color: var(--text-soft); margin: 14px 0 6px; }
.auth input {
  width: 100%; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--panel-2); color: var(--text); font-size: 15px;
}
.auth input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.btn-primary {
  width: 100%; margin-top: 22px; padding: 13px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border-radius: 12px; font-size: 15px; font-weight: 600;
  transition: filter .15s;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.auth-switch { text-align: center; margin-top: 18px; font-size: 14px; color: var(--text-soft); }
.auth-switch a { color: var(--accent); font-weight: 600; cursor: pointer; }
.auth-error { color: var(--danger); font-size: 13px; margin-top: 12px; text-align: center; min-height: 16px; }

/* ---------- Hlavní layout ---------- */
.app { display: flex; height: 100%; }
.sidebar {
  width: 30%; min-width: 300px; max-width: 460px;
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.chat-panel { flex: 1; display: flex; flex-direction: column; background: var(--chat-bg); position: relative; }

.side-header { height: 62px; background: var(--header); display: flex; align-items: center; padding: 0 14px; gap: 12px; }
.avatar {
  width: 42px; height: 42px; border-radius: 15px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 16px; overflow: hidden; flex-shrink: 0;
  background-size: cover; background-position: center;
}
.avatar.lg { width: 84px; height: 84px; border-radius: 28px; font-size: 32px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.side-header .me-name { flex: 1; font-weight: 600; font-size: 16px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; color: var(--text-soft); }
.icon-btn:hover { background: var(--panel-2); }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }

.search-box { padding: 8px 12px; background: var(--panel); }
.search-box input {
  width: 100%; padding: 10px 14px; border: none; border-radius: 12px;
  background: var(--panel-2); color: var(--text); font-size: 14px;
}
.search-box input:focus { outline: none; }

.conv-list { flex: 1; overflow-y: auto; }
.conv-item { display: flex; align-items: center; gap: 13px; padding: 11px 14px; cursor: pointer; }
.conv-item:hover, .conv-item.active { background: var(--panel-2); }
.conv-main { flex: 1; min-width: 0; border-bottom: 1px solid var(--border); padding-bottom: 11px; margin-top: 11px; }
.conv-item { padding-top: 0; padding-bottom: 0; }
.conv-item:last-child .conv-main { border-bottom: none; }
.conv-top { display: flex; justify-content: space-between; align-items: baseline; }
.conv-name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 12px; color: var(--text-soft); flex-shrink: 0; margin-left: 8px; }
.conv-bottom { display: flex; justify-content: space-between; align-items: center; margin-top: 3px; }
.conv-preview { font-size: 14px; color: var(--text-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 700;
  min-width: 20px; height: 20px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; padding: 0 6px; margin-left: 8px;
}
.avatar-wrap { position: relative; flex-shrink: 0; }
.presence-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--panel);
  position: absolute; bottom: -1px; right: -1px;
}
.list-hint { padding: 24px 16px; text-align: center; color: var(--text-soft); font-size: 14px; line-height: 1.5; }

/* ---------- Okno chatu ---------- */
.chat-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-soft); text-align: center; padding: 40px; gap: 18px;
}
.chat-empty svg { width: 110px; height: 110px; }
.chat-empty h2 { font-weight: 600; font-size: 26px; color: var(--text); }
.chat-empty p { max-width: 430px; font-size: 14px; line-height: 1.55; }

.chat-header {
  height: 62px; background: var(--header); display: flex; align-items: center;
  padding: 0 14px; gap: 12px; border-bottom: 1px solid var(--border); z-index: 3;
}
.chat-header .back { display: none; }
.chat-header .info { flex: 1; min-width: 0; cursor: pointer; }
.chat-header .info .name { font-weight: 600; font-size: 16px; }
.chat-header .info .status { font-size: 13px; color: var(--text-soft); }

/* Vlastní, originální pozadí chatu (jemné tečky v barvě značky) */
.messages {
  flex: 1; overflow-y: auto; padding: 18px 8%;
  display: flex; flex-direction: column; gap: 4px;
  background-color: var(--chat-bg);
  background-image: radial-gradient(circle at center, rgba(20,161,124,.10) 1.4px, transparent 1.5px);
  background-size: 26px 26px;
}
:root[data-theme="dark"] .messages { background-image: radial-gradient(circle at center, rgba(30,197,146,.07) 1.4px, transparent 1.5px); }

.msg {
  position: relative;
  max-width: 66%;
  padding: 7px 11px 8px;
  border-radius: 16px;
  box-shadow: var(--shadow);
  font-size: 14.5px; line-height: 1.4; word-wrap: break-word; white-space: pre-wrap;
}
.msg.out { align-self: flex-end; background: var(--out-bubble); border-bottom-right-radius: 5px; }
.msg.in  { align-self: flex-start; background: var(--in-bubble); border-bottom-left-radius: 5px; }
.msg .meta { display: flex; gap: 5px; align-items: center; justify-content: flex-end; margin-top: 3px; user-select: none; }
.msg .time { font-size: 11px; color: var(--text-soft); }
.msg .ticks { font-size: 12px; color: var(--text-soft); font-weight: 700; }
.msg .ticks.read { color: var(--tick-read); }
.msg img.attachment { max-width: 100%; border-radius: 12px; margin-bottom: 4px; display: block; cursor: pointer; }
.msg .file-att {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px;
  background: rgba(20,161,124,.08); border-radius: 12px; text-decoration: none; color: inherit; margin-bottom: 4px;
}
.msg .file-att svg { width: 30px; height: 30px; fill: var(--accent); flex-shrink: 0; }
.msg .file-att .fname { font-size: 14px; font-weight: 600; }
.msg .file-att .fsize { font-size: 12px; color: var(--text-soft); }

/* Hlasová zpráva */
.voice-msg { display: flex; align-items: center; gap: 10px; min-width: 190px; padding: 2px 0; }
.voice-play {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.voice-play svg { width: 20px; height: 20px; fill: #fff; }
.voice-body { flex: 1; }
.voice-bar { height: 4px; border-radius: 2px; background: rgba(20,161,124,.25); position: relative; overflow: hidden; }
.voice-bar > i { position: absolute; left: 0; top: 0; bottom: 0; width: 0%; background: var(--accent); border-radius: 2px; }
.voice-dur { font-size: 12px; color: var(--text-soft); margin-top: 5px; display: flex; align-items: center; gap: 6px; }
.voice-dur svg { width: 15px; height: 15px; fill: var(--accent); }

/* Reakce na zprávy */
.react-btn {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 30px; height: 30px; border-radius: 50%; background: var(--panel); box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity .12s; color: var(--text-soft);
}
.msg:hover .react-btn { opacity: 1; }
.msg.out .react-btn { left: -38px; }
.msg.in  .react-btn { right: -38px; }
.react-btn svg { width: 18px; height: 18px; fill: currentColor; }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.reaction-chip {
  display: inline-flex; align-items: center; gap: 3px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 1px 7px; font-size: 13px; cursor: pointer; line-height: 1.5;
}
.reaction-chip.mine { border-color: var(--accent); background: rgba(20,161,124,.12); }
.reaction-chip .cnt { font-size: 11px; color: var(--text-soft); font-weight: 600; }

.emoji-picker {
  position: fixed; z-index: 150; background: var(--panel); border-radius: 26px;
  box-shadow: 0 10px 40px rgba(0,0,0,.28); padding: 6px 8px; display: flex; gap: 2px;
}
.emoji-picker button { font-size: 26px; width: 42px; height: 42px; border-radius: 50%; transition: transform .1s, background .1s; }
.emoji-picker button:hover { transform: scale(1.25); background: var(--panel-2); }

.day-sep { align-self: center; background: var(--panel-2); color: var(--text-soft); font-size: 12px; padding: 5px 12px; border-radius: 10px; margin: 10px 0; box-shadow: var(--shadow); }
.typing-line { align-self: flex-start; color: var(--text-soft); font-size: 13px; font-style: italic; padding: 4px 9px; }
.enc-note {
  align-self: center; text-align: center; max-width: 520px;
  background: rgba(20,161,124,.12); color: var(--accent-dark); font-size: 12.5px;
  padding: 7px 14px; border-radius: 10px; margin: 4px 0 12px;
}
:root[data-theme="dark"] .enc-note { color: var(--tick-read); }

/* Composer */
.composer { min-height: 64px; background: var(--header); display: flex; align-items: flex-end; gap: 8px; padding: 9px 14px; }
.composer .icon-btn { flex-shrink: 0; }
.composer .input-wrap { flex: 1; background: var(--panel); border-radius: 22px; padding: 7px 15px; display: flex; }
.composer textarea { flex: 1; border: none; background: none; color: var(--text); resize: none; font-size: 15px; max-height: 120px; line-height: 1.4; padding: 4px 0; }
.composer textarea:focus { outline: none; }
.send-btn, .mic-btn {
  width: 47px; height: 47px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.send-btn:hover, .mic-btn:hover { filter: brightness(1.06); }
.send-btn svg, .mic-btn svg { width: 22px; height: 22px; fill: #fff; }
.mic-btn.recording { background: var(--danger); animation: pulse 1.1s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(229,72,77,.5);} 50% { box-shadow: 0 0 0 10px rgba(229,72,77,0);} }
.rec-bar {
  flex: 1; display: flex; align-items: center; gap: 12px; padding: 0 8px; color: var(--danger); font-weight: 600;
}
.rec-bar .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); animation: pulse 1.1s infinite; }
.rec-bar .cancel { margin-left: auto; color: var(--text-soft); font-weight: 500; }

/* ---------- Modaly ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal { background: var(--panel); border-radius: 18px; width: 100%; max-width: 420px; max-height: 85vh; overflow-y: auto; box-shadow: 0 16px 50px rgba(0,0,0,.4); }
.modal-header { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 18px; }
.modal-body { padding: 18px 20px; }
.modal-body label { display: block; font-size: 13px; color: var(--text-soft); margin: 12px 0 6px; }
.modal-body input, .modal-body textarea { width: 100%; padding: 11px 13px; border: 1px solid var(--border); border-radius: 11px; background: var(--panel-2); color: var(--text); font-size: 15px; }
.modal-body input:focus, .modal-body textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.search-result { display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-radius: 11px; cursor: pointer; }
.search-result:hover { background: var(--panel-2); }
.search-result .sr-name { font-weight: 600; }
.search-result .sr-user { font-size: 13px; color: var(--text-soft); }
.profile-view { text-align: center; padding: 10px 0 4px; }
.profile-view .avatar { margin: 0 auto 12px; }
.profile-view .pv-name { font-size: 20px; font-weight: 700; }
.profile-view .pv-user { color: var(--text-soft); margin-top: 2px; }
.profile-view .pv-about { margin-top: 14px; padding: 12px; background: var(--panel-2); border-radius: 11px; font-size: 14px; }

/* ---------- Hovor ---------- */
.call-screen { position: fixed; inset: 0; z-index: 200; background: #0a1613; display: flex; flex-direction: column; color: #fff; }
.call-remote-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #0a1613; }
.call-local-video { position: absolute; width: 120px; height: 160px; object-fit: cover; bottom: 120px; right: 20px; border-radius: 14px; border: 2px solid rgba(255,255,255,.3); background: #1d2a25; z-index: 2; }
.call-info { position: relative; z-index: 3; text-align: center; padding-top: 64px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.call-info .avatar { width: 116px; height: 116px; border-radius: 40px; font-size: 46px; }
.call-info .call-name { font-size: 26px; font-weight: 600; }
.call-info .call-state { font-size: 15px; color: rgba(255,255,255,.72); }
.call-controls { position: absolute; bottom: 0; left: 0; right: 0; z-index: 3; display: flex; justify-content: center; gap: 20px; padding: 34px; flex-wrap: wrap; }
.call-btn { width: 62px; height: 62px; border-radius: 50%; background: rgba(255,255,255,.16); color: #fff; display: flex; align-items: center; justify-content: center; }
.call-btn svg { width: 27px; height: 27px; fill: #fff; }
.call-btn.hangup { background: var(--danger); }
.call-btn.accept { background: var(--accent); }
.call-btn.active { background: #fff; }
.call-btn.active svg { fill: #0a1613; }
.call-btn .lbl { position: absolute; margin-top: 82px; font-size: 11px; color: rgba(255,255,255,.7); white-space: nowrap; }

.incoming-call { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 210; background: var(--panel); color: var(--text); border-radius: 18px; padding: 16px 20px; width: 340px; max-width: 92vw; box-shadow: 0 16px 50px rgba(0,0,0,.45); display: flex; align-items: center; gap: 14px; }
.incoming-call .ic-info { flex: 1; }
.incoming-call .ic-name { font-weight: 700; }
.incoming-call .ic-sub { font-size: 13px; color: var(--text-soft); }
.incoming-call .ic-actions { display: flex; gap: 10px; }
.ic-btn { width: 46px; height: 46px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.ic-btn svg { width: 22px; height: 22px; fill: #fff; }
.ic-btn.accept { background: var(--accent); }
.ic-btn.reject { background: var(--danger); }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #22302a; color: #fff; padding: 12px 20px; border-radius: 24px; font-size: 14px; z-index: 300; box-shadow: 0 6px 20px rgba(0,0,0,.3); animation: toastIn .2s ease; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } }

/* ---------- Mobil ---------- */
@media (max-width: 768px) {
  .sidebar { width: 100%; min-width: 0; max-width: none; }
  .app.chat-open .sidebar { display: none; }
  .app:not(.chat-open) .chat-panel { display: none; }
  .chat-header .back { display: flex; }
  .messages { padding: 12px 10px; }
  .msg { max-width: 82%; }
  .msg:hover .react-btn { opacity: 1; }
}
.spinner { width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Skupiny (Vlna 2) ---------- */
.avatar.group { background: linear-gradient(135deg, #0c8a90, #14a17c); }
.msg-sender { font-size: 12.5px; font-weight: 700; color: var(--accent); margin-bottom: 2px; }
:root[data-theme="dark"] .msg-sender { color: var(--tick-read); }
.msg .file-att { width: 100%; text-align: left; }
.grp-pick {
  display: flex; align-items: center; gap: 11px; padding: 8px 6px; border-radius: 10px; cursor: pointer;
}
.grp-pick:hover { background: var(--panel-2); }
.grp-pick input { width: 18px; height: 18px; accent-color: var(--accent); flex-shrink: 0; }
.grp-pick .avatar { width: 36px; height: 36px; font-size: 14px; }
#grpMembers { max-height: 46vh; overflow-y: auto; margin-top: 4px; }
