:root {
    color-scheme: light;
    --vio-orange: #f07800;
    --vio-orange-strong: #d86600;
    --vio-orange-soft: #fff1e5;
    --vio-orange-border: #f0b36a;
    --vio-on-accent: #ffffff;
    --vio-bluegrey: #6f8795;
    --vio-ink: #172027;
    --vio-muted: #5e6c75;
    --vio-line: #dbe3e8;
    --vio-soft: #f3f6f8;
    --vio-white: #ffffff;
    --vio-surface: #ffffff;
    --vio-surface-raised: #ffffff;
    --vio-surface-subtle: #eef3f5;
    --vio-surface-muted: #f8fafb;
    --vio-field: #ffffff;
    --vio-focus: rgb(240 120 0 / 32%);
    --vio-shadow: 0 1px 2px rgb(23 32 39 / 6%), 0 12px 34px rgb(23 32 39 / 8%);
    --vio-overlay-shadow: 0 22px 58px rgb(23 32 39 / 18%);
    --vio-danger: #a33520;
    --vio-danger-bg: #fff0ed;
    --vio-danger-border: #e0a59a;
    --vio-success: #1c6d3d;
    --vio-success-bg: #edf8f1;
    --vio-warning-text: #9b4f00;
    --vio-link: #1b647b;
    --vio-code-bg: #eef3f5;
    --vio-code-text: #24313a;
    --vio-diagram-node: #eef6f5;
    --vio-diagram-node-border: #2b7a78;
    --vio-diagram-axis: #9aa8ae;
    --vio-diagram-text: #52636d;
}

html[data-theme="dark"] {
    color-scheme: dark;
    --vio-orange: #ff9a32;
    --vio-orange-strong: #ffb164;
    --vio-orange-soft: #3a2717;
    --vio-orange-border: #8e5f2f;
    --vio-on-accent: #1a120a;
    --vio-bluegrey: #8ba3b0;
    --vio-ink: #e8eef2;
    --vio-muted: #a5b3bc;
    --vio-line: #2d3a43;
    --vio-soft: #0e1317;
    --vio-white: #171e23;
    --vio-surface: #171e23;
    --vio-surface-raised: #1c252b;
    --vio-surface-subtle: #26323a;
    --vio-surface-muted: #12191e;
    --vio-field: #11181d;
    --vio-focus: rgb(255 154 50 / 38%);
    --vio-shadow: 0 1px 2px rgb(0 0 0 / 28%), 0 16px 38px rgb(0 0 0 / 26%);
    --vio-overlay-shadow: 0 24px 70px rgb(0 0 0 / 42%);
    --vio-danger: #ffb4a6;
    --vio-danger-bg: #321b18;
    --vio-danger-border: #7b463d;
    --vio-success: #89d6a6;
    --vio-success-bg: #17291f;
    --vio-warning-text: #ffc47a;
    --vio-link: #78c3d8;
    --vio-code-bg: #10181d;
    --vio-code-text: #dbe7ee;
    --vio-diagram-node: #16302f;
    --vio-diagram-node-border: #5db9b5;
    --vio-diagram-axis: #6f828d;
    --vio-diagram-text: #b5c3cb;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--vio-soft);
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--vio-ink);
    background: var(--vio-soft);
    font: 15px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
    accent-color: var(--vio-orange);
}

a {
    color: inherit;
}

::selection {
    background: var(--vio-orange);
    color: var(--vio-on-accent);
}

.icon {
    display: inline-block;
    width: 1em;
    height: 1em;
    flex: none;
    fill: currentColor;
    pointer-events: none;
}

.portal-shell {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    display: flex;
    height: 100vh;
    flex-direction: column;
    gap: 24px;
    padding: 24px 16px;
    background: var(--vio-surface);
    border-right: 1px solid var(--vio-line);
}

.brand {
    display: flex;
    align-items: center;
    min-height: 52px;
}

.brand img {
    width: 142px;
    height: auto;
}

.nav-list {
    display: grid;
    gap: 5px;
}

.nav-group {
    display: grid;
    gap: 4px;
}

