*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --white: #ffffff;
    --ink: #111010;
    --ink-faint: #c0bbb0;
    --ink-mid: #7a756a;
    --dot-off: #e8e4dc;
    --dot-on: #8a7f6f;
    --bar-height: 44px;
}

html,
body {
    height: 100%;
}

body {
    min-height: 100%;
    display: flex;
    flex-direction: column;
    background-color: var(--white);
    color: var(--ink);
    font-family: "EB Garamond", Georgia, serif;
    -webkit-font-smoothing: antialiased;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 180px 180px;
    pointer-events: none;
    z-index: 0;
    opacity: 0.5;
}

.nav-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: env(safe-area-inset-top, 0px) 2rem 0;
    height: calc(var(--bar-height) + env(safe-area-inset-top, 0px));
    background-color: var(--white);
}

.nav-back {
    justify-self: start;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: "DM Mono", monospace;
    font-size: 0.6rem;
    font-weight: 300;
    letter-spacing: 0.2em;
    color: var(--ink-mid);
    text-decoration: none;
    transition: color 0.2s ease;
}
.nav-back:hover {
    color: var(--ink);
}

.nav-title-row {
    justify-self: center;
    display: flex;
    align-items: center;
    gap: 0.7rem;
}
.nav-title-row[hidden] {
    display: none;
}
.nav-title-line {
    width: 26px;
    height: 1px;
    background: var(--dot-off);
}
.nav-title-text {
    font-family: "EB Garamond", Georgia, serif;
    font-style: italic;
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--ink);
    white-space: nowrap;
}

.nav-history-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    background: none;
    border: none;
    color: var(--ink-mid);
    font-size: 0.85rem;
    cursor: pointer;
}
.nav-history-btn:hover {
    color: var(--ink);
}
.nav-history-btn[hidden] {
    display: none;
}

.stage {
    position: relative;
    z-index: 1;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem 1.5rem;
    min-height: 0;
}

.signin-gate {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.4rem;
    text-align: center;
    opacity: 0;
    transform: translateY(12px);
    animation: fadeUp 1s cubic-bezier(0.22, 1, 0.36, 1) 0.15s forwards;
}
.signin-gate[hidden] {
    display: none;
}
@keyframes fadeUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.gate-title {
    font-family: "EB Garamond", Georgia, serif;
    font-weight: 500;
    font-style: italic;
    font-size: clamp(1.4rem, 4vw, 2rem);
    color: var(--ink);
}

.quote-rule {
    width: 32px;
    height: 1px;
    background: var(--ink-faint);
    margin: 0 auto;
}

.identity-signin {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: none;
    border: 1px solid var(--dot-off);
    border-radius: 999px;
    padding: 0.6rem 1.2rem;
    font-family: "DM Mono", monospace;
    font-size: 0.6rem;
    letter-spacing: 0.06em;
    color: var(--ink-mid);
    cursor: pointer;
    transition:
        border-color 0.2s ease,
        color 0.2s ease;
}
.identity-signin:hover {
    border-color: var(--ink-mid);
    color: var(--ink);
}

.chat-wrap {
    width: 100%;
    height: 100%;
    display: flex;
    gap: 1.2rem;
}
.chat-wrap[hidden] {
    display: none;
}

.chat-history {
    width: 230px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    border-right: 1px solid var(--dot-off);
    padding-right: 1.2rem;
    min-height: 0;
}

.chat-tools-panel {
    width: 210px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    border-left: 1px solid var(--dot-off);
    padding-left: 1.2rem;
    overflow-y: auto;
}

.chat-tools-title {
    font-family: "DM Mono", monospace;
    font-size: 0.55rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-faint);
    margin-top: 0.6rem;
}
.chat-tools-title:first-child {
    margin-top: 0;
}

.chat-tools-empty {
    font-family: "EB Garamond", Georgia, serif;
    font-style: italic;
    font-size: 0.78rem;
    color: var(--ink-faint);
}

.nav-right-group {
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.nav-tools-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    background: none;
    border: none;
    color: var(--ink-mid);
    font-size: 0.85rem;
    cursor: pointer;
}
.nav-tools-btn:hover {
    color: var(--ink);
}
.nav-tools-btn[hidden] {
    display: none;
}

.chat-new-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: none;
    border: 1px solid var(--dot-off);
    border-radius: 999px;
    padding: 0.5rem 0.8rem;
    font-family: "DM Mono", monospace;
    font-size: 0.58rem;
    letter-spacing: 0.05em;
    color: var(--ink-mid);
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease;
}
.chat-new-btn:hover {
    border-color: var(--ink-mid);
    color: var(--ink);
}

