/* Tokeny barev; světlý/tmavý režim (prefers-color-scheme + ruční [data-theme]) */
:root {
  --accent: #2563eb; --accent-contrast: #fff;
  --bg: #f3f4f6; --panel: #ffffff; --panel-2: #f9fafb; --text: #111827; --muted: #6b7280; --border: #e5e7eb;
  --bubble-in: #ffffff; --bubble-out: #dbeafe; --bubble-out-text: #0b1b3a;
  --danger: #dc2626; --ok: #16a34a; --shadow: 0 8px 28px rgba(0,0,0,.18);
  --hover: rgba(0,0,0,.05); --focus: #2563eb;
  color-scheme: light dark;
}
:root[data-host="hasici"] { --accent: #c62828; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent: #60a5fa; --accent-contrast: #0b1220;
    --bg: #0b0f17; --panel: #121826; --panel-2: #0f1522; --text: #e5e7eb; --muted: #9ca3af; --border: #1f2937;
    --bubble-in: #1b2434; --bubble-out: #1e3a8a; --bubble-out-text: #e0ebff;
    --danger: #f87171; --ok: #4ade80; --shadow: 0 8px 28px rgba(0,0,0,.6); --hover: rgba(255,255,255,.07); --focus: #93c5fd;
  }
}
:root[data-theme="dark"] {
  --accent: #60a5fa; --accent-contrast: #0b1220;
  --bg: #0b0f17; --panel: #121826; --panel-2: #0f1522; --text: #e5e7eb; --muted: #9ca3af; --border: #1f2937;
  --bubble-in: #1b2434; --bubble-out: #1e3a8a; --bubble-out-text: #e0ebff;
  --danger: #f87171; --ok: #4ade80; --shadow: 0 8px 28px rgba(0,0,0,.6); --hover: rgba(255,255,255,.07); --focus: #93c5fd;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; -webkit-text-size-adjust: 100%; overflow: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
a { color: var(--accent); }
.muted { color: var(--muted); } .small { font-size: 12.5px; }
.noscript { padding: 1rem; }
.boot { display: grid; place-items: center; height: 100%; color: var(--muted); }

/* ---------- tlačítka a pole ---------- */
.btn { border: 1px solid var(--border); background: var(--panel); border-radius: 10px; padding: 8px 14px; min-height: 40px; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); color: var(--accent-contrast); border-color: transparent; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary.danger { background: var(--danger); }
.btn.danger-outline { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled, .icon-btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; width: 40px; height: 40px; border-radius: 50%; font-size: 18px; line-height: 1; display: inline-grid; place-items: center; flex: none; }
.icon-btn:hover { background: var(--hover); }
.link { border: 0; background: none; color: var(--accent); padding: 2px 4px; text-decoration: underline; font-size: inherit; }
input[type=text], input[type=tel], input[type=search], input[type=password], select, textarea {
  width: 100%; border: 1px solid var(--border); background: var(--panel-2); border-radius: 10px; padding: 9px 12px; min-height: 40px;
}
.field { display: block; margin: 10px 0; } .field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field-hint { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }
.form-error { color: var(--danger); font-size: 13.5px; min-height: 0; margin: 6px 0; }
.form-error:empty { display: none; }
.notice { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin: 10px 0; }
.btn-row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.tag { margin-left: 8px; font-size: 11.5px; padding: 1px 8px; border-radius: 99px; background: var(--hover); color: var(--muted); }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.inline-form .field { flex: 1 1 200px; margin: 0; }
.inline-form .form-error { flex-basis: 100%; }

/* ---------- přihlášení ---------- */
.auth-wrap { min-height: 100%; display: grid; place-items: center; padding: 16px; overflow: auto; }
.auth-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 24px; box-shadow: var(--shadow); }
.auth-brand { text-align: center; margin-bottom: 8px; } .auth-brand h1 { margin: 6px 0 0; font-size: 24px; } .auth-brand p { margin: 2px 0 0; }
.logo { width: 56px; height: 56px; border-radius: 16px; background: var(--accent); display: inline-grid; place-items: center; font-size: 28px; }
.logo.big { width: 84px; height: 84px; font-size: 42px; border-radius: 24px; }
.form h2 { font-size: 18px; margin: 12px 0 4px; }
.code-input { font-size: 24px; letter-spacing: .4em; text-align: center; }
.switch { text-align: center; margin: 14px 0 0; }

