/* =========================================
   1. MAIN CONTAINER & WIDGET
   ========================================= */
:root {
	--madne-mid-brd:#adb5bd;
	--madne-lite-bord:#e9ecef;
	--madne-liteu-bg:#ecf0e3;
   --madne-dargl-bg:#8b8b16;
   --madne-darho-bg:#636310;	

	/* --- chat message theme: colours + sizes used by the message rendering.
	   The admin's chat/admin/chat.css keeps a verbatim copy of this block and
	   the rules below; re-copy when either changes. --- */
	--madne-msg-maxw: 85%;
	--madne-msg-maxw-sm: 90%;
	--madne-msg-pad: 12px 16px;
	--madne-msg-radius: 18px;
	--madne-msg-radius-sharp: 4px;
	--madne-msg-bar: 4px;
	--madne-msg-gap: 15px;
	--madne-msg-line: 1.5;
	--madne-sender-size: 10px;

	--madne-user-fg: #2c3e50;
	--madne-admin-bg: #e8f5e9;
	--madne-admin-fg: #2e7d32;
	--madne-admin-brd: #4caf50;
	--madne-asst-bg: #f8f9fa;
	--madne-asst-fg: #343a40;

	--madne-link: #007bff;
	--madne-gps: #2e7d32;
	--madne-gps-brd: #4caf50;
	--madne-gps-hover: #1b5e20;
	--madne-code-bg: #f1f1f1;
	--madne-code-fg: #d63384;
	--madne-code-size: 0.9em;

	--madne-poi-size: 3em;
	--madne-card-indent: 3.6em;
	--madne-card-bg: #ffffff;
	--madne-card-brd: #eaeaea;
	--madne-card-brd-hover: #d0d0d0;
	--madne-card-img-bg: #f0f0f0;

	--madne-history-bg: #fcfcfc;
	--madne-history-pad: 20px 20px 30px;
	--madne-history-pad-sm: 15px;
--bg-svg-url: url("data:image/svg+xml,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%201600%20300'%20preserveAspectRatio%3D'xMidYMid%20slice'%3E%3Cpolygon%20points%3D'0%2C0%20280%2C0%20210%2C145'%20fill%3D'white'%20opacity%3D'.055'%2F%3E%3Cpolygon%20points%3D'0%2C0%20210%2C145%200%2C300'%20fill%3D'white'%20opacity%3D'.025'%2F%3E%3Cpolygon%20points%3D'280%2C0%20580%2C0%20480%2C115%20210%2C145'%20fill%3D'black'%20opacity%3D'.025'%2F%3E%3Cpolygon%20points%3D'280%2C0%20480%2C115%20210%2C145'%20fill%3D'white'%20opacity%3D'.035'%2F%3E%3Cpolygon%20points%3D'580%2C0%20870%2C0%20740%2C165%20480%2C115'%20fill%3D'white'%20opacity%3D'.065'%2F%3E%3Cpolygon%20points%3D'480%2C115%20740%2C165%20590%2C300%20210%2C145'%20fill%3D'white'%20opacity%3D'.035'%2F%3E%3Cpolygon%20points%3D'740%2C165%20870%2C0%201110%2C0%201030%2C135'%20fill%3D'black'%20opacity%3D'.02'%2F%3E%3Cpolygon%20points%3D'740%2C165%201030%2C135%20920%2C300%20590%2C300'%20fill%3D'white'%20opacity%3D'.05'%2F%3E%3Cpolygon%20points%3D'1110%2C0%201370%2C0%201310%2C150%201030%2C135'%20fill%3D'white'%20opacity%3D'.07'%2F%3E%3Cpolygon%20points%3D'1030%2C135%201310%2C150%201600%2C300%20920%2C300'%20fill%3D'white'%20opacity%3D'.025'%2F%3E%3Cpolygon%20points%3D'1370%2C0%201600%2C0%201600%2C300%201310%2C150'%20fill%3D'black'%20opacity%3D'.02'%2F%3E%3Cpolygon%20points%3D'0%2C300%20210%2C145%20590%2C300'%20fill%3D'black'%20opacity%3D'.018'%2F%3E%3Cpolygon%20points%3D'590%2C300%20920%2C300%20740%2C165'%20fill%3D'black'%20opacity%3D'.018'%2F%3E%3C%2Fsvg%3E");
}
#chat-container {
    position: fixed;
    bottom: 0;
    right: 0;width: auto;height: auto;
    z-index: 200;
