:root {
    color-scheme: dark;
    --bg: #0f1115;
    --panel: #161a22;
    --panel-alt: #1c2129;
    --border: #262c38;
    --text: #e6e9ef;
    --text-dim: #8b93a5;
    --accent: #5b8cff;
    --accent-dim: #2c3c66;
    --error: #ff6b6b;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    cursor: pointer;
    font-family: inherit;
}

/* Login */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    height: 100dvh;
    padding: 16px;
}

.login-card {
    width: min(320px, 100%);
    padding: 32px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    text-align: center;
}

.login-card h1 {
    margin: 0 0 4px;
    font-size: 1.4rem;
}

.login-card .subtitle {
    margin: 0 0 20px;
    color: var(--text-dim);
    font-size: 0.9rem;
}

.login-card form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.login-card input {
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--panel-alt);
    color: var(--text);
    font-size: 16px; /* 16px+ stops iOS Safari auto-zooming the page on focus */
}

.login-card button {
    padding: 10px 12px;
    border-radius: 8px;
    border: none;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}

.error {
    color: var(--error);
    font-size: 0.85rem;
    margin: 0 0 14px;
}

.success {
    color: #4cd38a;
    font-size: 0.85rem;
    margin: 0 0 14px;
}

/* Account */

.account-body {
    min-height: 100vh;
    min-height: 100dvh;
    padding: 24px 16px 48px;
}

.account-page {
    width: min(640px, 100%);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.account-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.back-link {
    color: var(--text-dim);
    font-size: 0.85rem;
}

.back-link:hover {
    color: var(--text);
}

.account-header {
    padding: 4px 0 8px;
}

.account-header h1 {
    margin: 0 0 4px;
    font-size: 1.5rem;
    font-weight: 700;
}

.account-header .subtitle {
    margin: 0;
    color: var(--text-dim);
    font-size: 0.9rem;
}

.account-section {
    padding: 20px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.account-section h2 {
    margin: 0 0 16px;
    font-size: 1rem;
    font-weight: 600;
}

.account-subheading {
    margin: 24px 0 8px;
    color: var(--text-dim);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.usage-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.usage-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 16px;
    background: var(--panel-alt);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.usage-card-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
}

.usage-label {
    font-size: 0.8rem;
    font-weight: 600;
}

.usage-images {
    color: var(--text-dim);
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
}

.usage-total {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.usage-total small {
    font-size: 0.8rem;
    font-weight: 400;
    color: var(--text-dim);
}

.usage-split {
    color: var(--text-dim);
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
}

.usage-table-wrap {
    overflow-x: auto;
}

.usage-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
}

.usage-table th,
.usage-table td {
    padding: 9px 8px;
    text-align: right;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
}

.usage-table th:first-child,
.usage-table td:first-child {
    padding-left: 0;
    text-align: left;
}

.usage-table th:last-child,
.usage-table td:last-child {
    padding-right: 0;
    font-weight: 600;
}

.usage-table th {
    color: var(--text-dim);
    font-size: 0.75rem;
    font-weight: 500;
}

.usage-table td {
    color: var(--text-dim);
}

.usage-table td:first-child,
.usage-table td:last-child,
.usage-table tr.current td {
    color: var(--text);
}

.usage-table tbody tr:last-child td {
    border-bottom: none;
}

.usage-note {
    margin: 16px 0 0;
    color: var(--text-dim);
    font-size: 0.8rem;
}

.account-option summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    cursor: pointer;
    list-style: none;
}

.account-option summary::-webkit-details-marker {
    display: none;
}

.option-title {
    display: block;
    font-size: 1rem;
    font-weight: 600;
}

.option-hint {
    display: block;
    margin-top: 2px;
    color: var(--text-dim);
    font-size: 0.85rem;
}

.option-chevron {
    color: var(--text-dim);
    font-size: 1.4rem;
    line-height: 1;
    transition: transform 0.15s ease;
}

.account-option[open] .option-chevron {
    transform: rotate(90deg);
}

.account-option summary:hover .option-chevron {
    color: var(--text);
}

.account-option-body {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.account-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 360px;
}

.account-form input {
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--panel-alt);
    color: var(--text);
    font-size: 16px; /* 16px+ stops iOS Safari auto-zooming the page on focus */
}

.account-form input:focus {
    outline: none;
    border-color: var(--accent);
}

.account-form button {
    margin-top: 4px;
    padding: 10px 12px;
    border-radius: 8px;
    border: none;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}

