/* Without this, width:100% + padding overflows the parent, which breaks the
   sidebar and chat column sizing. */
*, *::before, *::after { box-sizing: border-box; }

:root {
    --bg-gradient: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    --accent-color: #667eea;
    --satvik-color: #764ba2;
    --user-color: #38ef7d;
    --text-color: #2d3436;
    --mic-color: #ff7675;
    --pause-color: #fdcb6e;
    --clear-color: #fab1a0;
    --stop-color: #e17055;
    --base-font-size: 0.95rem;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-gradient);
    min-height: 100vh;
    color: var(--text-color);
}

.app {
    display: flex;
    min-height: 100vh;
}

.main {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 1rem;
}

.container {
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}

@media (max-width: 768px) {
    .main { padding: 0.5rem; }
    .container { border-radius: 14px; padding: 0.9rem; }
    .settings-controls { flex-wrap: wrap; }
    /* On a narrow screen the hint is the first thing to go, and Send takes the
       full width so it stays an easy thumb target. */
    .composer-hint { display: none; }
    .composer-buttons { width: 100%; margin-left: 0; }
    .send-btn { flex: 1 1 auto; }
    #user-input { min-height: 4.4em; }
}

h1 {
    text-align: center;
    margin-top: 0;
    font-weight: 300;
    letter-spacing: 2px;
    color: var(--satvik-color);
    font-size: calc(var(--base-font-size) * 2.5);
}

#chat-window {
    flex-grow: 1;
    overflow-y: auto;
    margin-bottom: 1.5rem;
    padding-right: 5px;
}

#chat-window::-webkit-scrollbar { width: 5px; }
#chat-window::-webkit-scrollbar-thumb { background: #ccc; border-radius: 10px; }

.message {
    margin-bottom: 1rem;
    padding: 0.8rem 1.2rem;
    border-radius: 15px;
    max-width: 80%;
    line-height: 1.4;
    font-size: var(--base-font-size);
    animation: fadeIn 0.3s ease;
    position: relative;
    word-wrap: break-word;
}

.message.user {
    align-self: flex-end;
    background-color: var(--user-color);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 2px;
}

.message.satvik {
    align-self: flex-start;
    background-color: var(--accent-color);
    color: white;
    border-bottom-left-radius: 2px;
}

.message.error {
    align-self: flex-start;
    background-color: var(--stop-color);
    color: white;
    border-bottom-left-radius: 2px;
}

/* Markdown block elements inside a bubble */
.message p { margin: 0 0 0.5em 0; }
.message p:last-child { margin-bottom: 0; }
.message ul, .message ol { margin: 0.3em 0 0.6em 1.2em; padding: 0; }
.message li { margin: 0.15em 0; }
.message h3, .message h4, .message h5, .message h6 {
    margin: 0.5em 0 0.3em 0;
    font-size: 1.05em;
    line-height: 1.3;
}
.message code {
    background: rgba(0, 0, 0, 0.22);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}
.message pre.code-block {
    background: rgba(0, 0, 0, 0.28);
    padding: 0.7em;
    border-radius: 8px;
    overflow-x: auto;
    white-space: pre;
    margin: 0.4em 0;
}
.message pre.code-block code { background: none; padding: 0; }

.message.image-container {
    align-self: flex-start;
    background: none;
    padding: 0;
    max-width: 100%;
}

.message.image-container img {
    max-width: 100%;
    border-radius: 15px;
    box-shadow: 0 10px 20px rgba(0,0,0,0.2);
    border: 3px solid white;
    cursor: zoom-in;
}

.image-caption {
    align-self: flex-start;
    max-width: 80%;
    margin-top: -0.6rem;
    margin-bottom: 1rem;
    font-size: 0.8rem;
    font-style: italic;
    color: var(--text-color);
    opacity: 0.75;
    white-space: pre-wrap;
}
.msg-stats {
    display: block;
    margin-top: 0.45rem;
    font-size: 0.7rem;
    opacity: 0.6;
    letter-spacing: 0.3px;
}

/* ---------- Output files ---------- */
.artifact-card {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    max-width: 80%;
    margin-bottom: 0.6rem;
    padding: 0.6rem 0.9rem;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-left: 4px solid var(--satvik-color);
    border-radius: 12px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
}

