/* MAP.BG Unified Chat UI (100% external stylesheet; CSP style-src 'self' compliant) */

.chat-tool-status-list {
    list-style: none;
    margin: 0.45rem 0 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.chat-tool-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-muted);
    font-size: 0.74rem;
    line-height: 1.25;
}

.chat-tool-pill.is-running {
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
}

.chat-tool-pill.is-done {
    color: var(--text-soft);
}

.chat-tool-pill.is-error {
    border-color: #f87171;
    color: #fca5a5;
}

.chat-stop-btn {
    flex-shrink: 0;
}

.chat-thread-messages {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    margin-block: 0.25rem 0.45rem;
}

.chat-bubble {
    padding: 0.55rem 0.72rem;
    border-radius: 10px;
    font-size: 0.85rem;
    line-height: 1.42;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.chat-bubble.is-user {
    align-self: flex-end;
    max-width: 90%;
    background: rgba(56, 189, 248, 0.14);
    border: 1px solid rgba(56, 189, 248, 0.3);
    color: #fff;
}

.chat-bubble.is-assistant {
    align-self: flex-start;
    max-width: 100%;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-soft);
}

.chat-bubble.is-streaming {
    border-color: var(--accent-cyan);
}

.chat-bubble.is-error {
    border-color: #f87171;
    color: #fecaca;
}