.nav-list a,
.sidebar-footer a {
    border-radius: 8px;
    color: var(--vio-muted);
    font-weight: 650;
    padding: 10px 12px;
    text-decoration: none;
    transition: background-color 140ms ease, color 140ms ease, border-color 140ms ease;
}

.nav-list a.active,
.nav-list a:hover {
    background: var(--vio-surface-subtle);
    color: var(--vio-ink);
}

.nav-list a.active {
    border-left: 4px solid var(--vio-orange);
    padding-left: 8px;
}

.nav-sublist {
    display: grid;
    gap: 2px;
    padding-left: 14px;
}

.nav-sublist a {
    min-height: 34px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 650;
    padding: 7px 10px;
}

.nav-sublist a.active {
    border-left-width: 3px;
    padding-left: 7px;
}

.sidebar-footer {
    margin-top: auto;
    display: grid;
    gap: 10px;
    color: var(--vio-muted);
    font-size: 13px;
}

.sidebar-footer span {
    overflow-wrap: anywhere;
    padding: 0 12px;
}

.sidebar-footer-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.sidebar-footer-actions a {
    min-width: 0;
}

.theme-toggle {
    display: inline-grid;
    width: 38px;
    min-width: 38px;
    height: 38px;
    min-height: 38px;
    place-items: center;
    border: 1px solid var(--vio-line);
    border-radius: 8px;
    background: var(--vio-surface-raised);
    color: var(--vio-muted);
    padding: 0;
    transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}

.theme-toggle:hover {
    background: var(--vio-surface-subtle);
    color: var(--vio-ink);
    filter: none;
}

.theme-toggle:focus-visible {
    outline: 3px solid var(--vio-focus);
    outline-offset: 2px;
}

.theme-toggle-floating {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 30;
    box-shadow: var(--vio-shadow);
}

.theme-toggle-icon {
    width: 16px;
    height: 16px;
}

.theme-toggle-icon-lightbulb {
    display: none;
}

.theme-toggle.is-dark .theme-toggle-icon-moon {
    display: none;
}

.theme-toggle.is-dark .theme-toggle-icon-lightbulb {
    display: inline-block;
}

.content {
    min-width: 0;
    padding: 32px;
}

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 24px;
}

.page-head h1,
.auth-panel h1 {
    margin: 0;
    font-size: 26px;
    font-weight: 750;
    line-height: 1.15;
}

.page-head p {
    margin: 5px 0 0;
    color: var(--vio-muted);
}

.panel {
    background: var(--vio-surface-raised);
    border: 1px solid var(--vio-line);
    border-radius: 8px;
    box-shadow: var(--vio-shadow);
    padding: 22px;
}

.panel + .panel {
    margin-top: 18px;
}

.grid {
    display: grid;
    gap: 18px;
}

.grid.two {
    grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
}

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

caption {
    margin: 0 0 14px;
    color: var(--vio-ink);
    font-size: 16px;
    font-weight: 750;
    text-align: left;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    border-bottom: 1px solid var(--vio-line);
    padding: 11px 10px;
    text-align: left;
    vertical-align: middle;
}

th {
    color: var(--vio-muted);
    font-size: 12px;
    font-weight: 750;
    text-transform: uppercase;
}

tr:last-child td {
    border-bottom: 0;
}

tbody tr:hover {
    background: var(--vio-surface-muted);
}

.table-subline {
    display: block;
    margin-top: 3px;
    color: var(--vio-muted);
    font-size: 12px;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.usage-summary {
    display: grid;
    min-width: 160px;
    gap: 5px;
}

.usage-summary span {
    font-weight: 650;
}

.usage-summary small {
    color: var(--vio-muted);
}

.usage-meter {
    width: 100%;
    height: 7px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--vio-surface-subtle);
}

.usage-meter span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--vio-orange);
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.metric-card {
    display: grid;
    gap: 4px;
    min-width: 0;
    padding: 18px;
    border: 1px solid var(--vio-line);
    border-radius: 8px;
    background: var(--vio-white);
}

.metric-card span {
    color: var(--vio-muted);
    font-size: 12px;
    font-weight: 750;
    text-transform: uppercase;
}