/* Account: itemised requests */

.usage-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px 16px;
    margin-top: 16px;
}

.usage-footer .usage-note {
    margin: 0;
}

.usage-link {
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 600;
}

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

.request-section {
    padding: 4px 20px;
}

.request-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.request-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}

.request-row:last-child {
    border-bottom: none;
}

.request-thumb {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--panel-alt);
    border: 1px solid var(--border);
}

.request-thumb.icon {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
}

.request-thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.request-main {
    flex: 1;
    min-width: 0;
}

.request-prompt {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    overflow-wrap: anywhere;
}

.request-meta {
    margin: 4px 0 0;
    color: var(--text-dim);
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.request-meta a:hover {
    color: var(--text);
    text-decoration: underline;
}

.muted {
    color: var(--text-dim);
}

.request-tokens {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    font-variant-numeric: tabular-nums;
}

.request-total {
    font-weight: 600;
    font-size: 0.95rem;
}

.request-split {
    color: var(--text-dim);
    font-size: 0.75rem;
    white-space: nowrap;
}

.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.85rem;
}

.pager a {
    color: var(--accent);
    font-weight: 600;
}

.pager-info {
    color: var(--text-dim);
}

@media (max-width: 480px) {
    .request-row {
        flex-wrap: wrap;
        row-gap: 6px;
    }

    .request-main {
        flex-basis: calc(100% - 62px);
    }

    /* Tokens drop onto their own line under the prompt, lined up with its text. */
    .request-tokens {
        flex-basis: 100%;
        flex-direction: row;
        align-items: baseline;
        gap: 8px;
        padding-left: 62px;
    }

    .request-total::after {
        content: " tokens";
        color: var(--text-dim);
        font-size: 0.75rem;
        font-weight: 400;
    }
}

/* Roles, costs and admin */

.role-badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 0.7rem;
    font-weight: 600;
    vertical-align: 1px;
}

.role-badge.admin {
    border-color: var(--accent-dim);
    background: var(--accent-dim);
    color: var(--accent);
}

.account-header .role-badge {
    margin-left: 6px;
}

.account-header .badge-row .role-badge {
    margin: 0 6px 0 0;
}

.account-link-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.account-link-row:hover .option-chevron {
    color: var(--text);
}

.usage-cost {
    margin-top: 4px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.request-cost {
    color: var(--text-dim);
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
}

.price-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
}

.price-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1 1 160px;
    color: var(--text-dim);
    font-size: 0.8rem;
}

.price-input {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--panel-alt);
    color: var(--text-dim);
}

.price-input:focus-within {
    border-color: var(--accent);
}

.price-input input {
    flex: 1;
    min-width: 0;
    padding: 10px 0;
    border: none;
    background: none;
    color: var(--text);
    font-size: 16px; /* 16px+ stops iOS Safari auto-zooming the page on focus */
    font-variant-numeric: tabular-nums;
    outline: none;
}

.price-form button {
    flex: 0 0 auto;
    padding: 11px 16px;
    border-radius: 8px;
    border: none;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}

@media (max-width: 480px) {
    .price-form button {
        flex-basis: 100%;
    }
}

.usage-note code {
    font-size: 0.75rem;
    color: var(--text);
}

.price-groups {
    flex-direction: column;
    align-items: stretch;
    gap: 18px;
}

.price-group {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin: 0;
    padding: 0;
    border: none;
    min-width: 0;
}

.price-group legend {
    width: 100%;
    margin-bottom: 8px;
    padding: 0;
    font-size: 0.85rem;
    font-weight: 600;
}

.price-groups button {
    align-self: flex-start;
}

/* Admin: users, credit and suspension */

.section-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.section-heading h2 {
    margin: 0;
}

.table-link:hover {
    color: var(--accent);
    text-decoration: underline;
}

.negative {
    color: var(--error) !important;
}

.positive {
    color: #4cd38a !important;
}

.role-badge.danger {
    border-color: rgba(255, 107, 107, 0.4);
    background: rgba(255, 107, 107, 0.12);
    color: var(--error);
}

.break-anywhere {
    overflow-wrap: anywhere;
}

.flash {
    margin: 0;
    padding: 12px 16px;
    border-radius: 10px;
    background: var(--panel);
    border: 1px solid var(--border);
}

.user-row {
    flex-wrap: nowrap !important;
}

.user-row .request-prompt .role-badge {
    margin-left: 4px;
}

