:root {
    --bg: #071019;
    --bg-accent: #0e1824;
    --panel: rgba(13, 23, 35, 0.94);
    --panel-strong: rgba(16, 28, 42, 0.98);
    --panel-soft: rgba(11, 20, 30, 0.8);
    --line: rgba(123, 151, 184, 0.16);
    --line-strong: rgba(123, 151, 184, 0.28);
    --text: #f3f5f8;
    --text-soft: #aab8ca;
    --blue: #68b2ff;
    --gold: #caa96b;
    --green: #4fd39a;
    --amber: #f3bb4d;
    --red: #ff6b73;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.32);
    --radius: 22px;
    --radius-sm: 14px;
    --font: "Segoe UI Variable", "Aptos", "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    background:
        radial-gradient(circle at top left, rgba(104, 178, 255, 0.14), transparent 30%),
        radial-gradient(circle at bottom right, rgba(202, 169, 107, 0.16), transparent 24%),
        linear-gradient(160deg, #050c13 0%, #09111a 45%, #060c12 100%);
    color: var(--text);
    font-family: var(--font);
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select {
    font: inherit;
}

code {
    font-family: Consolas, "Courier New", monospace;
}

.panel-body {
    min-height: 100vh;
}

.app-shell {
    display: grid;
    grid-template-columns: 290px 1fr;
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 28px 22px;
    background: linear-gradient(180deg, rgba(9, 16, 25, 0.96), rgba(7, 13, 20, 0.92));
    border-right: 1px solid var(--line);
    backdrop-filter: blur(18px);
}

.sidebar-brand,
.service-card-head,
.section-head,
.topbar,
.topbar-tools,
.dialog-actions,
.rule-card-head,
.toggle-row,
.log-row,
.service-card-actions,
.editor-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.brand-mark {
    width: 52px;
    height: 52px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, rgba(104, 178, 255, 0.22), rgba(202, 169, 107, 0.2));
    color: var(--text);
    font-weight: 700;
    letter-spacing: 0.08em;
    border: 1px solid rgba(202, 169, 107, 0.22);
}

.sidebar-brand h1,
.topbar h2,
.section-card h3,
.login-panel h1,
.login-panel h2 {
    margin: 0;
    font-weight: 650;
}

.sidebar-brand h1 {
    font-size: 1rem;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--gold);
    font-size: 0.72rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.sidebar-nav {
    margin-top: 34px;
    display: grid;
    gap: 8px;
}

.nav-link {
    border: 1px solid transparent;
    border-radius: 16px;
    padding: 14px 16px;
    color: var(--text-soft);
    transition: 0.18s ease;
}

.nav-link:hover,
.nav-link.is-active {
    color: var(--text);
    background: rgba(104, 178, 255, 0.08);
    border-color: rgba(104, 178, 255, 0.16);
}

.sidebar-footer {
    position: absolute;
    left: 22px;
    right: 22px;
    bottom: 24px;
    display: grid;
    gap: 12px;
}

.mini-stat {
    padding: 14px 16px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--line);
}

.mini-stat span,
.muted-copy,
.helper-text,
.kv-list dt,
.summary-grid span,
.status-chip span {
    color: var(--text-soft);
}

.mini-stat strong {
    display: block;
    margin-top: 6px;
}

.main-shell {
    padding: 28px;
}

.topbar {
    margin-bottom: 20px;
    padding: 22px 24px;
    border-radius: var(--radius);
    background: linear-gradient(135deg, rgba(14, 24, 36, 0.96), rgba(10, 18, 29, 0.88));
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}

.topbar-copy {
    margin: 6px 0 0;
    color: var(--text-soft);
}

.topbar-tools {
    flex-wrap: wrap;
    justify-content: flex-end;
}

.status-chip {
    padding: 10px 14px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--line);
    min-width: 120px;
}

.status-chip strong {
    display: block;
    margin-top: 4px;
}

.content-shell,
.card-grid,
.hero-grid,
.detail-grid,
.split-grid,
.summary-grid,
.rules-grid,
.action-grid,
.log-list {
    display: grid;
    gap: 20px;
}

.hero-grid {
    grid-template-columns: 2fr 1fr;
    margin-bottom: 20px;
}

.detail-grid,
.split-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-bottom: 20px;
}

.card-grid.four-up {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-bottom: 20px;
}

.card-grid.two-up {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-bottom: 20px;
}

.summary-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-top: 24px;
}

.summary-grid strong {
    display: block;
    margin-top: 8px;
    font-size: 1.08rem;
}

.section-card {
    padding: 24px;
    border-radius: var(--radius);
    background: linear-gradient(180deg, rgba(13, 22, 33, 0.95), rgba(10, 18, 28, 0.92));
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}

