/* ==========================================================================
   Chat (design Swarmind). Staví na site.css (proměnné, tlačítka, modaly, verdikt).
   Rozložení: postranní panel s rojem modelů + hlavní plocha s okny a polem pro otázku.
   Třídy a ID odpovídají app.js – neměnit bez úpravy skriptu.
   ========================================================================== */

body.page-chat { height: 100vh; height: 100dvh; overflow: hidden; }
.page-chat main { position: fixed; inset: 88px 0 0; display: flex; }
/* panel i plocha lícují přesně s okraji plovoucí navigace */
.chat-shell { flex: 1; min-width: 0; min-height: 0; display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 14px; padding: 0 var(--gutter) 14px; max-width: calc(var(--nav-max) + 2 * var(--gutter)); margin: 0 auto; width: 100%; }

/* ---------------------------------------------------------------- postranní panel */
.chat-side { min-height: 0; display: flex; flex-direction: column; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); overflow: hidden; }
.dropdown { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.side-toggle { display: flex; align-items: center; gap: 10px; padding: 18px 18px 12px; cursor: default; }
.side-title { display: flex; align-items: center; gap: 10px; font: 700 18px var(--display); letter-spacing: -0.02em; }
.side-title .icon { color: var(--accent); }
.picker-count { margin-left: auto; font: 700 12px var(--mono); color: var(--accent-ink); background: var(--accent); border-radius: 999px; padding: 3px 9px; }
.side-toggle .arrow { display: none; }
.dropdown-content { flex: 1; min-height: 0; overflow-y: auto; padding: 0 10px 10px; }
.side-hint { margin: 0 8px 10px; font-size: 13px; color: var(--dim); }
.dropdown-item { position: relative; display: grid; grid-template-columns: 22px 1fr auto 34px; align-items: center; gap: 10px; padding: 10px; border-radius: 14px; cursor: pointer;
    font-size: 14.5px; color: var(--text-2); transition: background .15s; }
.dropdown-item:hover { background: rgba(255, 255, 255, .04); }
.dropdown-item input { position: absolute; opacity: 0; pointer-events: none; }
.dropdown-item .item-logo { width: 22px; height: 22px; object-fit: contain; }
.dropdown-item .model-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dropdown-item .switch { grid-column: 4; position: relative; width: 34px; height: 20px; border-radius: 99px; background: var(--surface-3); transition: background .2s; }
.dropdown-item .switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--dim); transition: transform .25s var(--ease), background .2s; }
.dropdown-item input:checked ~ .switch { background: var(--accent); }
.dropdown-item input:checked ~ .switch::after { transform: translateX(14px); background: var(--accent-ink); }
.dropdown-item input:focus-visible ~ .switch { box-shadow: 0 0 0 3px var(--accent-soft); }
.dropdown-item.toggled { background: var(--accent-soft); color: var(--text); }
.dropdown-item.unavailable, .dropdown-item.locked { color: var(--dim); }
.dropdown-item.unavailable { cursor: not-allowed; }
.dropdown-item.unavailable .item-logo, .dropdown-item.locked .item-logo { opacity: .45; }
.model-badge { grid-column: 3; display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px; border-radius: 999px; font: 700 10px var(--mono); letter-spacing: .05em; }
.model-badge .icon { width: 11px; height: 11px; }
.model-badge.pro { background: var(--accent-soft); color: var(--accent); }
.model-badge.soon { background: var(--surface-3); color: var(--muted); }
.model-badge.own { background: var(--accent); color: var(--accent-ink); }
.dropdown-item:not(.locked) .icon-lock, .dropdown-item.locked .icon-pro { display: none; }
.dropdown-item.unavailable .switch { visibility: hidden; }
.dropdown-keys { width: 100%; margin-top: 6px; display: flex; align-items: center; gap: 10px; padding: 12px 10px; border-radius: 14px; font-size: 14px; color: var(--muted); }
.dropdown-keys:hover { color: var(--text); background: rgba(255, 255, 255, .04); }
.dropdown-keys .icon { width: 16px; height: 16px; color: var(--accent); }
.side-tools { padding: 10px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.side-tool { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 14px; font-size: 14px; color: var(--text-2); text-align: left; transition: background .2s, color .2s; }
.side-tool:hover { background: rgba(255, 255, 255, .04); color: var(--text); }
.side-tool .icon { width: 17px; height: 17px; color: var(--muted); }
.side-tool .switch { margin-left: auto; position: relative; width: 34px; height: 20px; border-radius: 99px; background: var(--surface-3); transition: background .2s; }
.side-tool .switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--dim); transition: transform .25s var(--ease), background .2s; }
.memory-btn.on .switch { background: var(--accent); }
.memory-btn.on .switch::after { transform: translateX(14px); background: var(--accent-ink); }
.memory-btn.on .icon { color: var(--accent); }
.keys-count { margin-left: auto; font: 700 11px var(--mono); color: var(--accent); }
.usage-status { margin: 0 10px 10px; padding: 14px; border-radius: 16px; background: var(--surface-2); display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font: 500 12.5px var(--mono); color: var(--muted); }
.usage-status:empty { display: none; }
.usage-tier { font: 700 13px var(--sans); color: var(--accent-ink); background: var(--accent); border-radius: 999px; padding: 2px 10px; }
.usage-sep { color: var(--line-2); }
.usage-status a { color: var(--text); }
.usage-status a:hover { color: var(--accent); }
.usage-status .icon { width: 15px; height: 15px; color: var(--warn); }

