/* =========================================================================
   Home Agent — stylesheet (dark theme)
   One property per line, grouped by section.
   ========================================================================= */

/* ------------------------------------------------------------------ theme */
:root {
    --bg: #0e1116;
    --panel: #151a22;
    --panel2: #1b2230;
    --line: #242c3a;
    --text: #e6ebf2;
    --dim: #8b96a8;
    --accent: #5b8cff;
    --accent2: #7aa2ff;
    --user: #22304b;
    --ok: #3fbf7f;
    --err: #e05c5c;
    --mono: ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;
}

/* ------------------------------------------------------------------- base */
* {
    box-sizing: border-box;
}
html {
    height: 100%;
}
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    display: grid;
    grid-template-columns: 280px 1fr;
    grid-template-rows: auto 1fr auto;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* -------------------------------------------------------------- sidebar -- */
aside {
    grid-row: 2;
    background: var(--panel);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 16px 12px;
}
.brand .logo {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--accent), #3b5fd9);
    display: grid;
    place-items: center;
    font-size: 16px;
}
.brand b {
    font-size: 15px;
}
.brand small {
    display: block;
    color: var(--dim);
    font-size: 11px;
}
.newbtn {
    margin: 4px 12px 12px;
    padding: 10px 14px;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 9px;
    cursor: pointer;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    font-size: 13px;
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
}
.newbtn:hover {
    background: var(--accent2);
}
.chats {
    flex: 1;
    overflow-y: auto;
    padding: 2px 8px 8px;
}
.chats .hd {
    padding: 10px 10px 6px;
    font-size: 11px;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--dim);
}
.chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    color: var(--dim);
    font-size: 13px;
    position: relative;
}
.chip:hover {
    background: var(--panel2);
    color: var(--text);
}
.chip.active {
    background: var(--panel2);
    color: var(--text);
    box-shadow: inset 2px 0 0 var(--accent);
}
.chip .t {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chip .x {
    opacity: 0;
    border: 0;
    background: none;
    color: var(--dim);
    cursor: pointer;
    font-size: 13px;
    padding: 2px 4px;
    border-radius: 4px;
}
.chip:hover .x {
    opacity: 1;
}
.chip .x:hover {
    color: var(--err);
    background: rgba(224, 92, 92, .12);
}
.chip .n {
    font-size: 11px;
    color: var(--dim);
}
.sbfoot {
    padding: 12px 14px;
    border-top: 1px solid var(--line);
    font-size: 12px;
    color: var(--dim);
    display: flex;
    align-items: center;
    gap: 8px;
}
.sbfoot[hidden] { display: none; }
.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--err);
    flex: none;
}
.dot.ok {
    background: var(--ok);
}

/* --------------------------------------------------------------- header -- */
header {
    grid-column: 1/3;
    grid-row: 1;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 22px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
}
header h1 {
    font-size: 20px;
    margin: 0;
    font-weight: 600;
    flex: 1;
    padding: 4px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.modelsel {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 4px 12px 10px;
    padding: 6px 8px;
    background: var(--panel2);
    border: 1px solid var(--line);
    border-radius: 10px;
}
.modelsel label {
    color: var(--dim);
    font-size: 12px;
    flex: none;
}
.modelsel select {
    flex: 1;
    min-width: 0;
    max-width: none;
    padding: 6px 8px;
}
.modelsel .btnghost {
    flex: none;
    padding: 6px 10px;
}
select {
    background: var(--panel2);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 13px;
    max-width: 260px;
    cursor: pointer;
}
select:focus {
    outline: none;
    border-color: var(--accent);
}
.btnghost {
    background: none;
    border: 1px solid var(--line);
    color: var(--dim);
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 12.5px;
    cursor: pointer;
}
.btnghost:hover {
    color: var(--text);
    border-color: var(--dim);
}

/* ----------------------------------------------------------- main / feed -- */
main {
    grid-row: 2;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
}
#feed {
    flex: 1;
    overflow-y: auto;
    padding: 22px 0 12px;
    scroll-behavior: smooth;
}
.inner {
    max-width: 860px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}
