:root {
    color: #172033;
    background: #f4f6f9;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-synthesis: none;
}

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

body {
    min-height: 100vh;
    min-height: 100dvh;
    margin: 0;
}

button,
input,
textarea {
    font: inherit;
}

.app-shell {
    width: min(100% - 2rem, 52rem);
    margin-inline: auto;
    padding: 2rem 0 max(2rem, env(safe-area-inset-bottom));
}

.app-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.app-header h1 {
    margin: 0.4rem 0 0.25rem;
    font-size: clamp(1.75rem, 5vw, 2.35rem);
    letter-spacing: -0.03em;
}

.app-header p,
.token-panel p {
    margin: 0;
    color: #657087;
    line-height: 1.5;
}

.back-link {
    color: #4c5b75;
    font-size: 0.9rem;
    text-decoration: none;
}

.back-link:hover {
    text-decoration: underline;
}

.token-panel,
.chat-log,
.chat-form {
    border: 1px solid #dce1e9;
    border-radius: 0.85rem;
    background: #fff;
    box-shadow: 0 0.5rem 1.5rem rgb(28 39 60 / 5%);
}

.token-panel {
    display: grid;
    grid-template-columns: auto minmax(12rem, 1fr);
    align-items: center;
    gap: 0.55rem 0.85rem;
    padding: 1rem;
}

.token-panel label {
    font-weight: 650;
}

.token-panel input,
.chat-form textarea {
    width: 100%;
    border: 1px solid #c9d0dc;
    border-radius: 0.6rem;
    color: inherit;
    background: #fff;
    outline: none;
}

.token-panel input {
    padding: 0.65rem 0.75rem;
}

.token-panel p {
    grid-column: 2;
    font-size: 0.8rem;
}

.token-panel input:focus,
.chat-form textarea:focus {
    border-color: #526ee8;
    box-shadow: 0 0 0 3px rgb(82 110 232 / 14%);
}

.chat-log {
    min-height: 22rem;
    max-height: 58vh;
    margin-top: 1rem;
    padding: 1rem;
    overflow-y: auto;
}

.message {
    width: fit-content;
    max-width: min(92%, 42rem);
    margin-bottom: 0.9rem;
    padding: 0.75rem 0.9rem;
    border-radius: 0.75rem;
    line-height: 1.6;
    overflow-wrap: anywhere;
}

.message:last-child {
    margin-bottom: 0;
}

.message p {
    margin: 0;
    white-space: pre-wrap;
}

.message-user {
    margin-left: auto;
    color: #fff;
    background: #405bd8;
    border-bottom-right-radius: 0.2rem;
}

.message-assistant {
    background: #eef1f6;
    border-bottom-left-radius: 0.2rem;
}

.message-system {
    max-width: 100%;
    color: #566277;
    background: #f7f8fa;
}

.message-error {
    color: #8b2530;
    background: #fff0f1;
}

.tool-list {
    margin-top: 0.75rem;
}

.tool-record {
    border-top: 1px solid #d4dae4;
    padding-top: 0.55rem;
}

.tool-record + .tool-record {
    margin-top: 0.55rem;
}

.tool-record summary {
    cursor: pointer;
    color: #43506a;
    font-size: 0.85rem;
    font-weight: 650;
}

.tool-record pre {
    max-width: 100%;
    margin: 0.55rem 0 0;
    padding: 0.65rem;
    overflow-x: auto;
    border-radius: 0.45rem;
    color: #dce6f5;
    background: #182134;
    font: 0.78rem/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.session-status,
.progress {
    min-height: 1.35rem;
    margin: 0.75rem 0;
    color: #657087;
    font-size: 0.85rem;
}

.progress {
    color: #405bd8;
    font-weight: 650;
}

.chat-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 0.75rem;
    padding: 0.8rem;
}

.chat-form textarea {
    min-height: 5rem;
    padding: 0.75rem;
    resize: vertical;
    line-height: 1.5;
}

.button {
    min-height: 2.65rem;
    padding: 0.65rem 1rem;
    border: 1px solid transparent;
    border-radius: 0.6rem;
    cursor: pointer;
    font-weight: 650;
}

.button-primary {
    color: #fff;
    background: #405bd8;
}

.button-secondary {
    color: #344158;
    border-color: #cbd2dd;
    background: #fff;
}

.button:hover:not(:disabled) {
    filter: brightness(0.96);
}

.button:focus-visible,
.back-link:focus-visible {
    outline: 3px solid rgb(82 110 232 / 28%);
    outline-offset: 2px;
}

.button:disabled,
input:disabled,
textarea:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.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: 40rem) {
    .app-shell {
        width: min(100% - 1rem, 52rem);
        padding-top: 1rem;
    }

    .app-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .token-panel {
        grid-template-columns: 1fr;
    }

    .token-panel p {
        grid-column: 1;
    }

    .chat-log {
        min-height: 45vh;
        max-height: none;
    }

    .message {
        max-width: 96%;
    }

    .chat-form {
        grid-template-columns: 1fr;
    }

    .chat-form .button {
        width: 100%;
    }
}