.user-row .request-tokens {
    flex-basis: auto !important;
    flex-direction: column !important;
    align-items: flex-end !important;
    padding-left: 0 !important;
}

.user-row .request-total::after {
    content: none !important;
}

.user-row .request-split {
    display: inline !important;
}

.user-row:hover .option-chevron {
    color: var(--text);
}

.user-row .request-meta {
    white-space: normal;
}

.price-form .note-field {
    flex: 2 1 220px;
}

.price-form .note-field .price-input {
    padding-left: 12px;
}

.note-cell {
    white-space: normal !important;
    min-width: 140px;
}

.toggle-form {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.toggle {
    flex-shrink: 0;
    position: relative;
    width: 46px;
    height: 26px;
    padding: 0;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--panel-alt);
    transition: background 0.15s ease;
}

.toggle-knob {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--text-dim);
    transition: transform 0.15s ease, background 0.15s ease;
}

.toggle.on {
    background: var(--accent);
    border-color: var(--accent);
}

.toggle.on .toggle-knob {
    transform: translateX(20px);
    background: #fff;
}

.balance-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.balance-amount {
    flex-shrink: 0;
    white-space: nowrap;
    font-size: 1.4rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.suspended-banner {
    margin: 0 24px 12px;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid rgba(255, 107, 107, 0.4);
    background: rgba(255, 107, 107, 0.12);
    color: var(--error);
    font-size: 0.85rem;
}

.prompt-form button[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

.add-user-form .checkbox-field {
    flex: 1 1 100%;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
}

.add-user-form .checkbox-field input {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

.select-input select {
    flex: 1;
    padding: 10px 0;
    border: none;
    background: none;
    color: var(--text);
    font-size: 16px;
    outline: none;
}

.select-input select option {
    background: var(--panel-alt);
}

.created-user {
    border-color: rgba(76, 211, 138, 0.4);
}

.created-user h2 {
    color: #4cd38a;
}

.credentials {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 16px;
    margin: 16px 0;
    padding: 14px 16px;
    border-radius: 10px;
    background: var(--panel-alt);
    border: 1px solid var(--border);
    font-size: 0.9rem;
}

.credentials dt {
    color: var(--text-dim);
}

.credentials dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.credentials .password {
    font-size: 1rem;
    letter-spacing: 0.04em;
    user-select: all;
}

.link-button.copy-button {
    margin-left: 10px;
    color: var(--accent);
}

.edit-row td {
    padding: 12px 0 16px !important;
    white-space: normal !important;
    text-align: left !important;
    background: var(--panel);
}

.edit-credit-form {
    align-items: flex-end;
}

.edit-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.edit-actions button {
    padding: 11px 16px;
    border-radius: 8px;
    font-weight: 600;
}

.price-form .secondary-button {
    border: 1px solid var(--border);
    background: var(--panel-alt);
    color: var(--text);
}

.price-form .danger-button {
    border: 1px solid rgba(255, 107, 107, 0.4);
    background: rgba(255, 107, 107, 0.12);
    color: var(--error);
}

.edited-note {
    display: block;
    margin-top: 2px;
    color: var(--text-dim);
    font-size: 0.75rem;
    font-style: italic;
}

.link-button.edit-credit {
    color: var(--accent);
}

.edit-heading {
    margin: 0 0 10px;
    color: var(--text-dim);
    font-size: 0.8rem;
}

@media (max-width: 480px) {
    /* Stack the credit history so rows (and their edit forms) fit the screen. */
    .credit-table thead {
        display: none;
    }

    .credit-table,
    .credit-table tbody {
        display: block;
    }

    .credit-table tr {
        display: grid;
        grid-template-columns: 1fr auto;
        gap: 4px 12px;
        padding: 12px 0;
        border-bottom: 1px solid var(--border);
    }

    .credit-table tr[hidden] {
        display: none;
    }

    .credit-table td {
        padding: 0 !important;
        border: none !important;
        text-align: left !important;
        white-space: normal !important;
        min-width: 0 !important;
    }

    .credit-table td:nth-child(2),
    .credit-table td:nth-child(5) {
        text-align: right !important;
    }

    .credit-table td:nth-child(3) {
        grid-column: 1 / -1;
    }

    .credit-table td:nth-child(4) {
        color: var(--text-dim) !important;
        font-weight: 400 !important;
        font-size: 0.8rem;
    }

    .credit-table tr.edit-row {
        display: block;
    }

    .credit-table tr.edit-row[hidden] {
        display: none;
    }

    .credit-table tr.edit-row td {
        display: block;
    }

    .edit-actions {
        flex-basis: 100%;
    }

    .price-form .edit-actions button {
        flex: 1 1 0;
    }
}

/* Portal layout */

.layout {
    display: flex;
    height: 100vh;
    height: 100dvh;
}

.sidebar {
    width: 260px;
    flex-shrink: 0;
    background: var(--panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-backdrop {
    display: none;
}

.mobile-topbar {
    display: none;
}

.icon-button {
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.2rem;
    line-height: 1;
    padding: 8px 10px;
    border-radius: 8px;
}

.icon-button:hover {
    background: var(--panel-alt);
}

body.no-scroll {
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.brand {
    font-weight: 700;
}

.link-button {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 0.8rem;
}

.link-button:hover {
    color: var(--text);
}

.sidebar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.new-chat-row {
    display: flex;
    gap: 8px;
    margin: 12px;
}

.new-chat {
    flex: 1;
    padding: 10px 8px;
    border-radius: 8px;
    background: var(--accent-dim);
    color: var(--accent);
    text-align: center;
    font-weight: 600;
    font-size: 0.9rem;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-balance {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
}

.sidebar-balance:hover {
    background: var(--panel-alt);
}

.sidebar-balance-label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-dim);
    font-size: 0.85rem;
}

.sidebar-balance-amount {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.chat-item-row {
    display: flex;
    align-items: center;
    border-radius: 8px;
}

.chat-item-row:hover {
    background: var(--panel-alt);
}

.chat-item-row.active {
    background: var(--accent-dim);
}

.chat-item {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding: 10px 12px;
    gap: 2px;
}

.chat-delete {
    flex-shrink: 0;
    margin-right: 6px;
    padding: 6px 8px;
    border-radius: 6px;
    border: none;
    background: none;
    color: var(--text-dim);
    font-size: 0.85rem;
}

.chat-delete:hover {
    color: var(--error);
    background: var(--border);
}

.chat-title {
    font-size: 0.88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-type {
    font-size: 0.8rem;
}

.chat-date {
    font-size: 0.72rem;
    color: var(--text-dim);
}

.empty {
    color: var(--text-dim);
    font-size: 0.85rem;
    padding: 12px;
}

/* Chat panel */

.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

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

.placeholder {
    margin: auto;
    text-align: center;
    color: var(--text-dim);
    max-width: 360px;
}

.placeholder h2 {
    color: var(--text);
    margin-bottom: 8px;
}

.message {
    display: flex;
}

.message.user {
    justify-content: flex-end;
}

.message.assistant {
    justify-content: flex-start;
}

.message .bubble {
    max-width: 65%;
    padding: 10px 14px;
    border-radius: 12px;
    background: var(--panel-alt);
    line-height: 1.4;
    font-size: 0.92rem;
}

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

.message.error .bubble {
    background: rgba(255, 107, 107, 0.12);
    color: var(--error);
}

.user-content {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    max-width: 65%;
}

.user-content .bubble {
    max-width: 100%;
}

.user-media {
    max-width: 220px;
    width: 100%;
}

.user-media a {
    display: block;
}

.user-media img {
    width: 100%;
    border-radius: 12px;
    border: 1px solid var(--border);
    display: block;
}

.user-media.multi {
    max-width: 260px;
}

.media-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

.media-grid a {
    display: block;
}

.media-grid img {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid var(--border);
    display: block;
}

.assistant-media {
    max-width: 420px;
    width: 100%;
}

.assistant-media a {
    display: block;
}

.assistant-media img {
    width: 100%;
    border-radius: 12px;
    border: 1px solid var(--border);
    display: block;
}

.token-usage {
    display: block;
    margin-top: 4px;
    font-size: 0.72rem;
    color: var(--text-dim);
}

.fork-button {
    display: inline-block;
    margin-top: 6px;
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--panel-alt);
    color: var(--text-dim);
    font-size: 0.72rem;
}

.fork-button:hover {
    color: var(--text);
    border-color: var(--accent);
}

.pending-placeholder {
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--panel-alt);
    color: var(--text-dim);
    font-size: 0.88rem;
    animation: pending-pulse 1.6s ease-in-out infinite;
}

@keyframes pending-pulse {
    0%, 100% {
        opacity: 0.6;
    }
    50% {
        opacity: 1;
    }
}

.prompt-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px 24px calc(16px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    background: var(--panel);
}

.prompt-row {
    display: flex;
    gap: 10px;
}

.attach-button {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel-alt);
    font-size: 1.1rem;
}

.attach-button.has-file {
    border-color: var(--accent);
    color: var(--accent);
}

.attachment-preview {
    padding: 8px;
    background: var(--panel-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.attachment-thumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.attachment-thumb-item {
    position: relative;
    width: 56px;
    height: 56px;
    flex-shrink: 0;
}

.attachment-thumb-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 6px;
    display: block;
}

.attachment-thumb-item button {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: var(--error);
    color: #fff;
    font-size: 0.65rem;
    line-height: 1;
    padding: 0;
}

.attachment-thumb-item button:hover {
    opacity: 0.85;
}

.prompt-form textarea {
    flex: 1;
    resize: none;
    height: 48px;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--panel-alt);
    color: var(--text);
    font-family: inherit;
    font-size: 16px; /* 16px+ stops iOS Safari auto-zooming the page on focus */
}

.prompt-form button {
    padding: 0 20px;
    border-radius: 10px;
    border: none;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    min-height: 44px;
}

.prompt-form button:disabled {
    opacity: 0.6;
    cursor: default;
}

.status {
    margin: 0 24px 12px;
    color: var(--error);
    font-size: 0.85rem;
}

@media (max-width: 760px) {
    .mobile-topbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        padding: 10px 8px;
        border-bottom: 1px solid var(--border);
        background: var(--panel);
        position: sticky;
        top: 0;
        z-index: 10;
    }

    .mobile-title {
        flex: 1;
        min-width: 0;
        text-align: center;
        font-weight: 600;
        font-size: 0.92rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: min(280px, 85vw);
        height: 100vh;
        height: 100dvh;
        z-index: 30;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }

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

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.65);
        z-index: 20;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
    }

    .sidebar-backdrop.open {
        opacity: 1;
        pointer-events: auto;
    }

    .messages {
        padding: 16px;
    }

    .prompt-form {
        padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    }

    .prompt-form textarea {
        height: 60px;
    }

    .message .bubble,
    .assistant-media,
    .user-content {
        max-width: 100%;
    }
}

/* Audio chats */

.type-tabs {
    display: inline-flex;
    gap: 4px;
    margin-bottom: 8px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel);
}