.msg {
    display: flex;
    gap: 12px;
    animation: fade .18s ease;
}
@keyframes fade {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: none; }
}
.avatar {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    flex: none;
    display: grid;
    place-items: center;
    font-size: 14px;
    font-weight: 700;
    margin-top: 2px;
}
.msg.user .avatar {
    background: var(--user);
    color: #bcd0ff;
}
.msg.assistant .avatar {
    background: linear-gradient(135deg, var(--accent), #3b5fd9);
    color: #fff;
}
.bubble {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.meta {
    font-size: 11.5px;
    color: var(--dim);
    display: flex;
    gap: 8px;
    align-items: baseline;
}
.meta .t {
    margin-left: auto;
}
.msg.user .meta {
    flex-direction: row-reverse;
}
.msg.user .meta .t {
    margin: 0;
}
body .msg.user .meta {
    justify-content: flex-end;
}
.content {
    white-space: pre-wrap;
    word-wrap: break-word;
}
.msg.user .content {
    background: var(--user);
    padding: 10px 14px;
    border-radius: 4px 14px 14px 14px;
    max-width: 100%;
}
.msg.assistant .content {
    color: var(--text);
}
/* Model reasoning — a collapsible, muted block above the answer */
.think {
    margin: 0 0 8px;
    border-left: 3px solid rgba(139,150,168,.35);
    border-radius: 4px;
    background: rgba(139,150,168,.07);
    font-size: 13px;
    color: var(--dim);
}
.think summary {
    cursor: pointer;
    padding: 5px 10px;
    font-size: 12px;
    letter-spacing: .02em;
    color: var(--dim);
    user-select: none;
    list-style: none;
}
.think summary::-webkit-details-marker { display: none; }
.think summary::before { content: "▸ "; transition: transform .15s; display: inline-block; }
.think[open] summary::before { content: "▾ "; }
.think-body {
    padding: 4px 10px 8px 24px;
    line-height: 1.55;
    color: var(--dim);
    max-height: 260px;
    overflow-y: auto;
}
.content .cursor {
    display: inline-block;
    width: 8px;
    height: 15px;
    background: var(--accent);
    vertical-align: -2px;
    animation: blink 1s steps(2) infinite;
    border-radius: 2px;
}
@keyframes blink {
    50% { opacity: 0; }
}

/* ------------------------------------------------------- markdown in body */
.content p {
    margin: .45em 0;
}
.content pre {
    background: #0b0e13;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px 14px;
    overflow-x: auto;
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.5;
    margin: .6em 0;
    position: relative;
}
.content pre .copy {
    position: absolute;
    top: 8px;
    right: 8px;
    border: 0;
    background: var(--panel2);
    color: var(--dim);
    border-radius: 6px;
    font-size: 11px;
    padding: 3px 8px;
    cursor: pointer;
    opacity: 0;
    transition: .15s;
}
.content pre:hover .copy {
    opacity: 1;
}
.content pre .copy:hover {
    color: var(--text);
}
.content code {
    font-family: var(--mono);
    font-size: .92em;
    background: #0b0e13;
    padding: .12em .38em;
    border-radius: 5px;
    border: 1px solid var(--line);
}
.content pre code {
    background: none;
    border: 0;
    padding: 0;
}
.content ul,
.content ol {
    margin: .45em 0;
    padding-left: 1.4em;
}
.content table {
    border-collapse: collapse;
    margin: .6em 0;
    display: block;
    overflow-x: auto;
    max-width: 100%;
}
.content th,
.content td {
    border: 1px solid var(--line);
    padding: 6px 11px;
    font-size: 13px;
    text-align: left;
}
.content th {
    background: var(--panel2);
    font-weight: 600;
}
.content h1,
.content h2,
.content h3 {
    margin: .7em 0 .35em;
    line-height: 1.3;
}
.content a {
    color: var(--accent2);
}
.content img {
    max-width: 100%;
    border-radius: 8px;
}
.shimmer {
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg, var(--panel2) 25%, var(--panel) 50%, var(--panel2) 75%);
    background-size: 200% 100%;
    animation: sh 1.2s infinite;
    margin: 6px 0;
    max-width: 280px;
}
@keyframes sh {
    to { background-position: -200% 0; }
}
.empty {
    margin: auto;
    text-align: center;
    color: var(--dim);
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 30px;
}
.empty .big {
    font-size: 44px;
}
.empty kbd {
    background: var(--panel2);
    border: 1px solid var(--line);
    border-radius: 5px;
    padding: 1px 6px;
    font-size: 12px;
}

/* -------------------------------------------------------------- composer -- */
footer {
    grid-column: 1/3;
    grid-row: 3;
    background: var(--panel);
    border-top: 1px solid var(--line);
    padding: 12px 18px 14px;
}
.comp {
    max-width: 860px;
    margin: 0 auto;
}
/* Attach button sits OUTSIDE the input bubble, inline with it (left side),
   stretched to the bubble's exact height with its label centred. */
.composerrow {
    display: flex;
    align-items: stretch;
    gap: 8px;
}
.composerrow .inputrow {
    flex: 1;
    min-width: 0;
}
.attachbtn {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: var(--panel2);
    color: var(--dim);
    font: inherit;
    font-size: 14px;
    white-space: nowrap;
    cursor: pointer;
    transition: border-color .15s, color .15s, background .15s;
}
.attachbtn:hover {
    border-color: var(--accent);
    color: var(--accent2);
    background: var(--panel);
}
.prevrow {
    display: none;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}
.prevrow.on {
    display: flex;
}
.prev {
    position: relative;
}
.prev img {
    width: 52px;
    height: 52px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--line);
}
.prev .rm {
    position: absolute;
    top: -7px;
    right: -7px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 0;
    background: var(--err);
    color: #fff;
    font-size: 11px;
    cursor: pointer;
    line-height: 1;
}
.inputrow {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: var(--panel2);
    border: 1px solid var(--line);
    border-radius: 13px;
    padding: 8px 8px 8px 12px;
    transition: border-color .15s;
}
.inputrow:focus-within {
    border-color: var(--accent);
}
textarea {
    flex: 1;
    background: none;
    border: 0;
    outline: none;
    resize: none;
    color: var(--text);
    font: inherit;
    line-height: 1.5;
    max-height: 260px;
    min-height: 24px;
    padding: 2px 0;
}
textarea::placeholder {
    color: var(--dim);
}
.tools {
    display: flex;
    gap: 4px;
    align-items: center;
}
.iconbtn {
    border: 0;
    background: none;
    color: var(--dim);
    width: 34px;
    height: 34px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 17px;
    display: grid;
    place-items: center;
    flex: none;
}
.iconbtn:hover {
    background: var(--line);
    color: var(--text);
}

