﻿:root {
    --app-bg: #edf4f8;
    --app-panel: rgba(255, 255, 255, 0.58);
    --app-panel-strong: rgba(255, 255, 255, 0.88);
    --app-border: rgba(111, 129, 150, 0.18);
    --app-text: #15191f;
    --app-muted: #687584;
    --app-soft: #e2ebf2;
    --app-accent: #102326;
    --app-blue: #4d91c8;
    --app-green: #78a99a;
    --app-warm: #f3b46b;
    --radius-sm: 8px;
    --radius-md: 16px;
}

html[data-chat-theme="dark"] {
    --app-bg: #172236;
    --app-panel: rgba(25, 36, 59, 0.82);
    --app-panel-strong: rgba(31, 44, 70, 0.96);
    --app-border: rgba(154, 177, 220, 0.26);
    --app-text: #f1f6ff;
    --app-muted: #b2bfd8;
    --app-soft: rgba(118, 145, 202, 0.2);
    --app-accent: #f6f8fb;
    --app-blue: #7db7ff;
}

html[data-chat-theme="terminal"] {
    --app-bg: #10151d;
    --app-panel: rgba(20, 26, 35, 0.78);
    --app-panel-strong: rgba(27, 34, 45, 0.96);
    --app-border: rgba(151, 163, 180, 0.22);
    --app-text: #edf2f7;
    --app-muted: #9aa7b7;
    --app-soft: #1f2936;
    --app-accent: #f6f8fb;
    --app-blue: #8ab4e6;
}

html {
    font-size: 14px;
}

@media (min-width: 768px) {
    html {
        font-size: 16px;
    }
}

html,
body {
    min-height: 100%;
}

body {
    color: var(--app-text);
    margin: 0;
}

.btn:focus,
.btn:active:focus,
.btn-link.nav-link:focus,
.form-control:focus,
.form-check-input:focus,
.form-select:focus {
    box-shadow: 0 0 0 0.1rem var(--app-panel-strong), 0 0 0 0.22rem rgba(102, 150, 200, 0.45);
}

