:root {
    color-scheme: light;
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-soft: #f8f8fa;
    --text: #17171c;
    --muted: #6b6d76;
    --line: #e4e5e9;
    --line-strong: #d4d5db;
    --accent: #ec5b30;
    --accent-dark: #c9421b;
    --accent-soft: #fff0e9;
    --success: #16855b;
    --success-soft: #e8f7f1;
    --warning: #a96408;
    --warning-soft: #fff4dc;
    --danger: #bc3342;
    --danger-soft: #fff0f2;
    --sidebar: #17171c;
    --shadow: 0 18px 50px rgb(26 28 36 / 8%);
    --radius: 16px;
    --radius-small: 10px;
    font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    background: var(--bg);
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background:
        radial-gradient(circle at 90% -10%, rgb(236 91 48 / 10%), transparent 34rem),
        var(--bg);
}

button,
input,
textarea,
select {
    font: inherit;
}

button,
select {
    cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
    cursor: not-allowed;
    opacity: 0.62;
}

[hidden] {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

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

.eyebrow,
.section-kicker {
    margin: 0 0 6px;
    color: var(--accent);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.16em;
}

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

.login-card {
    width: min(100%, 430px);
    padding: 42px;
    border: 1px solid rgb(255 255 255 / 80%);
    border-radius: 24px;
    background: rgb(255 255 255 / 94%);
    box-shadow: 0 30px 90px rgb(26 28 36 / 14%);
}

.login-card h1 {
    margin: 10px 0 8px;
    font-size: clamp(30px, 6vw, 42px);
    letter-spacing: -0.04em;
}

.login-card > .muted {
    margin: 0 0 30px;
    line-height: 1.7;
}

.brand-mark {
    display: inline-grid;
    width: 54px;
    height: 54px;
    margin-bottom: 22px;
    place-items: center;
    border-radius: 17px;
    color: #fff;
    background: linear-gradient(145deg, #ff7a4d, var(--accent-dark));
    box-shadow: 0 12px 28px rgb(236 91 48 / 28%);
    font-size: 18px;
    font-weight: 900;
    letter-spacing: -0.06em;
}

.brand-mark.small {
    width: 38px;
    height: 38px;
    margin: 0;
    border-radius: 12px;
    font-size: 13px;
}

.stack {
    display: grid;
    gap: 18px;
}

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

.sidebar {
    position: sticky;
    top: 0;
    display: flex;
    height: 100vh;
    flex-direction: column;
    padding: 26px 18px 20px;
    color: #fff;
    background: var(--sidebar);
}

.sidebar-brand,
.session-user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-brand {
    padding: 0 8px 30px;
}

.sidebar-brand strong,
.sidebar-brand small,
.session-user strong,
.session-user small {
    display: block;
}

.sidebar-brand small,
.session-user small {
    margin-top: 3px;
    color: #9698a2;
    font-size: 11px;
}

.main-nav {
    display: grid;
    gap: 7px;
}

.nav-item {
    display: grid;
    gap: 4px;
    width: 100%;
    padding: 13px 14px;
    border: 0;
    border-radius: 12px;
    color: #c7c8cd;
    background: transparent;
    text-align: left;
    transition: background 160ms ease, color 160ms ease;
}

.nav-item:hover {
    color: #fff;
    background: rgb(255 255 255 / 6%);
}

.nav-item.active {
    color: #fff;
    background: linear-gradient(120deg, rgb(236 91 48 / 30%), rgb(236 91 48 / 12%));
    box-shadow: inset 3px 0 var(--accent);
}

.nav-item span {
    font-size: 14px;
    font-weight: 700;
}

.nav-item small {
    color: #8e9099;
    font-size: 11px;
}

.sidebar-footer {
    display: grid;
    gap: 16px;
    margin-top: auto;
    padding-top: 20px;
    border-top: 1px solid rgb(255 255 255 / 9%);
}

.session-user {
    min-width: 0;
}

.session-user > span:last-child {
    min-width: 0;
}

.session-user strong {
    overflow: hidden;
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.avatar {
    display: grid;
    flex: 0 0 34px;
    height: 34px;
    place-items: center;
    border-radius: 50%;
    color: #fff;
    background: #3a3b43;
    font-size: 12px;
    font-weight: 800;
}

.workspace {
    min-width: 0;
}

.topbar {
    display: flex;
    min-height: 100px;
    align-items: center;
    justify-content: space-between;
    padding: 20px clamp(22px, 4vw, 52px);
    border-bottom: 1px solid var(--line);
    background: rgb(244 245 247 / 86%);
    backdrop-filter: blur(12px);
}

.topbar h1 {
    margin: 0;
    font-size: clamp(23px, 3vw, 30px);
    letter-spacing: -0.04em;
}

.topbar-meta,
.toolbar-actions,
.sticky-actions,
.sticky-actions > div,
.modal-actions,
.filters {
    display: flex;
    align-items: center;
    gap: 12px;
}

.connection-state {
    color: var(--success);
    font-size: 12px;
    font-weight: 700;
}

.connection-state::before {
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 7px;
    border-radius: 50%;
    background: currentColor;
    content: "";
}

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

.view {
    width: min(1460px, 100%);
    margin: 0 auto;
    padding: 34px clamp(18px, 4vw, 52px) 70px;
}

.page-toolbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
}

.page-toolbar h2 {
    margin: 0 0 7px;
    font-size: 21px;
    letter-spacing: -0.025em;
}

.page-toolbar p {
    margin: 0;
    font-size: 13px;
    line-height: 1.6;
}

.content-grid {
    display: grid;
    grid-template-columns: minmax(280px, 0.78fr) minmax(480px, 1.22fr);
    gap: 20px;
    align-items: start;
}

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

.level-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.level-stat-card {
    display: grid;
    gap: 5px;
    min-width: 0;
    padding: 18px 20px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.level-stat-card span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 750;
}

.level-stat-card strong {
    font-size: 26px;
    line-height: 1.15;
}

.level-stat-card small {
    overflow: hidden;
    color: var(--muted);
    font-size: 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.categories-panel {
    margin-bottom: 20px;
    padding: 22px;
}

.category-panel-heading {
    margin-bottom: 17px;
}

.category-panel-heading .muted {
    margin: 7px 0 0;
    font-size: 12px;
    line-height: 1.55;
}

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

.category-card {
    display: grid;
    gap: 16px;
    padding: 15px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface-soft);
}

.category-card-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.category-card-heading strong,
.category-card-heading small {
    display: block;
}

.category-card-heading strong {
    font-size: 14px;
}

.category-card-heading small {
    margin-top: 5px;
    color: var(--muted);
    font-size: 11px;
}

.editor-panel,
.plans-panel {
    padding: 24px;
}

.panel-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
}

.panel-heading h3 {
    margin: 0;
    font-size: 17px;
}

.version-label,
.save-state {
    color: var(--muted);
    font-size: 12px;
}

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

.span-2,
.span-all {
    grid-column: 1 / -1;
}

.field,
.compact-field {
    display: grid;
    gap: 7px;
    color: #454750;
    font-size: 12px;
    font-weight: 700;
}

.field input,
.field textarea,
.field select,
.compact-field select,
.search-field input {
    width: 100%;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-small);
    outline: 0;
    color: var(--text);
    background: #fff;
    font-size: 14px;
    font-weight: 500;
    transition: border-color 160ms ease, box-shadow 160ms ease;
}

