/* Global Styles */
body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: Arial, sans-serif;
}

/* Layout */
#container {
    display: flex;
    height: 100vh;
    overflow: hidden;
    position: relative; /* Enables z-index layering */
}

#emoflow-frame {
    flex-basis: 60%;
    height: 100%;
    border: none;
    min-width: 100px;
    pointer-events: auto;
    z-index: 1; /* LOWER layer */
}

#resizer {
    flex-basis: 5px;
    flex-shrink: 0;
    background-color: #ccc;
    cursor: col-resize;
    height: 100%;
}

#container.is-resizing #emoflow-frame {
    pointer-events: none;
}

#chat-container {
    flex-basis: 40%;
    flex-grow: 0;
    flex-shrink: 0;
    width: 0; /* enables flex-basis to control size */
    min-width: 250px;
    max-width: 100%; /* safeguard against overflow */
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#chat-window {
    flex-grow: 1;
    padding: 10px;
    overflow-y: auto;
    background: #f7f7f7;
    display: flex;
    flex-direction: column;
}

/* Chat Bubbles */
.message {
    margin: 6px 10px;
    padding: 10px 14px;
    border-radius: 16px;
    max-width: 85%;
    word-wrap: break-word;
    overflow-wrap: anywhere;   /* ✅ NEW */
    line-height: 1.5;
    box-sizing: border-box;
}

.user {
    background-color: #d0e6ff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.assistant {
    background-color: #e8f5e9;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.message p {
    margin: 0.7em 0;
}

/* Typing Animation */
.typing-animation {
    display: inline-block;
    font-size: 20px;
    margin-left: 5px;
}
.typing-animation span {
    display: inline-block;
    animation: blink 1.4s infinite;
    margin-right: 2px;
    font-weight: bold;
}
.typing-animation span:nth-child(2) { animation-delay: 0.2s; }
.typing-animation span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
    0% { opacity: 0.2; }
    20% { opacity: 1; }
    100% { opacity: 0.2; }
}

/* Input Area */
#input-container {
    padding: 10px 15px;
    background: #f9f9f9;
    border-top: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -2px 5px rgba(0,0,0,0.05);
    flex-shrink: 0;
}
.input-area-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background-color: #ffffff;
    border: 1px solid #dcdcdc;
    border-radius: 18px;
    padding: 5px 8px;
}
#chat-input {
    flex-grow: 1;
    border: none;
    resize: none;
    font-size: 15px;
    padding: 8px 5px;
    line-height: 1.4;
    max-height: 50vh;
    height: auto;
    overflow-y: auto;
    background: transparent;
    outline: none;
    font-family: inherit;
    box-sizing: border-box;
}
#send-btn-circle {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background-color: #333;
    color: white;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    transition: background-color 0.2s ease;
}
#send-btn-circle:hover {
    background-color: #000;
}

.button-area-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

#flow-selector {
    padding: 6px 10px;
    border: 1px solid #dcdcdc;
    border-radius: 18px;
    background-color: #f0f0f0;
    color: #333;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    height: 30px;
    box-sizing: border-box;
}
#flow-selector:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}
#init-btn {
    padding: 6px 14px;
    border: 1px solid #dcdcdc;
    border-radius: 18px;
    background-color: #f0f0f0;
    color: #333;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background-color 0.2s ease, border-color 0.2s ease;
    margin-top: 0;
    height: 30px;
    box-sizing: border-box;
}
#init-btn:hover {
    background-color: #e0e0e0;
    border-color: #c0c0c0;
}

/* Code Blocks */
.message pre {
    background: #282c34;
    padding: 12px 14px;
    border-radius: 10px;
    overflow-x: auto;
    font-family: 'Courier New', Courier, monospace;
    font-size: 14px;
    line-height: 1.5;
    margin: 1em 0;
    border: 1px solid #3a3f4b;
    color: #f8f8f2;
    white-space: pre-wrap;
}

.message code {
    background: #2d2d2d;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
    color: #f8f8f2;
}

.message pre, .message code {
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* Collapsible Bubble */
.collapsible-preview {
    position: relative;
    max-height: 200px;
    overflow: hidden;
    transition: max-height 0.3s ease;
}


/* Expanded removes height restriction */
.collapsible-preview.collapsible-expanded {
    max-height: none;
}

/* Only apply gradient when message is collapsed AND overflowing */
.collapsible-preview.has-gradient::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0; /* ✅ Ensures it spans entire width */
    height: 3em;
    pointer-events: none;
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0), #f7f7f7); /* Adjust per theme */
    border-radius: inherit; /* ✅ Optional: match rounded corners */
}

/* Match user bubble */
.message.user .collapsible-preview.has-gradient::after {
    background: linear-gradient(to bottom, rgba(208, 230, 255, 0), rgba(208, 230, 255, 1));
}

/* Match assistant bubble */
.message.assistant .collapsible-preview.has-gradient::after {
    background: linear-gradient(to bottom, rgba(232, 245, 233, 0), rgba(232, 245, 233, 1));
}

#model-selector {
    padding: 6px 10px;
    border: 1px solid #dcdcdc;
    border-radius: 18px;
    background-color: #f0f0f0;
    color: #333;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    height: 30px;
    box-sizing: border-box;
    appearance: auto;
    -webkit-appearance: auto;
    -moz-appearance: auto;
}

.copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background-color: transparent;
    border: none;
    cursor: pointer;
    z-index: 2;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.6;
    transition: opacity 0.2s ease;
}

.copy-btn:hover {
    opacity: 1;
}

.copy-btn svg {
    width: 16px;
    height: 16px;
    fill: #ccc;
    transition: fill 0.2s ease;
}

.copy-btn:hover svg {
    fill: #fff;
}

#copy-chat-btn {
    padding: 6px 14px;
    border: 1px solid #dcdcdc;
    border-radius: 18px;
    background-color: #f0f0f0;
    color: #333;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background-color 0.2s ease, border-color 0.2s ease;
    height: 30px;
    box-sizing: border-box;
}

#copy-chat-btn:hover {
    background-color: #e0e0e0;
    border-color: #c0c0c0;
}

#drop-zone {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    color: white;
    font-size: 22px;
    font-weight: bold;
    z-index: 10;  /* Must be higher than #chat-container's children */
    display: none;
    justify-content: center;
    align-items: center;
    border-radius: 12px;
}