:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-soft: #dbeafe;
    --success: #15803d;
    --success-soft: #dcfce7;
    --warning: #c2410c;
    --warning-soft: #ffedd5;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --text: #0f172a;
    --text-soft: #475569;
    --text-muted: #64748b;
    --line: #dbe4f0;
    --line-strong: #cbd5e1;
    --bg: #f3f7fc;
    --bg-panel: #ffffff;
    --bg-soft: #f8fbff;
    --shadow-sm: 0 8px 20px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 18px 48px rgba(15, 23, 42, 0.12);
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 18px;
    --space-sm: 10px;
    --space-md: 16px;
    --space-lg: 24px;
    --sidebar-width: 240px;
    --font-base: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; min-height: 100%; }

body {
    font-family: var(--font-base);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
img { max-width: 100%; display: block; }
button, input, select, textarea {
    font: inherit;
}

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

.sidebar {
    background: linear-gradient(180deg, #0f172a 0%, #172554 100%);
    color: rgba(255, 255, 255, 0.88);
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    position: sticky;
    top: 0;
    min-height: 100vh;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #fff;
}

.brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.16);
    font-weight: 700;
}

.brand-copy {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.brand-copy strong { font-size: 1rem; }
.brand-copy small { color: rgba(255, 255, 255, 0.66); font-size: 0.8rem; }

.user-card {
    padding: 14px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.08);
}

.user-card-name { font-weight: 600; }
.user-card-role { color: rgba(255, 255, 255, 0.68); font-size: 0.85rem; margin-top: 4px; }

.nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.nav a {
    color: rgba(255, 255, 255, 0.72);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    transition: background 0.2s ease, color 0.2s ease;
}

.nav a:hover,
.nav a.active {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
}

.sidebar-footer { margin-top: auto; }

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

.page-shell {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.page-header,
.section-head,
.section-head-split,
.sub-card-head,
.overlay-head,
.pagination-bar,
.toolbar,
.action-row,
.table-actions,
.console-topbar-actions,
.mini-metrics,
.split-layout,
.summary-grid {
    display: flex;
    gap: var(--space-md);
}

.page-header,
.section-head,
.section-head-split,
.overlay-head,
.pagination-bar,
.console-topbar,
.console-layout,
.split-layout,
.summary-grid {
    align-items: flex-start;
}

.page-header,
.section-head-split,
.overlay-head,
.pagination-bar,
.console-topbar,
.console-layout,
.split-layout {
    justify-content: space-between;
}

.page-header h1 {
    margin: 6px 0 0;
    font-size: 1.85rem;
    line-height: 1.2;
}

.section-head h2,
.section-head-split h2,
.sub-card-head h3,
.overlay-head h3 {
    margin: 0;
    font-size: 1.05rem;
    line-height: 1.3;
}

.page-note,
.section-note,
.result-note,
.cell-meta,
.helper-note,
.save-hint,
.metric-meta,
.text-muted {
    color: var(--text-muted);
}

.page-note,
.section-note,
.result-note,
.helper-note,
.save-hint,
.metric-meta {
    margin: 6px 0 0;
    font-size: 0.92rem;
}

.eyebrow {
    margin: 0;
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--primary);
}