.chat-history-list {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    overflow-y: auto;
}

.chat-tools {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.chat-divider {
    height: 1px;
    background: var(--dot-off);
    margin: 0.2rem 0;
}

.chat-search-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.chat-search-input {
    flex: 1;
    min-width: 0;
    background: var(--dot-off);
    border: none;
    border-radius: 999px;
    padding: 0.4rem 0.8rem;
    font-family: "EB Garamond", Georgia, serif;
    font-size: 0.8rem;
    color: var(--ink);
}
#kbSearchInput {
    padding: 0.32rem 0.65rem;
    font-size: 0.72rem;
}
.chat-search-input:focus {
    outline: 2px solid var(--ink-mid);
    outline-offset: 1px;
}

.chat-history-scroll {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.chat-section[hidden] {
    display: none;
}

.chat-section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-family: "DM Mono", monospace;
    font-size: 0.55rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-faint);
    margin-bottom: 0.4rem;
}

.chat-section-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: none;
    border: none;
    font-family: "DM Mono", monospace;
    font-size: 0.55rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-faint);
    cursor: pointer;
    margin-bottom: 0.4rem;
}
.chat-section-toggle i {
    transition: transform 0.15s ease;
}
.chat-section-toggle.is-open i {
    transform: rotate(180deg);
}

.chat-folder-add {
    background: none;
    border: none;
    color: var(--ink-faint);
    font-size: 0.6rem;
    cursor: pointer;
}
.chat-folder-add:hover {
    color: var(--ink);
}

.chat-folder-group {
    margin-bottom: 0.6rem;
}
.chat-folder-group .chat-history-list {
    max-height: 220px;
    overflow-y: auto;
}
.chat-folder-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.chat-folder-name {
    font-family: "DM Mono", monospace;
    font-size: 0.62rem;
    color: var(--ink-mid);
    padding: 0.2rem 0.4rem;
}
.chat-folder-rename {
    background: none;
    border: none;
    color: var(--ink-faint);
    font-size: 0.58rem;
    cursor: pointer;
    padding: 0.2rem 0.4rem;
}
.chat-folder-rename:hover {
    color: var(--ink);
}

.chat-history-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    border-radius: 8px;
    transition: background 0.15s ease;
}
.chat-history-item:hover,
.chat-history-item.is-active {
    background: var(--dot-off);
}