.section-card-wide {
    min-height: 220px;
}

.section-card-tall {
    min-height: 520px;
}

.action-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.button,
.action-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 14px;
    border: 1px solid var(--line-strong);
    padding: 12px 16px;
    cursor: pointer;
    transition: 0.18s ease;
}

.button:hover,
.action-button:hover {
    transform: translateY(-1px);
    border-color: rgba(104, 178, 255, 0.34);
}

.button-primary,
.action-button {
    color: #08111a;
    background: linear-gradient(135deg, var(--gold), #e2c791);
    border-color: rgba(226, 199, 145, 0.4);
    font-weight: 650;
}

.button-secondary {
    color: var(--text);
    background: rgba(104, 178, 255, 0.14);
}

.button-ghost {
    color: var(--text);
    background: rgba(255, 255, 255, 0.03);
}

.button-small {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 0.92rem;
}

.button-block {
    width: 100%;
}

.flash-stack {
    margin-bottom: 20px;
}

.banner {
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px solid var(--line);
    margin-bottom: 10px;
}

.banner-danger {
    background: rgba(255, 107, 115, 0.12);
    border-color: rgba(255, 107, 115, 0.24);
}

.banner-success {
    background: rgba(79, 211, 154, 0.12);
    border-color: rgba(79, 211, 154, 0.24);
}

.auth-setup-stack,
.auth-inline-actions {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    align-items: flex-start;
}

.auth-setup-stack {
    margin-top: 18px;
    margin-bottom: 18px;
}

.auth-setup-inline {
    margin-top: 24px;
}

.qr-panel {
    min-width: 220px;
    padding: 18px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
    display: grid;
    place-items: center;
}

.qr-panel svg {
    width: 100%;
    max-width: 220px;
    height: auto;
    border-radius: 10px;
}

.setup-copy {
    flex: 1;
    min-width: 220px;
}

.secret-pill {
    display: inline-block;
    margin-top: 6px;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid var(--line-strong);
    background: rgba(255, 255, 255, 0.04);
    font-family: Consolas, "Courier New", monospace;
    letter-spacing: 0.08em;
    word-break: break-all;
}

.inline-form,
.compact-form {
    margin-top: 16px;
}

.service-card .muted-copy {
    min-height: 48px;
}

.service-card-actions {
    justify-content: flex-start;
    margin-top: 18px;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 999px;
    display: inline-block;
}

.state-healthy {
    color: var(--green);
}

.state-degraded {
    color: var(--amber);
}

.state-offline {
    color: var(--red);
}

.state-unknown {
    color: var(--text-soft);
}

.status-dot.state-healthy,
.badge.state-healthy,
.meter span {
    background: linear-gradient(90deg, rgba(79, 211, 154, 0.92), rgba(118, 224, 180, 0.92));
}

.status-dot.state-degraded,
.badge.state-degraded {
    background: linear-gradient(90deg, rgba(243, 187, 77, 0.94), rgba(255, 210, 113, 0.94));
}

.status-dot.state-offline,
.badge.state-offline {
    background: linear-gradient(90deg, rgba(255, 107, 115, 0.94), rgba(255, 137, 144, 0.94));
}

.status-dot.state-unknown,
.badge.state-unknown {
    background: rgba(170, 184, 202, 0.32);
}

.badge {
    color: #08111a;
    padding: 10px 14px;
    border-radius: 999px;
    font-weight: 700;
}

.meter {
    height: 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.07);
    overflow: hidden;
}

.meter span {
    display: block;
    height: 100%;
    border-radius: inherit;
}

.metric-card h3 {
    margin: 0 0 16px;
    font-size: 1.6rem;
}

.kv-list {
    display: grid;
    gap: 14px;
    margin: 20px 0 0;
}

.kv-list.compact {
    margin-top: 14px;
    gap: 10px;
}