.metric-card strong {
    font-size: 28px;
    line-height: 1.1;
}

.error-cell {
    max-width: 320px;
    overflow-wrap: anywhere;
}

.button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: var(--vio-orange);
    color: var(--vio-on-accent);
    cursor: pointer;
    font: inherit;
    font-weight: 750;
    padding: 8px 14px;
    text-decoration: none;
    transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease, filter 140ms ease;
}

.button.secondary,
button.secondary {
    background: var(--vio-surface-raised);
    border-color: var(--vio-line);
    color: var(--vio-ink);
}

.button.danger,
button.danger {
    background: var(--vio-danger);
}

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

.button:focus-visible,
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid var(--vio-focus);
    outline-offset: 2px;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
    cursor: not-allowed;
    opacity: 0.62;
}

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

.form-row {
    display: grid;
    gap: 7px;
}

.form-row label {
    color: var(--vio-muted);
    font-size: 13px;
    font-weight: 750;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--vio-line);
    border-radius: 8px;
    background: var(--vio-field);
    color: var(--vio-ink);
    font: inherit;
    padding: 10px 12px;
    transition: border-color 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
}

input:hover,
select:hover,
textarea:hover {
    border-color: var(--vio-bluegrey);
}

textarea {
    min-height: 140px;
    resize: vertical;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.check-row input {
    width: 18px;
    height: 18px;
    accent-color: var(--vio-orange);
}

.checkbox-group {
    display: grid;
    gap: 10px;
}

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    background: var(--vio-surface-subtle);
    color: var(--vio-muted);
    font-size: 12px;
    font-weight: 750;
    padding: 4px 9px;
}

.badge.orange {
    background: var(--vio-orange-soft);
    color: var(--vio-warning-text);
}

.badge.green {
    background: #e7f7ed;
    color: #1f7a3c;
}

.badge.red {
    background: #fdeceb;
    color: #a22d25;
}

.badge.blue {
    background: #e8f2fb;
    color: #24618f;
}

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

.flash {
    margin-bottom: 16px;
    border-radius: 8px;
    padding: 12px 14px;
    font-weight: 700;
}

.flash-success {
    background: var(--vio-success-bg);
    color: var(--vio-success);
}

.flash-error {
    background: var(--vio-danger-bg);
    color: var(--vio-danger);
}

.auth-content {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 72px 24px 24px;
}

.auth-panel {
    width: min(100%, 420px);
    border-top: 4px solid var(--vio-orange);
}

.auth-panel .brand {
    margin-bottom: 26px;
}

.auth-panel .brand img {
    width: 164px;
}

.muted {
    color: var(--vio-muted);
}

.grafana-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 12px;
    margin-bottom: 16px;
}

.grafana-controls label {
    display: grid;
    min-width: 160px;
    gap: 6px;
}

.grafana-controls span {
    color: var(--vio-muted);
    font-size: 13px;
    font-weight: 750;
}

.grafana-frame {
    width: 100%;
    min-height: 520px;
    border: 1px solid var(--vio-line);
    border-radius: 8px;
    background: var(--vio-surface);
}

.assistant-widget {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 40;
}

.assistant-toggle {
    width: 52px;
    min-height: 52px;
    border-radius: 50%;
    box-shadow: var(--vio-overlay-shadow);
    line-height: 1;
}

.assistant-toggle-icon {
    width: 22px;
    height: 22px;
}

.assistant-panel {
    position: absolute;
    right: 0;
    bottom: 62px;
    display: grid;
    width: min(calc(100vw - 32px), 760px);
    height: min(720px, calc(100vh - 86px));
    overflow: hidden;
    border: 1px solid var(--vio-line);
    border-radius: 8px;
    background: var(--vio-surface);
    box-shadow: var(--vio-overlay-shadow);
}

.assistant-panel.assistant-panel--maximized {
    position: fixed;
    inset: 18px;
    right: 18px;
    bottom: 18px;
    width: auto;
    height: auto;
}

.assistant-panel[hidden] {
    display: none;
}

.assistant-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--vio-line);
    padding: 12px 14px;
}

.assistant-header-title {
    display: grid;
    min-width: 0;
}