/* ---------- rozložení ---------- */
.app { display: flex; height: 100dvh; height: 100vh; height: 100dvh; width: 100%; }
.sidebar { width: 360px; max-width: 40vw; min-width: 280px; display: flex; flex-direction: column; background: var(--panel); border-right: 1px solid var(--border); }
.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.sb-head { display: flex; align-items: center; gap: 4px; padding: 10px 8px 6px 12px; }
.me-btn { display: flex; align-items: center; gap: 10px; border: 0; background: none; flex: 1; min-width: 0; text-align: left; padding: 4px; border-radius: 10px; }
.me-btn:hover { background: var(--hover); }
.me-text { display: flex; flex-direction: column; min-width: 0; } .me-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search { padding: 6px 12px 10px; }
.conn-banner { background: #b45309; color: #fff; padding: 6px 12px; font-size: 13px; text-align: center; }
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.list-empty { padding: 24px 16px; color: var(--muted); text-align: center; }
.conv-item { display: flex; gap: 12px; padding: 10px 12px; text-decoration: none; color: inherit; align-items: center; border-left: 3px solid transparent; }
.conv-item:hover { background: var(--hover); } .conv-item.active { background: var(--hover); border-left-color: var(--accent); }
.conv-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.conv-top, .conv-bottom { display: flex; gap: 8px; justify-content: space-between; align-items: center; }
.conv-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item.unread .conv-title { font-weight: 700; }
.conv-time { font-size: 12px; color: var(--muted); flex: none; }
.conv-preview { color: var(--muted); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-preview.typing { color: var(--accent); font-style: italic; }
.badge { background: var(--accent); color: var(--accent-contrast); border-radius: 99px; font-size: 12px; font-weight: 700; min-width: 20px; padding: 1px 6px; text-align: center; flex: none; }
.avatar { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; color: #fff; font-weight: 600; flex: none; user-select: none; }

.chat-empty { margin: auto; text-align: center; color: var(--muted); padding: 24px; }
.chat-head { display: flex; align-items: center; gap: 4px; padding: 8px 8px; background: var(--panel); border-bottom: 1px solid var(--border); }
.chat-head .back { display: none; }
.head-main { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; border: 0; background: none; text-align: left; padding: 4px 6px; border-radius: 10px; }
.head-main:hover { background: var(--hover); }
.head-text { display: flex; flex-direction: column; min-width: 0; } .head-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-wrap { position: relative; flex: 1; min-height: 0; display: flex; }
.thread-scroll { flex: 1; overflow-y: auto; padding: 8px 12px; overscroll-behavior: contain; }
.thread { display: flex; flex-direction: column; gap: 3px; max-width: 900px; margin: 0 auto; min-height: 100%; justify-content: flex-end; }
.thread-empty, .older { text-align: center; color: var(--muted); padding: 16px; }
.day-sep, .unread-sep { text-align: center; margin: 10px 0 4px; } 
.day-sep span, .unread-sep span { background: var(--panel); border: 1px solid var(--border); border-radius: 99px; padding: 2px 12px; font-size: 12px; color: var(--muted); }
.unread-sep span { color: var(--accent); border-color: var(--accent); }
.jump { position: absolute; right: 16px; bottom: 12px; border: 0; background: var(--accent); color: var(--accent-contrast); border-radius: 99px; padding: 8px 14px; box-shadow: var(--shadow); font-weight: 600; }
.typing-line { min-height: 20px; padding: 0 16px 2px; font-size: 13px; color: var(--accent); font-style: italic; }

/* ---------- bubliny ---------- */
.msg-row { display: flex; align-items: flex-end; gap: 4px; max-width: 100%; }
.msg-row.mine { justify-content: flex-end; } .msg-row.theirs { justify-content: flex-start; }
.msg-row.mine .msg-menu-btn { order: -1; }
.msg-row.flash .bubble { outline: 2px solid var(--accent); }
.bubble { max-width: min(560px, 82%); padding: 6px 10px 4px; border-radius: 14px; background: var(--bubble-in); border: 1px solid var(--border); overflow-wrap: anywhere; position: relative; }
.mine .bubble { background: var(--bubble-out); color: var(--bubble-out-text); border-color: transparent; border-bottom-right-radius: 4px; }
.theirs .bubble { border-bottom-left-radius: 4px; }
.bubble.pending { opacity: .7; } .bubble.failed { outline: 1px solid var(--danger); }
.sender { font-size: 12.5px; font-weight: 700; color: var(--accent); margin-bottom: 1px; }
.msg-text { white-space: pre-wrap; word-break: break-word; }
.msg-text.deleted { font-style: italic; color: var(--muted); }
.msg-link { color: inherit; text-decoration: underline; }
.meta { display: flex; gap: 8px; align-items: center; justify-content: flex-end; font-size: 11.5px; opacity: .75; margin-top: 1px; flex-wrap: wrap; }
.meta .err { color: var(--danger); font-weight: 600; opacity: 1; }
.ticks.all { color: var(--ok); } .ticks.part { color: var(--accent); }
.msg-menu-btn { border: 0; background: transparent; border-radius: 50%; width: 28px; height: 28px; color: var(--muted); opacity: .45; flex: none; font-size: 16px; }
.msg-row:hover .msg-menu-btn, .msg-menu-btn:focus-visible { opacity: 1; background: var(--hover); }
.quote { display: block; width: 100%; text-align: left; border: 0; border-left: 3px solid var(--accent); background: var(--hover); border-radius: 6px; padding: 3px 8px; margin: 2px 0 4px; }
.quote-who { display: block; font-size: 12px; font-weight: 700; color: var(--accent); } .quote-text { display: block; font-size: 13px; opacity: .85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 2px; }
.react-chip { border: 1px solid var(--border); background: var(--panel); border-radius: 99px; padding: 1px 8px; font-size: 13px; display: inline-flex; gap: 4px; align-items: center; color: var(--text); }
.react-chip.mine { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, var(--panel)); }
.react-chip .cnt { font-size: 12px; }
.att { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); color: var(--text); margin: 2px 0; max-width: 100%; text-align: left; }
.att.gone { color: var(--muted); font-style: italic; } .att-meta { display: flex; flex-direction: column; min-width: 0; } .att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.att-image { display: block; border: 0; padding: 0; background: none; border-radius: 10px; overflow: hidden; margin: 2px 0; }
.att-img { display: block; max-width: 100%; max-height: 300px; min-width: 120px; min-height: 80px; object-fit: cover; border-radius: 10px; background: var(--hover); }

/* ---------- skladač ---------- */
.composer { background: var(--panel); border-top: 1px solid var(--border); padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
.compose-row { display: flex; align-items: flex-end; gap: 2px; max-width: 900px; margin: 0 auto; }
.compose-row textarea { resize: none; border-radius: 20px; min-height: 40px; max-height: 160px; padding: 9px 14px; line-height: 1.35; }
.icon-btn.send { background: var(--accent); color: var(--accent-contrast); margin-left: 2px; }
.icon-btn.send:hover { filter: brightness(1.1); background: var(--accent); }
.compose-banner { display: flex; align-items: center; gap: 8px; border-left: 3px solid var(--accent); background: var(--hover); border-radius: 8px; padding: 4px 8px; margin: 0 auto 6px; max-width: 900px; }
.cb-text { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 13px; } .cb-quote { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.attach-list { max-width: 900px; margin: 0 auto; display: flex; flex-direction: column; gap: 4px; }
.attach-list:not(:empty) { margin-bottom: 6px; }
.attach-chip { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 10px; padding: 2px 4px 2px 10px; background: var(--panel-2); }
.attach-chip.error { border-color: var(--danger); } .attach-chip progress { width: 80px; } .attach-chip .att-name { flex: 1; }

/* ---------- popover, emoji ---------- */
.popover { position: fixed; z-index: 100; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); max-width: calc(100vw - 16px); }
.menu { display: flex; flex-direction: column; padding: 4px; min-width: 200px; }
.menu-item { border: 0; background: none; text-align: left; padding: 9px 12px; border-radius: 8px; } .menu-item:hover { background: var(--hover); } .menu-item.danger { color: var(--danger); }
.quick-react { display: flex; gap: 2px; padding: 6px; border-bottom: 1px solid var(--border); }
.emoji-btn { border: 0; background: none; font-size: 24px; width: 40px; height: 40px; border-radius: 8px; line-height: 1; } .emoji-btn:hover { background: var(--hover); }
.emoji-panel { width: min(340px, calc(100vw - 16px)); }
.emoji-tabs { display: flex; border-bottom: 1px solid var(--border); overflow-x: auto; }
.emoji-tab { border: 0; background: none; font-size: 18px; padding: 8px 10px; border-bottom: 2px solid transparent; flex: none; } .emoji-tab.active { border-bottom-color: var(--accent); }
.emoji-grid { display: grid; grid-template-columns: repeat(7, 1fr); max-height: 240px; overflow-y: auto; padding: 4px; }

/* ---------- modální okna ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 50; display: grid; place-items: center; padding: 12px; }
.modal { background: var(--panel); border-radius: 16px; width: min(460px, 100%); max-height: calc(100dvh - 24px); display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal.wide { width: min(620px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 20px; border-bottom: 1px solid var(--border); }
.modal-title { margin: 0; font-size: 18px; } .modal-body { padding: 8px 20px 20px; overflow-y: auto; }
.dlg-section { padding: 12px 0; border-bottom: 1px solid var(--border); } .dlg-section:last-child { border-bottom: 0; }
.dlg-section h3 { margin: 0 0 8px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.dlg-sub { margin-top: 14px; }
.row-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; } .row-item .grow { flex: 1; min-width: 0; }
.tabs { display: flex; gap: 4px; margin: 6px 0 10px; } .tab { flex: 1; border: 0; border-bottom: 2px solid var(--border); background: none; padding: 8px; } .tab.active { border-bottom-color: var(--accent); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--hover); border-radius: 99px; padding: 2px 4px 2px 12px; }
.chip-x { border: 0; background: none; width: 24px; height: 24px; border-radius: 50%; }
.info-head { display: flex; align-items: center; gap: 14px; padding: 8px 0; } .info-head h3 { margin: 0; }
.lightbox { text-align: center; } .lightbox img { max-width: 100%; max-height: 70vh; border-radius: 8px; }
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 200; width: min(440px, calc(100vw - 24px)); pointer-events: none; }
.toast { background: #1f2937; color: #fff; border-radius: 10px; padding: 10px 14px; box-shadow: var(--shadow); } .toast.error { background: #b91c1c; }

/* ---------- mobil ---------- */
@media (max-width: 760px) {
  .sidebar { width: 100%; max-width: none; border-right: 0; }
  .app .chat { display: none; } .app[data-view="chat"] .sidebar { display: none; } .app[data-view="chat"] .chat { display: flex; }
  .chat-head .back { display: inline-grid; }
  .bubble { max-width: 88%; }
  .modal-backdrop { align-items: end; padding: 0; } .modal, .modal.wide { width: 100%; border-radius: 16px 16px 0 0; max-height: 92dvh; }
  .msg-menu-btn { opacity: .7; }
}
@media (prefers-reduced-motion: no-preference) { .toast { animation: pop .15s ease-out; } @keyframes pop { from { transform: translateY(8px); opacity: 0; } } }