.file-badge {
    flex: 0 0 auto;
    font-size: 0.65rem;
    font-weight: bold;
    letter-spacing: 0.6px;
    color: #fff;
    background: var(--satvik-color);
    padding: 3px 7px;
    border-radius: 5px;
}

.artifact-name {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 0.85rem;
    color: var(--text-color);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.artifact-size {
    flex: 0 0 auto;
    font-size: 0.72rem;
    color: var(--text-color);
    opacity: 0.6;
}

.artifact-dl {
    flex: 0 0 auto;
    font-size: 0.75rem;
    font-weight: bold;
    color: var(--satvik-color);
    text-decoration: none;
    padding: 0.3rem 0.6rem;
    border: 1px solid var(--satvik-color);
    border-radius: 14px;
    white-space: nowrap;
}
.artifact-dl:hover { background: var(--satvik-color); color: #fff; }

.file-building {
    font-style: italic;
    opacity: 0.85;
}

/* "Save as..." popover */
.save-menu {
    position: absolute;
    top: 26px;
    right: 5px;
    z-index: 20;
    display: none;
    flex-wrap: wrap;
    gap: 4px;
    width: 232px;
    padding: 8px;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 10px;
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
}
.save-menu.open { display: flex; }
.save-menu .menu-label {
    width: 100%;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-color);
    opacity: 0.55;
}
.save-menu button {
    padding: 0.3rem 0.55rem;
    font-size: 0.72rem;
    border-radius: 12px;
    background: rgba(118, 75, 162, 0.1);
    color: var(--satvik-color);
}
.save-menu button:hover { background: var(--satvik-color); color: #fff; }
.save-menu button:disabled { opacity: 0.4; }

.save-btn { right: 75px; }
.image-dl {
    display: inline-block;
    margin-top: 0.4rem;
    font-size: 0.75rem;
    color: var(--satvik-color);
    text-decoration: none;
    border: 1px solid var(--satvik-color);
    border-radius: 14px;
    padding: 0.25rem 0.6rem;
}
.image-dl:hover { background: var(--satvik-color); color: #fff; }

.copy-btn, .speak-btn, .save-btn {
    position: absolute;
    top: 5px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    border-radius: 5px;
    padding: 2px 6px;
    font-size: 0.7rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
}
.copy-btn { right: 5px; }
.speak-btn { right: 40px; }
.save-btn { right: 75px; }
.message:hover .copy-btn,
.message:hover .speak-btn,
.message:hover .save-btn { opacity: 1; }
.message.user .copy-btn, .message.user .speak-btn, .message.user .save-btn {
    color: #2d3436;
    background: rgba(0, 0, 0, 0.1);
}

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

/* ==========================================================
   COMPOSER
   ----------------------------------------------------------
   Stacked rather than a single flex-wrap row. Previously the
   settings, the font buttons, the attach pill, the textarea and
   four action buttons all shared one wrapping line, so the
   textarea - the only thing you actually type into - was
   squeezed to about a quarter of the width while the buttons
   wrapped onto a second line and left Send stranded mid-row.
   ========================================================== */
.chat-input-area {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    margin-top: 0.5rem;
}

/* Settings row: everything here is configuration, not a primary action. */
.composer-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
}

.settings-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-color);
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 20px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 14px; width: 14px;
    left: 3px; bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}
input:checked + .slider { background-color: var(--accent-color); }
input:checked + .slider:before { transform: translateX(20px); }

.font-controls { display: flex; gap: 4px; margin-right: 8px; align-items: center; }
.font-controls button { padding: 0.4rem 0.6rem; font-size: 0.9rem; min-width: 35px; }

#model-select {
    padding: 0.35rem 0.5rem;
    border-radius: 20px;
    border: 1px solid rgba(0,0,0,0.15);
    background: rgba(255,255,255,0.9);
    font-family: inherit;
    font-size: 0.8rem;
    color: var(--text-color);
    max-width: 160px;
    cursor: pointer;
}

.file-upload-container {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.5);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    color: var(--text-color);
    border: 1px solid rgba(0,0,0,0.1);
}

#file-input { display: none; }
.file-label { cursor: pointer; color: var(--satvik-color); font-weight: bold; text-decoration: underline; }
#file-name { max-width: 130px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.clear-file-btn {
    background: none;
    color: #ff7675;
    padding: 0 5px;
    font-size: 0.8rem;
    border-radius: 50%;
    width: 20px; height: 20px; min-width: 20px;
}
.clear-file-btn:hover { background: rgba(255, 118, 117, 0.2); }