.assistant-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.assistant-header strong {
    line-height: 1.2;
}

.assistant-header span,
.assistant-empty,
.assistant-tenant-select span {
    color: var(--vio-muted);
    font-size: 13px;
}

.assistant-thread-delete {
    width: 32px;
    min-height: 32px;
    border-radius: 8px;
    background: var(--vio-surface-raised);
    border-color: var(--vio-line);
    color: var(--vio-muted);
    padding: 0;
}

.assistant-maximize,
.assistant-close {
    display: inline-grid;
    place-items: center;
    width: 28px;
    height: 28px;
    min-height: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    color: var(--vio-muted);
    font-weight: 500;
    line-height: 1;
    padding: 0;
}

.assistant-close:hover {
    background: transparent;
    color: var(--vio-ink);
    filter: none;
}

.assistant-maximize:hover {
    background: transparent;
    color: var(--vio-ink);
    filter: none;
}

.assistant-maximize-icon {
    width: 14px;
    height: 14px;
}

.assistant-maximize-icon-compress {
    display: none;
}

.assistant-maximize[aria-pressed="true"] .assistant-maximize-icon-expand {
    display: none;
}

.assistant-maximize[aria-pressed="true"] .assistant-maximize-icon-compress {
    display: inline-block;
}

.assistant-action-icon {
    width: 14px;
    height: 14px;
}

.assistant-thread-delete .assistant-action-icon {
    width: 13px;
    height: 13px;
}

.assistant-maximize:focus-visible,
.assistant-close:focus-visible {
    outline: 2px solid var(--vio-orange);
    outline-offset: 2px;
}

.assistant-tenant-select {
    display: grid;
    gap: 6px;
    border-bottom: 1px solid var(--vio-line);
    padding: 10px 14px;
}

.assistant-layout {
    display: grid;
    min-height: 0;
    grid-template-columns: 220px minmax(0, 1fr);
}

.assistant-thread-list {
    display: grid;
    align-content: start;
    gap: 4px;
    overflow-y: auto;
    border-right: 1px solid var(--vio-line);
    background: var(--vio-surface-muted);
    padding: 10px;
}

.assistant-thread-action,
.assistant-thread-row button:first-child {
    justify-content: flex-start;
    width: 100%;
    min-height: 34px;
    overflow: hidden;
    border-radius: 6px;
    background: transparent;
    color: var(--vio-ink);
    font-size: 13px;
    padding: 7px 8px;
    text-align: left;
}

.assistant-thread-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 32px;
    gap: 4px;
}

.assistant-thread-row.active button:first-child {
    background: var(--vio-surface-subtle);
    border-left: 3px solid var(--vio-orange);
    padding-left: 6px;
}

.assistant-conversation {
    display: grid;
    min-width: 0;
    min-height: 0;
    grid-template-rows: minmax(0, 1fr) auto;
}

.assistant-messages {
    display: grid;
    align-content: start;
    gap: 10px;
    overflow-y: auto;
    padding: 14px;
}

.assistant-message {
    display: flex;
}

.assistant-message > div {
    max-width: min(82%, 560px);
    border: 1px solid var(--vio-line);
    border-radius: 8px;
    background: var(--vio-surface-raised);
    overflow-wrap: anywhere;
    padding: 10px 12px;
}

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

.assistant-message.user > div {
    border-color: var(--vio-orange-border);
    background: var(--vio-orange-soft);
}

.assistant-message.assistant > div {
    background: var(--vio-surface-muted);
}

.assistant-panel--maximized .assistant-message > div {
    max-width: min(92%, 920px);
}

.assistant-message.error > div {
    border-color: var(--vio-danger-border);
    background: var(--vio-danger-bg);
    color: var(--vio-danger);
}

.assistant-message.assistant h1,
.assistant-message.assistant h2,
.assistant-message.assistant h3,
.assistant-message.assistant h4,
.assistant-message.assistant h5,
.assistant-message.assistant h6 {
    margin: 0 0 8px;
    font-size: 16px;
    line-height: 1.25;
}

