:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #eff6ff;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --text: #18212f;
    --muted: #6b7280;
    --line: #e5e7eb;
    --page: #f5f7fb;
    --card: #ffffff;
    --sidebar: #101827;
    --sidebar-muted: #94a3b8;
    --radius: 14px;
    --shadow: 0 10px 35px rgba(15, 23, 42, .07);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--page); }
body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background: var(--page);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.55;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; }
.sidebar {
    position: fixed;
    z-index: 40;
    inset: 0 auto 0 0;
    width: 240px;
    display: flex;
    flex-direction: column;
    color: #fff;
    background: var(--sidebar);
    transition: transform .22s ease;
}
.brand {
    height: 74px;
    padding: 0 22px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-mark {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    font-size: 20px;
    font-weight: 800;
}
.brand strong { display: block; font-size: 16px; letter-spacing: .3px; }
.brand small { color: var(--sidebar-muted); font-size: 11px; }
.sidebar-nav { padding: 18px 12px; flex: 1; }
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 46px;
    margin-bottom: 6px;
    padding: 0 14px;
    border-radius: 10px;
    color: #cbd5e1;
    transition: .15s ease;
}
.sidebar-nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar-nav a.active { color: #fff; background: var(--primary); box-shadow: 0 8px 22px rgba(37,99,235,.32); }
.nav-icon { width: 20px; text-align: center; font-size: 18px; }
.sidebar-user {
    margin: 12px;
    padding: 13px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-radius: 12px;
    background: rgba(255,255,255,.07);
}
.avatar {
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: #fff;
    background: #334155;
    font-weight: 700;
}
.sidebar-user-text { min-width: 0; flex: 1; }
.sidebar-user-text strong, .sidebar-user-text small { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.sidebar-user-text small { color: var(--sidebar-muted); font-size: 12px; }
.logout-link { color: #cbd5e1; font-size: 12px; }
.logout-link:hover { color: #fff; }

.main-area { min-height: 100vh; margin-left: 240px; }
.topbar {
    position: sticky;
    z-index: 20;
    top: 0;
    min-height: 74px;
    padding: 12px 26px;
    display: flex;
    align-items: center;
    gap: 14px;
    background: rgba(255,255,255,.94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
}
.topbar h1 { margin: 0; font-size: 21px; line-height: 1.3; }
.topbar p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.menu-button {
    display: none;
    width: 40px;
    height: 40px;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--text);
    background: #fff;
    font-size: 19px;
}
.content { padding: 24px 26px 40px; }

.card {
    background: var(--card);
    border: 1px solid rgba(229,231,235,.9);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card-header {
    min-height: 58px;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--line);
}
.card-header h2, .card-header h3 { margin: 0; font-size: 16px; }
.card-body { padding: 18px; }
.card-footer { padding: 14px 18px; border-top: 1px solid var(--line); }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { padding: 19px; position: relative; overflow: hidden; }
.stat-card::after { content: ''; position: absolute; width: 80px; height: 80px; right: -26px; top: -28px; border-radius: 50%; background: var(--primary-soft); }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { margin-top: 7px; font-size: 27px; line-height: 1.2; font-weight: 750; }
.stat-note { margin-top: 7px; color: var(--muted); font-size: 12px; }

.two-columns { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, .8fr); gap: 20px; }
.stack { display: grid; gap: 20px; }

.button {
    min-height: 38px;
    padding: 8px 15px;
    border: 1px solid transparent;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-weight: 600;
    white-space: nowrap;
    transition: .15s ease;
}
.button:hover { transform: translateY(-1px); }
.button-primary { color: #fff; background: var(--primary); border-color: var(--primary); }
.button-primary:hover { background: var(--primary-dark); }
.button-secondary { color: var(--text); background: #fff; border-color: var(--line); }
.button-danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.button-link { min-height: auto; padding: 2px 5px; color: var(--primary); background: transparent; }
.button-small { min-height: 32px; padding: 5px 11px; font-size: 13px; }
.button-block { width: 100%; }

.role-badge, .badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 650;
}
.role-level1 { color: #7c3aed; background: #f3e8ff; }
.role-level2 { color: #0369a1; background: #e0f2fe; }
.role-dealer { color: #047857; background: #d1fae5; }
.badge-success { color: #047857; background: #d1fae5; }
.badge-muted { color: #475569; background: #f1f5f9; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); background: #fafafa; font-size: 12px; font-weight: 650; white-space: nowrap; }
tbody tr:hover { background: #fbfdff; }
tbody tr:last-child td { border-bottom: 0; }
.cell-main { font-weight: 650; }
.cell-sub { color: var(--muted); font-size: 12px; }
.actions { display: flex; align-items: center; gap: 7px; white-space: nowrap; }
.empty { padding: 42px 18px; text-align: center; color: var(--muted); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 17px 20px; }
.form-group { min-width: 0; }
.form-group.full { grid-column: 1 / -1; }
.form-group label { display: block; margin-bottom: 7px; color: #374151; font-weight: 650; }
.required::after { content: ' *'; color: var(--danger); }
.input, select.input, textarea.input {
    width: 100%;
    min-height: 42px;
    padding: 9px 12px;
    border: 1px solid #d6dae1;
    border-radius: 9px;
    outline: 0;
    color: var(--text);
    background: #fff;
    transition: .15s ease;
}
textarea.input { min-height: 100px; resize: vertical; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.form-help { margin-top: 5px; color: var(--muted); font-size: 12px; }
.form-actions { margin-top: 22px; display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.filter-bar { padding: 15px 18px; display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.filter-item { min-width: 150px; }
.filter-item.search { min-width: 230px; flex: 1; }
.filter-item label { display: block; margin-bottom: 5px; color: var(--muted); font-size: 12px; }

.alert {
    margin: 0 0 16px;
    padding: 12px 14px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    border: 1px solid;
    border-radius: 10px;
    transition: opacity .25s ease, transform .25s ease;
}
.alert button { border: 0; padding: 0 2px; color: inherit; background: transparent; font-size: 19px; line-height: 1; }
.alert-success { color: #166534; background: #f0fdf4; border-color: #bbf7d0; }
.alert-warning { color: #92400e; background: #fffbeb; border-color: #fde68a; }
.alert-danger { color: #991b1b; background: #fef2f2; border-color: #fecaca; }
.alert-info { color: #1e40af; background: #eff6ff; border-color: #bfdbfe; }
.alert-hide { opacity: 0; transform: translateY(-5px); }
.error-list { margin: 0; padding-left: 20px; }

.team-tree { display: grid; gap: 16px; }
.team-level { padding-left: 25px; border-left: 2px solid #dbeafe; }
.team-card { padding: 15px; display: flex; align-items: center; gap: 12px; }
.team-card .avatar { color: #1d4ed8; background: #dbeafe; }
.team-card-info { min-width: 0; flex: 1; }
.team-card-info strong { display: block; }
.team-card-info small { display: block; color: var(--muted); }

.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--line); }
.detail-item { min-height: 82px; padding: 15px 17px; background: #fff; }
.detail-item.full { grid-column: 1 / -1; }
.detail-label { color: var(--muted); font-size: 12px; }
.detail-value { margin-top: 6px; word-break: break-word; font-weight: 600; }

.auth-shell {
    min-height: 100vh;
    padding: 30px 18px;
    display: grid;
    place-items: center;
    background:
        radial-gradient(circle at 8% 8%, rgba(59,130,246,.18), transparent 32%),
        radial-gradient(circle at 90% 90%, rgba(99,102,241,.15), transparent 34%),
        #f5f7fb;
}
.auth-box { width: min(430px, 100%); }
.auth-box.wide { width: min(720px, 100%); }
.auth-brand { margin-bottom: 20px; text-align: center; }
.auth-brand .brand-mark { margin: 0 auto 10px; color: #fff; }
.auth-brand h1 { margin: 0; font-size: 24px; }
.auth-brand p { margin: 5px 0 0; color: var(--muted); }
.auth-card { padding: 26px; }
.auth-title { margin: 0 0 20px; font-size: 20px; text-align: center; }
.auth-links { margin-top: 17px; color: var(--muted); text-align: center; }
.auth-links a { color: var(--primary); font-weight: 650; }

.pagination { padding: 15px 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--line); }
.pagination-links { display: flex; gap: 6px; }
.page-link { min-width: 34px; height: 34px; padding: 0 9px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.page-link.active { color: #fff; border-color: var(--primary); background: var(--primary); }
.muted { color: var(--muted); }
.text-primary { color: var(--primary); }
.text-danger { color: var(--danger); }
.money { font-weight: 750; color: #b45309; }
.mobile-card-list { display: none; }
.sidebar-mask { display: none; }

.install-shell { min-height: 100vh; padding: 32px 18px; background: var(--page); }
.install-wrap { width: min(850px, 100%); margin: 0 auto; }
.install-head { margin-bottom: 20px; }
.install-head h1 { margin: 0 0 6px; }
.install-head p { margin: 0; color: var(--muted); }
.code-box { padding: 14px; overflow: auto; border-radius: 9px; color: #d1fae5; background: #0f172a; font: 13px/1.6 Consolas, monospace; white-space: pre-wrap; }

@media (max-width: 1100px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
    .sidebar { transform: translateX(-100%); box-shadow: 14px 0 40px rgba(15,23,42,.25); }
    .menu-open .sidebar { transform: translateX(0); }
    .sidebar-mask { position: fixed; z-index: 35; inset: 0; background: rgba(15,23,42,.45); }
    .menu-open .sidebar-mask { display: block; }
    .main-area { margin-left: 0; }
    .menu-button { display: grid; place-items: center; }
    .topbar { padding: 11px 15px; }
    .topbar h1 { font-size: 18px; }
    .topbar-actions .role-badge { display: none; }
    .content { padding: 16px 14px 30px; }
    .two-columns { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .form-group.full { grid-column: auto; }
    .detail-grid { grid-template-columns: 1fr; }
    .detail-item.full { grid-column: auto; }
}

@media (max-width: 620px) {
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-card { padding: 15px; }
    .stat-value { font-size: 22px; }
    .topbar-actions .button { width: 38px; padding: 0; font-size: 0; }
    .topbar-actions .button::before { content: '+'; font-size: 22px; }
    .desktop-table { display: none; }
    .mobile-card-list { display: grid; gap: 11px; padding: 12px; }
    .mobile-record { padding: 14px; border: 1px solid var(--line); border-radius: 11px; background: #fff; }
    .mobile-record-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
    .mobile-record-title { font-size: 15px; font-weight: 700; }
    .mobile-record-sub { color: var(--muted); font-size: 12px; }
    .mobile-record-grid { margin-top: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
    .mobile-record-grid div { color: var(--muted); font-size: 12px; }
    .mobile-record-grid strong { display: block; color: var(--text); font-size: 13px; }
    .mobile-record-actions { margin-top: 12px; padding-top: 10px; display: flex; gap: 10px; border-top: 1px solid var(--line); }
    .filter-bar { align-items: stretch; }
    .filter-item, .filter-item.search { width: 100%; min-width: 0; }
    .filter-bar .button { flex: 1; }
    .card-header { align-items: flex-start; }
    .form-actions { align-items: stretch; flex-direction: column-reverse; }
    .form-actions .button { width: 100%; }
    .pagination { flex-direction: column; }
    .auth-card { padding: 21px 17px; }
}