/* The textarea's own row. min-width:0 stops a long placeholder or value from
   pushing the flex item wider than the column. */
.composer-input {
    min-width: 0;
    width: 100%;
}

#user-input {
    width: 100%;
    padding: 0.9rem 1.1rem;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 16px;
    outline: none;
    background: rgba(255, 255, 255, 0.9);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
    font-size: var(--base-font-size);
    resize: none;
    font-family: inherit;
    line-height: 1.5;
    /* Three comfortable lines to start, then the JS grows it as you type. */
    min-height: 5.2em;
    max-height: 12em;
    overflow-y: auto;
}
/* A visible focus ring, so keyboard users can see where they are. */
#user-input:focus {
    border-color: var(--satvik-color);
    box-shadow: 0 0 0 3px rgba(118, 75, 162, 0.15);
}

.composer-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.composer-hint {
    font-size: 0.72rem;
    color: var(--text-color);
    opacity: 0.45;
}
.composer-buttons {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}
/* Send is the one primary action, so it is the one big filled button. */
.send-btn {
    padding: 0.7rem 1.6rem;
    font-size: calc(var(--base-font-size) * 1.05);
    font-weight: 600;
    min-width: 96px;
}

button {
    background: var(--satvik-color);
    color: white;
    border: none;
    padding: 0.8rem 1.2rem;
    border-radius: 25px;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(var(--base-font-size) * 1.2);
}
button:hover { transform: scale(1.05); background: var(--accent-color); }
button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

#mic-btn { background: var(--mic-color); }
#mic-btn.listening { animation: pulse 1.5s infinite; background: #d63031; }
#mic-btn.wake-word-active { background: var(--pause-color); color: #2d3436; }

#pause-btn { background: var(--pause-color); color: #2d3436; min-width: 45px; }
#clear-btn { background: var(--clear-color); color: #2d3436; }
#stop-btn { background: var(--stop-color); display: none; }
#stop-btn.visible { display: flex; }

@keyframes pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 118, 117, 0.7); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 10px rgba(255, 118, 117, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 118, 117, 0); }
}

#status-bar {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-color);
    opacity: 0.6;
    min-height: 1.1rem;
    margin-top: 0.5rem;
}

footer {
    text-align: center;
    margin-top: 0.6rem;
    font-size: var(--base-font-size);
    font-style: italic;
    opacity: 0.7;
}

/* ==========================================================
   AUTH SCREEN
   ========================================================== */
.auth-screen {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: var(--bg-gradient);
    overflow-y: auto;
}
.auth-screen[hidden] { display: none; }

.auth-card {
    width: 100%;
    max-width: 400px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    box-shadow: 0 18px 45px rgba(0, 0, 0, 0.16);
    padding: 2rem 1.75rem;
}

.auth-card h1 {
    text-align: center;
    margin: 0 0 0.2rem;
    font-weight: 300;
    letter-spacing: 2px;
    color: var(--satvik-color);
    font-size: calc(var(--base-font-size) * 2.2);
}

.auth-sub {
    text-align: center;
    margin: 0 0 1.4rem;
    font-size: 0.85rem;
    opacity: 0.65;
}

.auth-tabs {
    display: flex;
    gap: 6px;
    background: rgba(0, 0, 0, 0.05);
    padding: 4px;
    border-radius: 22px;
    margin-bottom: 1.3rem;
}
.auth-tab {
    flex: 1;
    background: transparent;
    color: var(--text-color);
    padding: 0.5rem;
    border-radius: 18px;
    font-size: 0.88rem;
    font-weight: 600;
}
.auth-tab.active {
    background: #fff;
    color: var(--satvik-color);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}
.auth-tab:hover { transform: none; }

#auth-form { display: flex; flex-direction: column; }
#auth-form label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    opacity: 0.6;
    margin: 0 0 0.3rem;
}
#auth-form input {
    padding: 0.7rem 0.85rem;
    margin-bottom: 1rem;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 12px;
    font-size: 0.95rem;
    font-family: inherit;
    background: #fff;
    color: var(--text-color);
    outline: none;
}
#auth-form input:focus {
    border-color: var(--satvik-color);
    box-shadow: 0 0 0 3px rgba(118, 75, 162, 0.15);
}

