/* =========================
   AI APP — revamp
   No second sidebar. Full-width editorial column,
   history as a slide-in sheet, model picker as a chip rail.
   Uses --bg / --surface / --border / --curve etc from main.css
========================= */

@keyframes aiFade{
    from{ opacity:0; transform:translateY(8px); }
    to{ opacity:1; transform:none; }
}

@keyframes aiTypingBounce{
    0%,60%,100%{ transform:translateY(0); opacity:.35; }
    30%{ transform:translateY(-3px); opacity:1; }
}

main:has(.ai-panel.active){
    padding:0;
    overflow:hidden;
    align-items:stretch;
    justify-content:stretch;
}

.ai-panel.active{
    width:100%;
    height:100%;
}

.ai-app{
    width:100%;
    height:100%;
    display:flex;
    flex-direction:column;
    overflow:hidden;
    animation:aiFade var(--speed-slow) var(--curve);
    position:relative;
}


/* =========================
   HEADER — echoes .home-header: eyebrow + Fraunces title,
   actions at the far end instead of a second rail.
========================= */

.ai-header{
    flex-shrink:0;
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:20px;
    padding:20px 36px;
    border-bottom:1px solid var(--border);
}

.ai-header-text{
    min-width:0;
}

.ai-eyebrow-row{
    display:flex;
    align-items:center;
    gap:9px;
    margin-bottom:8px;
}

.ai-eyebrow-rule{
    width:16px;
    height:1px;
    background:var(--accent);
    flex-shrink:0;
}

.ai-eyebrow{
    font-family:var(--font-mono);
    font-size:10.5px;
    letter-spacing:.1em;
    text-transform:uppercase;
    color:var(--muted);
    white-space:nowrap;
}

.ai-header-title{
    font-family:var(--font-display);
    font-size:25px;
    font-weight:600;
    letter-spacing:-.01em;
    color:var(--white);
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
}

.ai-header-actions{
    display:flex;
    align-items:center;
    gap:8px;
    flex-shrink:0;
}

.ai-header-btn{
    height:36px;
    display:flex;
    align-items:center;
    gap:7px;
    padding:0 13px;
    border-radius:9px;
    background:var(--surface);
    border:1px solid var(--border);
    color:var(--muted);
    font-size:12.5px;
    font-weight:600;
    cursor:pointer;
    transition:background var(--speed) var(--curve), border-color var(--speed) var(--curve), color var(--speed) var(--curve);
}

.ai-header-btn:hover{
    border-color:var(--border-strong);
    background:var(--surface-2);
    color:var(--text);
}

.ai-header-btn svg{
    width:14px;
    height:14px;
    stroke:currentColor;
    fill:none;
    stroke-width:1.7;
    flex-shrink:0;
}

.ai-header-btn.primary{
    background:var(--surface-2);
    border-color:var(--border-strong);
    color:var(--text);
}

.ai-header-btn.primary svg{
    stroke:var(--accent);
}

.ai-header-btn.primary:hover{
    background:var(--accent-dim);
    border-color:var(--accent);
}

.ai-icon-btn{
    width:36px;
    height:36px;
    flex-shrink:0;
    border-radius:9px;
    display:flex;
    align-items:center;
    justify-content:center;
    color:var(--muted);
    transition:background var(--speed) var(--curve), color var(--speed) var(--curve);
}

.ai-icon-btn:hover{
    background:var(--surface);
    color:var(--text);
}

.ai-icon-btn svg{
    width:15px;
    height:15px;
    stroke:currentColor;
    fill:none;
    stroke-width:1.7;
}


/* =========================
   MESSAGES — centered editorial column, like reading a document
========================= */

.ai-messages{
    flex:1;
    overflow-y:auto;
    padding:28px 36px 12px;
    display:flex;
    flex-direction:column;
    gap:20px;
}

.ai-messages::-webkit-scrollbar{
    width:6px;
}

.ai-messages::-webkit-scrollbar-thumb{
    background:var(--border-strong);
    border-radius:20px;
}


/* ---- empty state — matches .simple-panel proportions exactly ---- */

.ai-empty{
    margin:auto;
    width:min(760px,100%);
    text-align:center;
    display:flex;
    flex-direction:column;
    align-items:center;
}