.app-body {
    background: linear-gradient(135deg, #f9fbfc 0%, var(--app-bg) 48%, #e4f0f6 100%);
    min-height: 100vh;
    overflow: hidden;
}

html[data-chat-theme="dark"] .app-body {
    background: linear-gradient(135deg, #10192a 0%, var(--app-bg) 48%, #1b2941 100%);
}

html[data-chat-theme="terminal"] .app-body {
    background: #05080d;
}

.public-app-body {
    background: #f8fafc;
}

.text-muted {
    color: var(--app-muted) !important;
}

.app-body .card,
.app-body .dropdown-menu,
.app-body .list-group-item,
.app-body .modal-content {
    background: var(--app-panel-strong);
    border-color: var(--app-border);
    color: var(--app-text);
}

.app-body .modal-content {
    background: #f8fbfd;
}

html[data-chat-theme="dark"] .app-body .modal-content,
html[data-chat-theme="terminal"] .app-body .modal-content {
    background: #172236;
}

.app-body .modal-header,
.app-body .modal-footer {
    border-color: var(--app-border);
}

.app-body .table {
    --bs-table-bg: transparent;
    --bs-table-border-color: var(--app-border);
    --bs-table-color: var(--app-text);
    --bs-table-hover-bg: rgba(148, 163, 184, 0.1);
    --bs-table-striped-bg: rgba(148, 163, 184, 0.08);
    color: var(--app-text);
}

.app-body .table td,
.app-body .table th {
    border-color: var(--app-border);
}

.app-body .table thead th {
    color: var(--app-muted);
}

.app-body .form-control,
.app-body .form-select,
.app-body .form-check-input {
    background-color: var(--app-panel-strong);
    border-color: var(--app-border);
    color: var(--app-text);
}

.app-body .form-control::placeholder {
    color: var(--app-muted);
}

.app-body .form-control:focus,
.app-body .form-select:focus {
    background-color: var(--app-panel-strong);
    border-color: var(--app-blue);
    color: var(--app-text);
}

.app-body .form-check-input:checked {
    background-color: var(--app-blue);
    border-color: var(--app-blue);
}

.app-body .btn-link {
    color: var(--app-blue);
    text-decoration: none;
}

.app-body .btn-link:hover {
    color: var(--app-text);
}

.app-body .btn-outline-primary {
    border-color: var(--app-blue);
    color: var(--app-blue);
}

.app-body .btn-outline-primary:hover {
    background: var(--app-blue);
    border-color: var(--app-blue);
    color: #fff;
}

.app-body {
    font-family: var(--brand-font);
}

.app-body .btn:not(.btn-link):not(.btn-close) {
    border-radius: var(--brand-radius-pill);
    font-weight: 700;
    padding-left: 1rem;
    padding-right: 1rem;
}

.app-body .btn-primary,
.app-body .btn-primary:disabled {
    background-color: var(--app-accent);
    border-color: var(--app-accent);
    color: #fff;
}

.app-body .btn-primary:hover,
.app-body .btn-primary:focus,
.app-body .btn-primary:active {
    background-color: #1d3a3f;
    border-color: #1d3a3f;
    color: #fff;
}

html[data-chat-theme="dark"] .app-body .btn-primary,
html[data-chat-theme="terminal"] .app-body .btn-primary {
    background-color: var(--app-blue);
    border-color: var(--app-blue);
    color: #08101f;
}

html[data-chat-theme="dark"] .app-body .btn-primary:hover,
html[data-chat-theme="dark"] .app-body .btn-primary:focus,
html[data-chat-theme="terminal"] .app-body .btn-primary:hover,
html[data-chat-theme="terminal"] .app-body .btn-primary:focus {
    background-color: #9ccaff;
    border-color: #9ccaff;
    color: #08101f;
}

.app-body .btn-secondary,
.app-body .btn-outline-secondary {
    background-color: var(--app-panel-strong);
    border-color: var(--app-border);
    color: var(--app-text);
}

.app-body .btn-secondary:hover,
.app-body .btn-secondary:focus,
.app-body .btn-outline-secondary:hover,
.app-body .btn-outline-secondary:focus {
    background-color: var(--app-soft);
    border-color: var(--app-border);
    color: var(--app-text);
}

.app-body .btn-danger,
.app-body .btn-danger:hover,
.app-body .btn-danger:focus {
    background-color: var(--brand-danger);
    border-color: var(--brand-danger);
    color: #fff;
}

.app-body .btn-danger:hover {
    filter: brightness(0.92);
}

.app-body .alert-success {
    background: rgba(34, 197, 94, 0.12);
    border-color: rgba(34, 197, 94, 0.28);
    color: var(--app-text);
}

.app-shell {
    display: grid;
    grid-template-columns: 284px minmax(0, 1fr);
    gap: 18px;
    height: 100vh;
    padding: 16px;
}

.app-shell {
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    margin: 0;
    overflow: hidden;
    height: 100vh;
}

body.modal-open .app-shell {
    backdrop-filter: none;
}

html[data-chat-theme="dark"] .app-shell {
    background:
        linear-gradient(145deg, rgba(30, 43, 70, 0.9), rgba(19, 29, 48, 0.88));
    border-color: rgba(154, 177, 220, 0.24);
    box-shadow: 0 24px 70px rgba(5, 12, 24, 0.32);
}

.mobile-topbar,
.sidebar-backdrop {
    display: none;
}

.mobile-topbar-button {
    align-items: center;
    background: transparent;
    border: 0;
    border-radius: 999px;
    color: var(--app-text);
    display: inline-flex;
    font-size: 1.15rem;
    height: 42px;
    justify-content: center;
    text-decoration: none;
    width: 42px;
}

.mobile-topbar-button:hover,
.mobile-topbar-button:focus-visible {
    background: var(--app-soft);
    color: var(--app-text);
}

.app-sidebar {
    background: rgba(255, 255, 255, 0.44);
    border: 1px solid rgba(255, 255, 255, 0.62);
    border-radius: 26px;
    box-shadow: 0 18px 48px rgba(79, 99, 118, 0.1);
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 16px 14px;
}

html[data-chat-theme="dark"] .app-sidebar {
    background: rgba(17, 27, 47, 0.7);
}

.sidebar-brand,
.app-topbar {
    align-items: center;
    display: flex;
    justify-content: space-between;
}

.brand-logo-link {
    align-items: center;
    display: inline-flex;
    min-height: 38px;
    text-decoration: none;
}

.brand-logo {
    display: block;
    height: 34px;
    max-width: 210px;
    object-fit: contain;
}

.brand-logo-for-dark {
    display: none;
}

html[data-chat-theme="dark"] .brand-logo-for-light,
html[data-chat-theme="terminal"] .brand-logo-for-light {
    display: none;
}

html[data-chat-theme="dark"] .brand-logo-for-dark,
html[data-chat-theme="terminal"] .brand-logo-for-dark {
    display: block;
}

.icon-btn,
.send-btn {
    align-items: center;
    background: var(--app-accent);
    border: 0;
    border-radius: 999px;
    color: #fff;
    display: inline-flex;
    font-weight: 700;
    height: 34px;
    justify-content: center;
    text-decoration: none;
    width: 34px;
}

html[data-chat-theme="dark"] .icon-btn,
html[data-chat-theme="dark"] .send-btn,
html[data-chat-theme="terminal"] .icon-btn,
html[data-chat-theme="terminal"] .send-btn {
    background: #eef3f8;
    color: #111318;
}

html[data-chat-theme="dark"] .send-btn {
    background: #f4f8ff;
    color: #162238;
    box-shadow: 0 8px 22px rgba(125, 183, 255, 0.18);
}

.sidebar-nav {
    display: grid;
    gap: 8px;
    margin-top: 26px;
}

.sidebar-link,
.history-link {
    align-items: center;
    border-radius: 999px;
    color: var(--app-text);
    display: flex;
    gap: 10px;
    min-height: 38px;
    padding: 8px 12px;
    text-decoration: none;
}

.sidebar-link i {
    text-align: center;
    width: 18px;
}

.sidebar-link:hover,
.history-link:hover,
.sidebar-link.active {
    background: rgba(255, 255, 255, 0.82);
    color: var(--app-text);
}

.sidebar-link.active {
    background: var(--app-accent);
    color: #fff;
    box-shadow: 0 10px 24px rgba(16, 35, 38, 0.14);
}

html[data-chat-theme="dark"] .sidebar-link:hover,
html[data-chat-theme="dark"] .history-link:hover,
html[data-chat-theme="dark"] .sidebar-link.active,
html[data-chat-theme="terminal"] .sidebar-link:hover,
html[data-chat-theme="terminal"] .history-link:hover,
html[data-chat-theme="terminal"] .sidebar-link.active,
html[data-chat-theme="dark"] .history-row:hover,
html[data-chat-theme="terminal"] .history-row:hover {
    background: rgba(255, 255, 255, 0.08);
}

html[data-chat-theme="dark"] .sidebar-link.active {
    background: rgba(125, 183, 255, 0.14);
    box-shadow: 0 10px 24px rgba(5, 12, 24, 0.16);
}

html[data-chat-theme="dark"] .history-row:hover {
    background: rgba(125, 183, 255, 0.08);
}

.chat-history {
    flex: 1;
    margin-top: 20px;
    min-height: 0;
    overflow: auto;
    padding-top: 2px;
}

.sidebar-label {
    color: var(--app-muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    margin: 0 0 8px 10px;
    text-transform: uppercase;
}

.history-row {
    align-items: center;
    border-radius: 14px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 28px;
}

.history-row:hover {
    background: rgba(255, 255, 255, 0.72);
}

.history-link {
    color: var(--app-text);
    display: grid;
    font-size: 0.92rem;
    gap: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-title,
.history-time {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-time {
    color: var(--app-muted);
    font-size: 0.74rem;
    line-height: 1.25;
}

.history-delete-form {
    display: flex;
    justify-content: center;
    margin: 0;
    opacity: 0;
    pointer-events: none;
}

.history-row:hover .history-delete-form {
    opacity: 1;
    pointer-events: auto;
}

.history-delete-btn {
    align-items: center;
    background: transparent;
    border: 0;
    border-radius: var(--radius-sm);
    color: var(--app-muted);
    display: inline-flex;
    font-size: 1.1rem;
    height: 26px;
    justify-content: center;
    width: 26px;
}

.history-delete-btn:hover,
.history-delete-btn:focus-visible {
    background: #dc3545;
    color: #fff;
}

.history-row:focus-within .history-delete-form {
    opacity: 1;
    pointer-events: auto;
}

.empty-history {
    color: var(--app-muted);
    font-size: 0.9rem;
    margin: 8px 10px;
}

.sidebar-usage {
    background: rgba(255, 255, 255, 0.52);
    border: 1px solid rgba(255, 255, 255, 0.62);
    border-radius: 18px;
    display: grid;
    gap: 7px;
    margin: 8px 0 2px;
    padding: 12px;
}

.sidebar-usage .sidebar-label {
    margin-left: 0;
}

.usage-count {
    color: var(--app-text);
    font-size: 0.95rem;
    font-weight: 700;
}

.usage-progress {
    background: rgba(148, 163, 184, 0.22);
    border-radius: 999px;
    height: 8px;
    overflow: hidden;
}

.usage-progress span {
    background: linear-gradient(90deg, var(--app-green), var(--app-blue));
    border-radius: inherit;
    display: block;
    height: 100%;
    min-width: 0;
}

html[data-chat-theme="dark"] .usage-progress {
    background: rgba(154, 177, 220, 0.2);
}

html[data-chat-theme="dark"] .usage-progress span {
    background: linear-gradient(90deg, #7db7ff, #5de1bd);
}

html[data-chat-theme="dark"] .sidebar-usage,
html[data-chat-theme="terminal"] .sidebar-usage {
    background: rgba(255, 255, 255, 0.055);
    border-color: rgba(154, 177, 220, 0.18);
    box-shadow: none;
}

html[data-chat-theme="terminal"] .usage-progress {
    background: rgba(125, 245, 165, 0.13);
}

html[data-chat-theme="terminal"] .usage-progress span {
    background: linear-gradient(90deg, #7df5a5, #6bd7ff);
}

.usage-reset {
    color: var(--app-muted);
    font-size: 0.78rem;
    line-height: 1.3;
}

.sidebar-footer {
    align-items: center;
    border-top: 0;
    display: flex;
    gap: 10px;
    margin-top: auto;
    padding: 14px 2px 0;
    position: relative;
}

.dock-menu {
    display: inline-flex;
    position: relative;
}

.dock-button,
.dock-popover-button,
.theme-switcher button {
    align-items: center;
    background: rgba(255, 255, 255, 0.84);
    border: 1px solid rgba(105, 123, 145, 0.16);
    border-radius: 999px;
    box-shadow: 0 10px 24px rgba(70, 88, 108, 0.1);
    color: var(--app-text);
    cursor: pointer;
    display: inline-flex;
    height: 38px;
    justify-content: center;
    padding: 0;
    text-decoration: none;
    transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
    width: 38px;
}

.dock-button:hover,
.dock-menu[open] > .dock-button,
.dock-popover-button:hover,
.theme-switcher button:hover,
.theme-switcher button.active {
    background: var(--app-accent);
    color: #fff;
    transform: translateY(-1px);
}

.dock-button::-webkit-details-marker {
    display: none;
}

.dock-button::marker {
    content: "";
}

.dock-popover {
    background: rgba(255, 255, 255, 0.66);
    backdrop-filter: blur(18px);
    border: 1px solid rgba(255, 255, 255, 0.72);
    border-radius: 999px;
    bottom: calc(100% + 10px);
    box-shadow: 0 18px 42px rgba(70, 88, 108, 0.14);
    display: grid;
    gap: 8px;
    left: 0;
    padding: 8px;
    position: absolute;
    z-index: 20;
}

.dock-popover.theme-switcher {
    background: rgba(255, 255, 255, 0.66);
    border: 1px solid rgba(255, 255, 255, 0.72);
    box-shadow: 0 18px 42px rgba(70, 88, 108, 0.14);
    padding: 8px;
}

html[data-chat-theme="dark"] .dock-popover,
html[data-chat-theme="terminal"] .dock-popover {
    background: rgba(22, 32, 52, 0.78);
    border-color: rgba(154, 177, 220, 0.22);
}

html[data-chat-theme="dark"] .dock-button,
html[data-chat-theme="dark"] .dock-popover-button,
html[data-chat-theme="dark"] .theme-switcher button,
html[data-chat-theme="terminal"] .dock-button,
html[data-chat-theme="terminal"] .dock-popover-button,
html[data-chat-theme="terminal"] .theme-switcher button {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(154, 177, 220, 0.22);
    box-shadow: 0 12px 28px rgba(3, 8, 18, 0.22);
    color: var(--app-text);
}

html[data-chat-theme="dark"] .dock-button:hover,
html[data-chat-theme="dark"] .dock-menu[open] > .dock-button,
html[data-chat-theme="dark"] .dock-popover-button:hover,
html[data-chat-theme="dark"] .theme-switcher button:hover,
html[data-chat-theme="dark"] .theme-switcher button.active,
html[data-chat-theme="terminal"] .dock-button:hover,
html[data-chat-theme="terminal"] .dock-menu[open] > .dock-button,
html[data-chat-theme="terminal"] .dock-popover-button:hover,
html[data-chat-theme="terminal"] .theme-switcher button:hover,
html[data-chat-theme="terminal"] .theme-switcher button.active {
    background: var(--app-blue);
    border-color: rgba(125, 183, 255, 0.46);
    color: #08101f;
}

.app-main {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

html[data-chat-theme="dark"] .app-main {
    background: rgba(14, 24, 42, 0.32);
}

.app-topbar {
    background: transparent;
    border-bottom: 0;
    min-height: 70px;
    padding: 12px 10px 12px;
}

html[data-chat-theme="dark"] .app-topbar,
html[data-chat-theme="terminal"] .app-topbar {
    background: rgba(14, 18, 25, 0.7);
}

html[data-chat-theme="dark"] .app-topbar {
    background: rgba(16, 26, 44, 0.58);
}

.app-eyebrow {
    color: var(--app-muted);
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.topbar-actions {
    display: flex;
    gap: 8px;
}

.page-action-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.tenant-settings-header,
.dashboard-page-header {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 12px;
}

.soft-btn,
.dark-btn {
    align-items: center;
    border-radius: 999px;
    display: inline-flex;
    font-weight: 700;
    min-height: 38px;
    padding: 9px 15px;
    text-decoration: none;
}

.soft-btn {
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid var(--app-border);
    color: var(--app-text);
}

.dark-btn {
    background: var(--app-accent);
    color: #fff;
}

.soft-btn:hover,
.dark-btn:hover {
    color: #fff;
    background: var(--app-accent);
}

html[data-chat-theme="dark"] .soft-btn,
html[data-chat-theme="terminal"] .soft-btn {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(154, 177, 220, 0.22);
    color: var(--app-text);
}

html[data-chat-theme="dark"] .dark-btn,
html[data-chat-theme="terminal"] .dark-btn {
    background: var(--app-blue);
    border-color: rgba(125, 183, 255, 0.46);
    color: #08101f;
}

html[data-chat-theme="dark"] .soft-btn:hover,
html[data-chat-theme="terminal"] .soft-btn:hover {
    background: rgba(125, 183, 255, 0.18);
    color: var(--app-text);
}

.app-content {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 16px 10px 26px;
}

.app-content.page-content {
    padding-right: 18px;
}

.settings-side-nav {
    align-content: start;
    display: grid;
    gap: 8px;
    margin-top: 28px;
}

.settings-app-shell {
    grid-template-columns: 260px minmax(0, 1fr);
}

.settings-chat-link {
    font-weight: 800;
    margin-bottom: 18px;
}

.settings-sidebar .sidebar-label {
    margin-top: 4px;
}

.app-content.chat-content {
    overflow: hidden;
    padding: 0;
}

.app-content.page-content {
    scrollbar-width: thin;
}

.page-shell-body {
    overflow: auto;
}

.page-shell-body .app-shell {
    height: auto;
    min-height: calc(100vh - 20px);
    overflow: visible;
}

.page-shell-body .app-main {
    min-height: calc(100vh - 42px);
    overflow: visible;
}

.page-shell-body .app-content.page-content {
    overflow: visible;
    scrollbar-width: auto;
}

.app-content.page-content > h1:first-child,
.app-content.page-content > .d-flex:first-child {
    margin-top: 0;
}

.guest-main {
    margin: 0 auto;
    max-width: 920px;
    padding: 32px 20px;
}

.chat-workspace {
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    height: 100%;
    margin: 0;
    max-width: none;
    width: 100%;
}

.chat-thread {
    min-height: 0;
    overflow-y: auto;
    padding: 26px 38px 18px;
    scrollbar-width: thin;
}

html[data-chat-theme="dark"] .chat-thread {
    background:
        linear-gradient(180deg, rgba(125, 183, 255, 0.035), transparent 34%),
        linear-gradient(135deg, rgba(255, 255, 255, 0.018), rgba(93, 225, 189, 0.025));
}

.chat-empty-state {
    align-items: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: min(50vh, 440px);
    text-align: center;
}

.chat-empty-state h1 {
    font-family: inherit;
    font-size: clamp(2.1rem, 3.1vw, 3.35rem);
    font-weight: 800;
    letter-spacing: 0;
    margin: 18px 0 10px;
    max-width: 620px;
}

.chat-empty-state h1 span {
    display: block;
}

.chat-empty-state p {
    color: var(--app-muted);
    max-width: 620px;
}

.orbital-mark {
    align-items: center;
    background: rgba(255, 255, 255, 0.82);
    border: 1px solid rgba(255, 255, 255, 0.72);
    border-radius: 999px;
    box-shadow: 0 18px 46px rgba(70, 88, 108, 0.12);
    display: flex;
    font-family: inherit;
    font-size: 1.7rem;
    font-weight: 900;
    height: 76px;
    justify-content: center;
    width: 76px;
}

html[data-chat-theme="dark"] .orbital-mark {
    background: linear-gradient(180deg, rgba(44, 59, 88, 0.98), rgba(25, 36, 58, 0.98));
    border-color: rgba(154, 177, 220, 0.3);
    box-shadow: 0 18px 46px rgba(4, 10, 20, 0.28), 0 0 34px rgba(125, 183, 255, 0.12);
    color: #f1f6ff;
}

html[data-chat-theme="terminal"] .orbital-mark {
    color: #10151d;
}

.message-list {
    display: grid;
    gap: 18px;
    margin: 0;
    max-width: none;
    width: 100%;
}

.chat-message {
    display: grid;
    gap: 12px;
    grid-template-columns: 44px minmax(0, 1fr);
    width: 100%;
}

.message-avatar {
    align-items: center;
    background: var(--app-panel-strong);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-sm);
    display: flex;
    font-size: 0.78rem;
    font-weight: 800;
    height: 38px;
    justify-content: center;
}

.message-content {
    background: rgba(255, 255, 255, 0.76);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-md);
    justify-self: start;
    line-height: 1.6;
    max-width: min(720px, calc(100% - 72px));
    padding: 12px 15px;
    position: relative;
    width: auto;
}

html[data-chat-theme="dark"] .message-content {
    background: rgba(30, 42, 64, 0.88);
    box-shadow: 0 12px 34px rgba(5, 12, 24, 0.16);
}

.message-text {
    white-space: pre-wrap;
}

.message-text-block + .message-table-wrap,
.message-table-wrap + .message-text-block {
    margin-top: 12px;
}

.message-table-wrap {
    max-width: 100%;
    overflow-x: auto;
    white-space: normal;
}

.message-table {
    border-collapse: collapse;
    font-size: 0.94rem;
    min-width: 100%;
}

.message-table th,
.message-table td {
    border-bottom: 1px solid rgba(209, 219, 230, 0.9);
    padding: 8px 10px;
    text-align: left;
    vertical-align: top;
}

.message-table th {
    background: rgba(238, 243, 248, 0.82);
    font-weight: 800;
}

html[data-chat-theme="dark"] .message-table th {
    background: rgba(255, 255, 255, 0.08);
}

.message-table tr:last-child td {
    border-bottom: 0;
}

.message-debug-btn {
    align-items: center;
    background: rgba(255, 255, 255, 0.82);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-sm);
    color: var(--app-muted);
    display: inline-flex;
    height: 24px;
    justify-content: center;
    opacity: 0;
    padding: 0;
    position: absolute;
    right: 6px;
    top: 6px;
    transition: opacity 0.12s ease;
    width: 24px;
}

html[data-chat-theme="dark"] .message-debug-btn {
    background: rgba(14, 18, 25, 0.86);
}

.message-debug-btn i {
    display: block;
    font-size: 13px;
    height: auto;
    line-height: 1;
    width: auto;
}

.chat-message.assistant .message-content:hover .message-debug-btn,
.message-debug-btn:focus {
    opacity: 1;
}

.message-debug-btn + .debug-template + .message-text {
    padding-right: 26px;
}

.chat-message.assistant .message-content,
.chat-message.system .message-content {
    justify-self: start;
}

.chat-message.user {
    grid-template-columns: minmax(0, 1fr) 44px;
}

.chat-message.user .message-avatar {
    grid-column: 2;
    grid-row: 1;
}

.chat-message.user .message-content {
    background: rgba(32, 36, 43, 0.92);
    color: #fff;
    grid-column: 1;
    grid-row: 1;
    justify-self: end;
}

html[data-chat-theme="dark"] .chat-message.user .message-content {
    background: rgba(73, 103, 143, 0.92);
}

.chat-message.system .message-avatar {
    background: #fff3cd;
    border-color: #f0c36a;
    color: #7a5400;
}

.chat-message.system .message-content {
    background: rgba(255, 243, 205, 0.88);
    border-color: #f0c36a;
    color: #4f3b0a;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9rem;
}

.schema-change-list {
    display: grid;
    gap: 8px;
    margin: 12px 0 0;
    padding-left: 20px;
}

.schema-change-list ul {
    display: grid;
    gap: 4px;
    margin: 6px 0 0;
    padding-left: 20px;
}

.schema-change-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}

html[data-chat-theme="dark"] .chat-message.system .message-avatar,
html[data-chat-theme="terminal"] .chat-message.system .message-avatar {
    background: rgba(255, 194, 99, 0.12);
    border-color: rgba(255, 194, 99, 0.34);
    color: #f5c36f;
}

html[data-chat-theme="dark"] .chat-message.system .message-content {
    background: rgba(255, 194, 99, 0.1);
    border-color: rgba(255, 194, 99, 0.34);
    color: #f6d59a;
}

.chat-message.loading .message-content {
    align-items: center;
    display: flex;
    gap: 10px;
}

.loading-dots {
    display: inline-flex;
    gap: 4px;
}

.loading-dots span {
    animation: loading-dot 1s infinite ease-in-out;
    background: currentColor;
    border-radius: 999px;
    height: 5px;
    opacity: 0.4;
    width: 5px;
}

.loading-dots span:nth-child(2) {
    animation-delay: 0.15s;
}

.loading-dots span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes loading-dot {
    0%,
    80%,
    100% {
        opacity: 0.35;
        transform: translateY(0);
    }

    40% {
        opacity: 1;
        transform: translateY(-4px);
    }
}

.chat-composer {
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.88);
    border-radius: 18px;
    box-shadow: 0 20px 55px rgba(78, 96, 118, 0.18);
    margin: 0 38px 22px;
    max-width: none;
    padding: 12px;
    transition: padding 0.18s ease, border-radius 0.18s ease;
    width: auto;
}

html[data-chat-theme="dark"] .chat-composer {
    background: rgba(24, 34, 54, 0.9);
    border-color: rgba(154, 177, 220, 0.3);
    box-shadow: 0 18px 46px rgba(5, 12, 24, 0.26), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.composer-toolbar,
.composer-actions {
    align-items: center;
    display: flex;
    justify-content: space-between;
}

.composer-select {
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-sm);
    color: var(--app-text);
    max-width: 320px;
    padding: 8px 10px;
}

.chat-composer textarea {
    background: transparent;
    border: 0;
    color: var(--app-text);
    margin-top: 8px;
    min-height: 64px;
    outline: 0;
    resize: none;
    transition: min-height 0.18s ease, margin 0.18s ease;
    width: 100%;
}

.chat-composer.is-compact {
    border-radius: var(--radius-md);
    padding: 8px 10px;
}

.chat-composer.is-compact textarea {
    margin-top: 0;
    height: 28px;
    min-height: 28px;
    overflow: hidden;
}

.chat-composer.is-compact .composer-hint {
    display: none;
}

.composer-hint {
    color: var(--app-muted);
    font-size: 0.86rem;
}

.query-details {
    background: rgba(255, 255, 255, 0.65);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-md);
    margin: 18px auto;
    max-width: 860px;
    padding: 12px 14px;
}

.query-details summary {
    cursor: pointer;
    font-weight: 700;
}

.query-meta pre {
    background: #111318;
    border-radius: var(--radius-sm);
    color: #e9eef6;
    margin-top: 12px;
    padding: 14px;
    white-space: pre-wrap;
}

.debug-overlay {
    align-items: flex-start;
    background: rgba(17, 19, 24, 0.48);
    display: flex;
    inset: 0;
    justify-content: center;
    padding: 38px 20px;
    position: fixed;
    z-index: 5000;
}

.debug-overlay[hidden] {
    display: none;
}

.debug-modal-open {
    overflow: hidden;
}

.debug-dialog {
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-md);
    box-shadow: 0 24px 80px rgba(15, 23, 42, 0.28);
    max-height: min(78vh, 760px);
    max-width: min(880px, calc(100vw - 40px));
    overflow: hidden;
    width: 100%;
}

html[data-chat-theme="dark"] .debug-dialog,
html[data-chat-theme="terminal"] .debug-dialog {
    background: rgba(18, 24, 33, 0.98);
}

.debug-dialog-header {
    align-items: center;
    border-bottom: 1px solid var(--app-border);
    display: flex;
    justify-content: flex-end;
    padding: 12px 14px;
}

.debug-dialog-close {
    align-items: center;
    background: transparent;
    border: 0;
    border-radius: var(--radius-sm);
    color: var(--app-text);
    display: inline-flex;
    font-size: 1.6rem;
    height: 34px;
    justify-content: center;
    line-height: 1;
    padding: 0;
    width: 34px;
}

.debug-dialog-close:hover,
.debug-dialog-close:focus {
    background: rgba(32, 36, 43, 0.08);
}

.debug-dialog-body {
    color: var(--app-text);
    font-size: 0.9rem;
    line-height: 1.55;
    margin: 0;
    max-height: calc(min(78vh, 760px) - 68px);
    overflow: auto;
    padding: 18px;
}

.debug-dialog-body p {
    font-family: inherit;
    margin: 0;
}

.debug-dialog-body p + p,
.debug-dialog-body p + .debug-sql-wrapper,
.debug-sql-wrapper + p {
    margin-top: 8px;
}

.debug-transfer-section,
.debug-technical-section {
    display: grid;
    gap: 10px;
}

.debug-transfer-section + .debug-technical-section {
    border-top: 1px solid var(--app-border);
    margin-top: 18px;
    padding-top: 18px;
}

.debug-dialog-body h3 {
    font-size: 0.96rem;
    margin: 0;
}

.debug-sql-wrapper {
    margin: 10px 0;
}

.debug-sql-toolbar {
    align-items: center;
    background: #10141c;
    border: 1px solid rgba(246, 248, 251, 0.08);
    border-bottom: 0;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    color: #c9d4e4;
    display: flex;
    font-size: 0.78rem;
    font-weight: 700;
    justify-content: space-between;
    padding: 8px 10px;
}

.debug-sql-actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-end;
}

.debug-copy-sql-btn {
    align-items: center;
    background: rgba(246, 248, 251, 0.08);
    border: 1px solid rgba(246, 248, 251, 0.12);
    border-radius: var(--radius-sm);
    color: #f6f8fb;
    display: inline-flex;
    gap: 6px;
    line-height: 1;
    padding: 7px 9px;
}

.debug-copy-sql-btn i {
    display: block;
    line-height: 1;
}

.debug-copy-sql-btn:hover,
.debug-copy-sql-btn:focus {
    background: rgba(246, 248, 251, 0.16);
}

.debug-sql-block {
    background: #151922;
    border-radius: var(--radius-sm);
    color: #f6f8fb;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.88rem;
    line-height: 1.55;
    margin: 10px 0;
    overflow-x: auto;
    padding: 14px;
    white-space: pre-wrap;
}

.debug-sql-toolbar + .debug-sql-block {
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    margin-top: 0;
}

.debug-dashboard-transfer {
    align-items: center;
    background: rgba(238, 243, 248, 0.78);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-sm);
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px;
}