.auth-error {
    background: rgba(225, 112, 85, 0.12);
    border: 1px solid rgba(225, 112, 85, 0.4);
    color: #b3391f;
    padding: 0.55rem 0.7rem;
    border-radius: 10px;
    font-size: 0.82rem;
    margin-bottom: 0.9rem;
}
.auth-error[hidden] { display: none; }

.auth-submit {
    width: 100%;
    justify-content: center;
    padding: 0.75rem;
    font-size: 1rem;
    font-weight: 600;
}

.guest-btn {
    width: 100%;
    justify-content: center;
    margin-top: 0.7rem;
    padding: 0.6rem;
    background: transparent;
    color: var(--text-color);
    border: 1px solid rgba(0, 0, 0, 0.2);
    font-size: 0.85rem;
}
.guest-btn:hover { background: rgba(0, 0, 0, 0.05); color: var(--text-color); }
.guest-btn[hidden] { display: none; }

.auth-hint {
    text-align: center;
    font-size: 0.75rem;
    opacity: 0.55;
    margin: 1rem 0 0;
    line-height: 1.5;
}

/* ==========================================================
   SIDEBAR
   ========================================================== */
.sidebar {
    flex: 0 0 260px;
    width: 260px;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    padding: 1rem 0.8rem;
    background: rgba(255, 255, 255, 0.72);
    backdrop-filter: blur(10px);
    border-right: 1px solid rgba(0, 0, 0, 0.08);
}

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.3rem;
}
.brand {
    font-weight: 600;
    letter-spacing: 1.5px;
    color: var(--satvik-color);
    font-size: 1.05rem;
}

.icon-btn {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-color);
    padding: 0.35rem 0.6rem;
    border-radius: 8px;
    font-size: 0.9rem;
    min-width: 34px;
}
.icon-btn:hover { background: rgba(0, 0, 0, 0.1); color: var(--text-color); }
.icon-btn[hidden] { display: none; }

.new-chat {
    width: 100%;
    justify-content: center;
    padding: 0.6rem;
    font-size: 0.88rem;
    font-weight: 600;
}

.conv-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    opacity: 0.5;
    padding: 0.4rem 0.4rem 0.1rem;
}

.conv-list {
    flex: 1 1 auto;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-height: 0;
}

.conv-item {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0.5rem 0.5rem 0.5rem 0.7rem;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.83rem;
    color: var(--text-color);
    border: 1px solid transparent;
}
.conv-item:hover { background: rgba(0, 0, 0, 0.05); }
.conv-item.active {
    background: rgba(118, 75, 162, 0.12);
    border-color: rgba(118, 75, 162, 0.3);
    font-weight: 600;
}
.conv-title-text {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.conv-del {
    background: none;
    color: var(--text-color);
    opacity: 0;
    padding: 0 0.3rem;
    font-size: 0.8rem;
    border-radius: 6px;
    min-width: 22px;
    transition: opacity 0.15s;
}
.conv-item:hover .conv-del { opacity: 0.5; }
.conv-del:hover { background: rgba(225, 112, 85, 0.2); color: #b3391f; }

.conv-empty, .conv-loading {
    font-size: 0.78rem;
    opacity: 0.5;
    padding: 0.5rem 0.4rem;
    line-height: 1.5;
}

.sidebar-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    padding-top: 0.7rem;
    /* Pin to the bottom of the sidebar. .conv-list already grows to fill the
       space, so this is belt-and-braces: it keeps the profile flush against the
       bottom edge no matter how short or long the chat list is. Without it the
       footer sits directly under the last chat instead. */
    margin-top: auto;
    flex: 0 0 auto;
}
.who { display: flex; align-items: center; gap: 0.5rem; min-width: 0; }
.avatar {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--satvik-color);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
}
.who-name {
    font-size: 0.82rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.link-btn {
    background: none;
    color: var(--text-color);
    opacity: 0.6;
    font-size: 0.78rem;
    padding: 0.3rem 0.4rem;
    border-radius: 6px;
    flex: 0 0 auto;
}
.link-btn:hover { background: rgba(0, 0, 0, 0.07); opacity: 1; color: var(--text-color); }
.link-btn[hidden] { display: none; }

/* ==========================================================
   TOP BAR
   ========================================================== */
.topbar {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    max-width: 1100px;
    width: 100%;
    margin: 0 auto 0.7rem;
    padding: 0 0.3rem;
}
.conv-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-color);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.guest-badge {
    font-size: 0.7rem;
    background: var(--pause-color);
    color: #2d3436;
    padding: 0.2rem 0.55rem;
    border-radius: 10px;
    font-weight: 600;
    white-space: nowrap;
}
.guest-badge[hidden] { display: none; }