.field input,
.field select,
.compact-field select,
.search-field input {
    min-height: 42px;
    padding: 9px 11px;
}

.field textarea {
    min-height: 92px;
    padding: 11px;
    resize: vertical;
    line-height: 1.6;
}

.field input:focus,
.field textarea:focus,
.field select:focus,
.compact-field select:focus,
.search-field input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgb(236 91 48 / 12%);
}

.field small {
    color: var(--muted);
    font-size: 11px;
    font-weight: 500;
    line-height: 1.5;
}

.compact-field {
    grid-template-columns: auto minmax(120px, auto);
    align-items: center;
}

.plans-list {
    display: grid;
    gap: 18px;
}

.plan-card {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface-soft);
}

.plan-card-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 15px 17px;
    border-bottom: 1px solid var(--line);
    background: #fff;
}

.plan-card-heading strong {
    font-size: 14px;
}

.plan-card-body {
    padding: 18px;
}

.price-grid {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 12px;
    align-items: end;
}

.discount-readout {
    display: grid;
    min-width: 90px;
    min-height: 42px;
    place-items: center;
    padding: 8px;
    border-radius: 10px;
    color: var(--accent-dark);
    background: var(--accent-soft);
    font-size: 12px;
    font-weight: 800;
}

.switch-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-top: 16px;
}

.switch-option {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 11px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: #4a4c54;
    font-size: 12px;
    font-weight: 700;
}