/* ---------------------------------------------------------------- hlavní plocha */
.chat-main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.chat-stage { position: relative; flex: 1; min-height: 0; }
.chat-windows { height: 100%; display: grid; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); gap: 12px; padding-bottom: 12px; }
.chat-windows[data-count="1"] { --cols: 1; }
.chat-windows[data-count="3"] { --cols: 3; }
.chat-windows[data-count="4"] { --cols: 4; }
.is-empty .chat-windows { visibility: hidden; }
.chat-box-wrapper { min-width: 0; min-height: 0; display: flex; flex-direction: column; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line); overflow: hidden; animation: rise .5s var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(12px) scale(.99); } }
.chat-box-wrapper.dragging { opacity: .4; border-style: dashed; border-color: var(--accent-line); }
.chat-head { flex: none; display: flex; align-items: center; gap: 10px; padding: 14px 10px 14px 16px; background: var(--surface-2); }
.chat-logo { width: 30px; height: 30px; padding: 6px; border-radius: 10px; background: var(--bg); object-fit: contain; }
.chat-title { margin: 0; font: 700 15px var(--display); letter-spacing: -0.015em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-badge { font: 700 10px var(--mono); letter-spacing: .05em; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 2px 7px; }
.chat-tools { margin-left: auto; display: flex; gap: 2px; }
.chat-tool { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; color: var(--dim); transition: color .2s, background .2s; }
.chat-tool:hover { color: var(--text); background: rgba(255, 255, 255, .06); }
.chat-tool .icon { width: 15px; height: 15px; }
.drag-handle { cursor: grab; }
.chat-box { flex: 1; min-height: 0; overflow-y: auto; padding: 18px; }
.chat-content { display: flex; flex-direction: column; gap: 16px; }
.chat-content:empty::before { content: "Waiting for your question"; display: block; padding: 24px 0; text-align: center; font: 400 12.5px var(--mono); color: var(--dim); }

/* zprávy */
.chat-message { font-size: 14.5px; line-height: 1.7; color: var(--text-2); overflow-wrap: anywhere; }
.chat-message .model-logo { display: none; }
.chat-message.user { align-self: stretch; padding: 12px 14px; border-radius: 14px; background: var(--bg); border-left: 3px solid var(--accent); color: var(--text); white-space: pre-wrap; font-weight: 500; }
.animated-text > :first-child { margin-top: 0; }
.animated-text p { margin: 0 0 .75em; }
.animated-text p:last-child { margin-bottom: 0; }
.animated-text strong { color: var(--text); font-weight: 600; }
.animated-text ul, .animated-text ol { margin: 0 0 .75em; padding-left: 20px; }
.animated-text li + li { margin-top: 4px; }
.animated-text li::marker { color: var(--accent); }
.animated-text h3, .animated-text h4, .animated-text h5, .animated-text h6 { margin: 1em 0 .4em; font: 700 15px var(--display); color: var(--text); }
.animated-text code { font-size: 12.5px; color: var(--accent); background: var(--surface-3); border-radius: 5px; padding: 1px 5px; }
.animated-text pre { margin: .6em 0 .9em; padding: 12px 14px; overflow-x: auto; background: #070807; border: 1px solid var(--line); border-radius: 12px; }
.animated-text pre code { background: none; padding: 0; color: var(--text-2); line-height: 1.6; }
.animated-text a { color: var(--text); border-bottom: 1px solid var(--line-2); }
.chat-message.error, .chat-message.locked { padding: 12px 14px; border-radius: 14px; font-size: 14px; }
.chat-message.error { background: rgba(255, 123, 107, .08); border: 1px solid rgba(255, 123, 107, .3); color: #ffb3a8; }
.chat-message.locked { background: var(--accent-soft); border: 1px solid var(--accent-line); color: var(--text-2); }
.message-icon { display: inline-block; width: 15px; height: 15px; margin-right: 8px; vertical-align: -2px; }
.chat-message.locked .message-icon { color: var(--accent); }
.msg-note { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; font: 400 12px var(--mono); color: var(--dim); }
.msg-note .icon { width: 14px; height: 14px; }
.msg-files { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.msg-file { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 9px 0 4px; border-radius: 8px; background: var(--surface-2); font: 500 12px var(--mono); color: var(--text-2); }
.msg-file img { width: 20px; height: 20px; border-radius: 5px; object-fit: cover; }
.msg-file .icon { width: 14px; height: 14px; margin-left: 4px; color: var(--accent); }
.msg-sources { border-radius: 14px; background: var(--surface-2); font-size: 13px; }
.msg-sources summary { display: flex; align-items: center; gap: 8px; padding: 10px 12px; cursor: pointer; list-style: none; font: 500 12px var(--mono); color: var(--muted); }
.msg-sources summary::-webkit-details-marker { display: none; }
.msg-sources summary .icon { width: 14px; height: 14px; color: var(--accent); }
.msg-sources[open] summary { border-bottom: 1px solid var(--line); }
.msg-sources ol { margin: 0; padding: 8px 12px 10px 30px; display: flex; flex-direction: column; gap: 6px; color: var(--dim); }
.msg-sources li a { color: var(--text-2); }
.msg-sources li a:hover { color: var(--accent); }
.msg-sources li span { display: block; font: 400 11.5px var(--mono); color: var(--dim); }
.typing-loader { display: inline-flex; gap: 6px; padding: 8px 0; }
.typing-loader span { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); opacity: .25; animation: swarm-dot 1.1s infinite; }
.typing-loader span:nth-child(2) { animation-delay: .15s; }
.typing-loader span:nth-child(3) { animation-delay: .3s; }
@keyframes swarm-dot { 40% { opacity: 1; transform: translateY(-4px) scale(1.15); } }

/* ---------------------------------------------------------------- prázdný stav */
.chat-empty { position: absolute; inset: 0; z-index: 1; display: none; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 20px; }
.is-empty .chat-empty { display: flex; }
.empty-mark { width: 72px; height: 72px; border-radius: 22px; background: var(--accent); display: grid; place-items: center; box-shadow: 0 0 60px rgba(184, 242, 58, .3); animation: float 5s ease-in-out infinite; }
.empty-mark img { width: 72%; }
@keyframes float { 50% { transform: translateY(-8px); } }
.chat-empty h1 { margin-top: 26px; font-size: clamp(32px, 4vw, 56px); line-height: 1; letter-spacing: -0.045em; }
.chat-empty h1 span { color: var(--dim); }
.prompt-grid { margin-top: 34px; width: 100%; max-width: 720px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.prompt { display: flex; align-items: center; gap: 14px; padding: 16px 18px; text-align: left; font-size: 14.5px; line-height: 1.4; color: var(--text-2); border-radius: 18px; background: var(--surface); border: 1px solid var(--line);
    transition: border-color .2s, background .2s, transform .25s var(--ease); }
.prompt .icon { width: 36px; height: 36px; padding: 9px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); }
.prompt:hover { border-color: var(--accent-line); transform: translateY(-2px); color: var(--text); }
.prompt span { display: flex; flex-direction: column; gap: 3px; font-size: 13.5px; color: var(--muted); }
.prompt span b { font: 700 15.5px var(--display); color: var(--text); letter-spacing: -0.01em; }
.prompt { align-items: flex-start; }

/* přetažení souboru */
.drop-overlay { position: absolute; inset: 0 0 12px; z-index: 5; display: grid; place-items: center; border-radius: var(--r-lg); border: 2px dashed var(--accent); background: rgba(11, 12, 11, .88); opacity: 0; pointer-events: none; transition: opacity .15s; }
.dropping .drop-overlay { opacity: 1; }
.drop-overlay div { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.drop-overlay .icon { width: 30px; height: 30px; color: var(--accent); margin-bottom: 6px; }
.drop-overlay strong { font: 700 20px var(--display); }
.drop-overlay span { font-size: 14px; color: var(--muted); }

/* ---------------------------------------------------------------- pole pro otázku */
.composer-wrap { flex: none; width: 100%; max-width: 900px; margin: 0 auto; position: relative; }
.turn-actions { display: flex; justify-content: center; gap: 8px; margin-bottom: 10px; }
.quorum-btn span { font-weight: 500; opacity: .7; margin-left: 2px; }
.quorum-btn.loading .icon { animation: spin 1s linear infinite; }
.quorum-btn:disabled { opacity: .7; }
.web-hint { display: flex; align-items: center; gap: 10px; margin: 0 auto 10px; width: fit-content; max-width: 100%; padding: 6px 6px 6px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line-2); font-size: 13.5px; color: var(--muted); }
.web-hint .icon { width: 15px; height: 15px; color: var(--accent); }
.web-hint button { height: 30px; padding: 0 12px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-size: 13px; font-weight: 600; }
.composer { border-radius: 26px; background: var(--surface); border: 1px solid var(--line-2); transition: border-color .2s, box-shadow .2s; }
.composer:focus-within { border-color: var(--accent-line); box-shadow: 0 0 0 5px var(--accent-soft); }
.composer textarea { display: block; width: 100%; min-height: 58px; max-height: 200px; resize: none; border: 0; outline: 0; background: none; color: var(--text); padding: 18px 22px 4px; font: 400 16px/1.55 var(--sans); }
.composer textarea::placeholder { color: var(--dim); }
.composer-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px 10px 12px; }
.c-tool { display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-2); font-size: 14px; color: var(--text-2); cursor: pointer; transition: color .2s, border-color .2s, background .2s; }
.c-tool.attach-btn { width: 38px; padding: 0; justify-content: center; }
.c-tool:hover { color: var(--text); border-color: #4a524a; }
.c-tool .icon { width: 16px; height: 16px; }
.c-tool.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.c-tool[data-unavailable] { opacity: .5; }
.composer-hint { margin-left: auto; font-size: 12px; color: var(--dim); display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.send { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); flex: none; transition: background .2s, opacity .2s, transform .25s var(--ease); }
.send:hover { background: var(--accent-2); transform: scale(1.05); }
.send .icon { width: 19px; height: 19px; stroke-width: 2.6; }
.composer.busy .send, .send:disabled { opacity: .45; cursor: default; transform: none; }
.attach-list { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 14px 0; }
.attach-chip { display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 4px 0 5px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line-2); font: 500 12.5px var(--mono); color: var(--text-2); max-width: 240px; }
.attach-chip img { width: 22px; height: 22px; border-radius: 6px; object-fit: cover; }
.attach-chip > .icon { width: 15px; height: 15px; color: var(--accent); margin-left: 4px; }
.attach-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-chip button { width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center; color: var(--dim); }
.attach-chip button:hover { color: var(--text); background: rgba(255, 255, 255, .06); }
.attach-chip button .icon { width: 13px; height: 13px; }
.composer-note { margin: 8px 0 0; text-align: center; font-size: 12px; color: var(--dim); }

/* sdílení v modalu */
.share-preview { width: 100%; height: auto; border-radius: 16px; border: 1px solid var(--line); }
.share-link { margin-top: 16px; display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 16px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--bg); }
.share-link > .icon { width: 16px; height: 16px; color: var(--muted); }
.share-link input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--text); font: 400 13.5px var(--mono); }
.share-actions { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 8px; }
#share-modal .modal-note { margin-top: 14px; }