.type-tabs a {
    padding: 8px 14px;
    border-radius: 7px;
    color: var(--text-dim);
    font-size: 0.88rem;
    font-weight: 600;
}

.type-tabs a:hover {
    color: var(--text);
}

.type-tabs a.active {
    background: var(--accent-dim);
    color: var(--accent);
}

.audio-card {
    width: min(340px, 100%);
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--panel-alt);
}

.audio-card-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
    font-size: 0.85rem;
}

.audio-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.audio-card audio {
    display: block;
    width: 100%;
    height: 36px;
}

.text-card {
    width: min(720px, 100%);
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--panel-alt);
}

.text-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}

.text-card-title {
    font-size: 0.85rem;
    font-weight: 600;
}

.text-actions {
    display: flex;
    gap: 14px;
}

.text-card-body {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.5;
    font-size: 0.92rem;
}

.text-card .text-card-body {
    padding: 12px 14px;
}

.text-card-body.collapsed {
    max-height: 320px;
    overflow: hidden;
    -webkit-mask-image: linear-gradient(to bottom, #000 75%, transparent);
    mask-image: linear-gradient(to bottom, #000 75%, transparent);
}

.expand-button {
    display: block;
    width: 100%;
    padding: 10px;
    border: none;
    border-top: 1px solid var(--border);
    border-radius: 0 0 12px 12px;
    background: none;
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 600;
}

.expand-button:hover {
    background: var(--panel);
}

.answer {
    max-width: min(720px, 80%);
}

.message .answer .bubble {
    max-width: 100%;
}

.answer .token-usage .link-button {
    padding: 0;
    font-size: inherit;
}

.text-card.pending {
    border: none;
    background: none;
}

.pending-placeholder.text {
    aspect-ratio: auto;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 14px 16px;
}

.pending-placeholder.text small {
    font-size: 0.78rem;
}

.audio-preview {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-size: 0.85rem;
}

.audio-preview-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.audio-preview .audio-preview-remove {
    flex-shrink: 0;
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--error);
    color: #fff;
    font-size: 0.7rem;
    line-height: 1;
}

@media (max-width: 760px) {
    .answer {
        max-width: 100%;
    }
}
