/* ------------------------------
   Global layout
------------------------------ */

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
}

/* Base font to avoid Safari tiny rendering */
@media screen and (min-width: 0px) {
    body {
        font-size: 16px;
    }
}

/* ------------------------------
   Theme variables
------------------------------ */

body.light {
    --bg: #f7f7f9;
    --panel: #ffffff;
    --border: #dcdce0;
    --text: #222;
    --text-light: #555;
    --accent: #3a6df0;
    --assistant-bg: #eef3ff;
    --user-bg: #e9f7e9;
    --system-bg: #fff7d9;
}

body.dark {
    --bg: #1e1f22;
    --panel: #2a2b2f;
    --border: #3a3b3f;
    --text: #e6e6e6;
    --text-light: #aaa;
    --accent: #6d8dff;
    --assistant-bg: #2f3345;
    --user-bg: #2d4432;
    --system-bg: #4a3f1f;
}

/* ------------------------------
   Top bar
------------------------------ */

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background-color: var(--panel);
    border-bottom: 1px solid var(--border);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}
.topbar h1 {
    margin: 0;
    font-size: 1.6rem;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.theme-toggle {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
}

/* ------------------------------
   Main container
------------------------------ */

.app-container {
    max-width: 900px;
    width: 100%;
    margin: 1.5rem auto;
    padding: 0 1rem;
    box-sizing: border-box;
}

/* ------------------------------
   Settings panel
------------------------------ */

.settings {
    background: var(--panel);
    padding: 1rem 1.2rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.settings h2 {
    margin: 0;
    font-size: 1.2rem;
    color: var(--text-light);
}

.settings-content {
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.25s ease;
    max-height: 1000px;
    opacity: 1;
}

.settings-content.collapsed {
    max-height: 0;
    opacity: 0;
    pointer-events: none;
}

.field {
    display: flex;
    flex-direction: column;
    margin-bottom: 1rem;
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
}

.field.inline {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}

label {
    font-size: 0.9rem;
    margin-bottom: 0.3rem;
    color: var(--text-light);
}

input[type="text"],
input[type="password"],
input[type="number"],
textarea,
input[type="file"],
select {
    padding: 0.6rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #fff;
    font-size: 1rem;
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
    resize: none;
}

/* Model row */

.model-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.3rem;
}

.small-btn {
    padding: 0.4rem 0.7rem;
    font-size: 0.8rem;
    border-radius: 6px;
}

/* ------------------------------
   Chat container
------------------------------ */

.chat-container {
    background: var(--panel);
    padding: 1rem;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.chat-history {
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 1rem;
    padding-right: 0.5rem;
}

/* ------------------------------
   Status container
------------------------------ */

.stat-container {
    background: var(--panel);
    padding: 1rem;
    border-radius: 10px;
    border: 1px solid var(--border);
}

/* ------------------------------
   Messages
------------------------------ */

.message {
    padding: 0.8rem 1rem;
    border-radius: 14px;
    border: 1px solid var(--border);
    margin-top: 0.5rem;
    margin-bottom: 1.2rem;
    max-width: 85%;
    box-sizing: border-box;
    overflow-wrap: break-word;
    word-break: break-word;
    position: relative;
}

.message.user {
    margin-left: auto;
    background: var(--user-bg);
}

.message.assistant {
    margin-right: auto;
    background: var(--assistant-bg);
}

.message.system {
    margin-left: auto;
    margin-right: auto;
    background: var(--system-bg);
}

.message .label {
    font-weight: bold;
    margin-bottom: 0.3rem;
    color: var(--text-light);
}

.message .content {
    white-space: pre-wrap;
    overflow-wrap: break-word;
    word-break: break-word;
    max-width: 100%;
}

/* Copy button */
.copy-btn {
    background-color: var(--panel) !important;
    color: var(--text) !important;
    border: 1px solid var(--border) !important;
    padding: 0.25rem 0.6rem;
    border-radius: 6px;
    font-size: 0.75rem;
    cursor: pointer;
    opacity: 0.9;
    position: absolute;
    right: 10px;
    bottom: 10px;
    /* Reset browser defaults */
    appearance: none;
    -webkit-appearance: none;
}

.copy-btn:hover {
    background-color: var(--accent) !important;
    color: #fff !important;
    opacity: 1;
}

/* ------------------------------
   Typing indicator
------------------------------ */

.typing {
    display: flex;
    gap: 6px;
    padding: 0.5rem;
}
.typing {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    text-align: center;
    gap: 6px;
    padding: 8px 0;
    opacity: 0.7;
}
.typing span {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    animation: blink 1.4s infinite both;
}

.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
    0% { opacity: 0.2; }
    20% { opacity: 1; }
    100% { opacity: 0.2; }
}

.hidden {
    display: none;
}

/* ------------------------------
   Chat form & inputs
------------------------------ */

.chat-form {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

textarea {
    display: block;
}

#userMessage {
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
    resize: vertical;
    overflow-wrap: break-word;
    word-break: break-word;
}

/* ------------------------------
   Buttons
------------------------------ */

button {
    background: var(--accent);
    color: white;
    border: none;
    padding: 0.7rem 1.2rem;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
}

button:hover {
    background: #2f59c8;
}

.clear-btn {
    background: #e74c3c;
}

.clear-btn:hover {
    background: #c0392b;
}

.collapse-btn {
    padding: 0.3rem 0.8rem;
    font-size: 0.85rem;
}

/* ------------------------------
   Status line
------------------------------ */

.status {
    margin-left: 1rem;
    font-size: 0.9rem;
    color: var(--text-light);
}

.actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo {
    height: 64px;
    width: 64px;
}

.title {
    font-size: 1.5rem;
    margin: 0;
    color: var(--text);
}