.ai-empty .ai-eyebrow-row{
    justify-content:center;
}

.ai-empty-mark{
    width:56px;
    height:56px;
    border-radius:12px;
    background:var(--surface);
    border:1px solid var(--border);
    display:flex;
    align-items:center;
    justify-content:center;
    margin-bottom:18px;
}

.ai-empty-mark svg{
    width:22px;
    height:22px;
    stroke:var(--text);
    fill:none;
    stroke-width:1.5;
    opacity:.85;
}

.ai-empty h1{
    font-family:var(--font-display);
    font-size:28px;
    font-weight:600;
    letter-spacing:-.01em;
    color:var(--white);
}

.ai-empty p{
    font-size:14.5px;
    line-height:1.6;
    color:var(--muted);
    max-width:380px;
    margin-top:14px;
    margin-bottom:26px;
}

.ai-suggest-grid{
    display:grid;
    grid-template-columns:repeat(4,1fr);
    gap:10px;
    width:100%;
    text-align:left;
}

.ai-suggest-card{
    padding:15px;
    border-radius:12px;
    background:var(--surface);
    border:1px solid var(--border);
    cursor:pointer;
    transition:background var(--speed) var(--curve), border-color var(--speed) var(--curve);
}

.ai-suggest-card:hover{
    background:var(--surface-2);
    border-color:var(--border-strong);
}

.ai-suggest-card strong{
    display:block;
    font-family:var(--font-display);
    font-size:14px;
    font-weight:600;
}

.ai-suggest-card span{
    display:block;
    font-size:11.5px;
    color:var(--muted-dim);
    margin-top:4px;
    line-height:1.5;
}


/* ---- message bubbles ---- */

.ai-msg{
    display:flex;
    gap:12px;
    max-width:880px;
    width:100%;
    margin:0 auto;
}

.ai-msg.user{
    flex-direction:row-reverse;
}

.ai-msg-avatar{
    width:26px;
    height:26px;
    flex-shrink:0;
    border-radius:7px;
    display:flex;
    align-items:center;
    justify-content:center;
    font-family:var(--font-mono);
    font-size:9.5px;
    font-weight:600;
    background:var(--surface-3);
    border:1px solid var(--border);
    color:var(--muted);
    margin-top:2px;
}

.ai-msg.user .ai-msg-avatar{
    background:var(--surface-2);
    color:var(--text);
    border-color:var(--border-strong);
}

.ai-msg-body{
    max-width:calc(100% - 38px);
    display:flex;
    flex-direction:column;
}

.ai-msg.user .ai-msg-body{
    align-items:flex-end;
}

.ai-msg-bubble{
    padding:12px 15px;
    border-radius:12px;
    font-size:14px;
    line-height:1.65;
    background:var(--surface);
    border:1px solid var(--border);
    color:var(--text);
    white-space:pre-wrap;
    word-wrap:break-word;
}

.ai-msg.user .ai-msg-bubble{
    background:var(--surface-2);
    color:var(--text);
    border-color:var(--border-strong);
}

.ai-msg-meta{
    font-family:var(--font-mono);
    font-size:10px;
    color:var(--muted-dim);
    margin-top:6px;
    padding:0 4px;
}

.ai-typing{
    display:flex;
    gap:5px;
    padding:6px 4px;
}

.ai-typing span{
    width:5px;
    height:5px;
    border-radius:50%;
    background:var(--muted);
    animation:aiTypingBounce 1.1s infinite ease-in-out;
}

.ai-typing span:nth-child(2){ animation-delay:.15s; }
.ai-typing span:nth-child(3){ animation-delay:.3s; }

.ai-error-bubble{
    max-width:480px;
    margin:0 auto;
    padding:12px 16px;
    border-radius:12px;
    background:var(--surface);
    border:1px solid var(--border-strong);
    color:var(--muted);
    font-size:12.5px;
    line-height:1.6;
    text-align:center;
}

.ai-error-bubble strong{
    color:var(--text);
}


/* =========================
   COMPOSER + MODEL CHIP RAIL
   Signature element: model choice reads as a row of mono
   chips (like .home-meta-line), not a dropdown control.
========================= */

