:root {
    --color-primary: #0f172a;
    --color-secondary: #1e293b;
    --color-accent: #22c55e;
    --color-accent-strong: #16a34a;
    --color-background: #020617;
    --color-surface: #0b1220;
    --color-surface-raised: #111b2e;
    --color-muted: #172033;
    --color-border: #334155;
    --color-border-soft: #1e293b;
    --color-foreground: #f8fafc;
    --color-text: #dbe5f1;
    --color-text-muted: #94a3b8;
    --color-warning: #f59e0b;
    --color-danger: #ef4444;
    --color-info: #38bdf8;
    --shadow-card: 0 20px 60px rgb(0 0 0 / 24%);
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 22px;
    --sidebar-width: 252px;
    color-scheme: dark;
    font-family:
        Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system,
        BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    background: var(--color-background);
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--color-text);
    background:
        radial-gradient(circle at 85% 5%, rgb(34 197 94 / 10%), transparent 28rem),
        var(--color-background);
    font-size: 15px;
    line-height: 1.55;
}

button,
input,
select,
textarea {
    font: inherit;
}

button,
a {
    touch-action: manipulation;
}

button {
    cursor: pointer;
}

[hidden] {
    display: none !important;
}

.skip-link {
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: 1000;
    padding: 10px 14px;
    color: var(--color-background);
    background: var(--color-accent);
    border-radius: var(--radius-sm);
    transform: translateY(-150%);
}

.skip-link:focus {
    transform: translateY(0);
}

:focus-visible {
    outline: 3px solid var(--color-info);
    outline-offset: 3px;
}

.login-screen {
    min-height: 100dvh;
    display: grid;
    grid-template-columns: minmax(360px, 520px) minmax(420px, 1fr);
}

.login-panel,
.login-aside {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: clamp(32px, 7vw, 96px);
}

.login-panel {
    background: var(--color-surface);
    border-right: 1px solid var(--color-border-soft);
}

.login-aside {
    position: relative;
    overflow: hidden;
    background:
        linear-gradient(145deg, rgb(15 23 42 / 72%), rgb(2 6 23 / 92%)),
        repeating-linear-gradient(
            90deg,
            transparent 0,
            transparent 47px,
            rgb(51 65 85 / 22%) 48px
        );
}

.login-aside::after {
    content: "";
    position: absolute;
    right: -120px;
    bottom: -160px;
    width: 440px;
    height: 440px;
    border: 80px solid rgb(34 197 94 / 8%);
    border-radius: 50%;
}

.login-aside > * {
    position: relative;
    z-index: 1;
}

.login-aside h2 {
    max-width: 700px;
    margin: 8px 0 48px;
    color: var(--color-foreground);
    font-size: clamp(34px, 5vw, 68px);
    line-height: 1.08;
    letter-spacing: -0.04em;
}

