body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f0f2f5;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    /* Prevent body scroll when popups are present */
    position: relative;
}

/* Base Chat Window Style */
.chat-container {
    width: 100%;
    height: 100%;
    background: white;
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 0;
    left: 0;
    overflow: hidden;
}

/* Formatting for Popups */
.chat-container.popup {
    width: 95%;
    max-width: 500px;
    height: 500px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 8px;
    border: 1px solid #ccc;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.popup-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(255, 255, 255, 0.1);
    /* Very light background */
    backdrop-filter: blur(1px);
    z-index: 999;
    /* Just below the popup (popup starts at 1001) */
    pointer-events: auto;
    /* Blocks clicks to elements behind */
}

/* Maximized State */
/* Maximized State - Matches the main window size */
/* Maximized State - Matches the main window size */
.chat-container.maximized {
    top: 0 !important;
    left: 0 !important;
    transform: none !important;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    border-radius: 0 !important;
    /* z-index managed by JS */
}

.header {
    padding: 0;
    /* Removing padding from container to let children handle it */
    border-bottom: 1px solid #ddd;
    font-weight: bold;
    background: #fff;
    display: flex;
    align-items: stretch;
    /* Stretch to fill height */
    cursor: move;
    user-select: none;
    min-height: 40px;
}

.header-left {
    flex: 4;
    min-width: 0;
    overflow: hidden;
    background-color: #cecece;
    /* Dark Green */
    color: black;
    padding: 0px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    /* Added gap for icon */
    border-top-left-radius: 7px;
    /* Match container radius if needed, though strictly container has overflow hidden */
}

.header-left img {
    height: 48px;
    width: auto;
    flex-shrink: 0;
}

.header-title {
    white-space: normal;
    word-break: keep-all;
}

.header-right {
    flex: 6;
    min-width: 0;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 10px 20px;
    gap: 15px;
}

.header-instruction {
    color: green;
    /* Same as plus button */
    font-size: 0.9em;
    white-space: normal;
    word-break: keep-all;
    text-align: right;
}

.controls {
    display: flex;
    gap: 5px;
}

.btn-control {
    border: 1px solid #ccc;
    outline: none;
    background: #eee;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
}

.btn-plus {
    color: green;
}

.btn-max {
    color: blue;
}

.btn-close {
    color: red;
}

.sub-header {
    font-size: 0.8em;
    color: blue;
    text-align: center;
    padding: 10px;
    background-color: #f8f9fa;
    border-bottom: 1px solid #eee;
    /* Counteract chat-box padding */
    margin: -20px -20px 10px -20px;
    /* Ensure text wraps */
    white-space: normal;
    word-break: keep-all;
}

.chat-box {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message {
    max-width: 80%;
    padding: 10px 15px;
    border-radius: 15px;
    line-height: 1.5;
    word-wrap: break-word;
}

.user {
    align-self: flex-end;
    background: #007bff;
    color: white;
    border-bottom-right-radius: 2px;
}

.model {
    align-self: flex-start;
    background: transparent;
    color: black;
    width: 100%;
    max-width: 100%;
    padding: 0;
}

.input-area {
    padding: 20px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
    border-top: 1px solid #ddd;
    display: flex;
    gap: 10px;
    background: #fff;
}

input {
    flex: 1;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 20px;
    outline: none;
}

.send-btn {
    padding: 10px 20px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-weight: bold;
}

.send-btn:disabled {
    background: #ccc;
}

/* Markdown Styles */
.model p {
    margin: 0 0 10px 0;
}

.model pre {
    background: #333;
    color: #fff;
    padding: 10px;
    border-radius: 5px;
    overflow-x: auto;
}

/* Model Selector Styles */
.model-selector-container {
    padding: 5px 20px;
    background: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85em;
    border-top: 1px solid #eee;
}

.model-options {
    display: flex;
    gap: 15px;
    align-items: center;
}

.model-options label {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
}

.model-status {
    color: #555;
    font-weight: 600;
}

/* Donate Line */
.donate-line {
    background-color: #fff9c4;
    /* Pale Yellow */
    border-top: 1px solid #fbc02d;
    /* Darker Yellow border */
    border-bottom: 1px solid #fbc02d;
    padding: 2px 0;
    text-align: center;
    font-size: 0.75rem;
    color: #f57f17;
    /* Dark Orange/Yellow text */
    font-weight: bold;
}

/* Simple Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    width: 300px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.modal-btn {
    margin-top: 15px;
    padding: 8px 16px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
}

.btn-confirm {
    background: #007bff;
    color: white;
}

.btn-cancel {
    background: #eee;
    color: #333;
    margin-left: 10px;
}

.ad-banner {
    width: 90%;
    height: 80px;
    background: #f0f0f0;
    border: 2px dashed #ccc;
    margin: 10px auto;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #888;
    font-weight: bold;
    font-size: 1.2em;
    border-radius: 8px;
    flex-shrink: 0;
}

.fixed-ad-container {
    width: 100%;
    background: #fff;
    border-top: 1px solid #eee;
    padding: 5px 0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 90px;
    /* Ensure space for the ad */
}

.fixed-ad-container .ad-banner {
    margin: 0;
    /* Override margin for the fixed container context if needed */
}