.card,
.metric-card,
.sub-card,
.result-panel {
    background: var(--bg-panel);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.card,
.sub-card {
    padding: 20px;
}

.card-narrow {
    max-width: 720px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric-card {
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

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

.metric-label {
    font-size: 0.88rem;
    color: var(--text-soft);
}

.alert {
    border-radius: var(--radius-md);
    padding: 12px 14px;
    border: 1px solid transparent;
    font-size: 0.92rem;
}

.alert-success {
    color: var(--success);
    background: var(--success-soft);
    border-color: rgba(21, 128, 61, 0.15);
}

.alert-error {
    color: var(--danger);
    background: var(--danger-soft);
    border-color: rgba(220, 38, 38, 0.15);
}

.alert-warning {
    color: var(--warning);
    background: var(--warning-soft);
    border-color: rgba(194, 65, 12, 0.15);
}

.btn {
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 9px 14px;
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
    white-space: nowrap;
}

.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: 0.65; cursor: not-allowed; transform: none; }

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover { background: var(--primary-hover); color: #fff; }

.btn-secondary {
    background: var(--bg-soft);
    border-color: var(--line);
    color: var(--text);
}

.btn-secondary:hover {
    background: #eef4fb;
    color: var(--text);
}

.btn-warning {
    background: var(--warning-soft);
    border-color: rgba(194, 65, 12, 0.15);
    color: var(--warning);
}

.btn-danger {
    background: var(--danger-soft);
    border-color: rgba(220, 38, 38, 0.15);
    color: var(--danger);
}

.btn-block { width: 100%; }
.btn-sm { min-height: 34px; padding: 7px 12px; }
.btn-xs { min-height: 30px; padding: 5px 10px; font-size: 0.85rem; }

.btn-spinner {
    width: 14px;
    height: 14px;
    border-radius: 999px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    display: none;
    animation: spin 0.7s linear infinite;
}

.btn.is-loading .btn-spinner,
.btn[aria-busy="true"] .btn-spinner {
    display: inline-block;
}

.btn.is-loading .btn-text,
.btn[aria-busy="true"] .btn-text {
    opacity: 0.8;
}

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

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-md);
}

.form-grid-compact {
    gap: 14px;
}

.form-grid label,
.inline-select {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-grid label > span,
.inline-select > span {
    font-size: 0.88rem;
    color: var(--text-soft);
}

.full-width { grid-column: 1 / -1; }

input[type="text"],
input[type="url"],
input[type="password"],
input[type="number"],
select,
textarea {
    width: 100%;
    background: #fff;
    color: var(--text);
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    min-height: 40px;
    padding: 10px 12px;
    outline: none;
    transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

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

input:focus,
select:focus,
textarea:focus {
    border-color: rgba(37, 99, 235, 0.5);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

.switch-field {
    justify-content: space-between;
    align-items: center;
    flex-direction: row !important;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--bg-soft);
}

.switch-field input[type="checkbox"] {
    width: 42px;
    height: 24px;
    appearance: none;
    border-radius: 999px;
    background: #cbd5e1;
    position: relative;
    border: none;
    padding: 0;
    min-height: 24px;
}

.switch-field input[type="checkbox"]::after {
    content: "";
    width: 18px;
    height: 18px;
    border-radius: 999px;
    background: #fff;
    position: absolute;
    top: 3px;
    left: 3px;
    transition: transform 0.16s ease;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.22);
}

.switch-field input[type="checkbox"]:checked {
    background: var(--primary);
}

.switch-field input[type="checkbox"]:checked::after {
    transform: translateX(18px);
}

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-start;
}

.toolbar {
    flex-wrap: wrap;
}

.toolbar-inline {
    align-items: center;
}

.toolbar-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr)) auto auto;
    gap: 12px;
}

.table-wrap {
    overflow: auto;
}

.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    min-width: 720px;
}

.data-table thead th {
    text-align: left;
    padding: 12px 14px;
    font-size: 0.84rem;
    font-weight: 700;
    color: var(--text-muted);
    background: #f8fbff;
    border-bottom: 1px solid var(--line);
}

.data-table tbody td {
    padding: 14px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
    font-size: 0.94rem;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table-compact thead th,
.data-table-compact tbody td {
    padding-top: 11px;
    padding-bottom: 11px;
}

.cell-title {
    font-weight: 600;
    color: var(--text);
}

.cell-meta {
    margin-top: 4px;
    font-size: 0.84rem;
}

.text-regular { color: var(--text); }

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 24px;
    padding: 0 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
}

.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-muted { background: #eef2f7; color: var(--text-muted); }

.empty-state {
    text-align: center;
    padding: 36px 12px;
    color: var(--text-muted);
}

.table-actions {
    flex-wrap: wrap;
    gap: 8px;
}

.table-actions form { margin: 0; }

.pagination-bar {
    margin-top: 16px;
    flex-wrap: wrap;
    align-items: center;
}

.pagination-meta {
    color: var(--text-muted);
    font-size: 0.88rem;
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.inline-select {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 0.88rem;
}

.inline-select select {
    min-height: 34px;
    width: auto;
}

.split-layout {
    display: grid;
    grid-template-columns: minmax(320px, 0.95fr) minmax(0, 1.35fr);
}

.split-layout-wide {
    grid-template-columns: minmax(320px, 0.9fr) minmax(0, 1.45fr);
}

.stack-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.stack-list-compact {
    margin-top: 16px;
    gap: 10px;
}

.list-row {
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--bg-soft);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.sub-card {
    padding: 18px;
}

.console-layout {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 20px;
}

.console-sidebar,
.console-main {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.console-topbar {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.console-topbar-actions {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
}

.console-title {
    margin: 4px 0 0;
    font-size: 1.45rem;
}

.mini-metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.mini-metric {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--bg-soft);
    padding: 12px;
    min-width: 120px;
}

.mini-metric span {
    display: block;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.mini-metric strong {
    display: block;
    margin-top: 6px;
    font-size: 1rem;
}

.domain-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.domain-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--bg-soft);
    color: var(--text);
    transition: border-color 0.16s ease, background 0.16s ease, transform 0.16s ease;
}

.domain-list-item:hover {
    background: #eef4fb;
    border-color: #c7d6ea;
    transform: translateY(-1px);
    color: var(--text);
}

.domain-list-item.active {
    background: #eff6ff;
    border-color: rgba(37, 99, 235, 0.35);
    box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.12);
}

.domain-list-main {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.domain-list-main strong {
    font-size: 0.96rem;
}

.domain-list-main span {
    font-size: 0.82rem;
    color: var(--text-muted);
}

.overlay-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.36);
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 40;
}