.brand-lockup {
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand-lockup h1 {
    margin: 2px 0 0;
    color: var(--color-foreground);
    font-size: 28px;
    line-height: 1.2;
}

.brand-mark {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
    color: var(--color-background);
    background: var(--color-accent);
    border-radius: 14px 14px 4px 14px;
    font-weight: 800;
    letter-spacing: -0.06em;
}

.eyebrow {
    margin: 0;
    color: var(--color-accent);
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.14em;
}

.login-copy {
    margin: 30px 0;
    color: var(--color-text-muted);
}

.login-hint {
    margin-top: 20px;
    color: var(--color-text-muted);
    font-size: 12px;
}

.form-stack {
    display: grid;
    gap: 18px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.form-grid .field-wide {
    grid-column: 1 / -1;
}

.field {
    display: grid;
    gap: 7px;
    color: var(--color-text);
    font-size: 13px;
    font-weight: 600;
}

.field input,
.field select,
.field textarea,
.toolbar input,
.toolbar select {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    color: var(--color-foreground);
    background: var(--color-background);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    transition: border-color 180ms ease, box-shadow 180ms ease;
}

.field textarea {
    min-height: 96px;
    resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.toolbar input:focus,
.toolbar select:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgb(34 197 94 / 12%);
    outline: 0;
}

.form-error {
    min-height: 22px;
    margin: 0;
    color: #fca5a5;
}

.button {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 14px;
    color: var(--color-text);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-weight: 700;
    transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease;
}

.button:hover {
    background: rgb(148 163 184 / 8%);
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.46;
}

.button-primary {
    color: var(--color-background);
    background: var(--color-accent);
    border-color: var(--color-accent);
}

.button-primary:hover {
    background: var(--color-accent-strong);
    border-color: var(--color-accent-strong);
}

.button-secondary {
    color: var(--color-foreground);
    background: var(--color-secondary);
    border-color: var(--color-border);
}

.button-danger {
    color: #fecaca;
    background: rgb(239 68 68 / 9%);
    border-color: rgb(239 68 68 / 32%);
}

.button-ghost {
    border-color: var(--color-border-soft);
}

.button-small {
    min-height: 32px;
    padding: 5px 9px;
    font-size: 12px;
}

.button-block {
    width: 100%;
}

.flow-list {
    max-width: 700px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.flow-list li {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px;
    background: rgb(15 23 42 / 70%);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}

.flow-list span {
    color: var(--color-accent);
    font-family: Consolas, monospace;
}

.console {
    min-height: 100dvh;
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: 24px 16px;
    background: rgb(11 18 32 / 96%);
    border-right: 1px solid var(--color-border-soft);
}

.brand-lockup-compact {
    padding: 0 8px 24px;
}

.brand-lockup-compact .brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 11px 11px 3px 11px;
    font-size: 13px;
}

.brand-lockup-compact strong {
    display: block;
    margin-top: 3px;
    color: var(--color-foreground);
    font-size: 15px;
}

.primary-nav {
    display: grid;
    gap: 5px;
}

.primary-nav button {
    min-height: 44px;
    display: grid;
    grid-template-columns: 34px 1fr;
    align-items: center;
    padding: 9px 12px;
    color: var(--color-text-muted);
    text-align: left;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-weight: 650;
}

.primary-nav button:hover {
    color: var(--color-foreground);
    background: rgb(148 163 184 / 7%);
}

.primary-nav button[aria-current="page"] {
    color: var(--color-foreground);
    background: rgb(34 197 94 / 10%);
    border-color: rgb(34 197 94 / 25%);
}

.nav-index {
    color: var(--color-text-muted);
    font-family: Consolas, monospace;
    font-size: 10px;
}

.primary-nav button[aria-current="page"] .nav-index {
    color: var(--color-accent);
}

.sidebar-footer {
    margin-top: auto;
    display: grid;
    gap: 12px;
    padding: 18px 8px 0;
    border-top: 1px solid var(--color-border-soft);
}

.user-summary {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-summary strong,
.user-summary small {
    display: block;
}

.user-summary small {
    color: var(--color-text-muted);
}

.user-avatar {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    color: var(--color-background);
    background: #a7f3d0;
    border-radius: 50%;
    font-weight: 800;
}

.main-content {
    min-width: 0;
    padding: 32px clamp(20px, 4vw, 56px) 56px;
}

.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin: 0 auto 28px;
    max-width: 1500px;
}

.topbar h1 {
    margin: 4px 0;
    color: var(--color-foreground);
    font-size: clamp(28px, 3vw, 40px);
    line-height: 1.15;
    letter-spacing: -0.035em;
}

.page-description {
    margin: 0;
    color: var(--color-text-muted);
}

.page-content {
    max-width: 1500px;
    margin: 0 auto;
}

.section-gap {
    height: 16px;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.metric-card,
.panel {
    background: linear-gradient(180deg, rgb(17 27 46 / 94%), rgb(9 16 29 / 96%));
    border: 1px solid var(--color-border-soft);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
}

.metric-card {
    min-height: 130px;
    padding: 18px;
}

.metric-card small {
    display: block;
    color: var(--color-text-muted);
    font-weight: 650;
}

.metric-value {
    display: block;
    margin: 14px 0 4px;
    color: var(--color-foreground);
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 32px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.metric-meta {
    color: var(--color-text-muted);
    font-size: 12px;
}

.content-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(300px, 0.7fr);
    gap: 16px;
    margin-top: 16px;
}

.panel {
    min-width: 0;
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 17px 18px;
    border-bottom: 1px solid var(--color-border-soft);
}

.panel-header h2,
.dialog-header h2 {
    margin: 2px 0 0;
    color: var(--color-foreground);
    font-size: 17px;
}

.panel-body {
    padding: 18px;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 10px;
    margin-bottom: 14px;
}

.toolbar .field {
    min-width: 180px;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

th,
td {
    padding: 12px 14px;
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px solid var(--color-border-soft);
}

th {
    color: var(--color-text-muted);
    background: rgb(2 6 23 / 46%);
    font-size: 11px;
    font-weight: 750;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

tbody tr {
    transition: background-color 160ms ease;
}

tbody tr:hover {
    background: rgb(148 163 184 / 5%);
}

tbody tr:last-child td {
    border-bottom: 0;
}

.mono {
    font-family: "SFMono-Regular", Consolas, monospace;
    font-variant-numeric: tabular-nums;
}

.truncate {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 26px;
    padding: 3px 9px;
    color: var(--color-text-muted);
    background: rgb(148 163 184 / 8%);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    font-size: 11px;
    font-weight: 750;
}

.status::before {
    content: "";
    width: 7px;
    height: 7px;
    background: currentColor;
    border-radius: 50%;
}

.status-success {
    color: #86efac;
    background: rgb(34 197 94 / 8%);
    border-color: rgb(34 197 94 / 24%);
}

.status-warning {
    color: #fcd34d;
    background: rgb(245 158 11 / 8%);
    border-color: rgb(245 158 11 / 24%);
}

.status-danger {
    color: #fca5a5;
    background: rgb(239 68 68 / 8%);
    border-color: rgb(239 68 68 / 24%);
}

.status-info {
    color: #7dd3fc;
    background: rgb(56 189 248 / 8%);
    border-color: rgb(56 189 248 / 24%);
}

.empty-state,
.loading-state {
    display: grid;
    place-items: center;
    min-height: 180px;
    padding: 32px;
    color: var(--color-text-muted);
    text-align: center;
}

.loading-state::before {
    content: "";
    width: 24px;
    height: 24px;
    margin-bottom: 12px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-accent);
    border-radius: 50%;
    animation: spin 800ms linear infinite;
}

.integration-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.integration-card {
    min-height: 220px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px;
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border-soft);
    border-radius: var(--radius-md);
}

.integration-card h2 {
    margin: 0;
    color: var(--color-foreground);
    font-size: 19px;
}

.integration-card p {
    margin: 0;
    color: var(--color-text-muted);
}

.integration-card .actions {
    margin-top: auto;
}

.key-value {
    display: grid;
    grid-template-columns: minmax(120px, 0.4fr) minmax(0, 1fr);
    gap: 8px 18px;
    margin: 0;
}

.key-value dt {
    color: var(--color-text-muted);
}

.key-value dd {
    margin: 0;
    color: var(--color-foreground);
    overflow-wrap: anywhere;
}

.dialog {
    width: min(900px, calc(100vw - 32px));
    max-height: calc(100dvh - 32px);
    padding: 0;
    color: var(--color-text);
    background: transparent;
    border: 0;
}

.dialog::backdrop {
    background: rgb(0 0 0 / 64%);
    backdrop-filter: blur(4px);
}

.dialog-card {
    max-height: calc(100dvh - 32px);
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    overflow: hidden;
}

.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--color-border-soft);
}

.dialog-content {
    overflow: auto;
    padding: 20px;
}

.json-block {
    overflow: auto;
    margin: 0;
    padding: 16px;
    color: #bbf7d0;
    background: #020617;
    border: 1px solid var(--color-border-soft);
    border-radius: var(--radius-sm);
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 12px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.detail-section {
    padding: 18px;
    background: rgb(15 23 42 / 58%);
    border: 1px solid var(--color-border-soft);
    border-radius: var(--radius-md);
}

.detail-section + .detail-section,
.detail-section + .price-notice,
.price-notice + .raw-details {
    margin-top: 14px;
}

.detail-grid {
    grid-template-columns: minmax(130px, 0.32fr) minmax(0, 1fr);
}

.detail-grid dt,
.detail-grid dd {
    padding: 5px 0;
}

.detail-section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.detail-section-heading h3 {
    margin: 2px 0 0;
    color: var(--color-foreground);
    font-size: 17px;
}

.price-notice {
    display: grid;
    gap: 4px;
    padding: 15px 18px;
    color: #fde68a;
    background: rgb(245 158 11 / 8%);
    border: 1px solid rgb(245 158 11 / 25%);
    border-radius: var(--radius-md);
}

.price-notice span {
    color: var(--color-text-muted);
}

.raw-details {
    margin-top: 14px;
}

.raw-details summary {
    min-height: 44px;
    display: flex;
    align-items: center;
    color: var(--color-text-muted);
    cursor: pointer;
}

.raw-details[open] summary {
    color: var(--color-foreground);
}

.toast-region {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 100;
    width: min(380px, calc(100vw - 36px));
    display: grid;
    gap: 8px;
    pointer-events: none;
}

.toast {
    padding: 13px 15px;
    color: var(--color-foreground);
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border);
    border-left: 4px solid var(--color-accent);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-card);
}

