:root {
    --bg: #f4f6f7;
    --surface: #ffffff;
    --surface-2: #eef2f4;
    --surface-3: #f9fafb;
    --text: #172026;
    --muted: #60717d;
    --line: #d8e0e5;
    --accent: #0f766e;
    --accent-strong: #0b5f59;
    --warning: #a16207;
    --danger: #b42318;
    --ok: #177245;
    --nav: #17242b;
    --shadow: 0 12px 28px rgba(23, 32, 38, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-width: 320px;
    color: var(--text);
    background: var(--bg);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
}

button,
input,
select,
textarea {
    font: inherit;
    letter-spacing: 0;
}

button,
.link-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    border: 1px solid var(--accent);
    border-radius: 6px;
    padding: 8px 12px;
    color: #ffffff;
    background: var(--accent);
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
}

button:hover,
.link-button:hover {
    background: var(--accent-strong);
}

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

button.secondary,
.secondary-link-button {
    color: var(--text);
    border-color: var(--line);
    background: var(--surface);
}

button.secondary:hover,
.secondary-link-button:hover {
    background: var(--surface-2);
}

button.danger {
    border-color: var(--danger);
    background: var(--danger);
}

.icon-button {
    width: 34px;
    min-height: 34px;
    padding: 0;
    border-color: var(--line);
    color: var(--text);
    background: var(--surface);
}

input,
select,
textarea {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 10px;
    color: var(--text);
    background: #ffffff;
}

input[readonly] {
    color: var(--muted);
    background: var(--surface-2);
}

textarea {
    min-height: 130px;
    resize: vertical;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 0.86rem;
    line-height: 1.45;
}

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 0.84rem;
    font-weight: 700;
}

.form-help {
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px 12px;
    color: var(--muted);
    background: var(--surface-3);
    font-size: 0.88rem;
    line-height: 1.45;
}

.app-shell {
    display: grid;
    min-height: 100vh;
    grid-template-columns: 252px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    display: flex;
    height: 100vh;
    flex-direction: column;
    gap: 22px;
    border-right: 1px solid #263841;
    background: var(--nav);
    padding: 22px;
    color: #f8fbfc;
}

.brand {
    display: grid;
    gap: 4px;
}

.brand strong {
    font-size: 1.3rem;
    line-height: 1.1;
}

.brand span,
.eyebrow {
    color: #9fb0ba;
    font-size: 0.78rem;
    text-transform: uppercase;
}

.nav {
    display: grid;
    gap: 8px;
}

.nav-button {
    justify-content: flex-start;
    width: 100%;
    border-color: transparent;
    color: #dce6eb;
    background: transparent;
    text-align: left;
}

.nav-button:hover,
.nav-button.active {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.12);
}

.workspace {
    min-width: 0;
    padding: 26px;
}

.topbar,
.section-header,
.panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
}

.topbar {
    margin-bottom: 20px;
}

.topbar h1,
.section-header h2 {
    margin: 0;
    line-height: 1.1;
}

.topbar h1 {
    font-size: clamp(1.5rem, 2vw, 2.2rem);
}

.section-header {
    align-items: end;
    margin-bottom: 14px;
}

.section-header h2 {
    font-size: 1.3rem;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--muted);
}