pointer-events:none;
}
#chat-container>*{
pointer-events:all;	
}
#chat-container,#chat-container *{
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
	font-size: 0.9rem;
}

#chat-widget {
    width: 0;
    height: 0;
	margin: 0  1.5rem 1.5rem 0;
    background: white;
    border-radius: 12px;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8);
    transform-origin: bottom right;
    transition: opacity 0.25s ease, transform 0.25s ease, width 0.3s ease, height 0.3s ease, max-width 0.3s ease;
}

[data-chat="open"] #chat-widget {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
    width: 40dvw;
    max-width: 650px;
    height: 70dvh;  min-height: 450px;
}

[data-chat="expanded"] #chat-widget {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
    width: 80dvw;
    max-width: none;
    height: 80dvh;  min-height: 450px;
}

.initializing #chat-widget,
.initializing #chat-toggle-button,
.initializing #chat-close-overlay {
    transition: none !important;
}

/* =========================================
   2. HEADER & LAYOUT
   ========================================= */

#chat-header {
    flex: 0 0 auto;
    background: var(--madne-dargl-bg); /* Blue Header */
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 1.1rem;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1); 
background: var(--madne-dargl-bg) var(--bg-svg-url);
background-size: cover;
}

#chat-header-controls {
    display: flex;
    gap: 5px;
}

#chat-header-controls button {
    background: transparent;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s;
}

#chat-header-controls button:hover {
    background: rgba(255, 255, 255, 0.2);
}

#chat-close-button {
    display: none; /* Hidden by default, shown via JS if onCloseForm is set */
}

/* Close overlay */
#chat-close-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.98);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

#chat-close-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.close-form {
    text-align: center;
    padding: 20px;
}

.close-form h3 {
    margin: 0 0 10px;
    color: #333;
}

.close-form p {
    margin: 0 0 20px;
    color: #666;
}

.close-form-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.close-form-buttons button {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}

.close-form-buttons .forgetMeAndClose {
    background: #dc3545;
    color: white;
}

.close-form-buttons .demoCloseButton {
    background: #6c757d;
    color: white;
}

/* =========================================
   3. FLOATBAR
   ========================================= */

#chat-floatbar {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    background: #f8f9fa;
    border-bottom: 1px solid var(--madne-lite-bord);
    flex-wrap: wrap;
    align-items: center;
}

#chat-floatbar.hidden {
    display: none;
}

.fl-group {
    display: inline-flex;
    align-items: center;
}
.fl-group.hidden{display:none;}

.fl-but {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0.3em 0.8em;
    background: white;
    border: 1px solid #ddd;
    border-radius: 1.2em;
    font-size: 0.8em!important;
	line-height:1;
    cursor: pointer;
    transition: all 0.2s;
}
.fl-but .fl-cnt{ font-size: 1em!important;}
.fl-but:hover {
    background: var(--madne-lite-bord);
    border-color: var(--madne-mid-brd);
}

.fl-but.active {
    background: var(--madne-dargl-bg);
    color: white;
    border-color: var(--madne-dargl-bg);
}

/* Floatbar overlay */
#chat-floatbar-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.98);
    display: flex;
    flex-direction: column;
    z-index: 5;
    animation: overlayFadeIn 0.2s ease;
}

@keyframes overlayFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

#chat-floatbar-overlay.hidden {
    display: none;
}

.floatbar-overlay-content {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.floatbar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--madne-lite-bord);
    font-weight: 600;
}

.floatbar-close {
    background: none;
    border: none;
    font-size: 14px;
    cursor: pointer;
    padding: 4px 10px;
    color: #666;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.floatbar-close:hover {
    color: #333;
}

.floatbar-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.floatbar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-bottom: 1px solid #f0f0f0;
}