.chat-item-title {
    flex: 1;
    min-width: 0;
    text-align: left;
    background: none;
    border: none;
    padding: 0.5rem 0.4rem;
    font-family: "EB Garamond", Georgia, serif;
    font-size: 0.8rem;
    color: var(--ink-mid);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-history-item.is-active .chat-item-title {
    color: var(--ink);
    font-weight: 500;
}

.chat-item-actions {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    opacity: 0;
    transition: opacity 0.15s ease;
    padding-right: 0.3rem;
}
.chat-history-item:hover .chat-item-actions,
.chat-history-item.is-active .chat-item-actions {
    opacity: 1;
}

.chat-item-icon-btn {
    background: none;
    border: none;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    color: var(--ink-faint);
    font-size: 0.62rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-item-icon-btn:hover {
    color: var(--ink);
    background: var(--white);
}
.chat-item-icon-btn.is-on {
    color: var(--ink);
}

.chat-item-folder-wrap {
    position: relative;
}

.folder-menu {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    min-width: 220px;
    max-height: 320px;
    overflow-y: auto;
    background: var(--white);
    border: 1px solid var(--dot-off);
    border-radius: 12px;
    box-shadow: 0 6px 20px rgba(17, 16, 16, 0.16);
    padding: 0.4rem;
    gap: 0.15rem;
}
.folder-menu[hidden] {
    display: none;
}

.folder-menu-item {
    text-align: left;
    background: none;
    border: none;
    border-radius: 6px;
    padding: 0.55rem 0.65rem;
    font-family: "EB Garamond", Georgia, serif;
    font-size: 0.85rem;
    color: var(--ink-mid);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.folder-menu-item:hover {
    background: var(--dot-off);
    color: var(--ink);
}
.folder-menu-item.is-current {
    color: var(--ink);
    font-weight: 500;
}
.folder-menu-item.folder-menu-new {
    border-top: 1px solid var(--dot-off);
    margin-top: 0.15rem;
    padding-top: 0.5rem;
    color: var(--ink-faint);
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    gap: 0.8rem;
}

.chat-web-toggle {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: 100%;
    padding: 0.6rem 0.9rem;
    border-radius: 999px;
    background: var(--dot-off);
    border: 1px solid var(--dot-off);
    color: var(--ink-mid);
    font-family: "DM Mono", monospace;
    font-size: 0.6rem;
    letter-spacing: 0.03em;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.chat-web-toggle:hover {
    border-color: var(--ink-mid);
    color: var(--ink);
}
.chat-web-toggle[aria-pressed="true"] {
    background: var(--ink);
    color: var(--white);
}

.chat-model-select {
    width: 100%;
    appearance: none;
    -webkit-appearance: none;
    background-color: var(--dot-off);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%237a756a' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='5 8 10 13 15 8'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.7rem center;
    background-size: 12px;
    border: 1px solid var(--dot-off);
    border-radius: 999px;
    padding: 0.55rem 1.8rem 0.55rem 0.9rem;
    font-family: "DM Mono", monospace;
    font-size: 0.6rem;
    letter-spacing: 0.04em;
    color: var(--ink);
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}
.chat-model-select:hover {
    border-color: var(--ink-mid);
    background-color: var(--white);
}
.chat-model-select:focus {
    outline: none;
    border-color: var(--ink-mid);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    padding-right: 0.3rem;
}

.chat-empty {
    margin: auto;
    text-align: center;
    color: var(--ink-mid);
}
.chat-empty i {
    font-size: 1.6rem;
    color: var(--ink-faint);
}
.chat-empty .quote-rule {
    margin: 1.1rem auto;
}
.chat-empty p {
    font-family: "EB Garamond", Georgia, serif;
    font-style: italic;
    font-size: 0.95rem;
}
.chat-empty[hidden] {
    display: none;
}

.chat-message-row {
    display: flex;
    align-items: flex-end;
    gap: 0.55rem;
    max-width: 100%;
}
.chat-message-row.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.chat-message-row.assistant {
    align-self: flex-start;
}

.chat-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}
.chat-avatar-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--dot-off);
    color: var(--ink-mid);
    font-size: 0.7rem;
}

.chat-bubble {
    max-width: 78%;
    padding: 0.65rem 0.95rem;
    border-radius: 14px;
    font-family: "EB Garamond", Georgia, serif;
    font-size: 0.95rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}
.chat-bubble.user {
    background: var(--ink);
    color: var(--white);
    border-bottom-right-radius: 4px;
}
.chat-bubble.assistant {
    background: var(--dot-off);
    color: var(--ink);
    border-bottom-left-radius: 4px;
}
.chat-bubble.pending {
    color: var(--ink-mid);
    font-style: italic;
}
.chat-bubble.error {
    background: none;
    border: 1px solid #e05555;
    color: #b03a3a;
    font-family: "DM Mono", monospace;
    font-size: 0.65rem;
}

.chat-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.chat-attachments:empty {
    display: none;
}

.chat-attachment-chip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--dot-off);
    border-radius: 999px;
    padding: 0.4rem 0.5rem 0.4rem 0.8rem;
    font-family: "DM Mono", monospace;
    font-size: 0.62rem;
    color: var(--ink-mid);
    max-width: 260px;
}
.chat-attachment-chip i.fa-file-lines,
.chat-attachment-chip i.fa-file-word,
.chat-attachment-chip i.fa-file-excel,
.chat-attachment-chip i.fa-file-powerpoint,
.chat-attachment-chip i.fa-file-pdf,
.chat-attachment-chip i.fa-google-drive {
    flex-shrink: 0;
    color: var(--ink);
}
.chat-attachment-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-attachment-remove {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: none;
    border: none;
    color: var(--ink-faint);
    font-size: 0.6rem;
    cursor: pointer;
}
.chat-attachment-remove:hover {
    color: var(--ink);
    background: var(--white);
}

.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 0.6rem;
}
.chat-input {
    flex: 1;
    resize: none;
    max-height: 120px;
    background: var(--dot-off);
    border: none;
    border-radius: 14px;
    padding: 0.65rem 0.9rem;
    font-family: "EB Garamond", Georgia, serif;
    font-size: 0.95rem;
    color: var(--ink);
    line-height: 1.4;
}
.chat-input:focus {
    outline: 2px solid var(--ink-mid);
    outline-offset: 1px;
}
.chat-stop {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #b03a3a;
    color: var(--white);
    border: none;
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s ease;
}
.chat-stop:hover {
    opacity: 0.85;
}
.chat-stop[hidden] {
    display: none;
}

