:root {
    --primary: #165dff;
    --primary-hover: #4080ff;
    --primary-active: #0e42d2;
    --primary-soft: #e8f3ff;
    --success: #00b42a;
    --success-soft: #e8ffea;
    --warning: #ff7d00;
    --warning-soft: #fff7e8;
    --danger: #f53f3f;
    --danger-soft: #ffece8;
    --navy: #163355;
    --text-1: #1d2129;
    --text-2: #4e5969;
    --text-3: #86909c;
    --text-4: #c9cdd4;
    --border: #e5e6eb;
    --fill: #f2f3f5;
    --bg: #f2f3f5;
    --white: #fff;
    --sidebar: 232px;
    --topbar: 56px;
    --radius: 4px;
    --shadow: 0 4px 10px rgba(29, 33, 41, .06);
    --ease: cubic-bezier(.34, .69, .1, 1);
    --z-sidebar: 20;
    --z-topbar: 15;
    --z-mask: 18;
    --z-dropdown: 30;
    --z-skip: 100;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    color: var(--text-1);
    background: var(--bg);
    font: 14px/1.5 "PingFang SC", "HarmonyOS Sans", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.skip-link {
    position: absolute;
    left: 12px;
    top: -48px;
    z-index: var(--z-skip);
    background: var(--primary);
    color: #fff;
    padding: 8px 12px;
    border-radius: var(--radius);
}
.skip-link:focus { top: 12px; }

.icon { width: 16px; height: 16px; display: inline-block; vertical-align: -3px; flex: 0 0 16px; }
.req { color: var(--danger); font-style: normal; margin-left: 2px; }

.app-shell { display: flex; min-height: 100dvh; }
.sidebar {
    width: var(--sidebar);
    background: var(--white);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100dvh;
    z-index: var(--z-sidebar);
}
.brand {
    height: var(--topbar);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px;
    color: var(--text-1);
    border-bottom: 1px solid var(--border);
}
.brand:hover { color: var(--text-1); }
.brand-mark {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: var(--primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
}
.brand-mark.lg { width: 40px; height: 40px; font-size: 18px; border-radius: 8px; }
.brand-copy { display: flex; flex-direction: column; line-height: 1.2; }
.brand-copy strong { font-size: 15px; }
.brand-copy small { color: var(--text-3); font-size: 12px; }

.menu { padding: 12px 8px; overflow: auto; }
.menu-item,
.menu-group-title {
    min-height: 40px;
    border: 0;
    background: transparent;
    color: var(--text-2);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 0 12px;
    text-align: left;
    position: relative;
}
.menu-item:hover,
.menu-group-title:hover { background: var(--fill); color: var(--text-1); }
.menu-item.is-active {
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 500;
}
.menu-item.is-active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: 0 2px 2px 0;
    background: var(--primary);
}
.menu-arrow { margin-left: auto; transition: transform .2s var(--ease); }
.menu-group.is-open .menu-arrow { transform: rotate(90deg); }
.menu-sub { display: none; padding: 4px 0 8px 28px; }
.menu-group.is-open .menu-sub { display: block; }
.menu-sub .menu-item { min-height: 36px; }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    height: var(--topbar);
    background: var(--white);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    position: sticky;
    top: 0;
    z-index: var(--z-topbar);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }
.icon-btn {
    min-width: 36px;
    min-height: 36px;
    border: 0;
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.icon-btn:hover { background: var(--fill); color: var(--text-1); }
.breadcrumb { color: var(--text-3); display: flex; gap: 8px; align-items: center; }
.breadcrumb .is-current { color: var(--text-1); }
.breadcrumb-sep { color: var(--text-4); }
.team-chip { color: var(--text-3); font-size: 12px; }

.avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--navy);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}
.user-menu { position: relative; }
.user-trigger {
    border: 0;
    background: transparent;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 4px 6px;
    border-radius: var(--radius);
}
.user-trigger:hover { background: var(--fill); }
.user-meta { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2; }
.user-meta strong { font-size: 13px; }
.user-meta small { color: var(--text-3); font-size: 12px; }
.user-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    width: 220px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    z-index: var(--z-dropdown);
}
.user-menu.is-open .user-dropdown { display: block; }
.user-dropdown-head { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.user-dropdown-head strong, .user-dropdown-head span { display: block; }
.user-dropdown-head span { color: var(--text-3); font-size: 12px; margin-top: 2px; }
.dropdown-item {
    width: 100%;
    border: 0;
    background: transparent;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 10px 14px;
    color: var(--text-2);
}
.dropdown-item:hover { background: var(--fill); }
.dropdown-item.danger { color: var(--danger); }

.page-body { padding: 16px 20px 24px; flex: 1; }
.page-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}
.page-head h1 { margin: 0 0 4px; font-size: 20px; font-weight: 600; }
.page-head p, .muted { margin: 0; color: var(--text-3); }

.card {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
}
.card + .card, .table-card + .table-card { margin-top: 16px; }
.card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin: -16px -20px 16px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
}
.card-head h2 { margin: 0; font-size: 16px; font-weight: 600; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}
.stat-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat-card { display: flex; flex-direction: column; gap: 8px; position: relative; overflow: hidden; }
.stat-card::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
}
.stat-card.tone-primary::before { background: var(--primary); }
.stat-card.tone-success::before { background: var(--success); }
.stat-card.tone-warning::before { background: var(--warning); }
.stat-card.tone-danger::before { background: var(--danger); }
.stat-label { color: var(--text-3); }
.stat-value { font-size: 26px; line-height: 1.15; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat-card.tone-primary .stat-value { color: var(--primary); }
.stat-card.tone-success .stat-value { color: var(--success); }
.stat-card.tone-warning .stat-value { color: var(--warning); }
.stat-card.tone-danger .stat-value { color: var(--danger); }

.shortcut-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}
.shortcut-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-height: 88px;
    padding: 16px 18px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-1);
    transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.shortcut-card:hover {
    border-color: var(--primary);
    color: var(--text-1);
    box-shadow: var(--shadow);
}
.shortcut-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    background: var(--primary-soft);
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 36px;
}
.shortcut-card strong,
.shortcut-card small { display: block; }
.shortcut-card small { margin-top: 4px; color: var(--text-3); }

.step-flow {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin: 0 0 16px;
    padding: 0;
    list-style: none;
    color: var(--text-2);
}
.step-flow li { display: flex; align-items: center; gap: 8px; }
.step-flow em {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    font-style: normal;
    font-size: 12px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.team-board {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}
.team-tile {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    background: #fafbfc;
}
.team-tile strong,
.team-tile small { display: block; }
.team-tile small { margin-top: 4px; color: var(--text-3); }

.content-grid, .role-grid {
    display: grid;
    grid-template-columns: 1.2fr .8fr;
    gap: 16px;
}
.role-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.role-list, .plain-list, .perm-chips { margin: 0; padding: 0; list-style: none; }
.role-row + .role-row, .plain-list li + li { margin-top: 14px; }
.role-row p, .plain-list li { margin: 6px 0 0; color: var(--text-2); }
.plain-list li { padding-left: 14px; position: relative; }
.plain-list li::before {
    content: "";
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--primary);
    position: absolute;
    left: 0;
    top: 8px;
}