.floatbar-poi-img {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
}

.floatbar-poi-name {
    flex: 1;
    font-size: 13px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.floatbar-visit-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--madne-dargl-bg);
    color: white;
    text-decoration: none;
    font-size: 16px;
    flex-shrink: 0;
    transition: background 0.15s;
}

.floatbar-visit-btn:hover {
    background: var(--madne-darho-bg);
}

.floatbar-item-remove {
    background: none;
    border: none;
    color: #dc3545;
    cursor: pointer;
    padding: 4px 10px;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.floatbar-item-remove:hover {
    color: #a71d2a;
}

/* =========================================
   4. CHAT CONTENT
   ========================================= */

#chat-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    background-color: #ffffff;
}

#chat-history {
    flex: 1;
    overflow-y: auto;
    background: var(--madne-history-bg); 
    padding: var(--madne-history-pad);
    scroll-behavior: smooth;
}

#chat-input-wrapper {
    flex: 0 0 auto;
    border-top: 1px solid #f0f0f0;
    padding: 15px;
    background: white;
}

#chat-form {
    display: flex;
    gap: 12px;
    align-items: center;
    margin: 0;
    padding: 0;
}

#message-input {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 1em;
    padding: 0.45em 1em 0.5em 1em;
    outline: none;
    background: #f9f9f9;
    resize: none;
    line-height: 1.4;
    font-family: inherit;
    max-height: 100px;
    overflow-y: auto;
    transition: all 0.2s;
	scrollbar-width: thin;
}

#message-input:focus {
    background: white;
    border-color: var(--madne-dargl-bg);
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.15);
}

#send-button {
    background: var(--madne-dargl-bg); /* Blue Button */
    color: white;
    border: none;
    border-radius: 50%;
    width: 45px;
    height: 45px;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.1s;
    box-shadow: 0 2px 5px rgba(74, 144, 226, 0.3);
}

#send-button:hover {
    background: var(--madne-darho-bg);
    transform: translateY(-1px);
}

#send-button:active {
    transform: scale(0.95);
}

#send-button:disabled {
    background: #b0bec5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Enhanced button states for spam protection - keeping original design */
#send-button.sending {
    /* Keep original blue color */
    /* Only text changes indicate state */
}

#send-button.streaming {
    /* Keep original blue color */
    /* Only text changes indicate state */
}

/* =========================================
   3. MESSAGES (Speech Bubble + Border)
   ========================================= */

.message {
    margin-bottom: var(--madne-msg-gap);
    max-width: var(--madne-msg-maxw);
    padding: var(--madne-msg-pad);
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    animation: fadeIn 0.3s ease;
    position: relative;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- USER (BLUE) --- */
/* Bottom-Right corner is sharp */
.user-message {
    margin-left: auto;
    background-color: var(--madne-liteu-bg);
    color: var(--madne-user-fg);
    
    /* The uneven radius */
    border-radius: var(--madne-msg-radius) var(--madne-msg-radius) var(--madne-msg-radius-sharp) var(--madne-msg-radius);
    
    /* Border on the RIGHT side */
    border-right: var(--madne-msg-bar) solid var(--madne-dargl-bg);
}

/* --- ADMIN (GREEN) --- */
/* Bottom-Left corner is sharp */
.admin-message {
    margin-right: auto;
    background-color: var(--madne-admin-bg);
    color: var(--madne-admin-fg);
    
    /* The uneven radius */
    border-radius: var(--madne-msg-radius) var(--madne-msg-radius) var(--madne-msg-radius) var(--madne-msg-radius-sharp);
    
    /* Border on the LEFT side */
    border-left: var(--madne-msg-bar) solid var(--madne-admin-brd);
}

/* --- ASSISTANT (GREY) --- */
/* Bottom-Left corner is sharp */
.assistant-message {
    margin-right: auto;
    background-color: var(--madne-asst-bg);
    color: var(--madne-asst-fg);
    
    /* The uneven radius */
    border-radius: var(--madne-msg-radius) var(--madne-msg-radius) var(--madne-msg-radius) var(--madne-msg-radius-sharp);
    
    /* Border on LEFT side */
    border-left: var(--madne-msg-bar) solid var(--madne-mid-brd);
}


.message-sender {
    font-size: var(--madne-sender-size);
    font-weight: 700;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.7;
}

.message-content {
   display:block; line-height: var(--madne-msg-line);
    word-wrap: break-word;
}








/* =========================================
   4. MOBILE RESPONSIVE
   ========================================= */

@media (max-width: 800px) {
 #chat-widget {
margin:0;
    }

    [data-chat="open"] #chat-widget,
    [data-chat="expanded"] #chat-widget {
 width: 100dvw;
 height: 100dvh;
 max-width: 100dvw;
 max-height: 100dvh;
 min-height: 0;
 border-radius: 0;
 box-shadow: none;
    }