.chat-send {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--ink);
    color: var(--white);
    border: none;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s ease;
}
.chat-send:hover {
    opacity: 0.85;
}
.chat-send:disabled {
    opacity: 0.4;
    cursor: default;
}

.footer {
    position: sticky;
    bottom: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 2rem calc(0.6rem + env(safe-area-inset-bottom, 0px));
    background-color: var(--white);
}

.footer-rule {
    width: 32px;
    height: 1px;
    background: var(--dot-off);
}

.footer-center {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    white-space: nowrap;
}

.footer-copy {
    font-family: "DM Mono", monospace;
    font-size: 0.55rem;
    font-weight: 300;
    letter-spacing: 0.15em;
    color: var(--ink-mid);
}

.footer-legal-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ink-mid);
    font-size: 0.7rem;
    text-decoration: none;
    opacity: 0.5;
    transition: opacity 0.2s ease;
}
.footer-legal-icon:hover {
    opacity: 1;
}
@media (hover: none) and (pointer: coarse) {
    .chat-item-actions {
        opacity: 1;
    }
    .chat-item-icon-btn {
        width: 30px;
        height: 30px;
        font-size: 0.7rem;
    }
    .folder-menu-item {
        padding: 0.55rem 0.6rem;
        font-size: 0.85rem;
    }
}

.chat-kb-add {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    background: var(--white);
    border: 1px solid var(--dot-off);
    border-radius: 999px;
    padding: 0.55rem 0.9rem;
    font-family: "DM Mono", monospace;
    font-size: 0.6rem;
    letter-spacing: 0.03em;
    color: var(--ink-mid);
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.chat-kb-add:hover {
    border-color: var(--ink-mid);
    background: var(--dot-off);
    color: var(--ink);
}

.chat-kb-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.kb-sections {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.kb-modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(17, 16, 16, 0.55);
    padding: 1.5rem;
}
.kb-modal[hidden] {
    display: none;
}

.kb-modal-box {
    width: 100%;
    max-width: 420px;
    background: var(--white);
    border-radius: 16px;
    padding: 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
}

.kb-modal-textarea {
    min-height: 160px;
    resize: vertical;
    background: var(--dot-off);
    border: none;
    border-radius: 12px;
    padding: 0.7rem 0.9rem;
    font-family: "EB Garamond", Georgia, serif;
    font-size: 0.9rem;
    color: var(--ink);
    line-height: 1.4;
}
.kb-modal-textarea:focus {
    outline: 2px solid var(--ink-mid);
    outline-offset: 1px;
}

.kb-modal-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.8rem;
}

.kb-cancel-btn {
    background: none;
    border: none;
    font-family: "DM Mono", monospace;
    font-size: 0.6rem;
    letter-spacing: 0.05em;
    color: var(--ink-faint);
    cursor: pointer;
}
.kb-cancel-btn:hover {
    color: var(--ink);
}

.code-panel-overlay {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(17, 16, 16, 0.55);
    padding: 2rem;
}
.code-panel-overlay[hidden] {
    display: none;
}

.code-panel {
    width: fit-content;
    min-width: 420px;
    max-width: min(860px, 92vw);
    max-height: 82vh;
    display: flex;
    flex-direction: column;
    background: var(--white);
    border: 1px solid var(--dot-off);
    border-radius: 14px;
    overflow: hidden;
    transition: max-width 0.2s ease, max-height 0.2s ease;
}
.code-panel.is-expanded {
    max-width: 100%;
    max-height: 100%;
    width: 100%;
    height: 100%;
    border-radius: 0;
}

.code-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.7rem 1rem;
    background: var(--dot-off);
    flex-shrink: 0;
}

.code-panel-header-left {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    color: var(--ink-mid);
    font-size: 0.75rem;
    min-width: 0;
}

.code-panel-view-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: none;
    border: none;
    border-radius: 6px;
    color: var(--ink-faint);
    cursor: pointer;
    font-size: 0.72rem;
}
.code-panel-view-btn:hover {
    color: var(--ink-mid);
}
.code-panel-view-btn.is-active {
    background: var(--white);
    color: var(--ink);
}
.code-panel-view-btn[hidden] {
    display: none;
}