.ai-composer-wrap{
    flex-shrink:0;
    padding:0 36px 22px;
}

.ai-model-rail{
    display:flex;
    align-items:center;
    gap:6px;
    max-width:880px;
    margin:0 auto 10px;
    padding:0 2px;
    overflow-x:auto;
    scrollbar-width:none;
}

.ai-model-rail::-webkit-scrollbar{
    display:none;
}

.ai-model-rail-label{
    font-family:var(--font-mono);
    font-size:9.5px;
    letter-spacing:.06em;
    text-transform:uppercase;
    color:var(--muted-dim);
    flex-shrink:0;
    margin-right:4px;
    white-space:nowrap;
}

.ai-chip{
    flex-shrink:0;
    display:flex;
    align-items:center;
    gap:6px;
    height:26px;
    padding:0 10px;
    border-radius:100px;
    background:var(--surface);
    border:1px solid var(--border);
    font-family:var(--font-mono);
    font-size:11px;
    color:var(--muted);
    cursor:pointer;
    white-space:nowrap;
    transition:background var(--speed) var(--curve), border-color var(--speed) var(--curve), color var(--speed) var(--curve);
}

.ai-chip:hover{
    border-color:var(--border-strong);
    color:var(--text);
}

.ai-chip.active{
    background:var(--accent-dim);
    border-color:var(--accent);
    color:var(--accent);
}

.ai-chip-dot{
    width:5px;
    height:5px;
    border-radius:50%;
    background:currentColor;
    opacity:.7;
    flex-shrink:0;
}

.ai-chip-more{
    flex-shrink:0;
    height:26px;
    width:26px;
    display:flex;
    align-items:center;
    justify-content:center;
    border-radius:100px;
    background:var(--surface);
    border:1px solid var(--border);
    color:var(--muted);
    cursor:pointer;
    transition:background var(--speed) var(--curve), border-color var(--speed) var(--curve), color var(--speed) var(--curve);
}

.ai-chip-more:hover{
    border-color:var(--border-strong);
    color:var(--text);
}

.ai-chip-more svg{
    width:12px;
    height:12px;
    stroke:currentColor;
    fill:none;
    stroke-width:1.8;
}

.ai-composer{
    display:flex;
    align-items:flex-end;
    gap:10px;
    max-width:880px;
    margin:0 auto;
    background:var(--surface);
    border:1px solid var(--border);
    border-radius:14px;
    padding:8px 8px 8px 16px;
    transition:border-color var(--speed) var(--curve), background var(--speed) var(--curve);
}

.ai-composer:focus-within{
    border-color:var(--accent);
    background:var(--surface-2);
}

.ai-composer textarea{
    flex:1;
    background:none;
    border:none;
    outline:none;
    resize:none;
    color:var(--text);
    font-family:var(--font-body);
    font-size:14px;
    line-height:1.5;
    max-height:160px;
    padding:8px 0;
}

.ai-composer textarea::placeholder{
    color:var(--muted-dim);
}

.ai-send{
    width:38px;
    height:38px;
    flex-shrink:0;
    border-radius:10px;
    background:var(--surface-2);
    border:1px solid var(--border-strong);
    color:var(--text);
    display:flex;
    align-items:center;
    justify-content:center;
    cursor:pointer;
    transition:background var(--speed) var(--curve), border-color var(--speed) var(--curve), color var(--speed) var(--curve), opacity var(--speed) var(--curve);
}

.ai-send:hover:not(:disabled){
    background:var(--accent-dim);
    border-color:var(--accent);
    color:var(--accent);
}

.ai-send:disabled{
    opacity:.35;
    cursor:default;
}

.ai-send svg{
    width:15px;
    height:15px;
    stroke:currentColor;
    fill:none;
    stroke-width:2;
}

.ai-composer-footer{
    max-width:880px;
    margin:10px auto 0;
    text-align:center;
    font-family:var(--font-mono);
    font-size:10.5px;
    color:var(--muted-dim);
}


/* =========================
   MODEL PICKER SHEET
   opened from the "···" chip — full list, grouped by provider,
   styled like the changelog modal (same modal language site-wide).
========================= */