.debug-dashboard-transfer[hidden] {
    display: none;
}

.debug-dashboard-transfer .form-select {
    max-width: 320px;
}

.chat-alert,
.settings-panel {
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-md);
    padding: 18px;
}

html[data-chat-theme="dark"] .chat-alert,
html[data-chat-theme="dark"] .settings-panel,
html[data-chat-theme="terminal"] .chat-alert,
html[data-chat-theme="terminal"] .settings-panel {
    background: rgba(20, 26, 35, 0.82);
}

.chat-alert {
    margin: 0 auto 18px;
    max-width: 860px;
}

.settings-panel {
    max-width: 760px;
    margin: 0;
}

.tenant-settings {
    display: grid;
    gap: 20px;
    max-width: 1220px;
}

.tenant-settings-header {
    display: flex;
    justify-content: space-between;
}

.tenant-settings-header h1 {
    font-size: 1.35rem;
    margin-bottom: 0;
}

.tenant-settings-header p {
    color: var(--app-muted);
    margin: 0;
}

.workspace-settings-section {
    display: grid;
    gap: 12px;
    scroll-margin-top: 24px;
}

.workspace-section-header {
    align-items: flex-start;
    display: flex;
    gap: 14px;
    justify-content: space-between;
}

.workspace-section-header h2 {
    font-size: 1.15rem;
    margin: 0 0 3px;
}