.switch-option input {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

.benefits-editor {
    display: grid;
    gap: 9px;
    margin-top: 16px;
}

.benefits-heading,
.benefit-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.benefits-heading {
    justify-content: space-between;
    color: #454750;
    font-size: 12px;
    font-weight: 700;
}

.benefit-row input {
    flex: 1;
    min-width: 0;
    min-height: 38px;
    padding: 8px 10px;
    border: 1px solid var(--line-strong);
    border-radius: 9px;
    outline: 0;
    background: #fff;
}

.button,
.icon-button,
.mini-button {
    border: 0;
    border-radius: 10px;
    font-weight: 750;
    transition: transform 120ms ease, background 160ms ease, border-color 160ms ease;
}

.button:active,
.icon-button:active,
.mini-button:active {
    transform: translateY(1px);
}

.button {
    min-height: 40px;
    padding: 9px 15px;
    font-size: 13px;
}

.link-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.button.full {
    width: 100%;
}

.button.primary {
    color: #fff;
    background: var(--accent);
    box-shadow: 0 8px 20px rgb(236 91 48 / 18%);
}

.button.primary:hover {
    background: var(--accent-dark);
}

.button.secondary {
    border: 1px solid var(--line-strong);
    color: #303139;
    background: #fff;
}

.button.secondary:hover,
.button.ghost:hover {
    border-color: #b7b8c0;
    background: #f2f2f5;
}

.button.ghost {
    border: 1px solid var(--line);
    color: inherit;
    background: transparent;
}

.sidebar .button.ghost {
    border-color: rgb(255 255 255 / 14%);
    color: #d7d8dc;
}

.button.danger,
.mini-button.danger {
    color: var(--danger);
    background: var(--danger-soft);
}

.icon-button,
.mini-button {
    display: inline-grid;
    place-items: center;
    color: var(--muted);
    background: transparent;
}

.icon-button {
    width: 36px;
    height: 36px;
    font-size: 24px;
}

.mini-button {
    min-height: 32px;
    padding: 6px 10px;
    font-size: 11px;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    white-space: nowrap;
}

.badge.neutral {
    color: #5b5d66;
    background: #e8e9ed;
}

.badge.draft {
    color: var(--warning);
    background: var(--warning-soft);
}

.badge.published {
    color: var(--success);
    background: var(--success-soft);
}

.badge.archived {
    color: #676973;
    background: #e8e9ed;
}

.badge.free {
    color: #2d6c91;
    background: #e9f5fb;
}

.badge.premium {
    color: #8051a4;
    background: #f3ebfb;
}

.sticky-actions {
    position: sticky;
    bottom: 14px;
    z-index: 5;
    justify-content: space-between;
    padding: 14px 16px;
    border: 1px solid rgb(212 213 219 / 80%);
    border-radius: 14px;
    background: rgb(255 255 255 / 92%);
    box-shadow: 0 16px 40px rgb(20 22 29 / 14%);
    backdrop-filter: blur(14px);
}

.save-state.dirty {
    color: var(--warning);
    font-weight: 700;
}

.filters {
    flex-wrap: wrap;
    padding: 18px;
    border-bottom: 1px solid var(--line);
}

.search-field {
    flex: 1 1 280px;
}

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

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

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

th {
    color: var(--muted);
    background: var(--surface-soft);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

tbody tr:hover {
    background: #fbfbfc;
}

tbody tr:last-child td {
    border-bottom: 0;
}

.cell-main,
.cell-sub {
    display: block;
}

.cell-main {
    font-size: 13px;
    font-weight: 750;
}

.cell-sub {
    max-width: 300px;
    margin-top: 4px;
    overflow: hidden;
    color: var(--muted);
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.actions-column {
    width: 170px;
    text-align: right;
}

.row-actions {
    display: flex;
    justify-content: flex-end;
    gap: 7px;
}

.loading-panel,
.empty-state {
    padding: 44px 20px;
    color: var(--muted);
    text-align: center;
    font-size: 13px;
}

.audit-search {
    display: block;
    padding: 18px;
    border-bottom: 1px solid var(--line);
}

.audit-list {
    display: grid;
    margin: 0;
    padding: 0;
    list-style: none;
}

.audit-item {
    display: grid;
    grid-template-columns: 12px minmax(120px, 0.35fr) minmax(180px, 0.65fr) minmax(240px, 1fr);
    gap: 14px;
    align-items: start;
    padding: 17px 20px;
    border-bottom: 1px solid var(--line);
}

.audit-item:last-child {
    border-bottom: 0;
}

.audit-dot {
    width: 9px;
    height: 9px;
    margin-top: 5px;
    border: 2px solid #fff;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.audit-item strong,
.audit-item small {
    display: block;
}

.audit-item strong {
    font-size: 12px;
}

.audit-item small {
    margin-top: 4px;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.5;
}

.audit-details {
    margin: 0;
    overflow-wrap: anywhere;
    color: #4e5058;
    font: 11px/1.55 ui-monospace, SFMono-Regular, Consolas, monospace;
    white-space: pre-wrap;
}

.modal {
    width: min(calc(100% - 28px), 680px);
    max-height: calc(100vh - 40px);
    padding: 0;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 18px;
    color: var(--text);
    background: #fff;
    box-shadow: 0 30px 100px rgb(10 12 18 / 30%);
}

.modal::backdrop {
    background: rgb(20 21 27 / 58%);
    backdrop-filter: blur(4px);
}

.modal > form {
    padding: 25px;
}

.modal-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 22px;
}

.modal-heading h2,
.confirm-modal h2 {
    margin: 0;
    font-size: 20px;
}

.modal-actions {
    justify-content: flex-end;
    margin-top: 24px;
}

.modal-actions.centered {
    justify-content: center;
}

.confirm-modal {
    width: min(calc(100% - 28px), 440px);
    text-align: center;
}

.confirm-icon {
    display: grid;
    width: 46px;
    height: 46px;
    margin: 0 auto 16px;
    place-items: center;
    border-radius: 50%;
    color: var(--accent-dark);
    background: var(--accent-soft);
    font-size: 22px;
    font-weight: 900;
}

.confirm-modal p {
    margin: 12px 0 0;
    line-height: 1.65;
}

.form-error {
    margin: 0;
    padding: 10px 12px;
    border-radius: 9px;
    color: var(--danger);
    background: var(--danger-soft);
    font-size: 12px;
    line-height: 1.5;
}

.toast-region {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 100;
    display: grid;
    width: min(380px, calc(100vw - 36px));
    gap: 10px;
    pointer-events: none;
}

.toast {
    padding: 13px 15px;
    border: 1px solid var(--line);
    border-left: 4px solid var(--success);
    border-radius: 11px;
    background: #fff;
    box-shadow: 0 18px 48px rgb(20 22 29 / 18%);
    font-size: 12px;
    line-height: 1.55;
    animation: toast-in 180ms ease both;
}

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

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(-7px);
    }
}

@media (max-width: 1040px) {
    .content-grid {
        grid-template-columns: 1fr;
    }

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

    .audit-item {
        grid-template-columns: 12px 1fr 1fr;
    }

    .audit-details {
        grid-column: 2 / -1;
    }
}

@media (max-width: 760px) {
    .admin-shell {
        display: block;
        padding-bottom: 76px;
    }

    .sidebar {
        position: fixed;
        top: auto;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 20;
        display: block;
        width: auto;
        height: auto;
        padding: 8px 10px max(8px, env(safe-area-inset-bottom));
        border-top: 1px solid rgb(255 255 255 / 10%);
    }

    .sidebar-brand,
    .sidebar-footer {
        display: none;
    }

    .main-nav {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 5px;
    }

    .nav-item {
        padding: 9px 6px;
        text-align: center;
    }

    .nav-item.active {
        box-shadow: inset 0 -2px var(--accent);
    }

    .nav-item small {
        display: none;
    }

    .topbar {
        min-height: 82px;
        padding: 16px 18px;
    }

    .topbar-meta .badge {
        display: none;
    }

    .view {
        padding: 24px 14px 48px;
    }

    .page-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .toolbar-actions {
        justify-content: space-between;
    }

    .editor-panel,
    .plans-panel {
        padding: 18px;
    }

    .form-grid,
    .price-grid,
    .switch-row {
        grid-template-columns: 1fr;
    }

    .sticky-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .sticky-actions > div {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .filters {
        align-items: stretch;
        flex-direction: column;
    }

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

    .compact-field {
        grid-template-columns: 62px 1fr;
    }

    .audit-item {
        grid-template-columns: 10px 1fr;
    }

    .audit-item > *:not(.audit-dot) {
        grid-column: 2;
    }

    .login-card {
        padding: 30px 24px;
    }

    .modal > form {
        padding: 20px;
    }
}

@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;
    }
}
