:root {
    --bg: #eef2f6;
    --surface: #ffffff;
    --surface-muted: #f6f8fb;
    --line: #d8e0ea;
    --line-strong: #bcc8d6;
    --text: #17202a;
    --muted: #66758a;
    --blue: #2367e8;
    --blue-soft: #eaf1ff;
    --green: #158057;
    --green-soft: #e9f8f0;
    --amber: #b86711;
    --amber-soft: #fff4df;
    --red: #b52d2d;
    --red-soft: #fff0f0;
    --shadow: 0 10px 30px rgba(21, 31, 47, 0.08);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
    margin: 0;
    background: var(--bg);
}

button,
input,
textarea,
select {
    font: inherit;
}

a {
    color: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.56;
}

.workspace-shell {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr) 320px;
    height: 100vh;
    min-height: 680px;
    overflow: hidden;
    background: var(--bg);
}

.session-rail,
.inspector {
    background: #f9fbfd;
    border-color: var(--line);
    border-style: solid;
    min-width: 0;
}

.session-rail {
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 20px 16px;
    border-width: 0 1px 0 0;
}

.inspector {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px 18px;
    border-width: 0 0 0 1px;
    overflow: auto;
}

.brand-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: #182337;
    color: #fff;
    font-size: 13px;
    font-weight: 800;
}

.brand-row h1 {
    margin: 0;
    font-size: 17px;
    line-height: 1.1;
    letter-spacing: 0;
}

.brand-row p,
.auth-tile p,
.inspector-section p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
}

.primary-line,
.primary-button,
.secondary-button,
.send-button,
.icon-button,
.session-item {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
}

.primary-line,
.primary-button,
.secondary-button,
.send-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 38px;
    padding: 0 12px;
    font-size: 13px;
    font-weight: 700;
}

.primary-line span,
.primary-button span,
.secondary-button span,
.send-button span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.primary-line,
.primary-button,
.send-button {
    background: var(--blue);
    border-color: var(--blue);
    color: white;
}

.secondary-button {
    background: var(--surface);
}

.secondary-button.approve {
    color: var(--green);
    border-color: #9fd5b8;
}

.secondary-button.deny {
    color: var(--red);
    border-color: #e6aaaa;
}

.icon-button {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    flex: none;
    text-decoration: none;
}

.icon {
    width: 17px;
    height: 17px;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex: none;
}

