/* Qyokala — calm, minimal assistant interface */

body.ai-page-active {
    background: #f7f8fa;
    background-image: none;
}

body.ai-page-active .main {
    position: fixed;
    inset: calc(28px + var(--topbar-h)) 0 0;
    min-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    overflow: hidden;
}

body.ai-page-active .main-inner {
    width: 100%;
    max-width: none;
    height: 100%;
    padding: 0;
    overflow: hidden;
}

#pg-ai.active {
    height: 100%;
}

body.ai-page-active ::selection {
    background: #dce5f1;
    color: #111827;
}

#pg-ai {
    --qay-ink: #17191c;
    --qay-muted: #717780;
    --qay-soft: #f3f5f7;
    --qay-line: #e3e6ea;
    --qay-white: #ffffff;
    --qay-accent: #20242a;
    color: var(--qay-ink);
}

.qay-page-shell {
    width: 100%;
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.qai-header {
    width: min(920px, calc(100% - 3rem));
    min-height: 72px;
    margin: 0 auto;
    padding: 0 0.25rem;
    border-bottom: 1px solid var(--qay-line);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.qay-brand-mark {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    color: var(--qay-ink);
    background: #f4ce55;
    border: 1.5px solid #22262b;
    border-radius: 10px;
    box-shadow: 2px 2px 0 #22262b;
}

.qay-brand-mark svg {
    width: 18px;
    height: 18px;
    stroke-width: 1.8;
}

.qay-brand-copy {
    min-width: 0;
}

.qay-brand-copy h1 {
    margin: 0;
    color: var(--qay-ink);
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.015em;
    line-height: 1.25;
}

.qay-brand-copy p {
    margin: 0.1rem 0 0;
    color: var(--qay-muted);
    font-size: 0.78rem;
    line-height: 1.25;
}

.qay-header-state {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--qay-muted);
    font-size: 0.76rem;
}

.qay-header-state-dot {
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: #3f9f67;
    box-shadow: 0 0 0 3px rgba(63, 159, 103, 0.1);
}

.qay-neo-container {
    position: relative;
    width: min(920px, 100%);
    min-height: 0;
    margin: 0 auto;
    display: flex;
    flex: 1;
    flex-direction: column;
    overflow: hidden;
    background: transparent;
}

.qay-brain-strip {
    display: none;
    width: calc(100% - 3.5rem);
    margin: 0.8rem auto 0;
    padding: 0.65rem 0.75rem;
    align-items: center;
    gap: 0.75rem;
    color: var(--qay-muted);
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid var(--qay-line);
    border-radius: 12px;
    flex-shrink: 0;
}

.qay-brain-identity {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    min-width: 0;
}

.qay-brain-icon {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    color: #555d66;
    background: var(--qay-soft);
    border-radius: 8px;
    flex-shrink: 0;
}

.qay-brain-icon svg {
    width: 14px;
    height: 14px;
    stroke-width: 1.8;
}

.qay-brain-title {
    display: grid;
    line-height: 1.2;
}

.qay-brain-title strong {
    color: var(--qay-ink);
    font-size: 0.76rem;
    font-weight: 600;
}

.qay-brain-title span {
    margin-top: 0.1rem;
    font-size: 0.68rem;
}

.qay-brain-metrics {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.qay-brain-metric {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.5rem;
    color: #5f6670;
    background: var(--qay-soft);
    border-radius: 7px;
    font-size: 0.7rem;
    white-space: nowrap;
}

.qay-brain-metric svg {
    width: 12px;
    height: 12px;
    stroke-width: 1.8;
}

.qay-brain-metric.is-indexing svg {
    animation: qay-spin 1.1s linear infinite;
}

@keyframes qay-spin {
    to { transform: rotate(360deg); }
}

.qay-messages {
    min-height: 0;
    padding: 1.5rem 1.75rem 1rem;
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 1.5rem;
    overflow-x: hidden;
    overflow-y: auto;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: #d5d9de transparent;
}

.qay-messages::-webkit-scrollbar {
    width: 5px;
}

.qay-messages::-webkit-scrollbar-track {
    background: transparent;
}

.qay-messages::-webkit-scrollbar-thumb {
    background: #d5d9de;
    border: 0;
    border-radius: 999px;
}

.qay-msg {
    width: 100%;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    animation: qay-message-in 220ms ease-out;
}

.qay-msg.user {
    justify-content: flex-start;
    flex-direction: row-reverse;
}

@keyframes qay-message-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.qay-msg-avatar {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    color: #4d545c;
    background: var(--qay-white);
    border: 1px solid var(--qay-line);
    border-radius: 9px;
    flex-shrink: 0;
}

.qay-msg-avatar svg {
    width: 15px;
    height: 15px;
    stroke-width: 1.8;
}

.qay-msg.user .qay-msg-avatar {
    display: none;
}

.qay-bubble-text {
    max-width: min(78%, 680px);
    color: #2e3238;
    font-size: 0.94rem;
    line-height: 1.68;
    overflow-wrap: anywhere;
}

.qay-msg.user .qay-bubble-text {
    padding: 0.68rem 0.95rem;
    color: #292d32;
    background: #eceff2;
    border: 1px solid #d5d9de;
    border-radius: 15px 15px 4px 15px;
}

.qay-msg.ai .qay-bubble-text {
    padding: 0.15rem 0;
}

.qay-bubble-text strong {
    color: #17191c;
    font-weight: 600;
}

.qay-bubble-text em {
    font-style: italic;
}

.qay-bubble-text p {
    margin: 0.55rem 0;
}

.qay-bubble-text p:first-child {
    margin-top: 0;
}

.qay-bubble-text p:last-child {
    margin-bottom: 0;
}

.qay-bubble-text ul,
.qay-bubble-text ol {
    margin: 0.55rem 0;
    padding-left: 1.25rem;
    list-style: revert;
}

.qay-bubble-text li {
    margin: 0.22rem 0;
}

.qay-bubble-text code {
    padding: 0.12rem 0.3rem;
    color: #30363d;
    background: #eef0f2;
    border-radius: 4px;
    font-family: var(--mono);
    font-size: 0.84em;
}

.qay-bubble-text pre {
    margin: 0.8rem 0;
    padding: 0.9rem 1rem;
    color: #e7e9ec;
    background: #202328;
    border: 0;
    border-radius: 10px;
    overflow-x: auto;
    font-family: var(--mono);
    font-size: 0.82rem;
}

.qay-bubble-text pre code {
    padding: 0;
    color: inherit;
    background: transparent;
}

.qay-typing {
    height: 24px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.qay-typing span {
    width: 5px;
    height: 5px;
    background: #8c9299;
    border-radius: 50%;
    animation: qay-pulse 1.2s infinite ease-in-out both;
}

.qay-typing span:nth-child(1) { animation-delay: -0.24s; }
.qay-typing span:nth-child(2) { animation-delay: -0.12s; }

@keyframes qay-pulse {
    0%, 75%, 100% { opacity: 0.25; transform: translateY(0); }
    38% { opacity: 1; transform: translateY(-2px); }
}

.qay-welcome {
    width: min(640px, 100%);
    margin: auto;
    padding: 2rem 1rem;
    text-align: center;
}

.qay-welcome-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 1.1rem;
    display: grid;
    place-items: center;
    color: #394049;
    background: #f4ce55;
    border: 1.5px solid #22262b;
    border-radius: 13px;
    box-shadow: 3px 3px 0 #22262b;
}

.qay-welcome-icon svg {
    width: 22px;
    height: 22px;
    stroke-width: 1.7;
}

.qay-welcome h3 {
    margin: 0;
    color: var(--qay-ink);
    font-size: 1.38rem;
    font-weight: 600;
    letter-spacing: -0.025em;
}

.qay-welcome p {
    max-width: 500px;
    margin: 0.65rem auto 0;
    color: var(--qay-muted);
    font-size: 0.9rem;
    line-height: 1.6;
}

.qay-suggestions {
    margin-top: 1.5rem;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.55rem;
}

.qay-suggestion-chip {
    min-width: 0;
    padding: 0.7rem 0.8rem;
    color: #464c53;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid #cfd4d9;
    border-radius: 9px;
    box-shadow: 1.5px 1.5px 0 rgba(34, 38, 43, 0.18);
    font-size: 0.79rem;
    font-weight: 400;
    text-align: left;
    transition: color 160ms ease, background 160ms ease, border-color 160ms ease, transform 160ms ease;
    touch-action: manipulation;
}

.qay-suggestion-chip:hover {
    color: #17191c;
    background: var(--qay-white);
    border-color: #22262b;
    box-shadow: 2.5px 2.5px 0 #22262b;
    transform: translate(-1px, -1px);
}

.qay-input-area {
    width: min(790px, calc(100% - 3.5rem));
    margin: 0 auto;
    padding: 0.6rem 0 1.1rem;
    background: linear-gradient(180deg, rgba(247, 248, 250, 0), #f7f8fa 24%);
    flex-shrink: 0;
}

.qay-input-row {
    min-height: 54px;
    padding: 0.42rem 0.45rem 0.42rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    background: var(--qay-white);
    border: 1.5px solid #343940;
    border-radius: 15px;
    box-shadow: 3px 3px 0 rgba(34, 38, 43, 0.18);
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

.qay-input-row:focus-within {
    border-color: #181b1f;
    box-shadow: 3px 3px 0 #181b1f;
}

.qay-input {
    width: 100%;
    min-width: 0;
    flex: 1;
    min-height: 24px;
    max-height: 120px;
    padding: 0;
    color: var(--qay-ink);
    background: transparent;
    border: 0;
    outline: 0;
    resize: none;
    overflow-y: auto;
    font-family: var(--font);
    font-size: 0.92rem;
    font-weight: 400;
    line-height: 1.55;
}

.qay-input::placeholder {
    color: #9a9fa6;
    opacity: 1;
}

.qay-send-btn {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    color: #fff;
    background: var(--qay-accent);
    border: 1px solid #111418;
    border-radius: 11px;
    flex-shrink: 0;
    transition: background 150ms ease, transform 150ms ease, opacity 150ms ease;
    touch-action: manipulation;
}

.qay-send-btn svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    stroke-width: 1.9;
}

.qay-send-btn:hover {
    background: #080a0d;
    transform: translateY(-1px);
}

.qay-send-btn:active {
    transform: translateY(0) scale(0.97);
}

.qay-send-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none;
}

.qay-input-footer {
    margin-top: 0.45rem;
    padding: 0 0.35rem;
    display: flex;
    justify-content: center;
}

.qay-input-hint {
    color: #969ba2;
    font-size: 0.68rem;
}

.qay-library-results {
    margin-top: 1rem;
    display: grid;
    gap: 0.6rem;
}

.qay-library-group {
    overflow: hidden;
    background: rgba(255, 255, 255, 0.68);
    border: 1px solid #cfd4d9;
    border-radius: 10px;
    box-shadow: 1.5px 1.5px 0 rgba(34, 38, 43, 0.14);
}

.qay-library-group > summary {
    padding: 0.68rem 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #343940;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 500;
    list-style: none;
}

.qay-library-group > summary::-webkit-details-marker {
    display: none;
}

.qay-library-group > summary::before {
    content: "";
    width: 6px;
    height: 6px;
    border-right: 1.5px solid #7a8087;
    border-bottom: 1.5px solid #7a8087;
    transform: rotate(-45deg);
    transition: transform 150ms ease;
}

.qay-library-group[open] > summary::before {
    transform: rotate(45deg) translateY(-1px);
}

.qay-library-count {
    margin-left: auto;
    color: #8a9097;
    font-size: 0.7rem;
    font-weight: 400;
    white-space: nowrap;
}

.qay-library-list {
    max-height: 360px;
    display: grid;
    overflow-y: auto;
    border-top: 1px solid var(--qay-line);
}

.qay-library-item {
    padding: 0.72rem 0.8rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.qay-library-item + .qay-library-item {
    border-top: 1px solid #edf0f2;
}

.qay-library-info {
    min-width: 0;
    display: grid;
    gap: 0.12rem;
}

.qay-library-info strong,
.qay-library-info span {
    overflow: hidden;
    text-overflow: ellipsis;
}

.qay-library-info strong {
    color: #30353b;
    font-size: 0.78rem;
    font-weight: 500;
}

.qay-library-info span {
    color: #858b92;
    font-size: 0.69rem;
}

.qay-library-actions {
    display: flex;
    gap: 0.32rem;
    flex-shrink: 0;
}

.qay-library-actions a {
    min-height: 28px;
    padding: 0.3rem 0.5rem;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: #555c64;
    background: #f6f7f8;
    border: 1px solid #e1e4e7;
    border-radius: 7px;
    font-size: 0.67rem;
    font-weight: 500;
    text-decoration: none;
    touch-action: manipulation;
}

.qay-library-actions a:hover {
    color: #17191c;
    background: #eceff2;
}

.qay-library-actions svg {
    width: 11px;
    height: 11px;
}

.qay-sources {
    margin-top: 1rem;
    padding-top: 0.85rem;
    display: grid;
    gap: 0.38rem;
    border-top: 1px solid var(--qay-line);
}

.qay-sources > strong {
    margin-bottom: 0.1rem;
    color: #737980;
    font-size: 0.7rem;
    font-weight: 500;
}

.qay-sources a {
    min-width: 0;
    padding: 0.48rem 0.58rem;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    color: #565d65;
    background: #f5f6f7;
    border: 1px solid #e6e8eb;
    border-radius: 8px;
    font-size: 0.7rem;
    line-height: 1.35;
    text-decoration: none;
}

.qay-sources a:hover {
    color: #1f2328;
    background: #eef0f2;
}

.qay-source-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.qay-sources svg {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    body.ai-page-active .ticker-wrap {
        display: none;
    }

    body.ai-page-active .topbar {
        top: 0;
        padding: 0 0.85rem;
        border-bottom: 1px solid #e1e4e7;
        box-shadow: none;
    }

    body.ai-page-active .topbar .brand-icon {
        width: 32px;
        height: 32px;
        background: #f4ce55;
        border: 1px solid #22262b;
        border-radius: 9px;
        box-shadow: 2px 2px 0 #22262b;
        font-size: 0.9rem;
    }

    body.ai-page-active .topbar .brand-name {
        font-size: 0.98rem;
        font-weight: 600;
    }

    body.ai-page-active .sidebar {
        top: var(--topbar-h);
    }

    body.ai-page-active .main {
        inset: var(--topbar-h) 0 0;
        bottom: auto;
        height: calc(100vh - var(--topbar-h));
        height: calc(var(--qay-visual-vh, 100dvh) - var(--topbar-h));
    }

    .qay-page-shell {
        height: 100%;
        min-height: 0;
    }

    .qai-header {
        width: 100%;
        min-height: 54px;
        padding: 0 0.85rem;
        background: rgba(247, 248, 250, 0.94);
    }

    .qay-brand-mark {
        width: 30px;
        height: 30px;
        border-radius: 8px;
    }

    .qay-brand-mark svg {
        width: 15px;
        height: 15px;
    }

    .qay-brand-copy h1 {
        font-size: 0.92rem;
    }

    .qay-brand-copy p {
        font-size: 0.68rem;
    }

    .qay-header-state {
        font-size: 0.68rem;
    }

    .qay-brain-strip {
        width: calc(100% - 1rem);
        min-height: 40px;
        margin-top: 0.45rem;
        padding: 0.4rem 0.5rem;
        gap: 0.45rem;
        border-radius: 10px;
    }

    .qay-brain-title {
        display: none;
    }

    .qay-brain-metrics {
        width: auto;
        min-width: 0;
        margin-left: 0;
        flex: 1;
        flex-wrap: nowrap;
        justify-content: flex-end;
        overflow: hidden;
    }

    .qay-brain-metric {
        padding: 0.26rem 0.4rem;
        font-size: 0.63rem;
    }

    .qay-brain-icon {
        width: 26px;
        height: 26px;
    }

    .qay-messages {
        padding: 0.9rem 0.75rem 0.65rem;
        gap: 1rem;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
        scroll-padding-bottom: 0.75rem;
    }

    .qay-bubble-text {
        max-width: calc(100% - 40px);
        font-size: 0.88rem;
        line-height: 1.62;
    }

    .qay-msg {
        gap: 0.58rem;
    }

    .qay-msg-avatar {
        width: 28px;
        height: 28px;
        border-radius: 8px;
    }

    .qay-msg.user .qay-bubble-text {
        max-width: 88%;
        padding: 0.62rem 0.82rem;
        border-radius: 13px 13px 4px 13px;
    }

    .qay-welcome {
        width: 100%;
        padding: 1.1rem 0.15rem;
    }

    .qay-welcome h3 {
        font-size: 1.12rem;
    }

    .qay-welcome p {
        max-width: 310px;
        margin-top: 0.45rem;
        font-size: 0.78rem;
        line-height: 1.5;
    }

    .qay-welcome-icon {
        width: 42px;
        height: 42px;
        margin-bottom: 0.85rem;
        border-radius: 12px;
    }

    .qay-suggestions {
        width: min(100%, 420px);
        margin: 1rem auto 0;
        grid-template-columns: 1fr;
        gap: 0.42rem;
    }

    .qay-suggestion-chip {
        min-height: 40px;
        padding: 0.58rem 0.7rem;
        font-size: 0.75rem;
        border-radius: 9px;
    }

    .qay-input-area {
        width: 100%;
        padding: 0.55rem 0.75rem calc(max(0.75rem, env(safe-area-inset-bottom)) + 0.5rem);
        background: #f7f8fa;
        border-top: 1px solid #e6e8eb;
    }

    .qay-input-row {
        min-height: 50px;
        padding: 0.34rem 0.38rem 0.34rem 0.85rem;
        border-radius: 13px;
        box-shadow: 2px 2px 0 rgba(34, 38, 43, 0.18);
    }

    .qay-input {
        max-height: 96px;
        font-size: 16px;
        line-height: 1.45;
    }

    .qay-send-btn {
        width: 40px;
        height: 40px;
        border-radius: 11px;
    }

    .qay-input-footer {
        display: none;
    }

    .qay-library-item {
        align-items: flex-start;
        flex-direction: column;
        padding: 0.68rem 0.7rem;
    }

    .qay-library-actions {
        width: 100%;
    }

    .qay-library-actions a {
        min-height: 34px;
        justify-content: center;
        flex: 1;
    }

    .qay-library-list {
        max-height: 300px;
    }

    .qay-source-label {
        display: -webkit-box;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: normal;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
    }
}

@media (max-width: 420px) {
    .qay-brain-metric:nth-child(2) {
        display: none;
    }

    .qay-messages {
        padding-inline: 0.6rem;
    }

    .qay-input-area {
        padding-inline: 0.6rem;
    }
}

@media (max-width: 768px) and (max-height: 650px) {
    .qay-welcome-icon,
    .qay-welcome p {
        display: none;
    }

    .qay-welcome {
        padding-block: 0.75rem;
    }

    .qay-suggestions {
        margin-top: 0.75rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .qay-msg,
    .qay-typing span,
    .qay-brain-metric.is-indexing svg {
        animation: none;
    }

    .qay-messages {
        scroll-behavior: auto;
    }
}
