:root {
    color-scheme: light;
    --bg: #edf2f8;
    --panel: #ffffff;
    --ink: #111b2d;
    --muted: #66758f;
    --line: #d3dceb;
    --soft: #f5f7fb;
    --accent: #0b2f6b;
    --accent-strong: #06214d;
    --accent-soft: #e4ebf7;
    --amber: #8a6515;
    --assistant: #f3f6fb;
    --user: #0b2f6b;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0c1322;
    --panel: #111b2d;
    --ink: #eff4fb;
    --muted: #a8b5cb;
    --line: #2a3954;
    --soft: #17243a;
    --accent: #8eb4f2;
    --accent-strong: #c0d6fb;
    --accent-soft: #1b3155;
    --amber: #f0c772;
    --assistant: #18243a;
    --user: #d9e7ff;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--bg);
}

.app-shell {
    min-height: 100vh;
    padding: 24px;
}

.workspace {
    width: min(1180px, 100%);
    min-height: calc(100vh - 48px);
    margin: 0 auto;
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    position: relative;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 18px 60px rgba(21, 32, 26, 0.12);
}

.sidebar-toggle,
.sidebar-backdrop {
    display: none;
}

.sidebar-toggle {
    position: fixed;
    z-index: 35;
    top: 14px;
    right: 14px;
    width: 42px;
    min-width: 42px;
    min-height: 42px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--ink);
    background: var(--panel);
    box-shadow: 0 10px 30px rgba(17, 27, 45, 0.14);
}

.sidebar-toggle span {
    display: block;
    width: 17px;
    height: 2px;
    margin: 3px auto;
    border-radius: 999px;
    background: currentColor;
}

.lock-panel {
    width: min(440px, 100%);
    margin: min(12vh, 96px) auto 0;
    padding: 28px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 18px 60px rgba(21, 32, 26, 0.12);
}

.lock-brand {
    margin-bottom: 24px;
}

.lock-form {
    display: grid;
    gap: 12px;
}

.lock-form label {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
}

.lock-form input {
    width: 100%;
    min-height: 48px;
    padding: 0 13px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font: inherit;
}

.lock-form input:focus {
    outline: 3px solid rgba(11, 47, 107, 0.18);
    border-color: var(--accent);
}

.form-error {
    margin: 0;
    color: #8a2421;
    font-size: 14px;
}

.source-panel {
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 22px;
    background: #f8fafd;
    border-right: 1px solid var(--line);
}

:root[data-theme="dark"] .source-panel {
    background: #0e1728;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--line);
}

.brand .theme-toggle {
    margin-left: auto;
}

.brand-logo {
    width: 42px;
    height: 50px;
    object-fit: contain;
    flex: 0 0 auto;
}

