/* public/css/components/margin-chat.css
 *
 * Ask Margin — the floating launcher, the slide-in chat panel, and the Command
 * palette that can hand a question to it.
 *
 * Moved out of layouts/today.css, where these rules lived because the markup
 * they style was built by the Today page. Nothing here was ever Today-specific:
 * the launcher and the panel are position:fixed and the stylesheet was already
 * loaded on every page, so the components appeared on Today only because that
 * was the one place the JS created them. They are mounted on document.body now
 * (public/js/components/marginChat.js), and their styles belong beside them.
 *
 * Unchanged from the originals apart from this header — the layout was already
 * correct for a global element.
 */

/* ── Command palette ─────────────────────────────────────────────────────── */

.palette-overlay {
    position: fixed; inset: 0;
    background: rgba(6, 5, 88, 0.32);
    backdrop-filter: blur(8px);
    z-index: var(--z-overlay);
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding-top: 14vh;
}
.palette-overlay.open { display: flex; }
.palette {
    width: min(640px, 92vw);
    background: var(--white);
    border: 1px solid var(--rule-2);
    box-shadow: var(--shadow-hover);
    overflow: hidden;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
}
.palette-input {
    width: 100%;
    border: 0;
    border-bottom: 1px solid var(--rule);
    padding: var(--space-6);
    font-family: var(--font-title);
    font-size: var(--text-md);
    color: var(--ink);
    background: transparent;
    outline: none;
}
.palette-input::placeholder { color: var(--ink-dim); font-style: italic; }
.palette-section {
    padding: var(--space-4) var(--space-6) var(--space-2);
    font-family: var(--font-ui);
    font-size: 0.625rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--ink-dim);
}
.palette-body { overflow-y: auto; }
.palette-item {
    padding: var(--space-3) var(--space-6);
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
}
.palette-item:hover, .palette-item.sel { background: var(--paper); }
.palette-item-l { display: flex; align-items: center; gap: var(--space-4); }
.palette-icon {
    width: 28px; height: 28px;
    border-radius: 4px;
    background: var(--paper);
    display: grid; place-items: center;
    font-family: var(--font-title);
    font-size: var(--text-sm);
    color: var(--ink);
    flex-shrink: 0;
}
.palette-icon.ai { background: var(--gold); }
.palette-text { font-family: var(--font-body); font-size: var(--text-base); color: var(--ink); }
.palette-hint { font-family: var(--font-ui); font-size: 0.625rem; letter-spacing: 0.1em; color: var(--ink-dim); text-transform: uppercase; }
.palette-foot {
    padding: var(--space-3) var(--space-6);
    border-top: 1px solid var(--rule);
    font-family: var(--font-ui);
    font-size: 0.625rem;
    letter-spacing: 0.1em;
    color: var(--ink-dim);
    text-transform: uppercase;
}

/* ── AI launcher + panel ─────────────────────────────────────────────────── */

.ai-launcher {
    position: fixed;
    bottom: var(--space-8); right: var(--space-8);
    z-index: var(--z-toast, 400);
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-5) var(--space-3) var(--space-3);
    background: var(--ink);
    color: var(--paper);
    border-radius: 999px;
    cursor: pointer;
    box-shadow: var(--shadow-hover);
    font-family: var(--font-ui);
    font-size: var(--text-sm);
    letter-spacing: 0.04em;
}
.ai-launcher:hover { background: var(--coral-deep); }
.ai-launcher .glyph {
    width: 26px; height: 26px;
    border-radius: 50%;
    background: var(--gold);
    color: var(--ink);
    display: grid; place-items: center;
    font-family: var(--font-title);
    font-style: italic;
    font-size: 1rem;
    flex-shrink: 0;
}

.ai-panel {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: min(440px, 92vw);
    background: var(--white);
    border-left: 1px solid var(--rule-2);
    z-index: var(--z-overlay);
    transform: translateX(100%);
    transition: transform 0.35s ease;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-hover);
}
.ai-panel.open { transform: translateX(0); }
.ai-head {
    padding: var(--space-6) var(--space-6) var(--space-4);
    border-bottom: 1px solid var(--rule);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}
