/* Pengyplexity styles — Bootstrap-flavored, dependency-free.
   Served locally so tests run offline (no CDN). Colors are CSS custom
   properties defined in theme.css (loaded first) — see that file for the
   full light/dark/accent token set ported from Pengy's Qt theme. */

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

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

.display-6 { font-size: 2rem; font-weight: 700; }
.lead { font-size: 1.25rem; font-weight: 300; }
.py-5 { padding-top: 4rem; padding-bottom: 4rem; }
.text-muted { color: var(--muted); }

/* --- Login --- */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
}
.login-card {
    background: var(--input-bg);
    color: var(--fg);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,.15);
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
}
.login-title { font-size: 1.75rem; margin: 0 0 .25rem; }
.login-subtitle { color: var(--muted); margin: 0 0 1.5rem; }
.account-stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    width: 100%;
    max-width: 400px;
}
.account-stack .login-card { width: 100%; max-width: none; }
.account-topnav-back {
    position: fixed;
    top: 1.25rem;
    left: 1.25rem;
    display: inline-flex;
    align-items: center;
    padding: .5rem 1rem;
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--fg);
    text-decoration: none;
    font-size: .9rem;
    font-weight: 500;
    box-shadow: 0 2px 10px rgba(0,0,0,.15);
}
.account-topnav-back:hover { background: var(--hover); }

/* --- Forms --- */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 600; margin-bottom: .25rem; }
.form-control {
    width: 100%;
    padding: .5rem .75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
    box-sizing: border-box;
    background: var(--input-bg);
    color: var(--input-fg);
}
.form-control:focus { outline: 2px solid var(--focus); border-color: var(--focus); }

/* --- Buttons --- */
.btn {
    display: inline-block;
    padding: .5rem 1rem;
    border: none;
    border-radius: 6px;
    /* Variants set their own fill; without this a bare modifier (e.g. a lone
       .btn-danger) falls back to the browser's light-grey button face,
       which glares in dark mode. */
    background: transparent;
    color: var(--fg);
    /* Browsers don't inherit fonts into <button>; without these a button and
       an <a class="btn"> side by side differ in typeface and height. */
    font-family: inherit;
    line-height: 1.25;
    font-size: .95rem;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}
.btn-primary { background: var(--primary); color: var(--primary-fg); }
.btn-primary:hover { background: var(--primary-hover); }
/* The Ask button while a turn is running. Filled like .btn-primary (it is
   still the main action) rather than reusing .btn-danger, which is an
   outline-style modifier used by the delete buttons. */
.btn-stop { background: var(--danger); color: var(--primary-fg); }
.btn-stop:hover { background: var(--danger-hover); }
.btn-stop:disabled { opacity: .6; cursor: default; }
.btn-block { width: 100%; display: block; }
.btn-sm { padding: .3rem .6rem; font-size: .85rem; }
.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--fg);
}
.btn-outline:hover { background: var(--hover); }

/* --- Alerts --- */
.alert { padding: .75rem 1rem; border-radius: 6px; margin-bottom: 1rem; }
.alert-danger { background: color-mix(in srgb, var(--danger) 15%, var(--bg)); color: var(--danger); }
.alert-success { background: color-mix(in srgb, var(--success) 18%, var(--bg)); color: var(--success); }

/* The account page stacks two cards, taller than a laptop screen: pad so the
   top card clears the fixed back button instead of sitting flush at y=0. */
.account-wrapper { padding: 4.5rem 1rem 2rem; box-sizing: border-box; }

/* --- Chat layout --- */
/* dvh = the *visible* viewport. Plain 100vh on mobile includes the area
   behind the browser's address bar, which pushed the input off-screen and
   left a blank strip at the bottom when zooming. 100vh stays as a fallback. */
.chat-layout {
    display: flex;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* Sidebar */
.chat-sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--panel);
    border-right: 1px solid var(--border-soft);
    display: flex;
    flex-direction: column;
}
.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .25rem;
}
.sidebar-title { font-size: 1.1rem; margin: 0; white-space: nowrap; }
/* Title and "+ New" only just share the 260px sidebar; trim the button. */
.sidebar-header .btn { padding-inline: .5rem; }
/* One shared height so the sidebar and chat header dividers line up whether
   or not either one holds a button (e.g. a brand-new thread). */