/* Home Hero Assistant Card */
.home-assistant-card {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.home-chat-thread {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    max-height: 290px;
    overflow-y: auto;
    padding: 0.55rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: rgba(6, 16, 31, 0.52);
}

.home-chat-thread .chat-thread-messages {
    max-height: 210px;
    overflow-y: auto;
    margin-block: 0;
}

.home-chat-welcome {
    margin: 0;
    color: var(--text-soft);
    font-size: 0.87rem;
    line-height: 1.45;
}

.home-chat-examples {
    margin-top: 0.15rem;
}

.home-chat-artifacts {
    display: grid;
    gap: 0.45rem;
}

.home-artifact-card {
    display: grid;
    gap: 0.15rem;
    padding: 0.5rem 0.65rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    font-size: 0.8rem;
}

.home-artifact-card.is-selected {
    border-color: var(--accent-cyan);
    background: rgba(56, 189, 248, 0.1);
}

.home-artifact-card span {
    color: var(--text-muted);
}

.home-artifact-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.home-chat-form {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.home-chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 0.55rem;
    width: 100%;
}

.chat-composer-textarea,
.ask-chat-textarea {
    resize: none;
    min-height: 4.15rem;
    max-height: 9.5rem;
    line-height: 1.44;
    font-family: var(--font-sans, inherit);
    font-size: 0.9rem;
    font-weight: 400;
    letter-spacing: normal;
    flex: 1;
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
    padding: 0.58rem 0.78rem;
}

.home-chat-input-row .btn,
.ask-input-row .btn {
    min-height: 2.65rem;
    align-self: flex-end;
}

/* Ergonomic Map Ask Pane */
.ask-chat-pane:not(.hidden),
.map-sidebar.mode-ask .ask-chat-pane:not(.hidden) {
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
}

.ask-top-deck {
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.ask-chat-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.9rem 0.25rem;
}

.ask-chat-topbar .starter-caption {
    margin: 0;
    font-size: 0.77rem;
}

.ask-composer {
    padding: 0.2rem 0.9rem 0.65rem;
}

.ask-input-row {
    align-items: flex-end;
}

.ask-map-selection-bar:not(.hidden) {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.45rem;
    padding: 0.42rem 0.9rem;
    background: rgba(56, 189, 248, 0.08);
    border-bottom: 1px solid var(--border);
    font-size: 0.78rem;
    flex-shrink: 0;
}

.ask-map-sel-label {
    color: var(--accent-cyan);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ask-map-sel-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
}

.ask-sel-action {
    font-size: 0.74rem;
    padding: 0.24rem 0.5rem;
}

.ask-chat-thread {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0.75rem 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.ask-answer:empty,
.ask-places:empty {
    display: none;
}

.ask-answer.is-streaming {
    border-color: var(--accent-cyan);
}

.ask-answer.is-error {
    border-color: #f87171;
    color: #fecaca;
}

.ask-route-compare-list {
    display: grid;
    gap: 0.45rem;
    margin-block: 0.55rem 0.25rem;
}

.ask-route-compare-card {
    display: grid;
    gap: 0.2rem;
    width: 100%;
    padding: 0.55rem 0.7rem;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-soft);
    text-align: start;
    cursor: pointer;
    font: inherit;
    font-size: 0.82rem;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.ask-route-compare-card:hover,
.ask-route-compare-card:focus-visible {
    border-color: var(--accent-cyan);
    outline: none;
}

.ask-route-compare-card.is-selected {
    border-color: var(--accent-cyan);
    background: rgba(56, 189, 248, 0.1);
}

.ask-compare-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.ask-compare-title {
    font-weight: 600;
    color: #fff;
}

.ask-compare-badge {
    padding: 0.1rem 0.42rem;
    border-radius: 999px;
    border: 1px solid var(--accent-cyan);
    color: var(--accent-cyan);
    font-size: 0.7rem;
    font-weight: 600;
}

.ask-compare-meta {
    color: var(--text-muted);
    font-size: 0.78rem;
}

.chat-hidden {
    display: none;
}

.ask-route-legs {
    list-style: none;
    margin: 0.5rem 0 0.25rem;
    padding: 0;
    display: grid;
    gap: 0.35rem;
}

.ask-route-leg-btn {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.42rem 0.62rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-soft);
    text-align: start;
    cursor: pointer;
    font: inherit;
    font-size: 0.79rem;
}

.ask-route-leg-btn:hover,
.ask-route-leg-btn:focus-visible {
    border-color: var(--accent-cyan);
    outline: none;
}

.ask-leg-badge {
    padding: 0.12rem 0.42rem;
    border-radius: 999px;
    font-family: var(--font-mono);
    font-size: 0.71rem;
    font-weight: 700;
    white-space: nowrap;
}

.ask-leg-badge.leg-color-0 { background: rgba(56, 189, 248, 0.18); border: 1px solid rgba(56, 189, 248, 0.45); color: #7dd3fc; }
.ask-leg-badge.leg-color-1 { background: rgba(245, 158, 11, 0.18); border: 1px solid rgba(245, 158, 11, 0.5); color: #fcd34d; }
.ask-leg-badge.leg-color-2 { background: rgba(52, 211, 153, 0.18); border: 1px solid rgba(52, 211, 153, 0.45); color: #6ee7b7; }
.ask-leg-badge.leg-color-3 { background: rgba(167, 139, 250, 0.18); border: 1px solid rgba(167, 139, 250, 0.45); color: #ddd6fe; }
.ask-leg-badge.leg-color-4 { background: rgba(251, 113, 133, 0.18); border: 1px solid rgba(251, 113, 133, 0.45); color: #fecdd3; }

.ask-leg-stops {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #fff;
}

.ask-leg-dist {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--accent-cyan);
    white-space: nowrap;
}

.route-dir-icon-wrap {
    pointer-events: none;
}

.route-dir-arrow {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(4, 17, 29, 0.88);
    border: 1.5px solid currentColor;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    line-height: 1;
    font-weight: 900;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
}

.route-dir-leg-0 { color: #38bdf8; }
.route-dir-leg-1 { color: #fbbf24; }
.route-dir-leg-2 { color: #34d399; }
.route-dir-leg-3 { color: #c4b5fd; }
.route-dir-leg-4 { color: #fda4af; }

.route-dir-rot-0  { transform: rotate(0deg); }
.route-dir-rot-1  { transform: rotate(22.5deg); }
.route-dir-rot-2  { transform: rotate(45deg); }
.route-dir-rot-3  { transform: rotate(67.5deg); }
.route-dir-rot-4  { transform: rotate(90deg); }
.route-dir-rot-5  { transform: rotate(112.5deg); }
.route-dir-rot-6  { transform: rotate(135deg); }
.route-dir-rot-7  { transform: rotate(157.5deg); }
.route-dir-rot-8  { transform: rotate(180deg); }
.route-dir-rot-9  { transform: rotate(202.5deg); }
.route-dir-rot-10 { transform: rotate(225deg); }
.route-dir-rot-11 { transform: rotate(247.5deg); }
.route-dir-rot-12 { transform: rotate(270deg); }
.route-dir-rot-13 { transform: rotate(292.5deg); }
.route-dir-rot-14 { transform: rotate(315deg); }
.route-dir-rot-15 { transform: rotate(337.5deg); }

.route-avoid-pin-wrap {
    background: transparent;
    border: 0;
}

.route-avoid-pin {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(127, 29, 29, 0.92);
    border: 2px solid #fca5a5;
    color: #fecaca;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 800;
    line-height: 1;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

/* Wave 3.2: Spatial Query Summary & R-Tree Demo Link inside #askPlaces */
.ask-spatial-summary-item {
    list-style: none;
    margin-bottom: 0.35rem;
    padding: 0.45rem 0.65rem;
    border-radius: 8px;
    border: 1px solid rgba(56, 189, 248, 0.35);
    background: rgba(56, 189, 248, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.4rem;
    font-size: 0.78rem;
    color: var(--text-soft);
}

.ask-spatial-dist-tag {
    font-family: var(--font-mono);
    font-size: 0.73rem;
    color: var(--accent-cyan);
    white-space: nowrap;
}

/* Wave 3.3: Search Proximity Chip & Geolocation Controls */
.search-hint-actions {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    flex-wrap: wrap;
}

.search-proximity-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.14rem 0.48rem;
    border-radius: 999px;
    border: 1px solid rgba(56, 189, 248, 0.38);
    background: rgba(56, 189, 248, 0.1);
    color: #7dd3fc;
    font: inherit;
    font-size: 0.73rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.search-proximity-chip:hover,
.search-proximity-chip:focus-visible {
    border-color: var(--accent-cyan);
    background: rgba(56, 189, 248, 0.18);
    outline: none;
}

.search-proximity-chip.is-nationwide {
    border-color: var(--border);
    background: var(--bg-card);
    color: var(--text-muted);
}

.map-locate-btn {
    position: absolute;
    right: 10px;
    bottom: 92px;
    z-index: 820;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid rgba(148, 163, 184, 0.35);
    background: rgba(8, 18, 34, 0.92);
    color: #e2e8f0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.map-locate-btn:hover,
.map-locate-btn:focus-visible {
    color: #38bdf8;
    border-color: #38bdf8;
    outline: none;
}

.map-locate-btn.is-active {
    color: #38bdf8;
    border-color: rgba(56, 189, 248, 0.65);
}

.mapbg-user-geo-wrap {
    background: transparent;
    border: 0;
}

.mapbg-user-geo-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #3b82f6;
    border: 2.5px solid #ffffff;
    box-shadow: 0 0 0 5px rgba(59, 130, 246, 0.28), 0 2px 6px rgba(0, 0, 0, 0.45);
}

/* Wave 3.4: Zero-Ghosting BgLang Live Compose Mirror & HUD */
.chat-bglang-field {
    display: grid;
    flex: 1;
    min-width: 0;
    position: relative;
    border-radius: 10px;
    background: rgba(6, 16, 31, 0.72);
}

.chat-bglang-mirror,
.chat-bglang-field > textarea {
    grid-area: 1 / 1;
    width: 100%;
    min-width: 0;
    min-height: 4.15rem;
    max-height: 9.5rem;
    margin: 0;
    padding: 0.58rem 0.78rem;
    box-sizing: border-box;
    scrollbar-gutter: stable;
    font-family: var(--font-sans, inherit);
    font-size: 0.9rem;
    font-weight: 400;
    line-height: 1.44;
    letter-spacing: normal;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    word-break: normal;
    tab-size: 4;
}

.chat-bglang-mirror {
    display: none;
    pointer-events: none;
    user-select: none;
    overflow: hidden;
    border: 1px solid transparent;
    border-radius: 10px;
    color: #f1f5f9;
    z-index: 0;
}

.chat-bglang-field > textarea {
    position: relative;
    z-index: 1;
}

.chat-bglang-field.is-bglang-active > .chat-bglang-mirror {
    display: block;
}

.chat-bglang-field.is-bglang-active > textarea {
    color: transparent;
    -webkit-text-fill-color: transparent;
    caret-color: #38bdf8;
    background: transparent;
}

.chat-bglang-field.is-bglang-active > textarea::placeholder {
    color: var(--text-muted);
    -webkit-text-fill-color: var(--text-muted);
}

.chat-bglang-field.is-bglang-active > textarea::selection {
    background: rgba(56, 189, 248, 0.28);
    color: transparent;
    -webkit-text-fill-color: transparent;
}

.bglang-tok-verb { color: #7dd3fc; }
.bglang-tok-noun { color: #f8fafc; }
.bglang-tok-adj  { color: #6ee7b7; }
.bglang-tok-adv  { color: #fcd34d; }
.bglang-tok-proper { color: #c4b5fd; }
.bglang-tok-func { color: #94a3b8; }
.bglang-tok-dict { color: #e2e8f0; }
.bglang-tok-unknown {
    color: #fda4af;
    text-decoration-line: underline;
    text-decoration-style: wavy;
    text-decoration-color: rgba(251, 113, 133, 0.72);
    text-underline-offset: 3px;
}

.chat-bglang-hud {
    display: flex;
    flex-direction: column;
    gap: 0.28rem;
    margin-top: 0.28rem;
}

.chat-bglang-hud-meta {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    min-height: 1.35rem;
    font-size: 0.72rem;
    color: var(--text-muted);
}

.chat-bglang-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    padding: 0.1rem 0.44rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.69rem;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
}

.chat-bglang-toggle.is-active {
    border-color: rgba(56, 189, 248, 0.45);
    background: rgba(56, 189, 248, 0.11);
    color: #7dd3fc;
}

.chat-bglang-status {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: var(--font-mono);
    font-size: 0.7rem;
}

.chat-bglang-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.bglang-chip {
    padding: 0.14rem 0.48rem;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.32);
    background: rgba(15, 23, 42, 0.85);
    color: #e2e8f0;
    font: inherit;
    font-size: 0.74rem;
    cursor: pointer;
    transition: border-color 0.12s ease, background-color 0.12s ease;
}

.bglang-chip.is-primary {
    border-color: rgba(56, 189, 248, 0.5);
    background: rgba(56, 189, 248, 0.13);
    color: #bae6fd;
}

.home-chat-thread,
.chat-thread-messages,
.ask-chat-thread,
.ask-places {
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.32) transparent;
}

.home-chat-thread::-webkit-scrollbar,
.chat-thread-messages::-webkit-scrollbar,
.ask-chat-thread::-webkit-scrollbar,
.ask-places::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.home-chat-thread::-webkit-scrollbar-track,
.chat-thread-messages::-webkit-scrollbar-track,
.ask-chat-thread::-webkit-scrollbar-track,
.ask-places::-webkit-scrollbar-track {
    background: transparent;
}

.home-chat-thread::-webkit-scrollbar-thumb,
.chat-thread-messages::-webkit-scrollbar-thumb,
.ask-chat-thread::-webkit-scrollbar-thumb,
.ask-places::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.3);
    border-radius: 999px;
}

.home-chat-thread::-webkit-scrollbar-thumb:hover,
.chat-thread-messages::-webkit-scrollbar-thumb:hover,
.ask-chat-thread::-webkit-scrollbar-thumb:hover,
.ask-places::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.5);
}

.bglang-chip:hover,
.bglang-chip:focus-visible {
    border-color: #38bdf8;
    outline: none;
}

/* Wave 3.5: Pure-DOM Markdown Typography for Chat Answers */
.chat-markdown {
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.48;
}

.chat-markdown > :first-child {
    margin-top: 0;
}

.chat-markdown > :last-child {
    margin-bottom: 0;
}

.chat-md-p {
    margin: 0 0 0.48rem;
}

.chat-md-heading {
    font-weight: 700;
    color: #f8fafc;
    margin: 0.52rem 0 0.28rem;
    line-height: 1.32;
}

.chat-md-h1,
.chat-md-h2 {
    font-size: 0.94rem;
}

.chat-md-h3,
.chat-md-h4 {
    font-size: 0.88rem;
}

.chat-md-list {
    margin: 0.28rem 0 0.52rem;
    padding-inline-start: 1.25rem;
    display: grid;
    gap: 0.22rem;
}

.chat-md-sublist {
    margin: 0.2rem 0 0.1rem;
    padding-inline-start: 1.1rem;
}

.chat-markdown strong {
    color: #f8fafc;
    font-weight: 700;
}

.chat-markdown em {
    font-style: italic;
}

.chat-md-inline-code {
    padding: 0.08rem 0.34rem;
    border-radius: 5px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    background: rgba(15, 23, 42, 0.78);
    color: #bae6fd;
    font-family: var(--font-mono);
    font-size: 0.8em;
}

.chat-md-pre {
    margin: 0.42rem 0;
    padding: 0.55rem 0.7rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: rgba(6, 16, 31, 0.85);
    overflow-x: auto;
    white-space: pre;
}

.chat-md-code {
    font-family: var(--font-mono);
    font-size: 0.79rem;
    color: #e2e8f0;
}

.chat-md-hr {
    border: 0;
    border-top: 1px solid var(--border);
    margin: 0.55rem 0;
}

.chat-md-link {
    color: #38bdf8;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.chat-md-link:hover,
.chat-md-link:focus-visible {
    color: #7dd3fc;
}

@media (max-width: 860px) {
    .chat-composer-textarea,
    .ask-chat-textarea {
        min-height: 4.45rem;
    }
}