/* ==========================================================
   LIGHTBOX
   ========================================================== */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.82);
    padding: 2rem;
    cursor: zoom-out;
}
.lightbox[hidden] { display: none; }
.lightbox img {
    max-width: 92vw;
    max-height: 88vh;
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}
.lightbox-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    font-size: 1.1rem;
    padding: 0.4rem 0.7rem;
    border-radius: 50%;
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.35); }

/* Mobile: sidebar becomes a slide-over drawer */
@media (max-width: 820px) {
    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        z-index: 90;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        box-shadow: 0 0 30px rgba(0, 0, 0, 0.25);
    }
    .sidebar.open { transform: translateX(0); }
    .icon-btn { display: flex !important; }
}
@media (min-width: 821px) {
    #sidebar-close { display: none; }

    /* Keep the sidebar within the viewport and let the chat list scroll inside
       it. Without a bounded height the sidebar grows with the number of chats
       and pushes the profile block below the fold, so it is only "at the
       bottom" while you have few chats. Bounding it here makes that true
       always. (The mobile sidebar is position:fixed and already bounded.) */
    .sidebar {
        position: sticky;
        top: 1rem;
        /* Exactly one viewport tall, so the panel always reaches the bottom of
           the window and the profile sits flush against it. A max-height alone
           would let the panel shrink to its content and stop partway down. */
        height: calc(100vh - 2rem);
        overflow: hidden;
    }
}

/* ==========================================================
   RENAMING A CHAT
   ========================================================== */
.conv-edit {
    background: none;
    color: var(--text-color);
    opacity: 0;
    padding: 0 0.3rem;
    font-size: 0.8rem;
    border-radius: 6px;
    min-width: 22px;
    transition: opacity 0.15s;
}
.conv-item:hover .conv-edit { opacity: 0.5; }
.conv-edit:hover { background: rgba(118, 75, 162, 0.15); opacity: 1 !important; }

/* Inline text field that replaces the title while editing */
.conv-rename-input {
    flex: 1 1 auto;
    min-width: 0;
    font: inherit;
    font-size: 0.83rem;
    font-weight: 600;
    color: var(--satvik-color);
    background: #fff;
    border: 1px solid var(--satvik-color);
    border-radius: 7px;
    padding: 0.2rem 0.35rem;
    outline: none;
    box-shadow: 0 0 0 3px rgba(118, 75, 162, 0.15);
}

/* The title bar itself is the rename button */
button.conv-title {
    background: none;
    color: var(--text-color);
    font-size: 0.95rem;
    font-weight: 600;
    padding: 0.25rem 0.45rem;
    border-radius: 8px;
    border: 1px dashed transparent;
    text-align: left;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}
button.conv-title:hover {
    transform: none;
    background: rgba(0, 0, 0, 0.04);
    color: var(--text-color);
    border-color: rgba(0, 0, 0, 0.15);
}
.rename-hint { opacity: 0.5; }
.rename-hint:hover { opacity: 1; }


/* ==========================================================
   PHASE 2: EMAIL VERIFICATION, SIDEBAR TOOLS & MODALS
   ========================================================== */
#auth-email-wrap[hidden] { display: none; }

.auth-verify-box {
    background: rgba(118, 75, 162, 0.08);
    border: 1px solid rgba(118, 75, 162, 0.25);
    color: var(--text-color);
    padding: 0.7rem 0.85rem;
    border-radius: 10px;
    font-size: 0.82rem;
    line-height: 1.45;
    margin-bottom: 0.9rem;
}
.auth-verify-box[hidden] { display: none; }
.auth-verify-box a {
    display: inline-block;
    margin-top: 0.45rem;
    color: var(--satvik-color);
    font-weight: 600;
    word-break: break-all;
}
.resend-btn {
    margin-top: 0.4rem;
    padding-left: 0;
    text-decoration: underline;
}

.auth-pass-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
}
.auth-inline-link {
    font-size: 0.76rem;
    color: var(--satvik-color);
    opacity: 0.9;
    padding: 0;
    text-decoration: underline;
}
.auth-inline-link[hidden] { display: none; }