.ai-head h3 { font-family: var(--font-title); font-size: var(--text-lg); color: var(--ink); margin-bottom: 4px; }
.ai-head h3 em { font-family: var(--font-body); font-style: italic; color: var(--gold-deep); font-weight: 400; }
.ai-head p { font-family: var(--font-ui); font-size: 0.6875rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-dim); }
.ai-close {
    background: transparent;
    border: 1px solid var(--rule-2);
    width: 32px; height: 32px;
    border-radius: 50%;
    cursor: pointer;
    color: var(--ink-dim);
    font-size: var(--text-md);
    line-height: 1;
}
.ai-close:hover { color: var(--coral); border-color: var(--coral); }
.ai-head-actions { display: flex; gap: var(--space-2); align-items: center; flex-shrink: 0; }
.ai-threads, .ai-new {
    font-family: var(--font-ui);
    font-size: 0.625rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-dim);
    background: none;
    border: 1px solid var(--rule-2);
    padding: 6px 10px;
    cursor: pointer;
}
.ai-threads:hover, .ai-new:hover { color: var(--ink); border-color: var(--ink); }

/* Saved-conversation list (swaps in for the chat body) */
.ai-conversations { flex: 1; overflow-y: auto; padding: var(--space-5) var(--space-6); }
.ai-conversations-head {
    font-family: var(--font-ui);
    font-size: 0.625rem;
    letter-spacing: 0.24em;
    text-transform: uppercase;
    color: var(--ink-dim);
    margin-bottom: var(--space-4);
}
.ai-conversation-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    border: 1px solid var(--rule);
    background: var(--paper);
    margin-bottom: var(--space-3);
}
.ai-conversation-main { flex: 1; padding: var(--space-3) var(--space-4); cursor: pointer; min-width: 0; }
.ai-conversation-main:hover .ai-conversation-title { color: var(--gold-deep); }
.ai-conversation-title {
    font-family: var(--font-title);
    font-size: var(--text-sm);
    color: var(--ink);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ai-conversation-meta { font-family: var(--font-ui); font-size: var(--text-xs); color: var(--ink-dim); margin-top: 2px; }
.ai-conversation-delete {
    background: none;
    border: none;
    color: var(--ink-dim);
    font-size: var(--text-md);
    cursor: pointer;
    padding: var(--space-3);
}
.ai-conversation-delete:hover { color: var(--coral); }
.ai-conversations-note {
    font-family: var(--font-body);
    font-style: italic;
    font-size: var(--text-sm);
    color: var(--ink-dim);
    margin-top: var(--space-4);
}
.ai-bubble.notice { font-style: italic; font-size: var(--text-sm); color: var(--ink-dim); }
.ai-body { flex: 1; overflow-y: auto; padding: var(--space-5) var(--space-6); display: flex; flex-direction: column; gap: var(--space-4); }
.ai-bubble { font-family: var(--font-body); font-size: var(--text-base); line-height: 1.55; color: var(--ink); }
.ai-bubble.user {
    align-self: flex-end;
    max-width: 88%;
    padding: var(--space-3) var(--space-4);
    background: var(--paper);
    border: 1px solid var(--rule);
    border-radius: 14px 14px 4px 14px;
    font-family: var(--font-ui);
    font-size: var(--text-sm);
}
.ai-bubble.error { color: var(--coral-deep); }
.ai-foot { border-top: 1px solid var(--rule); padding: var(--space-4); display: flex; gap: var(--space-3); align-items: center; }
.ai-input { flex: 1; border: 0; background: transparent; font-family: var(--font-body); font-size: var(--text-base); color: var(--ink); outline: none; }
.ai-input::placeholder { color: var(--ink-dim); font-style: italic; }
.ai-send {
    background: var(--ink); color: var(--paper); border: 0;
    width: 34px; height: 34px; border-radius: 50%;
    cursor: pointer; font-family: var(--font-title); font-size: var(--text-md);
}
.ai-send:hover { background: var(--coral-deep); }
.ai-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 1100px) {
    /* Below this width the persistent bottom tab bar (navbar.css
       .mobile-tabbar, 64px tall) replaces the top nav — clear it and its
       right-aligned profile avatar instead of floating on top of them. */
    .ai-launcher {
        bottom: calc(64px + env(safe-area-inset-bottom, 0px) + var(--space-4));
        right: var(--space-4);
    }
}

@media (max-width: 480px) {
    .ai-launcher span:not(.glyph) { display: none; }
    .ai-launcher { padding: var(--space-3); }
}