/* ---------------------------------------------------------------- responzivita */
@media (max-width: 1280px) {
    .chat-shell { grid-template-columns: 260px minmax(0, 1fr); }
    .chat-windows[data-count="4"] { --cols: 2; grid-auto-rows: minmax(0, 1fr); }
}
@media (max-width: 900px) {
    .page-chat main { inset: 78px 0 0; }
    .chat-shell { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); padding: 0 var(--gutter) 10px; gap: 10px; }
    .chat-side { overflow: visible; position: relative; z-index: 20; }
    .dropdown { position: relative; }
    .side-toggle { cursor: pointer; padding: 14px 16px; }
    .side-toggle .arrow { display: inline-flex; color: var(--muted); transition: transform .2s; }
    .side-toggle .arrow.show { transform: rotate(180deg); }
    .dropdown-content { position: absolute; top: calc(100% + 8px); left: 0; right: 0; max-height: 60vh; padding: 10px; border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--line-2);
        box-shadow: 0 30px 80px rgba(0, 0, 0, .6); opacity: 0; visibility: hidden; transform: translateY(-6px); transition: opacity .2s, transform .25s var(--ease), visibility .2s; }
    .dropdown-content.show { opacity: 1; visibility: visible; transform: none; }
    .side-tools { flex-direction: row; overflow-x: auto; padding: 0 10px 10px; border-top: 0; }
    .side-tool { flex: none; border: 1px solid var(--line); border-radius: 999px; padding: 8px 12px; }
    .usage-status { display: none; }
    .chat-windows, .chat-windows[data-count] { --cols: 1; grid-auto-flow: column; grid-auto-columns: 88%; grid-template-columns: none; overflow-x: auto; scroll-snap-type: x mandatory; }
    .chat-box-wrapper { scroll-snap-align: start; }
    .prompt-grid { grid-template-columns: 1fr; }
    .chat-empty { justify-content: flex-start; overflow-y: auto; }
    .composer-hint, .composer-note { display: none; }
    .composer-row .send { margin-left: auto; }
    .quorum-btn span { display: none; }
}