.auth-tile {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.auth-tile.connected {
    border-color: #b8dec8;
    background: var(--green-soft);
}

.auth-tile.disconnected {
    border-color: #f0d2a8;
    background: var(--amber-soft);
}

.auth-title {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 13px;
    font-weight: 800;
}

.auth-tile code {
    display: block;
    margin-top: 8px;
    color: var(--muted);
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.section-label {
    color: #718096;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.session-list {
    display: grid;
    gap: 8px;
    overflow: auto;
}

.session-item {
    display: grid;
    gap: 4px;
    width: 100%;
    padding: 11px;
    text-align: left;
}

.session-item.active {
    border-color: #9ab8f6;
    background: var(--blue-soft);
}

.session-item span {
    font-size: 13px;
    font-weight: 800;
}

.session-item small {
    color: var(--muted);
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.session-owner {
    color: var(--blue);
}

.chat-pane {
    display: grid;
    grid-template-rows: auto auto 1fr auto;
    min-width: 0;
    background: var(--surface);
    container-type: inline-size;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 68px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--line);
}

.project-picker {
    flex: 1 1 auto;
    min-width: 0;
}

.project-picker span {
    display: block;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}

.project-picker strong {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
}

.topbar-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    min-width: 0;
}

.user-identity {
    max-width: 140px;
    overflow: hidden;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.logout-form {
    display: contents;
}

.model-select,
.mode-select {
    height: 38px;
    max-width: 210px;
    min-width: 0;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
}

.mode-select {
    width: 112px;
}

.policy-notice {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
}

.oauth-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin: 16px 20px 0;
    padding: 16px;
    border: 1px solid #f0d2a8;
    border-radius: 8px;
    background: var(--amber-soft);
}

.oauth-panel h2,
.empty-state h2,
.inspector-section h2 {
    margin: 0;
    font-size: 18px;
    line-height: 1.2;
    letter-spacing: 0;
}

.device-flow {
    display: grid;
    gap: 8px;
    min-width: 250px;
}

.device-flow a {
    color: var(--blue);
    font-size: 12px;
    font-weight: 700;
}

.device-code {
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 22px;
    font-weight: 800;
    letter-spacing: 0;
    text-align: center;
}

.transcript {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
    padding: 20px;
    overflow: auto;
    background: linear-gradient(#fff, #fff), var(--surface);
}

.empty-state {
    width: min(620px, 100%);
    margin: auto;
    padding: 28px;
    border: 1px dashed var(--line-strong);
    border-radius: 8px;
    background: var(--surface-muted);
    text-align: center;
}

.empty-state p {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.message {
    display: grid;
    gap: 6px;
    max-width: 820px;
}

.message.user {
    align-self: flex-end;
    width: min(720px, 86%);
}

.message.assistant {
    align-self: flex-start;
    width: min(820px, 92%);
}

.message-meta {
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}

.message.user .message-meta {
    text-align: right;
}

.message-body {
    padding: 13px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-muted);
    color: var(--text);
    font-size: 14px;
    line-height: 1.55;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.message.user .message-body {
    background: var(--blue);
    border-color: var(--blue);
    color: #fff;
}

.message.streaming .message-body {
    border-color: #b8dec8;
    background: var(--green-soft);
}

.cursor {
    display: inline-block;
    width: 7px;
    height: 1em;
    margin-left: 3px;
    transform: translateY(2px);
    background: var(--green);
    animation: blink 1s step-end infinite;
}

@keyframes blink {
    50% {
        opacity: 0;
    }
}

.tool-card {
    display: grid;
    gap: 12px;
    width: min(760px, 94%);
    padding: 14px;
    border: 1px solid #f0d2a8;
    border-radius: 8px;
    background: var(--amber-soft);
    box-shadow: var(--shadow);
}

.tool-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.tool-card-header strong,
.tool-card-header span {
    display: block;
}

.tool-card-header strong {
    font-size: 13px;
}

.tool-card-header span {
    color: var(--muted);
    font-size: 12px;
}

.tool-card pre {
    max-height: 180px;
    margin: 0;
    padding: 12px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: #26364a;
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
}

.tool-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.read-only-label {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

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

.composer textarea {
    width: 100%;
    min-height: 76px;
    max-height: 180px;
    resize: vertical;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    outline: none;
    color: var(--text);
    background: var(--surface);
    font-size: 14px;
    line-height: 1.45;
}

.composer textarea:focus {
    border-color: #9ab8f6;
    box-shadow: 0 0 0 3px rgba(35, 103, 232, 0.12);
}

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

.composer-actions span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.inspector-section {
    display: grid;
    gap: 10px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.inspector-section dl {
    display: grid;
    grid-template-columns: 80px minmax(0, 1fr);
    gap: 8px;
    margin: 0;
    font-size: 12px;
}

.inspector-section dt {
    color: var(--muted);
    font-weight: 800;
}

.inspector-section dd {
    min-width: 0;
    margin: 0;
    overflow-wrap: anywhere;
}

.tool-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 34px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: #314158;
    font-size: 12px;
    font-weight: 700;
}

.events {
    gap: 8px;
}

.event-row {
    display: grid;
    grid-template-columns: 58px minmax(0, 1fr);
    gap: 8px;
    padding: 8px 0;
    border-top: 1px solid var(--line);
}

.event-row:first-of-type {
    border-top: 0;
}

.event-row span {
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
}

.event-row p {
    margin: 0;
    color: var(--text);
    font-size: 12px;
    line-height: 1.35;
}

.event-row.error p {
    color: var(--red);
}

.event-row.warning p {
    color: var(--amber);
}

.event-row.success p {
    color: var(--green);
}

#blazor-error-ui {
    display: none;
    position: fixed;
    inset: auto 16px 16px 16px;
    z-index: 1000;
    padding: 12px 16px;
    border-radius: 8px;
    background: var(--red);
    color: white;
    box-shadow: var(--shadow);
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    float: right;
}

.auth-shell {
    display: grid;
    align-content: center;
    gap: 28px;
    width: min(460px, calc(100% - 32px));
    min-height: 100vh;
    margin: 0 auto;
    padding: 32px 0;
}

.auth-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.auth-brand strong,
.auth-brand span {
    display: block;
}

.auth-brand strong {
    font-size: 17px;
}

.auth-brand span {
    margin-top: 3px;
    color: var(--muted);
    font-size: 12px;
}

.auth-panel {
    display: grid;
    gap: 22px;
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.compact-panel {
    text-align: center;
}

.auth-panel-heading {
    display: grid;
    gap: 7px;
}

.auth-panel-heading h1,
.admin-header h1,
.panel-heading h2 {
    margin: 0;
    letter-spacing: 0;
}

.auth-panel-heading h1 {
    font-size: 26px;
}

.auth-panel-heading p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
}

.account-form {
    display: grid;
    gap: 16px;
}

.field-group {
    display: grid;
    gap: 7px;
}

.field-group > span {
    color: #405069;
    font-size: 12px;
    font-weight: 800;
}

.field-group input,
.field-group select {
    width: 100%;
    height: 42px;
    padding: 0 11px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    outline: none;
    background: var(--surface);
    color: var(--text);
}

.field-group input:focus,
.field-group select:focus {
    border-color: #7da4ef;
    box-shadow: 0 0 0 3px rgba(35, 103, 232, 0.12);
}

.check-row {
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--muted);
    font-size: 13px;
}

.check-row input {
    width: 16px;
    height: 16px;
}

.auth-submit {
    width: 100%;
    min-height: 42px;
    text-decoration: none;
}

.form-alert,
.validation-summary {
    margin: 0;
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.45;
}

.form-alert.error,
.validation-summary {
    border-color: #e6aaaa;
    background: var(--red-soft);
    color: var(--red);
}

.form-alert.success {
    border-color: #9fd5b8;
    background: var(--green-soft);
    color: var(--green);
}

.validation-summary:empty {
    display: none;
}

.validation-summary ul {
    margin: 0;
    padding-left: 18px;
}

.admin-shell {
    min-height: 100vh;
    background: var(--bg);
}

.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    min-height: 76px;
    padding: 14px clamp(18px, 4vw, 52px);
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

.admin-title-row,
.users-heading {
    display: flex;
    align-items: center;
    gap: 14px;
}

.admin-header h1 {
    margin-top: 3px;
    font-size: 22px;
}

.admin-content {
    display: grid;
    grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
    gap: 24px;
    width: min(1160px, calc(100% - 36px));
    margin: 0 auto;
    padding: 30px 0;
}

.user-create-panel,
.user-list-panel,
.user-policy-panel {
    align-self: start;
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.user-policy-panel {
    grid-column: 1 / -1;
}

.api-token-section {
    margin-top: 26px;
    padding-top: 24px;
    border-top: 1px solid var(--line);
}

.token-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.token-create-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.token-tools-policy {
    align-self: start;
}

.token-reveal {
    display: grid;
    grid-template-columns: minmax(160px, auto) minmax(0, 1fr) auto;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
    padding: 16px;
    border: 1px solid #85bd98;
    border-radius: 8px;
    background: var(--green-soft);
}

.token-reveal > div:first-child {
    display: grid;
    gap: 3px;
}

.token-reveal small {
    color: var(--muted);
}

.token-reveal code {
    min-width: 0;
    overflow-wrap: anywhere;
    font-size: 12px;
}

.token-reveal-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.token-table-wrap {
    margin-top: 22px;
}

.token-table {
    min-width: 840px;
}

.token-limits {
    display: block;
    max-width: 310px;
    color: var(--muted);
    line-height: 1.45;
}

.empty-table-cell {
    color: var(--muted);
    text-align: center !important;
}

.icon-button.deny:not(:disabled) {
    color: #b44747;
}

.panel-heading {
    display: grid;
    gap: 5px;
    margin-bottom: 20px;
}

.panel-heading h2 {
    font-size: 18px;
}

.users-heading {
    display: flex;
    justify-content: space-between;
}

.compact-form {
    gap: 13px;
}

.count-badge,
.role-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 24px;
    padding: 0 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 800;
}

.count-badge {
    background: var(--surface-muted);
    color: var(--muted);
}

.role-badge.admin {
    background: var(--amber-soft);
    color: var(--amber);
}

.role-badge.customer {
    background: var(--blue-soft);
    color: var(--blue);
}

.access-badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 0 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 800;
}

.access-badge.allowed {
    background: var(--green-soft);
    color: var(--green);
}

.access-badge.blocked {
    background: var(--surface-muted);
    color: var(--muted);
}

.policy-default {
    display: block;
    max-width: 200px;
    overflow: hidden;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-table td small {
    display: block;
    margin-top: 3px;
    color: var(--muted);
}

.policy-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
}

.policy-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.policy-fieldset {
    min-width: 0;
    margin: 0;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.policy-fieldset legend {
    padding: 0 6px;
    color: #405069;
    font-size: 12px;
    font-weight: 800;
}

.check-row > span {
    display: grid;
    gap: 2px;
}

.check-row small {
    color: var(--muted);
    line-height: 1.35;
}

.check-row.compact {
    align-items: flex-start;
    color: var(--text);
}

.policy-select {
    width: 100%;
    height: 42px;
    padding: 0 11px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
}

.policy-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    max-height: 220px;
    margin-top: 14px;
    overflow-y: auto;
}

.mode-options {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin: 0 0 16px;
}

.policy-default-mode {
    max-width: 240px;
}

.policy-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 20px;
}

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