.ai-sheet-overlay{
    position:fixed;
    inset:0;
    z-index:300;
    display:none;
    align-items:center;
    justify-content:center;
    background:rgba(0,0,0,.6);
    backdrop-filter:blur(6px);
    opacity:0;
    transition:opacity var(--speed-slow) var(--curve);
}

.ai-sheet-overlay.open{
    display:flex;
    opacity:1;
}

.ai-sheet{
    width:min(420px,88%);
    max-height:78vh;
    display:flex;
    flex-direction:column;
    background:var(--sidebar);
    border:1px solid var(--border-strong);
    border-radius:14px;
    overflow:hidden;
    position:relative;
    transform:translateY(10px);
    opacity:0;
    transition:transform var(--speed-slow) var(--curve), opacity var(--speed-slow) var(--curve);
}

.ai-sheet-overlay.open .ai-sheet{
    transform:none;
    opacity:1;
}

.ai-sheet-close{
    position:absolute;
    top:16px;
    right:16px;
    z-index:1;
    width:26px;
    height:26px;
    border-radius:7px;
    display:flex;
    align-items:center;
    justify-content:center;
    color:var(--muted);
    transition:background var(--speed) var(--curve), color var(--speed) var(--curve);
}

.ai-sheet-close:hover{
    background:var(--surface);
    color:var(--text);
}

.ai-sheet-close svg{
    width:13px;
    height:13px;
    stroke:currentColor;
    fill:none;
    stroke-width:2;
}

.ai-sheet-header{
    padding:24px 24px 16px;
    border-bottom:1px solid var(--border);
    flex-shrink:0;
}

.ai-sheet-header h2{
    font-family:var(--font-display);
    font-size:22px;
    font-weight:600;
    letter-spacing:-.01em;
    color:var(--white);
    margin-bottom:12px;
}

.ai-sheet-search{
    height:38px;
    display:flex;
    align-items:center;
    gap:9px;
    padding:0 12px;
    background:var(--surface);
    border:1px solid var(--border);
    border-radius:9px;
    transition:border-color var(--speed) var(--curve);
}

.ai-sheet-search:focus-within{
    border-color:var(--accent);
}

.ai-sheet-search svg{
    width:14px;
    height:14px;
    opacity:.5;
    stroke:currentColor;
    fill:none;
    stroke-width:1.6;
    flex-shrink:0;
}

.ai-sheet-search input{
    flex:1;
    min-width:0;
    background:none;
    border:none;
    outline:none;
    color:var(--text);
    font-size:13px;
}

.ai-sheet-body{
    padding:6px 10px;
    overflow-y:auto;
}

.ai-sheet-body::-webkit-scrollbar{
    width:5px;
}

.ai-sheet-body::-webkit-scrollbar-thumb{
    background:var(--border-strong);
    border-radius:20px;
}

.ai-sheet-group-label{
    font-family:var(--font-mono);
    font-size:10px;
    letter-spacing:.08em;
    text-transform:uppercase;
    color:var(--muted-dim);
    padding:14px 14px 6px;
}

.ai-sheet-group-label:first-child{
    padding-top:10px;
}

.ai-sheet-option{
    display:flex;
    align-items:center;
    gap:12px;
    padding:10px 14px;
    border-radius:9px;
    cursor:pointer;
    transition:background var(--speed) var(--curve);
}

.ai-sheet-option:hover{
    background:var(--surface);
}

.ai-sheet-option.selected{
    background:var(--surface-2);
}

.ai-sheet-option-mono{
    width:26px;
    height:26px;
    border-radius:7px;
    flex-shrink:0;
    background:var(--surface-3);
    border:1px solid var(--border);
    display:flex;
    align-items:center;
    justify-content:center;
    font-family:var(--font-mono);
    font-size:10px;
    font-weight:600;
    color:var(--muted);
}

.ai-sheet-option.selected .ai-sheet-option-mono{
    color:var(--accent);
    border-color:var(--accent-dim);
}

.ai-sheet-option-text{
    flex:1;
    min-width:0;
}

.ai-sheet-option-text strong{
    display:block;
    font-size:13px;
    font-weight:600;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
}