.workspace-section-header p {
    color: var(--app-muted);
    margin: 0;
}

.tenant-summary {
    background: var(--app-panel-strong);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-md);
    display: grid;
    gap: 1px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: hidden;
}

.tenant-summary > div {
    display: grid;
    gap: 4px;
    padding: 16px;
}

.tenant-summary span,
.tenant-action small {
    color: var(--app-muted);
    font-size: 0.82rem;
}

.tenant-summary strong {
    font-size: 1.05rem;
}

.tenant-action-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.tenant-action {
    align-items: flex-start;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-md);
    color: var(--app-text);
    display: flex;
    gap: 12px;
    padding: 16px;
    text-decoration: none;
}

html[data-chat-theme="dark"] .tenant-action,
html[data-chat-theme="terminal"] .tenant-action {
    background: var(--app-panel-strong);
}

.tenant-action:hover {
    background: var(--app-panel-strong);
    color: var(--app-text);
}

.tenant-action i {
    align-items: center;
    background: var(--app-soft);
    border-radius: var(--radius-sm);
    display: inline-flex;
    height: 34px;
    justify-content: center;
    width: 34px;
}

.tenant-action span {
    display: grid;
    gap: 2px;
}

.workspace-settings-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(12, minmax(0, 1fr));
}

.workspace-settings-card {
    background: var(--app-panel-strong);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-md);
    display: grid;
    gap: 10px;
    min-height: 138px;
    overflow: hidden;
    padding: 14px;
    position: relative;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.workspace-settings-card.span-full {
    min-height: 0;
}

