:root {
    color-scheme: light dark;
    --background: #fbfafc;
    --rail: #f2f0f6;
    --surface: #fff;
    --subtle: #f6f3fa;
    --fg: #211b2a;
    --muted: #655d70;
    --line: #e3ddeb;
    --accent: #5736aa;
    --accent-hover: #47288e;
    --accent-text: #fff;
    --accent-soft: #ece4fb;
    --code: #23202e;
    --code-text: #f2eafa;
    --danger: #a9214a;
    --shadow: 0 6px 28px rgba(42, 24, 66, .08);
    --rail-width: 236px;
    font: 15px/1.5 Inter, "Segoe UI", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
    :root {
        --background: #18151f;
        --rail: #211c2b;
        --surface: #262132;
        --subtle: #2d263a;
        --fg: #f1eaf8;
        --muted: #bcb0ca;
        --line: #3d354c;
        --accent: #c0a6ff;
        --accent-hover: #d0bbff;
        --accent-text: #221541;
        --accent-soft: #3b2c54;
        --code: #15121c;
        --code-text: #f2eafa;
        --danger: #ff9bb9;
        --shadow: 0 6px 28px rgba(0, 0, 0, .25);
    }
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; color: var(--fg); background: var(--background); }
a { color: var(--accent); text-underline-offset: .18em; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled, select:disabled { cursor: default; opacity: .55; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 3px;
}
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { overflow-wrap: anywhere; }
h1 { font-size: clamp(1.5rem, 2.4vw, 2.15rem); font-weight: 680; letter-spacing: -.035em; line-height: 1.12; }
h2 { font-size: 1.16rem; letter-spacing: -.02em; line-height: 1.3; }
hr { border: 0; border-top: 1px solid var(--line); margin: .7rem .55rem; }
input:not([type=checkbox]), select, textarea {
    width: 100%; color: var(--fg); background: var(--surface); border: 1px solid var(--line);
    border-radius: 9px; padding: .67rem .75rem; min-width: 0;
}
input[type=checkbox] { accent-color: var(--accent); }
textarea { resize: vertical; }
fieldset { min-width: 0; margin: 0; border: 1px solid var(--line); border-radius: 9px; }
legend { padding: 0 .35rem; }
small, .muted { color: var(--muted); }
.mono, code, pre, .device-code { font-family: "IBM Plex Mono", "Cascadia Code", Consolas, monospace; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; padding: .8rem; border-radius: 8px; margin: .25rem 0; background: var(--subtle); font-size: .85rem; }
summary { cursor: pointer; }
.primary, .button, .icon-button {
    color: var(--fg); background: var(--surface); border: 1px solid var(--line); border-radius: 9px;
    padding: .55rem .8rem; font-weight: 620; line-height: 1.35; text-decoration: none;
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem; white-space: nowrap;
}
.primary { color: var(--accent-text); background: var(--accent); border-color: var(--accent); }
.primary:hover:enabled, a.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.button:hover:enabled, a.button:hover, .icon-button:hover { background: var(--subtle); border-color: var(--accent); }
.icon-button { padding: .45rem .6rem; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.platform { display: grid; grid-template-columns: var(--rail-width) minmax(0, 1fr); min-height: 100dvh; }
.rail { background: var(--rail); border-right: 1px solid var(--line); padding: 1.35rem .85rem .9rem;
    position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 1.3rem; }
.brand { color: var(--fg); text-decoration: none; display: flex; align-items: center; gap: .7rem;
    font-size: 1.02rem; font-weight: 720; line-height: 1.2; letter-spacing: -.03em; }
.rail .brand { padding: 0 .5rem; }
.brand-mark, .empty-mark { display: grid; place-items: center; flex: none;
    width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: var(--accent-text); font-weight: 720; }
.rail nav { flex: 1; overflow: auto; }
.nav-item { display: flex; align-items: center; gap: .7rem; border-radius: 8px; margin: .13rem 0; padding: .5rem .62rem;
    color: var(--muted); text-decoration: none; font-size: .92rem; font-weight: 550; white-space: nowrap; }
.nav-item > span { color: var(--accent); width: 1.05rem; display: inline-grid; place-items: center; }
.nav-item:hover { background: var(--subtle); color: var(--fg); }
.nav-item.active { color: var(--accent); background: var(--accent-soft); font-weight: 650; }
.rail-footer { border-top: 1px solid var(--line); padding: .8rem .35rem 0; display: flex; align-items: center; gap: .5rem; }
.mobile-nav-toggle { display: none; }
.owner-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 610; font-size: .87rem; }
.main-pane { min-width: 0; }
.chat-shell { display: flex; flex-direction: column; height: 100dvh; }
.page-bar { display: flex; align-items: center; justify-content: space-between; gap: .75rem;
    padding: 1rem clamp(1rem, 3vw, 2rem); border-bottom: 1px solid var(--line); min-height: 65px; }
.page-bar h1 { font-size: 1.1rem; line-height: 1.35; overflow-wrap: anywhere; letter-spacing: -.01em; }
.chat-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.empty-chat { display: flex; flex-direction: column; justify-content: center; align-items: center;
    min-height: 100%; padding: 2rem 1rem; text-align: center; gap: 1rem; }
.empty-chat h2 { font-size: clamp(1.7rem, 4vw, 2.6rem); letter-spacing: -.06em; text-wrap: balance; }
.empty-chat p { color: var(--muted); text-wrap: balance; }
.empty-mark { width: 57px; height: 57px; border-radius: 17px; font-size: 1.7rem;
    background: var(--accent-soft); color: var(--accent); margin-bottom: .2rem; }
.prompt-row { display: flex; gap: .55rem; flex-wrap: wrap; justify-content: center; }
.prompt-row button { border: 1px solid var(--line); color: var(--fg); background: var(--surface);
    border-radius: 999px; padding: .42rem .8rem; font-size: .88rem; }
.prompt-row button:hover { border-color: var(--accent); }
.transcript, .composer-zone { width: min(860px, 100%); margin: 0 auto; padding: 1rem clamp(.75rem, 4vw, 1.7rem); }
.transcript { display: flex; flex-direction: column; gap: 1rem; padding-top: 1.5rem; }
.older { align-self: center; }
.message { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: .85rem; }
.avatar { color: var(--accent); background: var(--accent-soft); border-radius: 10px; font-weight: 700;
    width: 34px; height: 34px; flex: none; display: inline-grid; place-items: center; }
.avatar-small { width: 28px; height: 28px; }
.message.user .avatar { background: var(--subtle); color: var(--fg); border: 1px solid var(--line); }
.message-main { min-width: 0; }
.message-meta { display: flex; align-items: baseline; gap: .65rem; padding-top: .25rem; margin-bottom: .4rem; font-size: .88rem; }
.message-meta time { color: var(--muted); font-size: .78rem; }
.user-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.markdown { overflow-wrap: anywhere; }
.markdown > * + * { margin-top: .56rem; }
.markdown ul { margin-bottom: 0; padding-left: 1.35rem; }
.markdown pre { background: var(--code); color: var(--code-text); overflow-x: auto; white-space: pre; padding: .95rem; }
.markdown :not(pre) > code { background: var(--subtle); border-radius: 4px; padding: .05em .2em; }
.thinking { display: flex; align-items: center; gap: .45rem; color: var(--muted); }
.thinking > span { width: .5rem; height: .5rem; border-radius: 50%; background: var(--accent); animation: pulse 1.3s ease infinite; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .thinking > span { animation: none; } }
.composer-zone { padding-top: .65rem; padding-bottom: clamp(.6rem, 3vw, 1.6rem); }
.composer { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: .55rem; }
.composer:focus-within { border-color: var(--accent); }
.composer textarea { border: 0; background: transparent; resize: vertical; outline: none; min-height: 3.9rem; max-height: 35vh; }
.composer-bar { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: .45rem; }
.composer-selects { display: flex; align-items: center; flex-wrap: wrap; gap: .45rem; }
.composer-selects select { width: auto; max-width: 100%; font-size: .83rem; padding: .35rem .45rem;
    text-overflow: ellipsis; background: var(--subtle); }
.send { padding: .5rem .7rem; }
.event-panel { border: 1px solid var(--line); border-radius: 9px; padding: .65rem .8rem; }
.event-panel summary { font-weight: 600; }
.event-panel summary > span { color: var(--muted); margin-left: .3rem; font-weight: 400; }
.event-line { border-top: 1px solid var(--line); margin-top: .5rem; padding-top: .5rem; font-size: .85rem; }
.event-line > span { color: var(--muted); margin-right: .5rem; }
.admin-page { max-width: 1170px; margin: 0 auto; padding: clamp(1rem, 4vw, 3rem);
    display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.card, .list { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; min-width: 0; }
.card { padding: 1rem; }
.card > h2 { margin-bottom: .35rem; }
.stat-grid, .split-panel, .side-by-side { display: grid; gap: .85rem; align-items: start; }
.stat-grid { grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr)); }
.stat-grid .card { display: grid; gap: .25rem; }
.stat-grid .card span { color: var(--muted); font-size: .86rem; }
.split-panel { grid-template-columns: minmax(210px, 1fr) minmax(285px, 1.35fr); }
.side-by-side { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fields { display: grid; gap: .8rem; }
.fields label:not(.check) { display: grid; grid-template-columns: minmax(0, 1fr); gap: .3rem;
    font-weight: 560; font-size: .9rem; overflow-wrap: anywhere; }
.check { display: inline-flex; align-items: center; gap: .3rem; padding: .2rem .45rem;
    max-width: 100%; overflow-wrap: anywhere; font-size: .9rem; }
.check input { flex: none; }
.filter { display: flex; align-items: center; gap: .5rem; max-width: 660px; }
.filter input:not([type=checkbox]) { flex: 1; }
.list-row { display: flex; width: 100%; align-items: center; gap: .65rem; text-align: left;
    color: var(--fg); text-decoration: none; border: 0; background: transparent; padding: .65rem .85rem; }
.list-row + .list-row, .work-row + .work-row { border-top: 1px solid var(--line); }
button.list-row:hover, a.list-row:hover { background: var(--subtle); border-radius: inherit; }
.list-row > :not(.avatar) { min-width: 0; overflow-wrap: anywhere; }
.list-row small { display: block; }
.list-row > :last-child:not(:first-child):is(small, a) { margin-left: auto; }
.work-row > summary { padding: .75rem .85rem; overflow-wrap: anywhere; }
.work-row small { margin-left: .45rem; }
.details-body { padding: 0 .85rem .8rem; }
.details-body > * + * { margin-top: .5rem; }
.status { display: inline-flex; color: var(--accent); background: var(--accent-soft); border-radius: 999px;
    padding: .16rem .52rem; font-size: .8rem; font-weight: 640; }
.notice { padding: .65rem .8rem; background: var(--accent-soft); border-radius: 8px; overflow-wrap: anywhere; }
.notice > strong, .notice > a { display: block; }
.notice.error { color: var(--danger); border: 1px solid currentColor; background: var(--surface); }
.button.danger { color: var(--danger); border-color: currentColor; }
.scope { overflow-wrap: anywhere; }
.empty { color: var(--muted); padding: .9rem; }
.data-list { display: flex; gap: .6rem 1.4rem; flex-wrap: wrap; margin-top: .65rem; }
.data-list strong { display: block; }
.access-shell { display: grid; place-items: center; min-height: 100dvh; padding: 1rem; }
.access-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
    display: grid; gap: 1.15rem; width: min(100%, 440px); padding: clamp(1rem, 5vw, 2rem); }