.sidebar-header, .chat-header { box-sizing: border-box; min-height: 3.75rem; }
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: .5rem;
    border-bottom: 1px solid var(--border-soft);
}
.sidebar-nav-link {
    display: block;
    padding: .5rem .75rem;
    border-radius: 6px;
    text-decoration: none;
    color: var(--fg);
    font-size: .9rem;
    font-weight: 500;
}
.sidebar-nav-link:hover { background: var(--hover); }
.sidebar-nav-link.active { background: var(--primary); color: var(--primary-fg); }
.thread-list { flex: 1; overflow-y: auto; padding: .5rem; }
.thread-item {
    display: block;
    padding: .6rem .75rem;
    border-radius: 6px;
    text-decoration: none;
    color: var(--fg);
    margin-bottom: 2px;
}
.thread-item:hover { background: var(--hover); }
.thread-item.active { background: var(--primary); color: var(--primary-fg); }
.thread-title { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-date { display: block; font-size: .75rem; color: var(--muted); }
/* Derived from --primary-fg, not white: some accents (pink) use dark text. */
.thread-item.active .thread-date { color: color-mix(in srgb, var(--primary-fg) 70%, transparent); }
/* Sidebar thread row + delete control */
.thread-item-row {
    display: flex;
    align-items: center;
    border-radius: 6px;
    margin-bottom: 2px;
}
.thread-item-row.active { background: var(--primary); }
.thread-item-row .thread-item { flex: 1; min-width: 0; margin-bottom: 0; }
.thread-item-row.active .thread-item { color: var(--primary-fg); }
.thread-item-row.active .thread-date { color: color-mix(in srgb, var(--primary-fg) 70%, transparent); }
.thread-item-row:not(.active):hover { background: var(--hover); }
.thread-delete-form { display: flex; align-items: center; flex-shrink: 0; padding-right: .25rem; }
.thread-delete-btn {
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 1.15rem;
    line-height: 1;
    cursor: pointer;
    padding: .2rem .4rem;
    border-radius: 4px;
}
.thread-delete-btn:hover { color: var(--danger); background: var(--hover); }
.thread-item-row.active .thread-delete-btn { color: color-mix(in srgb, var(--primary-fg) 60%, transparent); }
.thread-item-row.active .thread-delete-btn:hover { color: var(--primary-fg); background: rgba(0,0,0,.15); }
.sidebar-footer {
    padding: .75rem 1rem;
    border-top: 1px solid var(--border-soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
}
.user-badge {
    font-weight: 600;
    font-size: .9rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-footer-actions { display: flex; gap: .4rem; flex-shrink: 0; }
.inline-form { display: inline-block; margin: 0; }

/* Chat main */
.chat-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg);
}
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .75rem 1.5rem;
    border-bottom: 1px solid var(--border-soft);
    background: var(--bg);
}
.chat-header-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.btn-danger { color: var(--danger); border: 1px solid var(--border); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 12%, var(--bg)); border-color: var(--danger); }
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 1.5rem;
}

/* Messages */
.message {
    display: flex;
    gap: .75rem;
    margin-bottom: 1.25rem;
}
.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: .85rem;
    flex-shrink: 0;
}
.message-user .message-avatar { background: var(--panel-3); color: var(--user-label); }
.message-assistant .message-avatar { background: var(--primary); color: var(--primary-fg); }
/* min-width: 0 lets wide content (code, tables) scroll inside the message
   instead of stretching the flex row past the screen edge. */
.message-body { flex: 1; min-width: 0; }
.message-content { white-space: pre-wrap; line-height: 1.5; overflow-wrap: anywhere; }
/* Rendered Markdown (assistant answers). Override white-space so headings/
   lists/paragraphs flow; pre-wrap still applies to pre/code blocks. */
.message-content.markdown-body { white-space: normal; }
.markdown-body { line-height: 1.6; }
.markdown-body p { margin: 0 0 .6rem; }
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
    margin: .9rem 0 .4rem;
    line-height: 1.25;
    font-weight: 700;
}
.markdown-body h1 { font-size: 1.35rem; }
.markdown-body h2 { font-size: 1.2rem; }
.markdown-body h3 { font-size: 1.1rem; }
.markdown-body h4, .markdown-body h5, .markdown-body h6 { font-size: 1rem; }
.markdown-body ul, .markdown-body ol { margin: 0 0 .6rem 1.25rem; padding: 0; }
.markdown-body li { margin-bottom: .15rem; }
.markdown-body code {
    background: var(--code-bg);
    color: var(--code-fg);
    border-radius: 4px;
    padding: .1em .35em;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .9em;
}
.markdown-body pre {
    background: var(--code-bg);
    color: var(--code-fg);
    border-radius: 8px;
    padding: .75rem 1rem;
    overflow-x: auto;
    overflow-wrap: normal;
    margin: 0 0 .6rem;
}
.table-scroll { overflow-x: auto; margin: 0 0 .6rem; }
.table-scroll > table { margin-bottom: 0; }
.markdown-body th, .markdown-body td { overflow-wrap: normal; }
.markdown-body pre code { background: transparent; color: inherit; padding: 0; }
.markdown-body blockquote {
    border-left: 3px solid var(--primary);
    margin: 0 0 .6rem;
    padding: .1rem 0 .1rem .75rem;
    color: var(--muted);
    background: var(--panel);
    border-radius: 0 6px 6px 0;
}
.markdown-body a { color: var(--link); text-decoration: none; }
.markdown-body a:hover { text-decoration: underline; }
.markdown-body table {
    border-collapse: collapse;
    margin: 0 0 .6rem;
    width: 100%;
    font-size: .9rem;
}
.markdown-body th, .markdown-body td {
    border: 1px solid var(--border-soft);
    padding: .4rem .6rem;
    text-align: left;
    vertical-align: top;
}
/* Headers stay on one line; a wide table scrolls in .table-scroll instead
   of squeezing columns until each header wraps word by word. */