.assistant-message.assistant p,
.assistant-message.assistant ul,
.assistant-message.assistant ol,
.assistant-message.assistant blockquote,
.assistant-message.assistant pre,
.assistant-message.assistant table {
    margin: 0 0 10px;
}

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

.assistant-message.assistant ul,
.assistant-message.assistant ol {
    padding-left: 20px;
}

.assistant-message.assistant li + li {
    margin-top: 4px;
}

.assistant-message.assistant code {
    border-radius: 4px;
    background: var(--vio-code-bg);
    color: var(--vio-code-text);
    font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
    font-size: 13px;
    padding: 2px 4px;
}

.assistant-message.assistant pre {
    overflow-x: auto;
    border: 1px solid var(--vio-line);
    border-radius: 6px;
    background: var(--vio-code-bg);
    padding: 10px;
}

.assistant-message.assistant pre code {
    border-radius: 0;
    background: transparent;
    padding: 0;
}

.assistant-message.assistant blockquote {
    border-left: 3px solid var(--vio-bluegrey);
    color: var(--vio-muted);
    padding-left: 10px;
}

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

.assistant-message.assistant th,
.assistant-message.assistant td {
    border: 1px solid var(--vio-line);
    padding: 6px 8px;
    text-align: left;
    vertical-align: top;
}

.assistant-message.assistant th {
    background: var(--vio-surface-subtle);
}

.assistant-message.assistant a {
    color: var(--vio-link);
    font-weight: 650;
}

.assistant-diagram {
    overflow-x: auto;
    border: 1px solid var(--vio-line);
    border-radius: 8px;
    background: var(--vio-surface-raised);
    padding: 10px;
}

.assistant-diagram-title {
    margin-bottom: 8px;
    color: var(--vio-code-text);
    font-weight: 700;
}

.assistant-diagram svg {
    display: block;
    width: 100%;
    min-width: 340px;
    height: auto;
}

.assistant-diagram figcaption {
    margin-top: 8px;
    color: var(--vio-muted);
    font-size: 12px;
    line-height: 1.4;
}

.assistant-diagram-axis {
    stroke: var(--vio-diagram-axis);
    stroke-width: 1.5;
}

.assistant-diagram-value,
.assistant-diagram-label,
.assistant-diagram-edge-label {
    fill: var(--vio-diagram-text);
    font-size: 12px;
}

.assistant-diagram-node {
    fill: var(--vio-diagram-node);
    stroke: var(--vio-diagram-node-border);
    stroke-width: 1.5;
}

.assistant-diagram-node-label {
    fill: var(--vio-code-text);
    font-size: 14px;
    font-weight: 700;
}

.assistant-diagram-edge {
    fill: none;
    stroke: var(--vio-diagram-text);
    stroke-width: 2;
}

.assistant-diagram-empty {
    color: var(--vio-muted);
    font-size: 13px;
    padding: 12px;
}

.assistant-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    border-top: 1px solid var(--vio-line);
    padding: 12px;
}

.assistant-form textarea {
    min-height: 48px;
    max-height: 150px;
    resize: vertical;
}

.assistant-form button {
    align-self: end;
}

.assistant-empty {
    margin: 0;
    padding: 8px;
}

@media (max-width: 900px) {
    .portal-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
        gap: 14px;
    }

    .nav-list {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        align-items: start;
    }

    .content {
        padding: 18px;
    }

    .page-head,
    .grid.two {
        grid-template-columns: 1fr;
        display: grid;
    }

    .metric-grid {
        grid-template-columns: 1fr;
    }

    .actions {
        justify-content: flex-start;
    }

    .assistant-widget {
        right: 14px;
        bottom: 14px;
    }

    .assistant-panel {
        right: -2px;
        width: calc(100vw - 24px);
        bottom: 58px;
        height: min(640px, calc(100vh - 78px));
    }

    .assistant-panel.assistant-panel--maximized {
        inset: 10px;
        right: 10px;
        bottom: 10px;
        width: auto;
        height: auto;
    }

    .assistant-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto minmax(0, 1fr);
    }

    .assistant-thread-list {
        max-height: 118px;
        border-right: 0;
        border-bottom: 1px solid var(--vio-line);
    }

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