.auth-otp-row {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    margin-top: 0.55rem;
}
.auth-otp-row input {
    margin-bottom: 0 !important;
    padding: 0.5rem 0.65rem !important;
    font-size: 0.86rem !important;
}
.auth-otp-inputs {
    display: flex;
    gap: 0.45rem;
    align-items: stretch;
}
.auth-otp-inputs input { flex: 1 1 auto; min-width: 0; }
.otp-btn {
    background: var(--satvik-color);
    color: #fff;
    border-radius: 10px;
    padding: 0.5rem 0.85rem;
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}
.auth-dev-otp {
    margin-top: 0.35rem;
    font-weight: 700;
    color: var(--satvik-color);
    letter-spacing: 1px;
}
.auth-otp-toggle {
    align-self: center;
    margin-top: 0.5rem;
    font-size: 0.78rem;
    color: var(--satvik-color);
    opacity: 0.85;
    text-decoration: underline;
}
.auth-otp-toggle[hidden] { display: none; }

.auth-forgot-title {
    font-weight: 700;
    margin-bottom: 0.2rem;
    color: var(--satvik-color);
}
.auth-forgot-sub {
    margin: 0 0 0.55rem;
    font-size: 0.8rem;
    opacity: 0.85;
}
.auth-forgot-msg {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    font-weight: 600;
}

.google-auth-wrap { margin-top: 0.7rem; }
.google-auth-wrap[hidden] { display: none; }
.auth-divider {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0.5rem 0 0.7rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.55;
}
.auth-divider::before,
.auth-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: rgba(0, 0, 0, 0.14);
}
.google-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    padding: 0.65rem 0.9rem;
    border-radius: 12px;
    background: #fff;
    color: #1f2937;
    border: 1px solid rgba(0, 0, 0, 0.16);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
}
.google-btn:hover { background: #f9fafb; border-color: rgba(0, 0, 0, 0.28); }
.google-g {
    display: inline-grid;
    place-items: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4285f4, #34a853, #fbbc05, #ea4335);
    color: #fff;
    font-weight: 800;
    font-size: 0.78rem;
}
.gsi-btn-host {
    margin-top: 0.45rem;
    display: flex;
    justify-content: center;
}

/* Onboarding Wizard */
.ob-card {
    background: #f9f8fd;
    border: 1px solid rgba(118, 75, 162, 0.22);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 0.85rem;
}
.ob-steps {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.9rem;
    font-size: 0.76rem;
    font-weight: 600;
}
.ob-step {
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.06);
    color: #6b7280;
}
.ob-step.active {
    background: var(--satvik-color);
    color: #fff;
}
.ob-name-banner {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--satvik-color);
    margin: 0.25rem 0 0.45rem;
}
.ob-rec-status {
    font-size: 0.82rem;
    color: var(--satvik-color);
    font-weight: 600;
}
.panel-section-title {
    margin: 1rem 0 0.5rem;
    padding-top: 0.85rem;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--satvik-color);
}

.sidebar-tools {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0.25rem 0 0.35rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}
.sidebar-tools[hidden] { display: none; }
.sidebar-tool-btn {
    width: 100%;
    text-align: left;
    justify-content: flex-start;
    background: rgba(255, 255, 255, 0.6);
    color: var(--text-color);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 9px;
    padding: 0.45rem 0.65rem;
    font-size: 0.82rem;
    font-weight: 500;
}
.sidebar-tool-btn:hover {
    background: rgba(118, 75, 162, 0.12);
    color: var(--satvik-color);
}
.sidebar-tool-btn[hidden] { display: none; }
.sidebar-tool-btn.admin-btn {
    border-color: rgba(118, 75, 162, 0.35);
    color: var(--satvik-color);
    font-weight: 600;
}

.topbar-signin {
    margin-left: auto;
    border: 1px solid rgba(118, 75, 162, 0.35);
    color: var(--satvik-color);
    opacity: 1;
    font-weight: 600;
    padding: 0.25rem 0.6rem;
}
.topbar-signin[hidden] { display: none; }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 250;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(20, 20, 35, 0.52);
    backdrop-filter: blur(4px);
    padding: 1rem;
}
.modal-overlay[hidden] { display: none; }

.modal-card {
    width: min(760px, 96vw);
    max-height: 88vh;
    background: #fff;
    color: var(--text-color);
    border-radius: 16px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.28);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.9rem 1.2rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}