.overlay-backdrop.is-visible {
    opacity: 1;
}

.overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 24px;
}

.overlay[hidden] { display: none; }

.overlay-panel {
    width: min(860px, 100%);
    max-height: calc(100vh - 48px);
    overflow: auto;
    background: #fff;
    border-radius: 18px;
    border: 1px solid var(--line);
    box-shadow: var(--shadow-md);
    padding: 22px;
    transform: translateY(10px);
    opacity: 0;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.overlay.is-open .overlay-panel {
    transform: translateY(0);
    opacity: 1;
}

.overlay-drawer {
    justify-content: flex-end;
}

.overlay-drawer .overlay-panel {
    width: min(760px, 100%);
    height: calc(100vh - 48px);
    max-height: calc(100vh - 48px);
}

.overlay-modal-narrow .overlay-panel {
    width: min(640px, 100%);
}

body.overlay-open {
    overflow: hidden;
}

.media-preview {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--bg-soft);
}

.media-preview img {
    border-radius: 12px;
    max-height: 220px;
    object-fit: cover;
}

.toast-stack {
    position: fixed;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 100;
}

.toast {
    min-width: 220px;
    max-width: 320px;
    padding: 12px 14px;
    border-radius: 12px;
    color: #fff;
    box-shadow: var(--shadow-md);
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.toast-success { background: #166534; }
.toast-error { background: #b91c1c; }
.toast-warning { background: #c2410c; }

.standalone-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, 0.12), transparent 28%),
        linear-gradient(180deg, #f8fbff 0%, #eef4fb 100%);
}

.result-shell {
    width: min(680px, 100%);
}

.result-panel {
    padding: 32px;
    text-align: center;
}

.result-panel h1 {
    margin: 8px 0 0;
    font-size: 2rem;
    line-height: 1.2;
}

.auth-shell {
    width: min(520px, 100%);
}

.auth-panel {
    text-align: left;
}

.helper-note {
    margin-top: 14px;
    padding: 12px 14px;
    background: var(--bg-soft);
    border-radius: 12px;
    border: 1px solid var(--line);
    font-size: 0.88rem;
}

.landing-page {
    min-height: 100vh;
    background: linear-gradient(180deg, #dbeafe 0%, #eff6ff 100%);
    background-size: cover;
    background-position: center;
    position: relative;
}

.landing-backdrop {
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.28), rgba(15, 23, 42, 0.48));
}

.landing-shell {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.landing-panel {
    max-width: 720px;
    color: #fff;
    background: rgba(15, 23, 42, 0.6);
    border-color: rgba(255, 255, 255, 0.14);
    backdrop-filter: blur(16px);
}

.landing-panel .eyebrow,
.landing-panel .result-note,
.landing-panel .landing-subtitle,
.landing-panel .landing-target {
    color: rgba(255, 255, 255, 0.84);
}

.landing-target {
    margin-top: 14px;
    padding: 12px 14px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    word-break: break-all;
}

.action-row {
    flex-wrap: wrap;
    align-items: center;
}

.action-row-center {
    justify-content: center;
    margin-top: 18px;
}

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

    .console-layout,
    .split-layout,
    .split-layout-wide {
        grid-template-columns: 1fr;
    }
}

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

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

    .main-content {
        padding: 18px;
    }

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

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

@media (max-width: 640px) {
    .summary-grid,
    .mini-metrics,
    .toolbar-grid {
        grid-template-columns: 1fr;
    }

    .overlay,
    .overlay-drawer {
        padding: 0;
        align-items: stretch;
    }

    .overlay-panel,
    .overlay-drawer .overlay-panel {
        width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }

    .toast-stack {
        left: 16px;
        right: 16px;
        top: 16px;
    }

    .toast {
        max-width: none;
        width: 100%;
    }
}