.workspace-settings-card:hover {
    border-color: rgba(102, 150, 200, 0.44);
    transform: translateY(-1px);
}

.workspace-settings-card > * {
    position: relative;
    z-index: 1;
}

.workspace-settings-card header {
    align-items: flex-start;
    display: flex;
    gap: 12px;
    justify-content: space-between;
}

.workspace-settings-card h2,
.workspace-settings-card h3 {
    margin: 0;
}

.workspace-settings-card h2 {
    font-size: 1rem;
}

.workspace-settings-card h3 {
    font-size: 0.95rem;
}

.workspace-settings-card header p,
.workspace-empty-text {
    color: var(--app-muted);
    margin: 2px 0 0;
}

.span-third {
    grid-column: span 4;
}

.span-quarter {
    grid-column: span 3;
}

.span-five {
    grid-column: span 5;
}

.span-half {
    grid-column: span 6;
}

.span-two-thirds {
    grid-column: span 8;
}

.span-full {
    grid-column: 1 / -1;
}

.icon-edit-btn {
    align-items: center;
    background: var(--app-soft);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-sm);
    color: var(--app-text);
    display: inline-flex;
    height: 30px;
    justify-content: center;
    min-width: 30px;
}

.icon-edit-btn:hover {
    border-color: var(--app-blue);
    color: var(--app-blue);
}

.workspace-detail-list,
.connection-card dl {
    display: grid;
    gap: 6px;
    margin: 0;
}

.workspace-detail-list > div,
.connection-card dl > div {
    display: grid;
    gap: 2px;
}

.workspace-detail-list dt,
.connection-card dt {
    color: var(--app-muted);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
}

.workspace-detail-list dd,
.connection-card dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.workspace-chip-list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.workspace-chip-list > div,
.users-stat-grid > div {
    background: rgba(148, 163, 184, 0.09);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-sm);
    padding: 8px;
}

.workspace-metric {
    display: grid;
    gap: 2px;
}

.workspace-metric strong {
    font-size: 1.35rem;
    line-height: 1;
}

.workspace-metric span,
.connection-card span {
    color: var(--app-muted);
}

.workspace-renewal-list {
    display: grid;
    gap: 7px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.workspace-renewal-list li {
    align-items: center;
    border-top: 1px solid var(--app-border);
    display: flex;
    gap: 12px;
    justify-content: space-between;
    font-size: 0.9rem;
    padding-top: 7px;
}

.workspace-renewal-list li > span {
    display: grid;
    gap: 1px;
}

.workspace-renewal-list li small {
    color: var(--app-muted);
}

.workspace-renewal-list li > strong {
    white-space: nowrap;
}

.workspace-renewal-list li:first-child {
    border-top: 0;
    padding-top: 0;
}

.audit-action-card {
    align-content: space-between;
}

.workspace-action-button {
    align-items: center;
    background: var(--app-accent);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--app-panel-strong);
    display: inline-flex;
    font-weight: 700;
    gap: 10px;
    justify-content: space-between;
    padding: 10px 12px;
    text-decoration: none;
}

.workspace-action-button:hover {
    background: var(--app-blue);
    color: #fff;
}

.users-overview {
    align-items: center;
    display: flex;
    gap: 14px;
}

.users-orb {
    align-items: center;
    background: linear-gradient(145deg, rgba(102, 150, 200, 0.22), rgba(126, 107, 255, 0.18));
    border: 1px solid var(--app-border);
    border-radius: 999px;
    color: var(--app-blue);
    display: inline-flex;
    font-size: 1.25rem;
    height: 54px;
    justify-content: center;
    width: 54px;
}

.users-overview strong {
    display: block;
    font-size: 2.6rem;
    line-height: 0.95;
}

.users-overview span {
    color: var(--app-muted);
}

.users-stat-grid {
    display: grid;
    gap: 10px;
    grid-template-columns: minmax(150px, 240px);
    margin: 0;
}

.users-stat-grid dt {
    color: var(--app-muted);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
}

.users-stat-grid dd {
    font-size: 1.1rem;
    font-weight: 800;
    margin: 2px 0 0;
}

.tenant-user-list {
    display: grid;
    gap: 10px;
}

.tenant-user-row {
    align-items: center;
    background: rgba(148, 163, 184, 0.08);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-sm);
    display: grid;
    gap: 12px;
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 10px;
}

.tenant-user-main {
    display: grid;
    gap: 2px;
}

.tenant-user-main span,
.tenant-user-main small,
.tenant-user-row label span {
    color: var(--app-muted);
}

.tenant-user-row label,
.settings-form-grid label {
    display: grid;
    gap: 4px;
}