.send {
    border: 0;
    background: var(--accent);
    color: #fff;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    cursor: pointer;
    font-size: 15px;
    display: grid;
    place-items: center;
    flex: none;
}
.send:hover {
    background: var(--accent2);
}
.send:disabled {
    background: var(--line);
    color: var(--dim);
    cursor: default;
}
.stop {
    background: var(--err);
}
.hint {
    max-width: 860px;
    margin: 7px auto 0;
    font-size: 11.5px;
    color: var(--dim);
    display: flex;
    justify-content: space-between;
}
.hint .err {
    color: var(--err);
}

/* --------------------------------------------------------------- incognito */
.incogbtn {
    margin: 4px 12px 10px;
    padding: 9px 14px;
    border: 1px solid var(--line);
    border-radius: 9px;
    cursor: pointer;
    background: var(--panel2);
    color: var(--dim);
    font-size: 13px;
    font-weight: 500;
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
    flex: none;
}
#incogBanner[hidden] {
    display: none;
}
.incogbtn:hover {
    border-color: var(--accent2);
    color: var(--text);
}
.incogbtn.on {
    border-color: var(--accent2);
    background: rgba(91, 140, 255, .12);
    color: var(--accent2);
}
.incogbanner {
    margin: 0 12px 8px;
    padding: 8px 10px;
    font-size: 12px;
    color: var(--accent2);
    background: rgba(91, 140, 255, .10);
    border: 1px solid rgba(122, 162, 255, .35);
    border-radius: 8px;
    display: flex;
    gap: 6px;
    align-items: center;
    line-height: 1.35;
}
body.incognito .chats {
    display: none;
}
body.incognito #chatTitle {
    color: var(--accent2);
}
.menuBtn {
    display: none;
}
.scrim {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    z-index: 19;
    border: 0;
    padding: 0;
}