.ai-sheet-option-text span{
    display:block;
    font-family:var(--font-mono);
    font-size:10px;
    color:var(--muted-dim);
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
    margin-top:1px;
}

.ai-free-tag{
    flex-shrink:0;
    display:flex;
    align-items:center;
    font-family:var(--font-mono);
    font-size:9px;
    font-weight:600;
    letter-spacing:.03em;
    text-transform:uppercase;
    color:var(--accent);
    background:var(--accent-dim);
    border:1px solid rgba(201,195,154,.35);
    padding:3px 6px;
    border-radius:4px;
    line-height:1;
}

.ai-sheet-option-check{
    width:14px;
    height:14px;
    flex-shrink:0;
    stroke:var(--accent);
    fill:none;
    stroke-width:2;
    opacity:0;
}

.ai-sheet-option.selected .ai-sheet-option-check{
    opacity:1;
}

.ai-sheet-empty{
    padding:24px 14px;
    text-align:center;
    font-size:12.5px;
    color:var(--muted-dim);
}


/* =========================
   HISTORY SHEET
   Same modal shell as the model picker; conversations
   listed like changelog rows (numbered-feeling, but by day-group).
========================= */

.ai-history-empty{
    padding:28px 14px;
    text-align:center;
    font-size:12.5px;
    line-height:1.6;
    color:var(--muted-dim);
}

.ai-history-group-label{
    font-family:var(--font-mono);
    font-size:10px;
    letter-spacing:.08em;
    text-transform:uppercase;
    color:var(--muted-dim);
    padding:14px 14px 6px;
}

.ai-history-group-label:first-child{
    padding-top:10px;
}

.ai-history-row{
    display:flex;
    align-items:center;
    gap:12px;
    padding:11px 14px;
    border-radius:9px;
    cursor:pointer;
    transition:background var(--speed) var(--curve);
}

.ai-history-row:hover{
    background:var(--surface);
}

.ai-history-row.active{
    background:var(--surface-2);
}

.ai-history-row-mono{
    width:26px;
    height:26px;
    border-radius:7px;
    flex-shrink:0;
    background:var(--surface-3);
    border:1px solid var(--border);
    display:flex;
    align-items:center;
    justify-content:center;
    font-family:var(--font-mono);
    font-size:10px;
    font-weight:600;
    color:var(--muted);
}

.ai-history-row.active .ai-history-row-mono{
    color:var(--accent);
    border-color:var(--accent-dim);
}

.ai-history-row-text{
    flex:1;
    min-width:0;
}

.ai-history-row-text strong{
    display:block;
    font-size:13px;
    font-weight:500;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
}

.ai-history-row-del{
    width:26px;
    height:26px;
    flex-shrink:0;
    border-radius:7px;
    display:flex;
    align-items:center;
    justify-content:center;
    opacity:0;
    color:var(--muted);
    transition:opacity var(--speed) var(--curve), background var(--speed) var(--curve), color var(--speed) var(--curve);
}

.ai-history-row:hover .ai-history-row-del{
    opacity:.6;
}

.ai-history-row-del:hover{
    opacity:1 !important;
    background:var(--surface-3);
    color:var(--text);
}

.ai-history-row-del svg{
    width:12px;
    height:12px;
    stroke:currentColor;
    fill:none;
    stroke-width:1.7;
}


/* =========================
   MOBILE
========================= */

@media(max-width:900px){

    .ai-header{
        padding:18px 18px 14px;
    }

    .ai-header-title{
        font-size:19px;
    }

    .ai-header-btn span{
        display:none;
    }

    .ai-header-btn{
        width:36px;
        padding:0;
        justify-content:center;
    }

    .ai-messages{
        padding:22px 16px 8px;
    }

    .ai-composer-wrap{
        padding:0 16px 18px;
    }

    .ai-model-rail{
        margin:0 auto 10px;
    }

    .ai-suggest-grid{
        grid-template-columns:1fr;
    }

    .ai-sheet{
        width:92%;
    }
}

@media(max-width:1200px) and (min-width:901px){

    .ai-suggest-grid{
        grid-template-columns:repeat(2,1fr);
    }
}