.tenant-user-row label span,
.settings-form-grid label > span {
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.settings-form-grid {
    display: grid;
    gap: 12px;
}

.settings-check-row {
    align-items: center;
    display: flex;
    gap: 10px;
}

.settings-check-row span {
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: none;
}

.connections-section {
    min-height: 0;
}

.connection-card-grid {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(auto-fill, minmax(210px, 280px));
    justify-content: start;
}

.connection-card {
    background: rgba(255, 255, 255, 0.42);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-md);
    color: var(--app-text);
    display: grid;
    gap: 10px;
    min-height: 132px;
    padding: 12px;
    position: relative;
    text-decoration: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.connection-card-heading {
    align-items: start;
    display: flex;
    gap: 10px;
    justify-content: space-between;
}

.connection-card-description {
    color: var(--app-muted);
    font-size: 0.86rem;
    line-height: 1.35;
    margin: 0;
    overflow-wrap: anywhere;
}

.connection-card:hover {
    border-color: rgba(102, 150, 200, 0.45);
    box-shadow: 0 14px 28px rgba(74, 91, 111, 0.12);
    transform: translateY(-1px);
}

html[data-chat-theme="dark"] .connection-card,
html[data-chat-theme="terminal"] .connection-card {
    background: rgba(255, 255, 255, 0.055);
    border-color: rgba(154, 177, 220, 0.18);
}

html[data-chat-theme="dark"] .connection-card:hover,
html[data-chat-theme="terminal"] .connection-card:hover {
    border-color: rgba(125, 183, 255, 0.4);
    box-shadow: 0 18px 42px rgba(3, 8, 18, 0.24);
}

html[data-chat-theme="dark"] .workspace-settings-card {
    background:
        linear-gradient(145deg, rgba(30, 39, 66, 0.96), rgba(15, 23, 41, 0.96));
    border-color: rgba(132, 154, 198, 0.16);
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.2);
}

html[data-chat-theme="dark"] .workspace-settings-card:hover {
    border-color: rgba(105, 163, 255, 0.34);
    box-shadow: 0 22px 48px rgba(0, 0, 0, 0.28);
}

html[data-chat-theme="dark"] .workspace-settings-card:nth-child(2),
html[data-chat-theme="dark"] .connection-card-add {
    border-color: rgba(126, 107, 255, 0.32);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 16px 36px rgba(0, 0, 0, 0.16);
}

html[data-chat-theme="dark"] .icon-edit-btn,
html[data-chat-theme="dark"] .connection-card-add i {
    background: rgba(125, 183, 255, 0.16);
    border-color: rgba(125, 183, 255, 0.26);
    color: #d7e8ff;
}

html[data-chat-theme="terminal"] .icon-edit-btn,
html[data-chat-theme="terminal"] .connection-card-add i {
    background: rgba(107, 215, 255, 0.12);
    border-color: rgba(107, 215, 255, 0.25);
    color: #9be5ff;
}

html[data-chat-theme="dark"] .workspace-chip-list > div,
html[data-chat-theme="dark"] .users-stat-grid > div,
html[data-chat-theme="dark"] .tenant-user-row {
    background: rgba(255, 255, 255, 0.035);
}

html[data-chat-theme="dark"] .workspace-action-button {
    background: rgba(105, 126, 255, 0.18);
    border-color: rgba(105, 126, 255, 0.28);
    color: #edf3ff;
}

html[data-chat-theme="dark"] .workspace-action-button:hover {
    background: #69a3ff;
    color: #08101f;
}

.connection-card-button {
    align-self: end;
    justify-self: start;
}

.connection-card-add {
    align-items: center;
    border: 2px dashed var(--app-border);
    justify-content: center;
    justify-items: center;
    text-align: center;
}

.connection-card-add i {
    align-items: center;
    background: var(--app-soft);
    border-radius: 999px;
    display: inline-flex;
    font-size: 1.1rem;
    height: 38px;
    justify-content: center;
    width: 38px;
}

.connection-card-add:hover {
    border-color: var(--app-blue);
    color: var(--app-blue);
}

.schema-table-browser {
    display: grid;
    gap: 18px;
}

.schema-table-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

.schema-table-card {
    background: var(--app-panel-strong);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-md);
    color: var(--app-text);
    cursor: pointer;
    display: grid;
    gap: 8px;
    min-height: 150px;
    padding: 18px 16px 16px;
    position: relative;
    text-align: left;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.schema-table-card:hover,
.schema-table-card:focus-visible {
    border-color: rgba(102, 150, 200, 0.45);
    box-shadow: 0 14px 28px rgba(74, 91, 111, 0.12);
    color: var(--app-text);
    outline: 0;
    transform: translateY(-1px);
}

.schema-table-card-meta,
.schema-table-card-key,
.schema-table-modal-summary span,
.schema-field-list-header {
    color: var(--app-muted);
}

.schema-field-list-header {
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.schema-table-card strong {
    font-size: 1.05rem;
    overflow-wrap: anywhere;
}

.schema-table-card-meta {
    display: flex;
    flex-wrap: wrap;
    font-size: 0.82rem;
    gap: 8px;
}

.schema-table-card-key {
    font-size: 0.82rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.schema-table-card.is-excluded {
    border-color: rgba(239, 68, 68, 0.36);
    padding-right: 48px;
}

.schema-table-card-excluded-icon {
    align-items: center;
    background: rgba(239, 68, 68, 0.14);
    border: 1px solid rgba(239, 68, 68, 0.5);
    border-radius: 999px;
    color: #ff7777;
    display: inline-flex;
    font-size: 1rem;
    height: 28px;
    justify-content: center;
    position: absolute;
    right: 12px;
    top: 12px;
    width: 28px;
}

.schema-table-modal .modal-content {
    background: #f8fbfd;
    border: 1px solid var(--app-border);
    color: var(--app-text);
}

.schema-table-modal .modal-header,
.schema-table-modal .modal-footer {
    border-color: var(--app-border);
}

.schema-table-modal .modal-title {
    font-size: 1.35rem;
    margin: 0;
    overflow-wrap: anywhere;
}

.schema-table-modal-summary {
    display: grid;
    gap: 10px;
    grid-template-columns: minmax(220px, 1.4fr) repeat(3, minmax(130px, 1fr));
    margin-bottom: 16px;
}

.schema-table-modal-summary > div,
.schema-toggle {
    background: rgba(148, 163, 184, 0.09);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-sm);
    display: grid;
    gap: 4px;
    padding: 10px 12px;
}

.schema-toggle {
    align-items: center;
    cursor: pointer;
    display: flex;
    gap: 10px;
}

.schema-table-modal-summary strong {
    overflow-wrap: anywhere;
}

.schema-table-description {
    display: grid;
    gap: 6px;
    margin-bottom: 16px;
}

.schema-relation-list {
    background: rgba(148, 163, 184, 0.08);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-md);
    display: grid;
    gap: 8px;
    margin-bottom: 16px;
    padding: 12px;
}

.schema-relation-list h3 {
    font-size: 0.95rem;
    margin: 0;
}

.schema-relation-list ul {
    display: grid;
    gap: 7px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.schema-relation-list li {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    overflow-wrap: anywhere;
}

.schema-relation-list i {
    color: var(--app-blue);
}

.schema-field-list {
    display: grid;
    gap: 8px;
}

.schema-field-list-header,
.schema-field-row {
    display: grid;
    gap: 12px;
    grid-template-columns: minmax(180px, 1fr) 64px minmax(240px, 1.8fr);
}

.schema-field-list-header {
    border-bottom: 1px solid var(--app-border);
    padding: 0 10px 8px;
}

.schema-field-row {
    align-items: center;
    background: rgba(148, 163, 184, 0.07);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-sm);
    padding: 10px;
}

.schema-field-row > div:first-child {
    display: grid;
    gap: 2px;
}

.schema-field-row strong {
    overflow-wrap: anywhere;
}

.schema-field-type {
    color: var(--app-muted);
    font-size: 0.78rem;
    line-height: 1.25;
}

.schema-field-samples {
    color: var(--app-muted);
    font-size: 0.78rem;
    margin-top: 6px;
}

.schema-field-samples summary {
    color: var(--app-blue);
    cursor: pointer;
    font-weight: 700;
}

.schema-field-samples ul {
    display: grid;
    gap: 3px;
    list-style: none;
    margin: 6px 0 0;
    padding: 0;
}

.schema-field-samples li {
    background: rgba(148, 163, 184, 0.1);
    border-radius: 5px;
    overflow-wrap: anywhere;
    padding: 3px 6px;
}

.schema-field-exclude {
    justify-self: center;
}

html[data-chat-theme="dark"] .schema-table-card {
    background:
        linear-gradient(145deg, rgba(31, 44, 70, 0.96), rgba(22, 33, 55, 0.96));
    box-shadow: 0 16px 36px rgba(5, 12, 24, 0.16);
}

