/* DumbAI — chat UI. Teplé neutrály, terakotový akcent, světlý/tmavý dle systému. */

:root {
    --bg: #FAF9F5;
    --surface: #FFFFFF;
    --surface-2: #F3F1EA;
    --border: #E5E1D8;
    --text: #2A2620;
    --muted: #6E675D;
    --accent: #C15F3C;
    --accent-hover: #A84E2F;
    --accent-soft: #F7E9E2;
    --warn-bg: #FBF3DC;
    --warn-border: #E4D194;
    --error-bg: #F9E7E4;
    --error-border: #DEA79D;
    --shadow: 0 1px 3px rgba(74, 60, 48, 0.08);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #262624;
        --surface: #30302E;
        --surface-2: #3A3A37;
        --border: #44443F;
        --text: #ECEAE4;
        --muted: #A6A196;
        --accent: #D97757;
        --accent-hover: #E68A6C;
        --accent-soft: #453530;
        --warn-bg: #3D3728;
        --warn-border: #6B5F35;
        --error-bg: #43302C;
        --error-border: #7A4A40;
        --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
    font-family: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
}

/* ---------- topbar ---------- */

.topbar {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.7rem 1.1rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 10;
}

.logo { border-radius: 8px; display: block; }

.icon-btn {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    color: var(--muted);
    border-radius: 9px;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- sidebar ---------- */

#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 40;
    width: 280px;
    max-width: 82vw;
    height: 100dvh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 0.7rem;
    transform: translateX(-100%);
    transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}
#sidebar.open { transform: none; }

#sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgba(0, 0, 0, 0.35);
}

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.2rem 0.3rem 0.6rem;
}
.sidebar-title { font-weight: 650; letter-spacing: -0.01em; }

.new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    width: 100%;
    border: 1px solid var(--border);
    background: var(--accent-soft);
    color: var(--accent);
    font: inherit;
    font-weight: 600;
    font-size: 0.9rem;
    padding: 0.6rem;
    border-radius: 11px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.new-chat-btn:hover { background: var(--accent); color: var(--surface); border-color: var(--accent); }

.history-search {
    width: 100%;
    margin-top: 0.55rem;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font: inherit;
    font-size: 0.88rem;
    padding: 0.45rem 0.7rem;
    border-radius: 9px;
    transition: border-color 0.15s;
}
.history-search:focus { outline: none; border-color: var(--accent); }
.history-search::placeholder { color: var(--muted); }

.search-hit {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    width: 100%;
    text-align: left;
    border: none;
    background: none;
    color: var(--text);
    font: inherit;
    padding: 0.55rem 0.6rem;
    border-radius: 9px;
    cursor: pointer;
    transition: background 0.12s;
}
.search-hit:hover { background: var(--surface-2); }
.hit-fact {
    font-size: 0.85rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.hit-chat { font-size: 0.72rem; color: var(--muted); }

.chat-list {
    list-style: none;
    margin-top: 0.7rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.chat-row {
    display: flex;
    align-items: center;
    border-radius: 9px;
    transition: background 0.12s;
}
.chat-row:hover { background: var(--surface-2); }

.chat-item {
    flex: 1;
    min-width: 0;
    text-align: left;
    border: none;
    background: none;
    color: var(--text);
    font: inherit;
    font-size: 0.9rem;
    padding: 0.55rem 0.6rem;
    border-radius: 9px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-row:has(.chat-item.active) { background: var(--accent-soft); }
.chat-item.active { color: var(--accent); font-weight: 600; }
.chat-item.is-draft { cursor: default; font-style: italic; }

.chat-action {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    margin-right: 0.15rem;
    border: none;
    background: none;
    color: var(--muted);
    border-radius: 7px;
    cursor: pointer;
    display: none;
    place-items: center;
    transition: background 0.12s, color 0.12s;
}
.chat-row:hover .chat-action { display: grid; }
.rename-chat:hover { background: var(--accent-soft); color: var(--accent); }
.delete-chat:hover { background: var(--error-bg); color: var(--accent); }

@media (hover: none) {
    .chat-action { display: grid; }
}

.chat-empty {
    color: var(--muted);
    font-size: 0.85rem;
    padding: 0.6rem;
    text-align: center;
}

.brand { display: flex; flex-direction: column; line-height: 1.25; }
.brand-name { font-weight: 650; letter-spacing: -0.01em; }
.brand-sub { font-size: 0.76rem; color: var(--muted); }

/* ---------- thread ---------- */

#thread {
    flex: 1;
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
    padding: 1.4rem 1rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
}

#empty-state {
    margin: auto;
    text-align: center;
    padding: 2rem 1rem;
    max-width: 26rem;
}
#empty-state img { border-radius: 12px; margin-bottom: 1rem; }
#empty-state h1 { font-size: 1.5rem; letter-spacing: -0.02em; margin-bottom: 0.4rem; }
#empty-state p { color: var(--muted); font-size: 0.95rem; }

/* uživatelský dotaz */
.turn-user {
    align-self: flex-end;
    max-width: 85%;
    background: var(--accent-soft);
    border-radius: 16px 16px 4px 16px;
    padding: 0.6rem 0.95rem;
    white-space: pre-wrap;
    word-break: break-word;
}

/* odpověď */
.turn-assistant {
    align-self: stretch;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1rem 1.15rem;
    box-shadow: var(--shadow);
}

.section-label {
    font-size: 0.72rem;
    font-weight: 650;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--muted);
    margin-bottom: 0.5rem;
}