#chat-header { padding: 12px 15px; }
#chat-history { padding: var(--madne-history-pad-sm); }
    
 .message { max-width: var(--madne-msg-maxw-sm); }
}

/* =========================================
   5. STATUS & UTILITIES
   ========================================= */

#chat-toggle-button {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 1001;
    /* Oval shape */
    border-radius: 2rem;
    min-width: 10rem;
    height: auto;
    /* Flex layout for title/subtitle */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1.2;
    padding:0.35rem 1rem 0.45rem 1rem;
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
    transition: opacity 0.2s ease, transform 0.2s ease;
    /* Keep existing colors */
    background: var(--madne-dargl-bg);
    color: white;
    border: none;cursor:pointer;
    box-shadow: 0 4px 20px rgba(74, 144, 226, 0.4);
    gap: 2px;	background: var(--madne-dargl-bg) var(--bg-svg-url);    background-size:auto 300%;
}

#chat-toggle-button:hover {
    background: var(--madne-darho-bg);
    transform: scale(1.05);
}

[data-menu-open]  #chat-toggle-button,
[data-chat="open"] #chat-toggle-button,
[data-chat="expanded"] #chat-toggle-button {
    opacity: 0;
    pointer-events: none;
    transform: scale(1.1);
}

.toggle-title {
    font-weight: 600;
    font-size: 1rem!important;
}

.toggle-subtitle {
    font-size: 0.75rem!important;
    opacity: 0.9;
}

/* Badge */
#chat-toggle-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #dc3545;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
}

#chat-toggle-badge.hidden {
    display: none;
}

#takeover-status {
    position: sticky;
    top: 0;
    z-index: 10;
    display: none;
    padding: 8px;
    margin-bottom: 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    text-align: center;
    width: 100%;
    box-sizing: border-box;
}

#takeover-status.admin-control {
    display: block;
    background-color: #ffebee;
    border: 1px solid #ffcdd2;
    color: #c62828;
}

/* Streaming Animation - no longer pulses, user can read while generating */
.message.streaming {
    background-color: var(--madne-asst-bg);
    border-left: var(--madne-msg-bar) solid var(--madne-dargl-bg);
    /* Removed: animation and color pulse - prevents flicker/jump on stream end */
}
/* Creates a fade-out effect at the bottom of the message while it streams */
.message.streaming .message-content p[data-current] {
    -webkit-mask-image: linear-gradient(to bottom, black calc(100% - 1.2em), transparent 100%);
    mask-image: linear-gradient(to bottom, black calc(100% - 1.2em), transparent 100%);
    /* This ensures the very last line always looks like it's emerging smoothly */
}

.stream-inline-error {
margin: 0.25em 0; 
padding-top: 0.25em; 
border: 1px dashed rgba(0,0,0,0.2); 
font-size: 0.9em; opacity: 0.9;
font-style: italic;
}

/* Removed: streamingPulse and subtle-pulse animations - no longer needed */



/* Smart Links & Map Styles */
.smart-link {
    display: inline-block; padding:1px 2px; line-height:1em;
    border-radius: 5px;
    text-decoration: none!important; font-weight: 500;
    transition: all 0.2s ease;
}
.smart-link .icon {
   margin-left:1px; margin-right:2px;
}
.smart-link.map{
    background-color: #e8f5e9; /* Light Green */
    color: #2e7d32;
    border: 1px solid #c8e6c9;
}