/* ------------------------------------------------------- mobile layout -- */
@media (max-width: 760px) {
    body {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
    }
    header,
    footer {
        grid-column: 1;
    }
    header {
        padding: 10px 14px;
        gap: 10px;
    }
    .menuBtn {
        display: inline-flex;
        flex: none;
    }
    header h1 {
        font-size: 16px;
        padding: 0;
    }
    aside {
        grid-row: auto;
        grid-column: 1;
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: min(320px, 86vw);
        z-index: 20;
        transform: translateX(-102%);
        transition: transform .18s ease;
        box-shadow: 8px 0 30px rgba(0, 0, 0, .45);
        border-right: 1px solid var(--line);
        height: 100vh;
        height: 100dvh;
    }
    body.nav-open aside {
        transform: none;
    }
    body.nav-open .scrim {
        display: block;
    }
    main {
        grid-column: 1;
    }
    #feed {
        padding-bottom: 24px;
    }
    .comp,
    .inner,
    .hint {
        max-width: none;
    }
    .modelsel select {
        max-width: none;
    }
    .msg .bubble {
        max-width: 85%;
    }
    .empty {
        padding: 40px 16px;
    }
    .empty .big {
        font-size: 40px;
    }
}
@media (max-width: 480px) {
    .attachbtn {
        display: none;
    }
    .msg .bubble {
        max-width: 92%;
    }
    .chip {
        font-size: 12.5px;
    }
}

/* ---------------------------------------------------------------- scrollbars */
::-webkit-scrollbar {
    width: 10px;
}
::-webkit-scrollbar-thumb {
    background: var(--line);
    border-radius: 5px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--dim);
}

/* ============================================================= auth splash */
.auth-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: radial-gradient(1200px 600px at 50% -10%, #1a2333, var(--bg));
    overflow: auto;
}
.auth-overlay[hidden] { display: none; }
.auth-inner {
    width: 100%;
    max-width: 380px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 26px 24px 22px;
    box-shadow: 0 24px 60px -20px #000c;
}
.auth-brand { text-align: center; margin-bottom: 20px; }
.auth-logo { font-size: 40px; line-height: 1; margin-bottom: 6px; }
.auth-brand h1 { margin: 0; font-size: 22px; letter-spacing: .2px; }
.auth-tag { margin: 6px 0 0; color: var(--dim); font-size: 13px; }
.auth-panel h2 { margin: 0 0 14px; font-size: 16px; }
.auth-sub { margin: 0 0 14px; color: var(--dim); font-size: 12.5px; }
.auth-sub .muted { color: var(--dim); opacity: .8; }
.auth-field { margin-bottom: 12px; }
.auth-field label { display: block; font-size: 12.5px; color: var(--dim); margin-bottom: 5px; }
.auth-field input {
    width: 100%;
    box-sizing: border-box;
    background: var(--panel2);
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 10px 11px;
    color: var(--text);
    font: 14px/1.4 system-ui, sans-serif;
    outline: none;
}
.auth-field input:focus { border-color: var(--accent); }
.auth-err { margin: 12px 0 0; color: var(--err); font-size: 13px; }
.auth-sublink { margin-top: 14px; font-size: 13px; }
.auth-sublink a { color: var(--accent2); text-decoration: none; }
.auth-sublink a:hover { text-decoration: underline; }
.auth-tiles { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.auth-tile {
    padding: 9px 12px;
    background: var(--panel2);
    border: 1px solid var(--line);
    border-radius: 10px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text);
    transition: border-color .12s, background .12s;
}
.auth-tile:hover { border-color: var(--accent); }
.auth-tile.sel { border-color: var(--accent); background: var(--user); }
.auth-tile .badge { font-size: 10px; color: var(--dim); display: block; margin-top: 2px; }

/* ---- buttons (shared) ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 1px solid var(--line);
    background: var(--panel2);
    color: var(--text);
    border-radius: 9px;
    padding: 10px 14px;
    font-size: 14px;
    cursor: pointer;
    transition: background .12s, border-color .12s, transform .05s;
    width: 100%;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---- signed-in user chip in sidebar ---- */
.sbfoot#userFoot { border-top: 1px solid var(--line); }
.chip-user { font-weight: 600; font-size: 13px; }