.facts { list-style: none; margin-bottom: 0.4rem; }
.facts li {
    position: relative;
    padding: 0.42rem 0 0.42rem 1.1rem;
}
.facts li + li { border-top: 1px solid var(--border); }
.facts li::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0.95em;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
}

.source-link {
    display: inline-block;
    margin-left: 0.45rem;
    padding: 0.04rem 0.5rem;
    font-size: 0.74rem;
    color: var(--accent);
    background: var(--accent-soft);
    border-radius: 999px;
    text-decoration: none;
    vertical-align: 2px;
    max-width: 14rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.source-link:hover { background: var(--accent); color: var(--surface); }

/* akce u faktu: citace do schránky, drill-down */
.fact-action {
    display: inline-grid;
    place-items: center;
    width: 22px;
    height: 22px;
    margin-left: 0.15rem;
    border: none;
    background: none;
    color: var(--muted);
    border-radius: 6px;
    cursor: pointer;
    vertical-align: -4px;
    transition: background 0.12s, color 0.12s;
}
.fact-action:hover { background: var(--accent-soft); color: var(--accent); }
.fact-action span { display: contents; }
.cite-btn .icon-check { display: none; }
.cite-btn.copied .icon-check { display: contents; }
.cite-btn.copied .icon-copy { display: none; }
.cite-btn.copied { color: var(--accent); }

.citations-block { margin-top: 1rem; }
.citation {
    background: var(--surface-2);
    border-left: 3px solid var(--accent);
    border-radius: 0 10px 10px 0;
    padding: 0.65rem 0.9rem;
}
.citation + .citation { margin-top: 0.6rem; }
.citation .quote { font-style: italic; }
.citation .context { font-size: 0.82rem; color: var(--muted); margin-top: 0.3rem; }

.provider-note {
    background: var(--warn-bg);
    border: 1px solid var(--warn-border);
    border-radius: 8px;
    padding: 0.45rem 0.7rem;
    font-size: 0.82rem;
    margin-bottom: 0.8rem;
}

.turn-error {
    align-self: stretch;
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    border-radius: 14px;
    padding: 0.8rem 1rem;
    font-size: 0.92rem;
}

/* skeleton při načítání */
.skeleton-line {
    height: 0.85rem;
    border-radius: 5px;
    background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%);
    background-size: 200% 100%;
    margin: 0.65rem 0;
}
.skeleton-line.w60 { width: 60%; }
.skeleton-line.w85 { width: 85%; }
.skeleton-line.w45 { width: 45%; }

@media (prefers-reduced-motion: no-preference) {
    .skeleton-line { animation: shimmer 1.4s ease infinite; }
    @keyframes shimmer {
        0% { background-position: 200% 0; }
        100% { background-position: -200% 0; }
    }
    .turn-user, .turn-assistant, .turn-error { animation: rise 0.25s cubic-bezier(0.16, 1, 0.3, 1); }
    @keyframes rise {
        from { opacity: 0; transform: translateY(8px); }
        to { opacity: 1; transform: none; }
    }
}

/* stub pro historii */
.load-stub {
    background: none;
    border: 1px dashed var(--border);
    border-radius: 14px;
    color: var(--muted);
    font: inherit;
    font-size: 0.86rem;
    padding: 0.55rem 1rem;
    cursor: pointer;
    align-self: flex-start;
    transition: border-color 0.15s, color 0.15s;
}
.load-stub:hover { border-color: var(--accent); color: var(--accent); }

.history-divider {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    color: var(--muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.history-divider::before, .history-divider::after {
    content: "";
    flex: 1;
    border-top: 1px solid var(--border);
}

/* ---------- composer ---------- */

#composer {
    position: sticky;
    bottom: 0;
    background: linear-gradient(transparent, var(--bg) 35%);
    padding: 0.8rem 1rem calc(0.7rem + env(safe-area-inset-bottom));
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
}

.composer-box {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 0.55rem 0.55rem 0.55rem 1rem;
    box-shadow: var(--shadow);
    transition: border-color 0.15s;
}
.composer-box:focus-within { border-color: var(--accent); }

#query-input {
    flex: 1;
    border: none;
    background: none;
    resize: none;
    font: inherit;
    color: var(--text);
    max-height: 10rem;
    padding: 0.25rem 0;
}
#query-input:focus { outline: none; }
#query-input::placeholder { color: var(--muted); }

#send-btn {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 10px;
    background: var(--accent);
    color: #FAF9F5;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background 0.15s, transform 0.1s;
}
#send-btn:hover:not(:disabled) { background: var(--accent-hover); }
#send-btn:active:not(:disabled) { transform: scale(0.94); }
#send-btn:disabled { background: var(--border); color: var(--muted); cursor: default; }

.composer-hint {
    text-align: center;
    font-size: 0.72rem;
    color: var(--muted);
    margin-top: 0.45rem;
}

@media (max-width: 640px) {
    .composer-hint { display: none; }
    .turn-user { max-width: 95%; }
}