.kv-list div {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.kv-list dd {
    margin: 0;
    text-align: right;
}

.log-list {
    gap: 14px;
}

.log-row {
    align-items: flex-start;
    padding: 16px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.log-row p {
    margin: 6px 0 0;
    color: var(--text-soft);
}

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

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

.data-table th,
.data-table td {
    padding: 14px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    text-align: left;
    vertical-align: top;
}

.data-table th {
    color: var(--text-soft);
    font-weight: 500;
}

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

.field input,
.field select,
.field textarea {
    width: 100%;
    padding: 13px 14px;
    border-radius: 14px;
    border: 1px solid var(--line-strong);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
}

.toggle-row {
    padding: 18px 0 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    margin-bottom: 24px;
}

.toggle-row small {
    display: block;
    margin-top: 6px;
    color: var(--text-soft);
}

.rules-grid {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.rule-card {
    padding: 18px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    display: grid;
    gap: 16px;
}

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

.map-frame {
    width: 100%;
    min-height: 440px;
    border: 0;
    border-radius: 18px;
    background: #071019;
}

.editor-file-list {
    display: grid;
    gap: 10px;
}

.editor-file-link {
    display: grid;
    gap: 4px;
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-soft);
    transition: 0.18s ease;
}

.editor-file-link:hover,
.editor-file-link.is-active {
    color: var(--text);
    border-color: rgba(104, 178, 255, 0.18);
    background: rgba(104, 178, 255, 0.08);
}

.editor-file-link span,
.editor-meta span {
    color: var(--text-soft);
    font-size: 0.92rem;
}

.editor-meta {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.config-editor-form {
    display: grid;
    gap: 18px;
    margin-top: 22px;
}

.code-editor-shell {
    border-radius: 18px;
    border: 1px solid rgba(104, 178, 255, 0.14);
    background:
        linear-gradient(180deg, rgba(8, 14, 22, 0.98), rgba(9, 16, 25, 0.96));
    overflow: hidden;
}

.code-editor-area {
    min-height: 420px;
    border: 0;
    border-radius: 0;
    resize: vertical;
    background: transparent;
    color: var(--text);
    font-family: Consolas, "Cascadia Code", "Courier New", monospace;
    line-height: 1.6;
    white-space: pre;
}

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

.machine-rule-card {
    margin-top: 24px;
}

.confirm-dialog {
    border: 0;
    padding: 0;
    background: transparent;
}

.confirm-dialog::backdrop {
    background: rgba(5, 10, 15, 0.66);
    backdrop-filter: blur(8px);
}

.confirm-dialog-card {
    width: min(440px, calc(100vw - 32px));
    padding: 24px;
    border-radius: 24px;
    background: linear-gradient(180deg, rgba(15, 24, 37, 0.98), rgba(10, 18, 28, 0.95));
    color: var(--text);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}

.toast-stack {
    position: fixed;
    right: 24px;
    bottom: 24px;
    display: grid;
    gap: 12px;
    z-index: 50;
}

.toast {
    min-width: 220px;
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: rgba(10, 18, 28, 0.96);
    box-shadow: var(--shadow);
}

.toast.is-success {
    border-color: rgba(79, 211, 154, 0.24);
}

.toast.is-error {
    border-color: rgba(255, 107, 115, 0.24);
}

.login-body {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 32px;
}

.login-shell {
    width: min(1080px, 100%);
    display: grid;
    grid-template-columns: 1.2fr 0.9fr;
    border-radius: 30px;
    overflow: hidden;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}

.login-panel {
    padding: 48px;
}

.login-panel-brand {
    background:
        radial-gradient(circle at top left, rgba(104, 178, 255, 0.18), transparent 35%),
        linear-gradient(160deg, rgba(11, 21, 33, 0.98), rgba(8, 14, 22, 0.96));
}

.login-panel-form {
    background: linear-gradient(160deg, rgba(9, 17, 27, 0.98), rgba(7, 13, 20, 0.96));
}

.login-copy {
    max-width: 460px;
    color: var(--text-soft);
    font-size: 1.02rem;
    line-height: 1.65;
}

.login-meta-list {
    margin-top: 40px;
    display: grid;
    gap: 18px;
}

.login-meta-list div {
    padding: 16px 18px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.login-meta-list span {
    display: block;
    color: var(--text-soft);
    margin-bottom: 6px;
}

.login-form {
    display: grid;
    gap: 18px;
    margin-top: 26px;
}

@media (max-width: 1180px) {
    .card-grid.four-up,
    .summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 980px) {
    .app-shell,
    .login-shell,
    .hero-grid,
    .detail-grid,
    .split-grid,
    .card-grid.two-up {
        grid-template-columns: 1fr;
    }

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

    .sidebar-footer {
        position: static;
        margin-top: 24px;
    }

    .topbar,
    .topbar-tools {
        align-items: flex-start;
        flex-direction: column;
    }
}

@media (max-width: 720px) {
    .main-shell,
    .sidebar,
    .login-panel {
        padding: 20px;
    }

    .card-grid.four-up,
    .summary-grid,
    .rules-grid {
        grid-template-columns: 1fr;
    }

    .auth-setup-stack,
    .auth-inline-actions,
    .editor-actions {
        flex-direction: column;
    }

    .editor-meta {
        justify-content: flex-start;
    }
}