.access-panel h1 { font-size: 1.8rem; }
#blazor-error-ui { display: none; position: fixed; bottom: .75rem; left: 1rem; right: 1rem; z-index: 10;
    padding: .8rem 1rem; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
#blazor-error-ui .dismiss { float: right; border: 0; background: transparent; color: var(--fg); }
@media (max-width: 900px) {
    :root { --rail-width: 192px; }
    .split-panel { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px), (pointer: coarse) {
    .primary, .button, .icon-button, .nav-item, .prompt-row button, .composer-selects select,
    input:not([type=checkbox]), .fields select, .check { min-height: 44px; }
    .icon-button { min-width: 44px; }
}
@media (max-width: 640px) {
    .platform { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
    .platform:has(.chat-shell) { height: 100dvh; grid-template-rows: auto minmax(0, 1fr); }
    .platform:has(.chat-shell) > .main-pane { min-height: 0; }
    .rail { position: static; height: auto; display: grid; align-items: center;
        grid-template-columns: minmax(0, 1fr) auto auto; gap: .55rem;
        padding: .65rem; border-right: 0; border-bottom: 1px solid var(--line); }
    .rail .brand { grid-column: 1; grid-row: 1; padding: 0; }
    .rail nav { display: none; }
    .rail nav.is-open { grid-column: 1 / -1; grid-row: 2; display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .25rem; max-height: 45dvh;
        overflow: auto; padding: .2rem; }
    .rail nav .nav-item { white-space: normal; overflow-wrap: anywhere; gap: .45rem; }
    .rail nav .nav-item > span { flex: none; }
    .rail nav hr { display: none; }
    .rail-footer { grid-column: 3; grid-row: 1; padding: 0; border: 0; }
    .mobile-nav-toggle { grid-column: 2; grid-row: 1; display: inline-flex; }
    .owner-name { max-width: 72px; }
    .chat-shell { height: 100%; }
    .page-bar { min-height: 54px; padding: .6rem .75rem; }
    .admin-page { padding: .85rem; }
    .message { gap: .55rem; }
    .filter { flex-wrap: wrap; }
    .primary, .button { max-width: 100%; white-space: normal; overflow-wrap: anywhere; text-align: center; }
    input:not([type=checkbox]), select, textarea, .composer-selects select { font-size: max(16px, 1rem); }
}
@media (max-width: 420px) {
    .rail-footer .avatar, .rail-footer .owner-name { display: none; }
    .side-by-side { grid-template-columns: minmax(0, 1fr); }
}