.kicker {
    margin: 0 0 5px;
    color: var(--accent);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

h1,
h2 {
    margin: 0;
    letter-spacing: 0;
}

h1 {
    font-size: 21px;
    line-height: 1.15;
}

.source-block,
.sidebar-empty {
    padding: 16px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.sidebar-empty {
    min-height: 120px;
    display: grid;
    place-items: center;
    color: var(--muted);
    text-align: center;
    line-height: 1.4;
}

.sidebar-empty p {
    margin: 0;
    max-width: 190px;
    font-size: 14px;
}

.sidebar-footer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 12px;
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid var(--line);
}

.sidebar-footer.cost-only {
    grid-template-columns: 1fr;
}

.session-cost {
    display: grid;
    gap: 3px;
    color: var(--muted);
    font-size: 12px;
}

.session-cost strong {
    color: var(--ink);
    font-size: 13px;
}

.donation-link {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 0 10px;
    border: 1px solid var(--accent);
    border-radius: 8px;
    color: #fff;
    background: var(--accent);
    font-size: 12px;
    font-weight: 800;
    text-decoration: none;
}

.donation-link:hover {
    background: var(--accent-strong);
}

.paypal-donation {
    margin-top: 0;
}

.paypal-donation form {
    display: inline-grid;
    width: 100%;
    justify-items: center;
    align-content: start;
    gap: 5px;
}

.paypal-button {
    width: auto;
    min-width: 126px;
    min-height: 32px;
    border: 0;
    border-radius: 6px;
    padding: 0 18px;
    color: #000;
    background: #ffd140;
    font-family: "Helvetica Neue", Arial, sans-serif;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
}

.paypal-button:hover {
    background: #ffc439;
}

.paypal-cards {
    max-width: 110px;
    height: auto;
}

.paypal-note {
    color: var(--muted);
    font-size: 9px;
}

.paypal-note img {
    height: 10px;
    vertical-align: middle;
}

.source-block h2 {
    margin-bottom: 12px;
    font-size: 15px;
}

.priority-list {
    display: grid;
    gap: 9px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.priority-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
    font-size: 14px;
}

.priority-list span {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border-radius: 999px;
    color: var(--accent-strong);
    background: var(--accent-soft);
    font-size: 12px;
    font-weight: 800;
}

.meta-list {
    display: grid;
    gap: 12px;
    margin: 0;
}

.meta-list div {
    display: grid;
    gap: 3px;
}

.meta-list dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.meta-list dd {
    margin: 0;
    font-size: 14px;
    line-height: 1.35;
}

.chat-panel {
    min-height: inherit;
    display: grid;
    grid-template-rows: 1fr auto;
    background: var(--panel);
}

.status-pill {
    flex: 0 0 auto;
    min-width: 90px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    background: var(--soft);
    font-size: 14px;
    text-align: center;
}

.status-pill.busy {
    color: var(--amber);
    border-color: #e3c98f;
    background: #fff7e5;
}

:root[data-theme="dark"] .status-pill.busy {
    background: #382f1d;
}

.theme-toggle {
    display: grid;
    place-items: center;
    min-width: 44px;
    width: 44px;
    min-height: 44px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--ink);
    background: var(--soft);
}

.theme-toggle:hover {
    color: var(--accent-strong);
    background: var(--accent-soft);
}

.theme-icon {
    font-size: 20px;
    line-height: 1;
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 24px;
    overflow-y: auto;
}

.message {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.message.user {
    align-items: flex-end;
}

.bubble {
    position: relative;
    max-width: min(740px, 88%);
    padding: 14px 16px;
    border-radius: 8px;
    line-height: 1.55;
    white-space: pre-wrap;
}

.assistant .bubble {
    padding-right: 48px;
    padding-bottom: 38px;
    white-space: normal;
}

.bubble p,
.bubble ol,
.bubble ul,
.table-scroll {
    margin: 0 0 12px;
}

.bubble p:last-child,
.bubble ol:last-child,
.bubble ul:last-child,
.table-scroll:last-child {
    margin-bottom: 0;
}

.bubble ol,
.bubble ul {
    padding-left: 24px;
}

.bubble li {
    margin: 0 0 7px;
}

.bubble li:last-child {
    margin-bottom: 0;
}

.bubble strong {
    font-weight: 800;
}

.bubble a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 3px;
    overflow-wrap: anywhere;
}

.bubble a:hover {
    color: var(--accent-strong);
}

.table-scroll {
    max-width: 100%;
    overflow-x: auto;
}

.bubble table {
    width: 100%;
    min-width: 560px;
    border-collapse: collapse;
    white-space: normal;
    font-size: 15px;
    line-height: 1.4;
}

.bubble th,
.bubble td {
    padding: 9px 10px;
    border: 1px solid #cbd9ef;
    text-align: left;
    vertical-align: top;
}

.bubble th {
    color: #10213d;
    background: #e7eef9;
    font-weight: 800;
}

:root[data-theme="dark"] .bubble th,
:root[data-theme="dark"] .bubble td {
    border-color: #36527c;
}

:root[data-theme="dark"] .bubble th {
    color: #eff4fb;
    background: #1b3155;
}

.assistant .bubble {
    background: var(--assistant);
    border: 1px solid #d7e1f0;
}

.user .bubble {
    color: #fff;
    background: var(--user);
}

:root[data-theme="dark"] .user .bubble {
    color: #10213d;
}

.message.error .bubble {
    color: #6f201f;
    background: #fff0ef;
    border: 1px solid #f0c7c3;
}

.message-meta {
    width: fit-content;
    margin: 7px 4px 0;
    padding: 4px 8px;
    color: #43546f;
    background: #eef3fb;
    border: 1px solid #d7e1f0;
    border-radius: 999px;
    font-size: 12px;
    line-height: 1.3;
}