.markdown-body th { background: var(--panel); font-weight: 600; white-space: nowrap; }
.markdown-body strong { font-weight: 700; }
.message-sources {
    margin-top: .5rem;
    font-size: .85rem;
    color: var(--muted);
    padding: .5rem .75rem;
    background: var(--panel);
    border-radius: 6px;
}
.message-sources ul { margin: .25rem 0 0 1rem; padding: 0; }
.message-sources a { color: var(--link); text-decoration: none; }

/* Input area */
.chat-input-area {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-soft);
    background: var(--bg);
}
.chat-input-form {
    display: flex;
    align-items: flex-end;
    gap: .75rem;
}
.chat-input {
    flex: 1;
    width: auto;
    resize: none;
    border-radius: 8px;
    max-height: 40vh;
    max-height: 40dvh;
}
.chat-input-form .btn {
    flex-shrink: 0;
}

/* Artifacts (charts / images / reports) */
.artifact {
    margin-top: .75rem;
    padding: .5rem .75rem;
    background: var(--panel);
    border: 1px solid var(--border-soft);
    border-radius: 8px;
}
.artifact-inline img,
.markdown-body img {
    max-width: 100%;
    max-height: 380px;
    display: block;
    border-radius: 6px;
}
.artifact-link,
.artifact-doc a {
    display: inline-block;
    margin-top: .5rem;
    font-size: .85rem;
    color: var(--link);
    text-decoration: none;
    word-break: break-all;
}
.artifact-label {
    display: inline-block;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--muted);
    margin-right: .35rem;
}

/* Streaming */
.hidden { display: none; }
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--primary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.activity-indicator { font-size: .85rem; color: var(--muted); margin-top: .25rem; }

/* --- Admin --- */
.admin-layout {
    display: flex;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}