html[data-chat-theme="dark"] .schema-table-card:hover,
html[data-chat-theme="dark"] .schema-table-card:focus-visible {
    border-color: rgba(125, 183, 255, 0.42);
    box-shadow: 0 18px 42px rgba(5, 12, 24, 0.28);
}

html[data-chat-theme="dark"] .schema-table-modal-summary > div,
html[data-chat-theme="dark"] .schema-toggle,
html[data-chat-theme="dark"] .schema-relation-list,
html[data-chat-theme="dark"] .schema-field-row {
    background: rgba(255, 255, 255, 0.04);
}

html[data-chat-theme="dark"] .schema-table-modal .modal-content {
    background:
        linear-gradient(145deg, rgba(31, 44, 70, 0.98), rgba(18, 29, 49, 0.98));
    box-shadow: 0 26px 80px rgba(3, 8, 18, 0.46);
}

html[data-chat-theme="dark"] .schema-table-modal .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
    opacity: 0.75;
}

html[data-chat-theme="dark"] .schema-table-card.is-excluded {
    border-color: rgba(248, 113, 113, 0.42);
}

html[data-chat-theme="dark"] .schema-table-card-excluded-icon {
    background: rgba(248, 113, 113, 0.14);
    border-color: rgba(248, 113, 113, 0.55);
    color: #ff8a8a;
}

.tenant-user-quotas {
    background: var(--app-panel-strong);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-md);
    display: grid;
    gap: 14px;
    padding: 16px;
}

.tenant-user-quotas h2 {
    font-size: 1.1rem;
    margin: 0 0 4px;
}

.tenant-user-quotas p {
    color: var(--app-muted);
    margin: 0;
}

.tenant-user-quota-list {
    display: grid;
    gap: 10px;
}

.tenant-user-quota-row {
    align-items: end;
    border-top: 1px solid var(--app-border);
    display: grid;
    gap: 12px;
    grid-template-columns: minmax(0, 1fr) minmax(150px, 190px) auto;
    padding-top: 12px;
}

.tenant-user-quota-main {
    display: grid;
    gap: 2px;
}

.tenant-user-quota-main span,
.tenant-user-quota-main small,
.tenant-user-quota-row label span {
    color: var(--app-muted);
}

.tenant-user-quota-row label {
    display: grid;
    gap: 4px;
}

.tenant-user-quota-row label span {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
}

.audit-primary-meta {
    color: var(--app-muted);
    display: flex;
    flex-wrap: wrap;
    font-size: 0.82rem;
    gap: 10px;
    margin-bottom: 4px;
}

.audit-request-list {
    display: grid;
    gap: 12px;
    max-width: 1080px;
}

.audit-request-card {
    align-items: center;
    background: var(--app-panel-strong);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-md);
    display: grid;
    gap: 16px;
    grid-template-columns: minmax(0, 1fr) auto auto;
    padding: 16px;
}

.audit-request-main {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.audit-request-main span,
.audit-request-main p,
.audit-request-meta dt {
    color: var(--app-muted);
}

.audit-request-main h2 {
    font-size: 1rem;
    margin: 0;
    overflow-wrap: anywhere;
}

.audit-request-main p {
    margin: 0;
}

.audit-request-meta {
    display: flex;
    gap: 10px;
    margin: 0;
}

.audit-request-meta div {
    background: rgba(148, 163, 184, 0.08);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-sm);
    min-width: 86px;
    padding: 8px 10px;
}

.audit-request-meta dt {
    font-size: 0.68rem;
    font-weight: 800;
    text-transform: uppercase;
}

.audit-request-meta dd {
    font-weight: 800;
    margin: 0;
}

.settings-list {
    display: grid;
    gap: 8px 18px;
    grid-template-columns: 160px minmax(0, 1fr);
}

.settings-list dt {
    color: var(--app-muted);
}

.settings-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 20px;
}

.audit-event-list {
    display: grid;
    gap: 14px;
}

.audit-event {
    background: var(--app-panel-strong);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.audit-event header {
    align-items: center;
    border-bottom: 1px solid var(--app-border);
    display: flex;
    justify-content: space-between;
    gap: 14px;
    padding: 12px 14px;
}

.audit-event header span,
.audit-meta {
    color: var(--app-muted);
}

.audit-event header p {
    color: var(--app-muted);
    margin: 3px 0 2px;
}

.audit-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: flex-end;
}

.audit-event pre {
    background: #111722;
    color: #f5f7fb;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.86rem;
    line-height: 1.5;
    margin: 0;
    max-height: 520px;
    overflow: auto;
    padding: 14px;
    white-space: pre-wrap;
}

.audit-json .json-key {
    color: #93c5fd;
}

.audit-json .json-string {
    color: #86efac;
}

.audit-json .json-number {
    color: #fcd34d;
}

.audit-json .json-bool {
    color: #f0abfc;
}

.audit-json .json-null {
    color: #c4b5fd;
}

.audit-json .json-punctuation {
    color: #94a3b8;
}

.dashboard-page {
    display: grid;
    gap: 18px;
}

.dashboard-page-header {
    align-items: flex-start;
    display: flex;
    gap: 16px;
    justify-content: space-between;
}

.dashboard-page-header h1 {
    margin-bottom: 6px;
}

.dashboard-page-header p,
.dashboard-back-link {
    color: var(--app-muted);
    margin: 0;
}

.dashboard-back-link {
    display: inline-flex;
    gap: 8px;
    margin-bottom: 8px;
    text-decoration: none;
}

.dashboard-viewbar {
    align-items: center;
    display: flex;
    justify-content: flex-start;
}

.dashboard-view-toggle {
    background: var(--app-panel-strong);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-sm);
    display: inline-flex;
    gap: 4px;
    padding: 4px;
}

.dashboard-view-toggle a {
    align-items: center;
    border-radius: 6px;
    color: var(--app-muted);
    display: inline-flex;
    gap: 8px;
    padding: 8px 10px;
    text-decoration: none;
}

.dashboard-view-toggle a.active {
    background: var(--app-accent);
    color: var(--app-panel-strong);
}

.dashboard-list {
    display: grid;
    gap: 10px;
    max-width: 920px;
}

.dashboard-list-item {
    align-items: center;
    background: var(--app-panel-strong);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-md);
    color: var(--app-text);
    display: flex;
    justify-content: space-between;
    padding: 14px 16px;
    text-decoration: none;
}

.dashboard-list-item:hover {
    color: var(--app-text);
    transform: translateY(-1px);
}

.dashboard-list-item span:first-child {
    display: grid;
    gap: 2px;
}

.dashboard-list-item small {
    color: var(--app-muted);
}

.dashboard-table-card {
    background: var(--app-panel-strong);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-md);
    overflow-x: auto;
}

.dashboard-overview-table {
    margin: 0;
    min-width: 640px;
}