.smart-link.map:hover {
    background-color: #c8e6c9;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}



/* Inline Code Style */
.inline-code {
    background: var(--madne-code-bg);
    padding: 2px 5px;
    border-radius: 4px;
    font-family: monospace;
    font-size: var(--madne-code-size);
    color: var(--madne-code-fg);
}

/* Markdown Styles within Message */
.message-content strong { font-weight: 700; color: inherit; }
.message-content em { font-style: italic; }
.message-content a { color: var(--madne-link); text-decoration: underline; }
.message-content a.gps-link { color: var(--madne-gps); text-decoration: none; border-bottom: 1px dashed var(--madne-gps-brd); }
.message-content a.gps-link:hover { color: var(--madne-gps-hover); border-bottom-style: solid; }





@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Status Indicator - inline span at end of message-content */
.status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    vertical-align: baseline;
}

.status-indicator.hidden {
    display: none;
}

.status-indicator .status-spinner {
    width: 1em;
    height: 1em;
    border: 2px solid #d0d0d0;
    border-top: 2px solid var(--madne-dargl-bg);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.status-indicator .status-text {
    font-size: 0.9em;
    color: #666;
    font-style: italic;
}



/* Unclassed p in message content */
.message-content p {
    margin: 0;
    padding: 0;
    display: block;
    position: relative;
	 border-color: #eaeaea;
}

/* List items with data-bullet (2em width) */
p[data-bullet] {
    padding-left: var(--madne-poi-size);
    position: relative;
    margin: 0.25em 0;
}

p[data-bullet]::before {
    content: attr(data-bullet);
    position: absolute;
    left: 0;
    width: var(--madne-poi-size);
    text-align: center;
}

/* LLM markdown headings rendered as bold text lines - the chat window is too
   small for real heading sizes, and "###" syntax must never reach the user.
   Levels differ only by spacing; the model's ** bold ** is dropped, the
   paragraph itself is bold. font-size stays inherited. */
.message-content p.hdr-1,
.message-content p.hdr-2,
.message-content p.hdr-3,
.message-content p.hdr-4 {
    font-size: inherit;
    font-weight: 700;
    margin: 0.6em 0 0.15em;
}

.message-content p.hdr-3 { margin-top: 0.45em; }
.message-content p.hdr-4 { margin-top: 0.3em; }

/* POI image placeholder (2em width) */
p[data-link]::before {
    content: '';
position: absolute; top:0.25em;left: 0.25em; width: var(--madne-poi-size); height: var(--madne-poi-size);max-height:calc(100% - 0.5em);
    background: var(--madne-card-img-bg);
    border-radius: 3px;
}

p[data-link] IMG{
	position: absolute; top:0.25em;left: 0.25em; width: var(--madne-poi-size); height: var(--madne-poi-size);max-height:calc(100% - 0.5em); object-fit: cover; border-radius: 3px;
}
p[data-current] IMG{display:none;}

/* POI thumbnail prepended to a list answer. Generated by chat/data/indexer3e.php
   as storage/thumbs/{id}.jpg at 400px wide, so constrain it rather than let a
   full-width photo push the message around. */
.message-content img.poi-img {
  display: block;
  max-width: 100%;
  width: var(--madne-poi-size);
  height: var(--madne-poi-size);object-fit:auto;
  margin: 0;
  border-radius: 5px;
}


/* =========================================
    Rich Point of Interest (POI) - using data-link
    ========================================= */
p[data-link] {
    background: var(--madne-card-bg);
    border: 1px solid var(--madne-card-brd);
    border-radius: 8px;
    padding: 0.3em 0.3em 0.3em var(--madne-card-indent);
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
    transition: all 0.2s ease;
    margin: 0.5rem 0;
}

p[data-link]:hover {
    box-shadow: 0 4px 10px rgba(0,0,0,0.08);
    border-color: var(--madne-card-brd-hover);
    transform: translateY(-1px);
}



p[data-link] A:first-of-type{font-weight:normal;text-decoration:none;}