.code-panel-title {
    font-family: "DM Mono", monospace;
    font-size: 0.65rem;
    letter-spacing: 0.03em;
    color: var(--ink-mid);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.code-panel-actions {
    display: flex;
    align-items: center;
    gap: 0.2rem;
    flex-shrink: 0;
}

.code-panel-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: none;
    border: none;
    font-family: "DM Mono", monospace;
    font-size: 0.6rem;
    color: var(--ink-mid);
    cursor: pointer;
    padding: 0.35rem 0.55rem;
    border-radius: 6px;
}
.code-panel-btn:hover {
    background: var(--white);
    color: var(--ink);
}

.code-panel-body {
    flex: 1;
    display: flex;
    overflow: auto;
    background: var(--white);
    font-family: "DM Mono", monospace;
    font-size: 0.8rem;
    line-height: 1.65;
}
.code-panel-body[hidden] {
    display: none;
}

.code-panel-gutter {
    flex-shrink: 0;
    padding: 1rem 0.7rem;
    text-align: right;
    color: var(--ink-faint);
    background: var(--dot-off);
    white-space: pre;
    user-select: none;
    border-right: 1px solid var(--dot-off);
}

.code-panel-pre {
    margin: 0;
    padding: 1rem 1.2rem;
    color: var(--ink);
    white-space: pre;
    flex: 1;
}

.code-panel-pre .token.comment,
.code-panel-pre .token.prolog,
.code-panel-pre .token.doctype {
    color: var(--ink-faint);
    font-style: italic;
}
.code-panel-pre .token.string,
.code-panel-pre .token.attr-value {
    color: #6b7d4f;
}
.code-panel-pre .token.keyword,
.code-panel-pre .token.selector,
.code-panel-pre .token.tag {
    color: #7a5a8a;
}
.code-panel-pre .token.function,
.code-panel-pre .token.class-name {
    color: #b0633a;
}
.code-panel-pre .token.attr-name,
.code-panel-pre .token.property {
    color: #4a7a8c;
}
.code-panel-pre .token.punctuation {
    color: var(--ink-mid);
}
.code-panel-pre .token.number,
.code-panel-pre .token.boolean {
    color: #b0633a;
}

.file-cards {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-top: 0.6rem;
}

.file-card {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    border: 1px solid var(--dot-off);
    border-radius: 10px;
    padding: 0.55rem 0.7rem;
    background: var(--white);
    cursor: pointer;
    line-height: 1.3;
}
.chat-bubble.user .file-card {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
}

.file-card-icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--dot-off);
    color: var(--ink-mid);
    font-size: 0.85rem;
}

.file-card-info {
    flex: 1;
    min-width: 0;
}
.file-card-name {
    margin: 0;
    font-family: "EB Garamond", Georgia, serif;
    font-size: 0.85rem;
    line-height: 1.3;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.file-card-meta {
    margin: 0;
    font-family: "DM Mono", monospace;
    font-size: 0.58rem;
    line-height: 1.4;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

.file-card-download {
    flex-shrink: 0;
    background: none;
    border: 1px solid var(--dot-off);
    border-radius: 999px;
    padding: 0.4rem 0.8rem;
    font-family: "DM Mono", monospace;
    font-size: 0.6rem;
    line-height: 1;
    color: var(--ink-mid);
    cursor: pointer;
}
.file-card-download:hover {
    border-color: var(--ink-mid);
    color: var(--ink);
}

.file-cards-download-all {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    align-self: flex-start;
    margin-top: 0.5rem;
    background: none;
    border: none;
    font-family: "DM Mono", monospace;
    font-size: 0.62rem;
    color: var(--ink-mid);
    cursor: pointer;
    text-decoration: underline;
    padding: 0.2rem 0;
}
.file-cards-download-all:hover {
    color: var(--ink);
}

.reasoning-box {
    margin-bottom: 0.6rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px dashed var(--dot-off);
}
.chat-bubble.user .reasoning-box {
    border-bottom-color: rgba(255, 255, 255, 0.2);
}

.reasoning-box summary {
    cursor: pointer;
    font-family: "DM Mono", monospace;
    font-size: 0.6rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ink-faint);
    user-select: none;
}
.chat-bubble.user .reasoning-box summary {
    color: rgba(255, 255, 255, 0.55);
}

.reasoning-text {
    margin-top: 0.5rem;
    font-family: "EB Garamond", Georgia, serif;
    font-style: italic;
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--ink-mid);
    white-space: pre-wrap;
}
.chat-bubble.user .reasoning-text {
    color: rgba(255, 255, 255, 0.75);
}