.topbar-actions,
.toolbar,
.form-actions,
.action-bar,
td.actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.notice {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
    border: 1px solid var(--line);
    border-left: 4px solid var(--accent);
    border-radius: 8px;
    padding: 12px 12px 12px 14px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.notice.error {
    border-left-color: var(--danger);
}

.notice.ok {
    border-left-color: var(--ok);
}

.notice strong,
.notice p {
    margin: 0;
}

.notice p {
    margin-top: 4px;
    color: var(--muted);
}

.notice pre {
    max-height: 180px;
    margin: 10px 0 0;
    overflow: auto;
    white-space: pre-wrap;
    color: #f3f8fb;
    background: #17242b;
    border-radius: 6px;
    padding: 10px;
    font-size: 0.82rem;
}

.view {
    display: none;
}

.view.active {
    display: block;
}

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

.metric,
.panel,
.modal-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.metric {
    display: grid;
    gap: 8px;
    min-height: 104px;
    padding: 18px;
}

.metric span {
    color: var(--muted);
    font-size: 0.85rem;
}

.metric strong {
    font-size: 2rem;
    line-height: 1;
}

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

.tenants-list-panel {
    width: 100%;
}

.users-list-panel {
    width: 100%;
}

.two-columns {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.admin-grid {
    grid-template-columns: minmax(420px, 1.05fr) minmax(360px, 0.95fr);
}

.panel {
    min-width: 0;
    overflow: hidden;
}

.stacked-panel {
    display: grid;
    align-content: start;
}

.panel-header {
    align-items: center;
    border-bottom: 1px solid var(--line);
    padding: 13px 16px;
}

.panel-header h2,
.panel-header h3 {
    margin: 0;
    font-size: 1rem;
    line-height: 1.2;
}

.form-panel {
    display: grid;
    align-content: start;
    gap: 12px;
    padding: 0 16px 16px;
}

.form-panel > .panel-header,
.embedded-form > .panel-header {
    margin: 0 -16px 2px;
}

.embedded-form {
    box-shadow: none;
}

.divider-top {
    border-top: 1px solid var(--line);
}

.textarea-label {
    margin-top: 4px;
}

.selection-badge {
    max-width: 190px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 4px 9px;
    color: var(--muted);
    background: var(--surface-3);
    font-size: 0.78rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.form-actions {
    margin-top: 4px;
}

.action-bar {
    border-top: 1px solid var(--line);
    padding-top: 12px;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

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

.toolbar {
    margin-bottom: 14px;
}

.toolbar label {
    min-width: min(420px, 100%);
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    min-width: 620px;
    border-collapse: collapse;
}

.tenants-table {
    min-width: 860px;
}

.users-table {
    min-width: 760px;
}

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

th {
    color: var(--muted);
    background: var(--surface-3);
    font-size: 0.76rem;
    font-weight: 800;
    text-transform: uppercase;
}

td {
    font-size: 0.9rem;
}

td.actions {
    justify-content: flex-end;
    white-space: nowrap;
}

.selected-row {
    background: #eef8f6;
}

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

.missing-value {
    color: var(--danger);
    font-weight: 700;
}

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

.chip {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    border-radius: 999px;
    padding: 3px 9px;
    color: var(--accent-strong);
    background: #dff3ef;
    font-size: 0.78rem;
    font-weight: 800;
}

.chip.warning {
    color: var(--warning);
    background: #fff2d8;
}

.chip.danger {
    color: var(--danger);
    background: #ffe2de;
}

.uuid,
code {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 0.8rem;
    word-break: break-all;
}

.output-block {
    min-height: 360px;
    margin: 0;
    padding: 16px;
    overflow: auto;
    color: #d5f3e7;
    background: #13201b;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 0.84rem;
    line-height: 1.45;
}

.modal-dialog {
    width: min(760px, calc(100vw - 32px));
    max-width: 100%;
    border: 0;
    padding: 0;
    color: var(--text);
    background: transparent;
}

.modal-dialog.wide-dialog {
    width: min(980px, calc(100vw - 32px));
}

.modal-dialog::backdrop {
    background: rgba(23, 32, 38, 0.48);
}

.modal-panel {
    max-height: calc(100vh - 48px);
    margin: 0;
    overflow: hidden;
}

.modal-panel.form-panel {
    gap: 0;
    padding: 0;
}

.modal-panel > .panel-header {
    margin: 0;
}

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

.modal-body {
    display: grid;
    max-height: calc(100vh - 184px);
    overflow: auto;
    gap: 12px;
    padding: 16px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    border-top: 1px solid var(--line);
    padding: 14px 16px;
    background: var(--surface-3);
}

.tenant-create-only,
.tenant-edit-only,
.user-edit-only {
    display: grid;
    gap: 12px;
}

.action-bar.user-edit-only {
    display: flex;
}

.modal-section-form {
    padding: 0;
}

.modal-subsection {
    border-top: 1px solid var(--line);
    padding-top: 14px;
}

.modal-subsection-header h3 {
    margin: 0;
    font-size: 1rem;
    line-height: 1.2;
}

.user-access-table table {
    min-width: 680px;
}

[hidden] {
    display: none !important;
}

.auth-page,
.welcome-page {
    min-height: 100vh;
    padding: 32px;
}

.auth-page {
    display: grid;
    place-items: center;
}

.auth-panel {
    display: grid;
    width: min(420px, 100%);
    gap: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 24px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.auth-panel h1,
.welcome-header h1 {
    margin: 0;
}

.secondary-link {
    color: var(--accent-strong);
    text-align: center;
}

.welcome-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 20px;
}

.definition-list {
    display: grid;
    grid-template-columns: 140px minmax(0, 1fr);
    gap: 12px;
    margin: 0;
    padding: 18px;
}

.definition-list dt {
    color: var(--muted);
    font-weight: 700;
}

.definition-list dd {
    margin: 0;
    min-width: 0;
    word-break: break-word;
}

.pluginbase-section {
    margin-top: 18px;
}

.pluginbase-frame {
    display: block;
    width: 100%;
    min-height: 620px;
    border: 0;
    background: var(--surface);
}

.empty-state {
    margin: 0;
    padding: 18px;
    color: var(--muted);
}

.loading-panel {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px;
    color: var(--muted);
}

.loading-dot {
    width: 12px;
    height: 12px;
    border: 2px solid var(--line);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

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

    .sidebar {
        position: static;
        height: auto;
    }

    .nav {
        grid-template-columns: repeat(3, minmax(120px, 1fr));
    }

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

@media (max-width: 680px) {
    .workspace,
    .sidebar,
    .auth-page,
    .welcome-page {
        padding: 16px;
    }

    .topbar,
    .section-header {
        display: grid;
    }

    .nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .metric-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    button,
    .link-button {
        width: 100%;
        white-space: normal;
    }

    .icon-button {
        width: 34px;
    }

    .form-actions,
    .action-bar,
    td.actions {
        align-items: stretch;
    }
}