.dashboard-overview-table th {
    color: var(--app-muted);
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.dashboard-overview-table td,
.dashboard-overview-table th {
    padding: 13px 16px;
    vertical-align: middle;
}

.dashboard-overview-table a {
    color: var(--app-text);
    font-weight: 700;
    text-decoration: none;
}

.dashboard-overview-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.dashboard-overview-card {
    background-position: center;
    background-size: cover;
    border: 1px solid var(--app-border);
    border-radius: var(--radius-md);
    display: grid;
    min-height: 156px;
    overflow: hidden;
    position: relative;
}

.dashboard-overview-card-link {
    color: inherit;
    display: grid;
    gap: 8px;
    min-height: 156px;
    padding: 18px;
    text-decoration: none;
}

.dashboard-overview-card-link:hover {
    color: inherit;
}

.dashboard-overview-card strong {
    font-size: 1.08rem;
}

.dashboard-overview-card span {
    opacity: 0.86;
}

.dashboard-style-btn {
    background: rgba(255, 255, 255, 0.82);
    position: absolute;
    right: 10px;
    top: 10px;
}

.dashboard-card-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.dashboard-card {
    background: var(--app-panel-strong);
    border: 1px solid var(--app-border);
    border-radius: var(--radius-md);
    display: grid;
    gap: 12px;
    min-height: 280px;
    padding: 16px;
}

.dashboard-card header {
    align-items: flex-start;
    display: flex;
    gap: 12px;
    justify-content: space-between;
}

.dashboard-card h2 {
    font-size: 1rem;
    margin: 0 0 4px;
}

.dashboard-card p {
    color: var(--app-muted);
    margin: 0;
}

.card-config-btn {
    align-items: center;
    background: transparent;
    border: 1px solid var(--app-border);
    border-radius: var(--radius-sm);
    color: var(--app-muted);
    display: inline-flex;
    height: 32px;
    justify-content: center;
    width: 32px;
}

.card-config-btn:hover {
    background: var(--app-soft);
    color: var(--app-text);
}

.dashboard-table-wrap {
    max-height: 360px;
    overflow: auto;
}

.dashboard-table {
    margin: 0;
    min-width: 100%;
}

.dashboard-chart-wrap {
    height: 320px;
    min-height: 0;
}

.dashboard-card-error {
    background: rgba(220, 53, 69, 0.12);
    border: 1px solid rgba(220, 53, 69, 0.28);
    border-radius: var(--radius-sm);
    color: #a52834;
    padding: 10px 12px;
}

.dashboard-card-note {
    font-size: 0.84rem;
}

.dashboard-card-delete {
    margin: 0;
}

.dashboard-sql-input {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9rem;
}

html[data-chat-theme="terminal"] .app-shell {
    background: #080c12;
    border-color: rgba(102, 204, 255, 0.18);
    box-shadow: 0 22px 70px rgba(0, 0, 0, 0.46);
}

html[data-chat-theme="terminal"] .app-sidebar,
html[data-chat-theme="terminal"] .app-topbar {
    background: #0b1017;
}

html[data-chat-theme="terminal"] .brand-mark,
html[data-chat-theme="terminal"] .chat-empty-state h1 {
    font-family: inherit;
}

html[data-chat-theme="terminal"] .chat-thread {
    background:
        linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
        #070a0f;
    background-size: 100% 32px;
    padding: 22px 28px 18px;
}

html[data-chat-theme="terminal"] .message-list {
    display: block;
}

html[data-chat-theme="terminal"] .chat-message {
    align-items: start;
    display: grid;
    gap: 10px;
    grid-template-columns: 64px minmax(0, 1fr);
    margin-bottom: 7px;
}

html[data-chat-theme="terminal"] .chat-message.user {
    grid-template-columns: 64px minmax(0, 1fr);
}

html[data-chat-theme="terminal"] .message-avatar,
html[data-chat-theme="terminal"] .chat-message.user .message-avatar {
    background: transparent;
    border: 0;
    border-radius: 0;
    color: #7df5a5;
    display: block;
    font-family: inherit;
    font-size: 0.86rem;
    font-weight: 800;
    grid-column: 1;
    grid-row: 1;
    height: auto;
    justify-content: start;
    line-height: 1.45;
    padding-top: 1px;
    text-align: right;
}

html[data-chat-theme="terminal"] .message-avatar::before {
    content: "<";
}

html[data-chat-theme="terminal"] .message-avatar::after {
    content: ">";
}

html[data-chat-theme="terminal"] .chat-message.assistant .message-avatar {
    color: #6bd7ff;
}

html[data-chat-theme="terminal"] .chat-message.system .message-avatar {
    color: #ffd166;
}

html[data-chat-theme="terminal"] .message-content,
html[data-chat-theme="terminal"] .chat-message.user .message-content {
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    color: #6bd7ff;
    font-family: inherit;
    grid-column: 2;
    grid-row: 1;
    justify-self: stretch;
    line-height: 1.45;
    max-width: none;
    padding: 0;
}

html[data-chat-theme="terminal"] .chat-message.user .message-content {
    color: #7df5a5;
}

html[data-chat-theme="terminal"] .chat-message.system .message-content {
    color: #ffd166;
}

html[data-chat-theme="terminal"] .message-debug-btn {
    background: #101722;
    border-color: rgba(107, 215, 255, 0.3);
    color: #6bd7ff;
    right: 0;
    top: -3px;
}

html[data-chat-theme="terminal"] .message-debug-btn + .debug-template + .message-text {
    padding-right: 32px;
}

html[data-chat-theme="terminal"] .chat-composer {
    background: #0b1017;
    border-color: rgba(125, 245, 165, 0.24);
    border-radius: 0;
    box-shadow: none;
}

html[data-chat-theme="terminal"] .chat-composer textarea {
    caret-color: #7df5a5;
    color: #f1f5f9;
}

html[data-chat-theme="terminal"] .composer-hint {
    color: #6bd7ff;
}

html[data-chat-theme="terminal"] .message-table th {
    background: rgba(107, 215, 255, 0.1);
}

html[data-chat-theme="terminal"] .message-table th,
html[data-chat-theme="terminal"] .message-table td {
    border-color: rgba(107, 215, 255, 0.2);
}

@media (max-width: 900px) {
    .app-body {
        overflow: auto;
    }

    .app-shell,
    .settings-app-shell,
    .page-shell-body .app-shell {
        display: flex;
        flex-direction: column;
        gap: 0;
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;
        overflow: visible;
        padding: 0;
    }

    .mobile-topbar {
        align-items: center;
        backdrop-filter: blur(16px);
        background: var(--app-panel-strong);
        border-bottom: 1px solid var(--app-border);
        display: flex;
        gap: 8px;
        justify-content: space-between;
        padding: 8px 10px;
        padding-top: max(8px, env(safe-area-inset-top));
        position: sticky;
        top: 0;
        z-index: 30;
    }

    .mobile-topbar .brand-logo {
        height: 28px;
    }

    .app-sidebar {
        background: var(--app-bg);
        border-radius: 0 22px 22px 0;
        bottom: 0;
        left: 0;
        max-height: none;
        overflow-y: auto;
        padding-bottom: max(16px, env(safe-area-inset-bottom));
        position: fixed;
        top: 0;
        transform: translateX(-105%);
        transition: transform 0.22s ease, visibility 0s linear 0.22s;
        visibility: hidden;
        width: min(300px, 86vw);
        z-index: 50;
    }

    html[data-chat-theme="dark"] .app-sidebar,
    html[data-chat-theme="terminal"] .app-sidebar {
        background: var(--app-bg);
    }

    body.sidebar-open .app-sidebar {
        transform: none;
        transition: transform 0.22s ease;
        visibility: visible;
    }

    body.sidebar-open {
        overflow: hidden;
    }

    .sidebar-backdrop {
        background: rgba(10, 16, 24, 0.4);
        display: block;
        inset: 0;
        position: fixed;
        z-index: 40;
    }

    .sidebar-backdrop[hidden] {
        display: none;
    }

    .sidebar-footer {
        flex-wrap: wrap;
    }

    .app-main,
    .page-shell-body .app-main {
        flex: 1;
        min-height: 0;
    }

    .app-content.page-content {
        padding: 18px 14px 32px;
    }

    .chat-shell-body,
    .chat-shell-body .app-shell {
        height: 100vh;
        height: 100dvh;
        min-height: 0;
        overflow: hidden;
    }

    .chat-shell-body .app-main {
        overflow: hidden;
    }

    .chat-thread {
        padding: 16px 12px 12px;
    }

    .chat-composer {
        margin: 0 10px max(10px, env(safe-area-inset-bottom));
    }

    .chat-message,
    .chat-message.user {
        grid-template-columns: minmax(0, 1fr);
    }

    .chat-message .message-avatar {
        display: none;
    }

    .message-content {
        max-width: 100%;
    }

    .chat-message.user .message-content {
        grid-column: 1;
        justify-self: end;
        max-width: 86%;
    }

    .tenant-summary,
    .tenant-action-grid,
    .workspace-settings-grid,
    .workspace-chip-list,
    .audit-request-card,
    .users-stat-grid,
    .tenant-user-quota-row,
    .tenant-user-row,
    .schema-table-modal-summary,
    .schema-field-row,
    .dashboard-card-grid {
        grid-template-columns: 1fr;
    }

    .workspace-section-header {
        display: grid;
    }

    .schema-field-list-header {
        display: none;
    }

    .schema-field-row {
        align-items: start;
    }

    .audit-request-meta {
        flex-wrap: wrap;
    }

    .span-quarter,
    .span-third,
    .span-five,
    .span-half,
    .span-two-thirds,
    .span-full {
        grid-column: 1;
    }

    .topbar-actions {
        display: none;
    }
}

@media (hover: none) {
    .history-delete-form,
    .message-debug-btn {
        opacity: 1;
        pointer-events: auto;
    }
}