.msg-heading {
    margin: 0.6rem 0 0.3rem;
    font-family: "EB Garamond", Georgia, serif;
    font-weight: 600;
    line-height: 1.3;
}
h3.msg-heading {
    font-size: 1.08rem;
}
h4.msg-heading {
    font-size: 1rem;
}
h5.msg-heading,
h6.msg-heading {
    font-size: 0.92rem;
}
.chat-bubble > .msg-heading:first-child {
    margin-top: 0;
}

.msg-list {
    margin: 0.3rem 0 0.5rem;
    padding-left: 1.3rem;
}
.msg-list li {
    margin-bottom: 0.2rem;
}
.msg-list .msg-list {
    margin: 0.2rem 0;
}

.msg-task-list {
    list-style: none;
    padding-left: 0.3rem;
}
.msg-task {
    display: flex;
    align-items: flex-start;
    gap: 0.4rem;
}
.msg-task input[type="checkbox"] {
    margin-top: 0.3rem;
    accent-color: var(--ink-mid);
}

.msg-quote {
    margin: 0.5rem 0;
    padding: 0.4rem 0.9rem;
    border-left: 3px solid var(--dot-off);
    color: var(--ink-mid);
    font-style: italic;
}
.chat-bubble.user .msg-quote {
    border-left-color: rgba(255, 255, 255, 0.3);
}

.msg-table {
    width: 100%;
    margin: 0.6rem 0;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.msg-table th,
.msg-table td {
    border: 1px solid var(--dot-off);
    padding: 0.4rem 0.65rem;
    text-align: left;
}
.chat-bubble.user .msg-table th,
.chat-bubble.user .msg-table td {
    border-color: rgba(255, 255, 255, 0.2);
}
.msg-table th {
    background: var(--dot-off);
    font-family: "DM Mono", monospace;
    font-size: 0.6rem;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--ink-mid);
}
.chat-bubble.user .msg-table th {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.8);
}

.chat-bubble del {
    opacity: 0.6;
}

.msg-hr {
    border: none;
    border-top: 1px solid var(--dot-off);
    margin: 0.6rem 0;
}
.chat-bubble.user .msg-hr {
    border-top-color: rgba(255, 255, 255, 0.25);
}

.chat-bubble code {
    background: var(--dot-off);
    border: 1px solid rgba(17, 16, 16, 0.06);
    border-radius: 999px;
    padding: 0.15rem 0.55rem;
    font-family: "DM Mono", monospace;
    font-size: 0.78em;
    white-space: nowrap;
}
.chat-bubble.user code {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.2);
}

.chat-bubble a {
    color: inherit;
    text-decoration: underline;
}

@media (max-width: 720px) {
    .chat-wrap {
        max-height: none;
        height: 100%;
    }
    .chat-history {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 90;
        width: 240px;
        background: var(--white);
        padding: calc(var(--bar-height) + 1rem) 1rem 1rem;
        border-right: 1px solid var(--dot-off);
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }
    .chat-history.is-open {
        transform: translateX(0);
    }
    .chat-tools-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        z-index: 90;
        width: 240px;
        background: var(--white);
        padding: calc(var(--bar-height) + 1rem) 1rem 1rem;
        border-left: 1px solid var(--dot-off);
        transform: translateX(100%);
        transition: transform 0.25s ease;
    }
    .chat-tools-panel.is-open {
        transform: translateX(0);
    }
    .nav-history-btn {
        display: flex;
    }
    .nav-tools-btn {
        display: flex;
    }
    .nav-title-line {
        width: 14px;
    }
    .nav-title-text {
        font-size: 0.7rem;
    }
    .nav-back span {
        display: none;
    }
    .chat-input,
    .chat-search-input {
        font-size: 16px;
    }
    .chat-bubble {
        max-width: 90%;
        font-size: 0.9rem;
    }
    .chat-divider {
        margin: 0.4rem 0;
    }
    .stage {
        padding: 0.75rem 1rem;
    }
    .footer {
        padding: 0.5rem 1rem calc(0.5rem + env(safe-area-inset-bottom, 0px));
    }
    .footer-center {
        font-size: 0.48rem;
        white-space: normal;
        text-align: center;
    }
}

@media (prefers-reduced-motion: reduce) {
    .signin-gate {
        animation: none;
        opacity: 1;
        transform: none;
    }
    .chat-history {
        transition: none;
    }
    .chat-tools-panel {
        transition: none;
    }
}