.modal-head h2 {
    margin: 0;
    font-size: 1.05rem;
    color: var(--satvik-color);
}
.modal-body {
    padding: 1rem 1.2rem 1.3rem;
    overflow-y: auto;
    font-size: 0.88rem;
}

.modal-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    padding-bottom: 0.6rem;
}
.modal-tab {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-color);
    border-radius: 8px;
    padding: 0.4rem 0.75rem;
    font-size: 0.82rem;
    font-weight: 600;
}
.modal-tab.active {
    background: var(--satvik-color);
    color: #fff;
}

.panel-form {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    margin-bottom: 1rem;
}
.panel-form label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: #4b5563;
}
.panel-form input[type="text"],
.panel-form input[type="password"],
.panel-form input[type="url"],
.panel-form input[type="number"],
.panel-form select,
.panel-form textarea {
    font: inherit;
    font-size: 0.86rem;
    padding: 0.5rem 0.65rem;
    border: 1px solid rgba(0, 0, 0, 0.16);
    border-radius: 8px;
    background: #fafafa;
    color: var(--text-color);
}
.panel-form textarea { resize: vertical; min-height: 70px; }

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.7rem;
}
.form-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}
.checkbox-row {
    display: flex !important;
    flex-direction: row !important;
    align-items: center;
    gap: 0.45rem !important;
    font-size: 0.84rem !important;
    color: var(--text-color) !important;
    font-weight: 500 !important;
}

.panel-msg {
    padding: 0.5rem 0.7rem;
    border-radius: 8px;
    font-size: 0.82rem;
    margin-bottom: 0.7rem;
}
.panel-msg.ok { background: rgba(16, 185, 129, 0.12); color: #065f46; }
.panel-msg.err { background: rgba(225, 112, 85, 0.14); color: #b3391f; }

.item-list {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}
.item-card {
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    padding: 0.65rem 0.8rem;
    background: #fcfcfd;
}
.item-card.disabled { opacity: 0.6; }
.item-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
}
.item-card-title { font-weight: 600; font-size: 0.88rem; }
.item-card-body { font-size: 0.82rem; color: #4b5563; white-space: pre-wrap; word-break: break-word; }
.item-card-actions { display: flex; gap: 0.35rem; align-items: center; }

.btn-sm {
    padding: 0.28rem 0.55rem;
    font-size: 0.75rem;
    border-radius: 6px;
}
.btn-secondary {
    background: rgba(0, 0, 0, 0.07);
    color: var(--text-color);
}
.btn-secondary:hover { background: rgba(0, 0, 0, 0.14); color: var(--text-color); }
.btn-danger {
    background: rgba(225, 112, 85, 0.15);
    color: #b3391f;
}
.btn-danger:hover { background: rgba(225, 112, 85, 0.28); color: #8c230d; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 0.55rem;
    margin-bottom: 1rem;
}
.stat-box {
    background: #f8f7fc;
    border: 1px solid rgba(118, 75, 162, 0.16);
    border-radius: 10px;
    padding: 0.55rem 0.7rem;
}
.stat-val { font-size: 1.15rem; font-weight: 700; color: var(--satvik-color); }
.stat-lbl { font-size: 0.72rem; color: #6b7280; }

.pill {
    display: inline-block;
    padding: 0.15rem 0.45rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
}
.pill.ok { background: rgba(16, 185, 129, 0.16); color: #065f46; }
.pill.warn { background: rgba(245, 158, 11, 0.18); color: #92400e; }
.pill.err { background: rgba(239, 68, 68, 0.15); color: #991b1b; }
.pill.admin { background: rgba(118, 75, 162, 0.16); color: var(--satvik-color); }

.admin-table-wrap { overflow-x: auto; }
.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}
.admin-table th, .admin-table td {
    text-align: left;
    padding: 0.45rem 0.5rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    vertical-align: middle;
}
.admin-table th {
    font-size: 0.72rem;
    text-transform: uppercase;
    color: #6b7280;
}

.lid-badge {
    font-size: 0.72rem;
    background: rgba(118, 75, 162, 0.12);
    color: var(--satvik-color);
    padding: 0.2rem 0.55rem;
    border-radius: 10px;
    font-weight: 600;
    white-space: nowrap;
}
.lid-badge[hidden] { display: none; }