.toast-error {
    border-left-color: var(--color-danger);
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 1100px) {
    .metric-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .integration-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    .login-screen {
        grid-template-columns: 1fr;
    }

    .login-aside {
        display: none;
    }

    .console {
        display: block;
    }

    .sidebar {
        position: static;
        width: 100%;
        height: auto;
        padding: 16px;
        border-right: 0;
        border-bottom: 1px solid var(--color-border-soft);
    }

    .brand-lockup-compact {
        padding-bottom: 14px;
    }

    .primary-nav {
        display: flex;
        overflow-x: auto;
        padding-bottom: 4px;
    }

    .primary-nav button {
        min-width: 128px;
    }

    .sidebar-footer {
        grid-template-columns: 1fr auto;
        align-items: center;
        margin-top: 12px;
        padding-top: 12px;
    }

    .main-content {
        padding-top: 24px;
    }
}

@media (max-width: 700px) {
    body {
        font-size: 16px;
    }

    .login-panel {
        min-height: 100dvh;
        padding: 28px 20px;
        border-right: 0;
    }

    .main-content {
        padding: 20px 14px 40px;
    }

    .topbar {
        align-items: stretch;
        flex-direction: column;
        gap: 14px;
    }

    .metric-grid,
    .content-grid,
    .form-grid,
    .flow-list {
        grid-template-columns: 1fr;
    }

    .table-wrap {
        overflow: visible;
    }

    table,
    thead,
    tbody,
    tr,
    th,
    td {
        display: block;
    }

    thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
    }

    tbody {
        display: grid;
        gap: 10px;
        padding: 12px;
    }

    tbody tr {
        padding: 10px 12px;
        background: rgb(2 6 23 / 36%);
        border: 1px solid var(--color-border-soft);
        border-radius: var(--radius-sm);
    }

    tbody td {
        display: grid;
        grid-template-columns: minmax(90px, 0.38fr) minmax(0, 1fr);
        gap: 10px;
        padding: 7px 0;
        border: 0;
    }

    tbody td::before {
        content: attr(data-label);
        color: var(--color-text-muted);
        font-size: 12px;
        font-weight: 700;
    }

    .truncate {
        max-width: none;
        white-space: normal;
    }

    .actions {
        grid-column: 1 / -1;
    }

    .button {
        min-height: 44px;
    }

    .key-value {
        grid-template-columns: 1fr;
    }

    .detail-grid dt {
        padding-bottom: 0;
    }

    .detail-grid dd {
        padding-top: 0;
        padding-bottom: 10px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