.message-sources {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    max-width: min(740px, 88%);
    margin: 7px 4px 0;
}

.sources-label,
.source-badge,
.message-sources a {
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 12px;
    line-height: 1.3;
}

.sources-label {
    color: var(--muted);
    padding-left: 0;
}

.source-badge,
.message-sources a {
    color: #123569;
    background: #e7eef9;
    border: 1px solid #cbd9ef;
    text-decoration: none;
}

.message-sources a:hover {
    color: var(--accent-strong);
    border-color: var(--accent);
}

.message-actions {
    position: absolute;
    right: 9px;
    bottom: 8px;
    display: flex;
}

.secondary-action {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    min-width: 0;
    width: 30px;
    min-height: 30px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--ink);
    background: var(--soft);
}

.secondary-action:hover {
    color: var(--accent-strong);
    background: var(--accent-soft);
}

.secondary-action svg {
    width: 15px;
    height: 15px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

:root[data-theme="dark"] .message-meta {
    color: #c1cde0;
    background: #17243a;
    border-color: #2a3c5d;
}

:root[data-theme="dark"] .source-badge,
:root[data-theme="dark"] .message-sources a {
    color: #dbe8ff;
    background: #1b3155;
    border-color: #36527c;
}

.assistant .typing-bubble {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    width: fit-content;
    min-width: 0;
    min-height: 0;
    padding: 8px 12px;
}

.assistant .typing-bubble span {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--accent);
    opacity: 0.35;
    animation: typing-dot 1.15s infinite ease-in-out;
}

.typing-bubble span:nth-child(2) {
    animation-delay: 0.16s;
}

.typing-bubble span:nth-child(3) {
    animation-delay: 0.32s;
}

@keyframes typing-dot {
    0%,
    80%,
    100% {
        transform: translateY(0);
        opacity: 0.32;
    }

    40% {
        transform: translateY(-5px);
        opacity: 0.9;
    }
}

.composer {
    display: grid;
    gap: 10px;
    padding: 18px;
    border-top: 1px solid var(--line);
    background: #f8fafd;
}

:root[data-theme="dark"] .composer {
    background: #0e1728;
}

textarea {
    width: 100%;
    min-height: 82px;
    max-height: 190px;
    resize: vertical;
    padding: 13px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font: inherit;
    line-height: 1.45;
    background: #fff;
}

:root[data-theme="dark"] textarea,
:root[data-theme="dark"] .lock-form input {
    color: var(--ink);
    background: #0c1322;
}

textarea:focus {
    outline: 3px solid rgba(11, 47, 107, 0.18);
    border-color: var(--accent);
}

.composer-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.composer-actions p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

button {
    flex: 0 0 auto;
    min-width: 112px;
    min-height: 46px;
    padding: 0 20px;
    border: 0;
    border-radius: 8px;
    color: #fff;
    background: var(--accent);
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

button:hover {
    background: var(--accent-strong);
}

button:disabled {
    cursor: wait;
    opacity: 0.68;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 860px) {
    .app-shell {
        padding: 0;
    }

    .workspace {
        min-height: 100vh;
        grid-template-columns: 1fr;
        border: 0;
        border-radius: 0;
    }

    .sidebar-toggle {
        display: block;
    }

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 25;
        display: block;
        background: rgba(10, 18, 32, 0.36);
    }

    .sidebar-backdrop[hidden] {
        display: none;
    }

    .source-panel {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 30;
        width: min(320px, 86vw);
        transform: translateX(-100%);
        transition: transform 180ms ease;
        gap: 12px;
        padding: 16px;
        border-right: 0;
        border-bottom: 0;
        border-right: 1px solid var(--line);
        box-shadow: 18px 0 50px rgba(17, 27, 45, 0.18);
    }

    .sidebar-open .source-panel {
        transform: translateX(0);
    }

    .brand {
        padding-bottom: 0;
        border-bottom: 0;
    }

    .source-block {
        display: none;
    }

    .chat-panel {
        min-height: 100vh;
    }

    .messages {
        padding-top: 72px;
    }
}

@media (max-width: 560px) {
    .messages {
        padding: 18px;
    }

    .bubble {
        max-width: 94%;
    }

    .composer-actions {
        align-items: stretch;
        flex-direction: column;
    }

    button {
        width: 100%;
    }
}