.admin-sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--panel);
    border-right: 1px solid var(--border-soft);
    display: flex;
    flex-direction: column;
}
.admin-nav {
    flex: 1;
    padding: .5rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.admin-nav .thread-item.active { background: var(--primary); color: var(--primary-fg); }
.admin-main {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    padding: 2rem 2.5rem;
    background: var(--bg);
}
.admin-main h1 { font-size: 1.5rem; margin: 0 0 1.5rem; }
.admin-card {
    background: var(--input-bg);
    border: 1px solid var(--border-soft);
    border-radius: 10px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.admin-card h2 {
    font-size: 1.05rem;
    margin: 0 0 1rem;
    font-weight: 600;
}
.form-row {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
}
/* Rows zero their groups' margin to bottom-align the fields, so the row
   itself restores the gap before whatever follows it. */
.form-row:not(:last-child) { margin-bottom: 1rem; }
.form-row .form-group { margin-bottom: 0; flex: 1 1 180px; }
.form-group-check { flex: 0 0 auto; }
.form-group-check label {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-weight: 500;
    white-space: nowrap;
}
.input-sm { padding: .3rem .5rem; font-size: .85rem; width: auto; }
.field-hint { margin: .35rem 0 0; font-size: .8rem; color: var(--muted); }
.field-hint code {
    background: var(--code-bg);
    color: var(--code-fg);
    border-radius: 4px;
    padding: .05em .3em;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.field-toggle { margin-top: .4rem; }
/* The system prompt is Markdown-ish config text; keep it monospace now that
   .form-control inherits the UI font. */
#set-system-message { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9rem; }

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
}
.admin-table th, .admin-table td {
    text-align: left;
    padding: .65rem .75rem;
    border-bottom: 1px solid var(--border-soft);
    vertical-align: middle;
    /* Dates and headers stay on one line; tables sit in .table-scroll. */
    white-space: nowrap;
}
.admin-table th {
    font-weight: 600;
    color: var(--muted);
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.admin-table tbody tr:hover { background: var(--hover); }
/* One row; a narrow screen scrolls the table (.table-scroll) rather than
   stacking the buttons into a column that the scroller clips. */
.actions-cell { display: flex; align-items: center; gap: .5rem; }

.badge {
    display: inline-block;
    padding: .2rem .55rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
}
.badge-enabled { background: color-mix(in srgb, var(--success) 20%, var(--bg)); color: var(--success); }
.badge-disabled { background: var(--panel-3); color: var(--muted); }
/* How well a memory matched the search — a strong hit reads differently from
   a near miss, so a weak result is not mistaken for an answer. */
.badge-match { font-variant-numeric: tabular-nums; }
.badge-match-strong { background: color-mix(in srgb, var(--success) 20%, var(--bg)); color: var(--success); }
.badge-match-weak { background: color-mix(in srgb, var(--warning) 22%, var(--bg)); color: var(--warning); }
.badge-match-unscored { background: var(--panel-3); color: var(--muted); }
.memory-advisory, .memory-denominator { font-size: .85rem; margin: .25rem 0 .75rem; }

.btn-warning { background: color-mix(in srgb, var(--warning) 25%, var(--bg)); color: var(--warning); }
.btn-warning:hover { background: color-mix(in srgb, var(--warning) 40%, var(--bg)); }
.btn-success { background: color-mix(in srgb, var(--success) 20%, var(--bg)); color: var(--success); }
.btn-success:hover { background: color-mix(in srgb, var(--success) 35%, var(--bg)); }

/* --- Memories --- */
.memories-intro { margin-top: -.75rem; margin-bottom: 1.25rem; }
.memory-search-form { display: flex; gap: .5rem; }
.memory-search-form .form-control { flex: 1; }
.memory-item {
    padding: 1rem 0;
    border-bottom: 1px solid var(--border-soft);
}
.memory-item:last-child { border-bottom: none; }
.memory-item-header {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-bottom: .35rem;
}
.memory-item-title { font-weight: 600; }
.memory-item-summary { margin: 0 0 .5rem; color: var(--fg); }
.memory-item-tags { margin-bottom: .5rem; }
.memory-tag {
    display: inline-block;
    background: color-mix(in srgb, var(--primary) 14%, var(--bg));
    color: var(--primary);
    border-radius: 999px;
    padding: .1rem .6rem;
    font-size: .75rem;
    margin-right: .35rem;
}
.memory-item-actions { display: flex; gap: .5rem; }

/* --- Workspace --- */
.workspace-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}
.workspace-header h1 { margin: 0; }
.workspace-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    gap: 1rem;
}
.workspace-group-header h2 { font-size: 1.05rem; margin: 0; }
.workspace-group-header h2 a { color: inherit; text-decoration: none; }
.workspace-group-header h2 a:hover { text-decoration: underline; }
.workspace-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
}
.workspace-item { text-align: center; }
.workspace-thumb-link, .workspace-doc-link { display: block; }
.workspace-thumb {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border-soft);
    background: var(--panel);
}
.workspace-doc-link {
    width: 100%;
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 1px solid var(--border-soft);
    background: var(--panel);
    font-size: 2.5rem;
}
.workspace-item-meta {
    margin-top: .4rem;
    font-size: .75rem;
}
.workspace-item-name {
    display: block;
    color: var(--muted);
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.workspace-item-name:hover { text-decoration: underline; }

/* --- Appearance (theme picker, on the Account page) --- */
.theme-mode-options {
    display: flex;
    gap: 1.25rem;
    flex-wrap: wrap;
}
.theme-mode-options label {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-weight: 500;
    cursor: pointer;
}
.accent-swatches {
    display: flex;
    gap: .6rem;
    flex-wrap: wrap;
}
.accent-swatch {
    position: relative;
    display: block;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,.08);
}
.accent-swatch input {
    position: absolute;
    inset: 0;
    opacity: 0;
    margin: 0;
    cursor: pointer;
}
.accent-swatch:has(input:checked) {
    border-color: var(--fg);
}
.accent-swatch-default, .accent-swatch-blue { background: #1e66f5; }
.accent-swatch-teal { background: #179299; }
.accent-swatch-green { background: #40a02b; }
.accent-swatch-orange { background: #df8e1d; }
.accent-swatch-red { background: #d20f39; }
.accent-swatch-pink { background: #ea76cb; }
.accent-swatch-purple { background: #8839ef; }

/* --- Mobile --- */
/* Desktop defaults for the mobile-only chrome (drawer toggle, top bar). */
.mobile-only, .mobile-topbar, .drawer-toggle { display: none; }
.drawer-toggle {
    border: none;
    background: transparent;
    color: var(--fg);
    font-size: 1.35rem;
    line-height: 1;
    width: 2.5rem;
    height: 2.5rem;
    margin-left: -.5rem;
    border-radius: 6px;
    cursor: pointer;
    flex-shrink: 0;
}
.drawer-toggle:hover { background: var(--hover); }

@media (max-width: 768px) {
    .desktop-only { display: none; }
    .btn.mobile-only { display: inline-block; }
    .chat-header.mobile-only, .drawer-toggle { display: flex; align-items: center; justify-content: center; }
    .chat-header.mobile-only { justify-content: space-between; }

    /* Sidebar becomes an off-canvas drawer. */
    .chat-sidebar, .admin-sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        z-index: 50;
        width: min(85vw, 300px);
        min-width: 0;
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: 0 0 30px rgba(0,0,0,.25);
        visibility: hidden;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        box-sizing: border-box;
    }
    body.drawer-open .chat-sidebar,
    body.drawer-open .admin-sidebar {
        transform: none;
        visibility: visible;
    }
    /* Backdrop behind the open drawer; taps on it close the drawer (base.html). */
    .chat-layout::after, .admin-layout::after {
        content: "";
        position: fixed;
        inset: 0;
        z-index: 40;
        background: rgba(0,0,0,.4);
        opacity: 0;
        pointer-events: none;
        transition: opacity .2s ease;
    }
    body.drawer-open .chat-layout::after,
    body.drawer-open .admin-layout::after {
        opacity: 1;
        pointer-events: auto;
    }

    /* Bigger tap targets in the drawer. */
    .thread-item { padding: .75rem; }
    .thread-delete-btn { font-size: 1.4rem; padding: .5rem .7rem; }
    .sidebar-nav-link { padding: .7rem .75rem; }

    /* Chat pane */
    .chat-header {
        gap: .5rem;
        padding: .5rem .75rem;
        padding-top: calc(.5rem + env(safe-area-inset-top));
    }
    .chat-header-title { flex: 1; min-width: 0; font-size: 1rem; }
    .chat-messages { padding: 1rem .75rem; }
    .message { gap: .5rem; }
    .message-avatar { width: 26px; height: 26px; font-size: .75rem; }
    .markdown-body img, .artifact-inline img { max-height: 60vh; }
    .chat-input-area {
        padding: .5rem .75rem;
        padding-bottom: calc(.5rem + env(safe-area-inset-bottom));
    }
    .chat-input-form { gap: .5rem; }
    .chat-input-form .btn { padding: .6rem 1rem; }

    /* Admin-style pages (workspace, memories, admin) */
    .admin-layout { flex-direction: column; }
    .mobile-topbar {
        display: flex;
        align-items: center;
        gap: .5rem;
        padding: .5rem .75rem;
        padding-top: calc(.5rem + env(safe-area-inset-top));
        border-bottom: 1px solid var(--border-soft);
        background: var(--bg);
    }
    .mobile-topbar-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .admin-main {
        padding: 1rem .75rem;
        padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
    }
    .admin-main h1 { font-size: 1.3rem; margin-bottom: 1rem; }
    .admin-card { padding: 1rem; margin-bottom: 1rem; }
    .form-row .form-group { flex-basis: 100% !important; }
    .workspace-header, .workspace-group-header { flex-wrap: wrap; gap: .5rem; }
    .workspace-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .75rem; }
    .memory-search-form { flex-wrap: wrap; }
    .memory-search-form .form-control { flex-basis: 100%; }
    .admin-table { font-size: .85rem; }

    /* Login / account */
    .login-wrapper {
        flex-direction: column;
        justify-content: flex-start;
        padding: 1rem;
        padding-top: calc(1rem + env(safe-area-inset-top));
        box-sizing: border-box;
        min-height: 100dvh;
    }
    .login-wrapper > .login-card { margin: auto 0; }
    /* border-box: width:100% plus padding otherwise overflows the phone and
       the browser zooms the whole page out to fit it. */
    .login-card { padding: 1.5rem; box-sizing: border-box; }
    .account-topnav-back { position: static; align-self: flex-start; margin-bottom: 1rem; }

    /* iOS zooms into any focused field under 16px and never zooms back out. */
    .form-control, .input-sm { font-size: 16px; }
}