@container (max-width: 820px) {
    .topbar {
        align-items: stretch;
        flex-direction: column;
        gap: 10px;
    }

    .topbar-actions {
        width: 100%;
    }

    .model-select {
        flex: 1 1 auto;
    }

    .user-identity {
        margin-left: auto;
    }
}

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

.user-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.user-table th,
.user-table td {
    padding: 12px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
}

.user-table th {
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
}

@media (max-width: 1100px) {
    .workspace-shell {
        grid-template-columns: 240px minmax(0, 1fr);
    }

    .inspector {
        display: none;
    }
}

@media (max-width: 760px) {
    .workspace-shell {
        grid-template-columns: 1fr;
        height: auto;
        min-height: 100vh;
        overflow: auto;
    }

    .session-rail {
        border-width: 0 0 1px 0;
    }

    .session-list {
        grid-auto-flow: column;
        grid-auto-columns: minmax(180px, 1fr);
        overflow-x: auto;
    }

    .chat-pane {
        min-height: 720px;
    }

    .topbar,
    .oauth-panel {
        align-items: stretch;
        flex-direction: column;
    }

    .topbar-actions {
        flex-wrap: wrap;
        width: 100%;
    }

    .user-identity {
        order: 4;
        width: 100%;
        max-width: 100%;
    }

    .model-select {
        flex: 1.4 1 0;
    }

    .mode-select {
        flex: 0.8 1 0;
    }

    .oauth-panel .primary-button,
    .device-flow {
        width: 100%;
    }

    .device-flow {
        min-width: 0;
    }

    .project-picker strong {
        max-width: 100%;
    }

    .message.user,
    .message.assistant {
        width: 100%;
    }

    .auth-panel {
        padding: 22px 18px;
    }

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

    .admin-content {
        grid-template-columns: 1fr;
    }

    .policy-grid,
    .mode-options,
    .token-create-grid {
        grid-template-columns: 1fr;
    }

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