.tag {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 0 8px;
    border-radius: 2px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 12px;
}
.tag-navy { background: #e8f0f8; color: var(--navy); }
.tag-plain { background: var(--fill); color: var(--text-2); }
.tag-success { background: var(--success-soft); color: #2a6a2a; }
.tag-warn { background: var(--warning-soft); color: #a35400; }

.perm-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.perm-chips li {
    background: var(--fill);
    color: var(--text-2);
    border-radius: 2px;
    padding: 4px 8px;
    font-size: 12px;
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}
.filter-bar .field { min-width: 140px; }
.field-grow { min-width: 180px; flex: 1; }
.filter-actions { display: flex; gap: 8px; }

.table-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}
.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    width: min(320px, 100%);
    height: 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0 10px;
    color: var(--text-3);
    background: var(--white);
}
.search-box input { border: 0; outline: 0; width: 100%; background: transparent; }
.table-wrap { overflow: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
    text-align: left;
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.table th {
    color: var(--text-3);
    font-weight: 500;
    background: #f7f8fa;
    position: sticky;
    top: 0;
    z-index: 1;
}
.table tbody tr:hover { background: #fafbfc; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .col-action { text-align: right; }
.table code, code {
    background: var(--fill);
    color: var(--navy);
    border-radius: 2px;
    padding: 1px 6px;
    font-size: 12px;
}
.table-actions { display: flex; align-items: center; justify-content: flex-end; gap: 4px; }
.table-actions form { margin: 0; }
.inline-form { display: flex; align-items: center; gap: 8px; }
.inline-form select { height: 32px; min-width: 140px; }

.empty-state { text-align: center; padding: 56px 16px; color: var(--text-3); }
.empty-state .icon { width: 36px; height: 36px; }
.empty-state h3 { margin: 12px 0 6px; color: var(--text-1); font-size: 16px; }
.empty-state p { margin: 0 0 16px; }
.empty-state .btn { margin-top: 4px; }

.form { display: grid; gap: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.field { display: grid; gap: 6px; }
.field > span { color: var(--text-2); }
.field-full { grid-column: 1 / -1; }
.field-help { color: var(--text-3); font-size: 12px; }
.form-actions { display: flex; gap: 8px; }
.form-actions.sticky {
    position: sticky;
    bottom: 0;
    padding: 12px 0 4px;
    background: linear-gradient(180deg, transparent, var(--bg) 28%);
}
.pager {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-top: 16px;
}
.pager-links { display: flex; align-items: center; gap: 8px; }
.money-cny { color: var(--primary); font-weight: 600; font-variant-numeric: tabular-nums; }
.rate-hint { color: var(--text-3); }
.item-table input[type="text"],
.item-table input[type="number"] { width: 100%; min-width: 96px; }
.input-addon {
    display: flex;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--white);
}
.input-addon .currency-label {
    padding: 0 8px;
    color: var(--text-3);
    background: #fafbfc;
    border-right: 1px solid var(--border);
    font-size: 12px;
}
.input-addon input { border: 0 !important; box-shadow: none !important; border-radius: 0; }
.password-field { position: relative; }
.password-field input { width: 100%; padding-right: 40px; }
.password-field .icon-btn {
    position: absolute;
    right: 2px;
    top: 50%;
    transform: translateY(-50%);
}

input[type="text"],
input[type="password"],
input[type="search"],
input[type="date"],
input[type="number"],
input[type="tel"],
select {
    height: 36px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0 12px;
    background: var(--white);
    color: var(--text-1);
    outline: none;
    transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
select {
    appearance: none;
    padding-right: 28px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2386909c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}
input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(22, 93, 255, .12);
}
input::placeholder, textarea::placeholder { color: var(--text-4); }
input:disabled,
select:disabled,
textarea:disabled { background: var(--fill); color: var(--text-3); cursor: not-allowed; }

textarea {
    width: 100%;
    min-height: 120px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    background: var(--white);
    color: var(--text-1);
    outline: none;
    resize: vertical;
}

.btn {
    min-height: 36px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 0 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: var(--fill);
    color: var(--text-1);
    transition: background .2s var(--ease), border-color .2s var(--ease), transform .15s var(--ease);
}
.btn:hover { background: #e5e6eb; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-primary:disabled,
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; }
.btn.is-loading { pointer-events: none; opacity: .72; }
.btn-text {
    min-height: 32px;
    padding: 0 8px;
    background: transparent;
    color: var(--text-2);
}
.btn-text:hover { background: var(--fill); color: var(--primary); }
.btn-text.danger,
.dropdown-item.danger { color: var(--danger); }
.btn-text.danger:hover { background: var(--danger-soft); color: var(--danger); }

.alert {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 12px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    border: 1px solid transparent;
    transition: opacity .2s var(--ease);
}
.alert-success { background: var(--success-soft); color: #2a6a2a; border-color: #b7f0bf; }
.alert-danger { background: var(--danger-soft); color: #b01011; border-color: #fdcdc5; }
.alert-warning { background: var(--warning-soft); color: #a35400; border-color: #ffe4ba; }

.auth-body { min-height: 100dvh; background: var(--white); }
.auth-shell { min-height: 100dvh; display: grid; grid-template-columns: 420px 1fr; }
.auth-brand {
    background:
        linear-gradient(180deg, rgba(22, 93, 255, .16), transparent 38%),
        #10243f;
    color: #dce6f2;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px 40px;
}
.auth-brand-inner { max-width: 300px; }
.auth-brand h1 { margin: 20px 0 10px; color: #fff; font-size: 28px; }
.auth-brand p { margin: 0 0 24px; color: #b7c4d6; }
.auth-points { margin: 0; padding: 0; list-style: none; }
.auth-points li { padding: 8px 0 8px 16px; position: relative; color: #d5deea; }
.auth-points li::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary);
    position: absolute;
    left: 0;
    top: 14px;
}
.auth-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    padding: 32px 16px;
}
.auth-card {
    width: min(440px, 100%);
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 32px 28px;
}
.auth-card h2 { margin: 0 0 6px; font-size: 22px; }
.auth-sub { margin: 0 0 24px; color: var(--text-3); }
.auth-switch { margin: 8px 0 0; text-align: center; color: var(--text-3); }

.check-list { display: grid; gap: 8px; margin-bottom: 20px; }
.check-item {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius);
    background: var(--fill);
}
.check-item small { color: var(--text-3); }
.check-item.is-ok { background: var(--success-soft); }
.check-item.is-bad { background: var(--danger-soft); }

.toolbox-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(280px, .9fr);
    gap: 16px;
    align-items: start;
}
.qr-preview-card { min-height: 360px; }
.qr-preview {
    min-height: 280px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fafbfc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
}
.qr-preview canvas { display: block; }
#qr-error { color: var(--danger); }

.error-body { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.error-card { text-align: center; width: min(420px, 100%); padding: 40px 28px; }
.error-card strong { font-size: 48px; color: var(--primary); display: block; letter-spacing: .04em; }
.error-card h1 { margin: 8px 0; }
.error-card p { color: var(--text-3); margin: 0 0 20px; }

.sidebar-mask {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(29, 33, 41, .35);
    z-index: var(--z-mask);
}

@media (max-width: 1100px) {
    .stat-grid, .stat-grid-3, .role-grid, .content-grid, .form-grid-4, .shortcut-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 900px) {
    .auth-shell { grid-template-columns: 1fr; }
    .auth-brand { min-height: 220px; padding: 32px 24px; }
    .form-grid, .form-grid-4 { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        transform: translateX(-100%);
        transition: transform .24s var(--ease);
    }
    .app-shell.is-sidebar-open .sidebar { transform: none; }
    .app-shell.is-sidebar-open .sidebar-mask { display: block; }
    .stat-grid, .stat-grid-2, .stat-grid-3, .role-grid, .content-grid, .toolbox-grid, .shortcut-grid { grid-template-columns: 1fr; }
    .user-meta { display: none; }
    .page-head { flex-direction: column; align-items: flex-start; }
    .page-body { padding: 12px; }
    .btn, .icon-btn, .menu-item, .user-trigger { min-height: 44px; }
    input, select { min-height: 44px; height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}
