:root {
    --admin-bg: #f5f7fb;
    --admin-surface: #ffffff;
    --admin-surface-subtle: #f8fafc;
    --admin-sidebar: #111827;
    --admin-sidebar-soft: #1f2937;
    --admin-text: #172033;
    --admin-text-muted: #687386;
    --admin-border: #e4e9f1;
    --admin-primary: #4f46e5;
    --admin-primary-dark: #4338ca;
    --admin-primary-soft: #eef2ff;
    --admin-success: #14866d;
    --admin-success-soft: #e9f8f2;
    --admin-warning: #b66b0a;
    --admin-warning-soft: #fff7e6;
    --admin-danger: #c2414b;
    --admin-danger-soft: #fff0f1;
    --admin-info: #2563a8;
    --admin-info-soft: #edf6ff;
    --admin-radius: 14px;
    --admin-radius-sm: 9px;
    --admin-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .05);
    --admin-sidebar-width: 256px;
    --admin-topbar-height: 72px;
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
    margin: 0;
    color: var(--admin-text);
    background: var(--admin-bg);
    font-family: Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

a { color: var(--admin-primary); }

:focus-visible {
    outline: 3px solid rgba(79, 70, 229, .22);
    outline-offset: 2px;
}

/* App shell */
.admin-shell { min-height: 100vh; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1040;
    display: flex;
    width: var(--admin-sidebar-width);
    min-height: 100vh;
    flex-direction: column;
    color: #d6dbea;
    background: var(--admin-sidebar);
    border-right: 1px solid rgba(255, 255, 255, .06);
    transition: width .22s ease, transform .22s ease;
}

.sidebar-header {
    display: flex;
    min-height: var(--admin-topbar-height);
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.brand-mark {
    display: grid;
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    place-items: center;
    color: #fff;
    background: var(--admin-primary);
    border-radius: 11px;
    box-shadow: 0 7px 18px rgba(79, 70, 229, .35);
    font-size: 19px;
}

.brand-copy { min-width: 0; }
.brand-title { color: #fff; font-size: 15px; font-weight: 700; letter-spacing: .02em; }
.brand-subtitle { color: #8e99ad; font-size: 11px; margin-top: 1px; }

.sidebar-nav {
    display: block !important;
    flex: 1;
    overflow: auto;
    padding: 14px 12px 24px;
    scrollbar-width: thin;
}

.nav-section-label {
    padding: 14px 10px 6px;
    color: #748096;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .14em;
    text-transform: uppercase;
}

.sidebar .nav-link {
    position: relative;
    display: flex;
    min-height: 42px;
    align-items: center;
    gap: 11px;
    margin: 2px 0;
    padding: 10px 12px;
    color: #aeb7c8;
    border-radius: 9px;
    text-decoration: none;
    cursor: pointer;
    transition: color .16s ease, background .16s ease;
}

.sidebar .nav-link i { width: 20px; font-size: 17px; text-align: center; }
.sidebar .nav-link span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar .nav-link:hover { color: #fff; background: rgba(255, 255, 255, .06); }
.sidebar .nav-link.active { color: #fff; background: rgba(99, 102, 241, .18); }
.sidebar .nav-link.active::before {
    position: absolute;
    top: 11px;
    bottom: 11px;
    left: -12px;
    width: 3px;
    content: "";
    background: #818cf8;
    border-radius: 0 4px 4px 0;
}

.sidebar-footer { padding: 12px; border-top: 1px solid rgba(255, 255, 255, .08); }
.sidebar-collapse {
    display: flex;
    width: 100%;
    align-items: center;
    gap: 11px;
    padding: 9px 12px;
    color: #8e99ad;
    background: transparent;
    border: 0;
    border-radius: 8px;
}
.sidebar-collapse:hover { color: #fff; background: rgba(255, 255, 255, .05); }

.main-wrapper {
    min-height: 100vh;
    margin-left: var(--admin-sidebar-width);
    transition: margin-left .22s ease;
}

.top-navbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    display: flex;
    min-height: var(--admin-topbar-height);
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 12px 28px;
    background: rgba(255, 255, 255, .92);
    border-bottom: 1px solid var(--admin-border);
    backdrop-filter: blur(14px);
}

.topbar-leading { display: flex; min-width: 0; align-items: center; gap: 12px; }
.mobile-menu-btn { display: none; }
.page-heading { min-width: 0; }
.page-title { margin: 0; color: var(--admin-text); font-size: 20px; font-weight: 700; line-height: 1.25; }
.page-description { margin: 2px 0 0; color: var(--admin-text-muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.user-menu { position: relative; }
.user-menu-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 7px 5px 5px;
    color: var(--admin-text);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 11px;
}
.user-menu-toggle:hover, .user-menu-toggle[aria-expanded="true"] { background: var(--admin-surface-subtle); border-color: var(--admin-border); }
.user-avatar {
    display: grid;
    width: 34px;
    height: 34px;
    place-items: center;
    color: #fff;
    background: #273248;
    border-radius: 10px;
    font-weight: 700;
    text-transform: uppercase;
}
.user-meta { text-align: left; }
.user-name { display: block; max-width: 140px; overflow: hidden; font-size: 13px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.user-role { display: block; color: var(--admin-text-muted); font-size: 11px; }

.content-area { width: 100%; max-width: 1600px; margin: 0 auto; padding: 26px 28px 48px; }
.content-area.is-loading { opacity: .58; pointer-events: none; }
.sidebar-backdrop { display: none; }

body.sidebar-collapsed .sidebar { width: 76px; }
body.sidebar-collapsed .main-wrapper { margin-left: 76px; }
body.sidebar-collapsed .brand-copy,
body.sidebar-collapsed .nav-section-label,
body.sidebar-collapsed .sidebar .nav-link span,
body.sidebar-collapsed .sidebar-collapse span { display: none; }
body.sidebar-collapsed .sidebar-header { justify-content: center; padding-inline: 10px; }
body.sidebar-collapsed .sidebar .nav-link { justify-content: center; padding-inline: 10px; }
body.sidebar-collapsed .sidebar-collapse { justify-content: center; }
body.sidebar-collapsed .sidebar-collapse i { transform: rotate(180deg); }

/* Content primitives */
.content-card, .card {
    margin-bottom: 22px;
    background: var(--admin-surface);
    border: 1px solid var(--admin-border);
    border-radius: var(--admin-radius);
    box-shadow: var(--admin-shadow);
}
.content-card { padding: 22px; }
.content-card > .d-flex:first-child { min-height: 38px; }
.content-card h4, .card-header h4 {
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 0;
    color: var(--admin-text);
    font-size: 16px;
    font-weight: 700;
}
.content-card h4 i { color: var(--admin-primary); }
.card { overflow: hidden; }
.card:hover { box-shadow: var(--admin-shadow); }
.card-header { padding: 15px 18px; background: var(--admin-surface); border-bottom: 1px solid var(--admin-border); }
.card-body { padding: 18px; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}
.stat-card {
    position: relative;
    min-height: 154px;
    padding: 20px;
    overflow: hidden;
    background: var(--admin-surface);
    border: 1px solid var(--admin-border);
    border-radius: var(--admin-radius);
    box-shadow: var(--admin-shadow);
}
.stat-card:hover { border-color: #d5dbea; }
.stat-card-icon {
    display: grid;
    width: 38px;
    height: 38px;
    margin-bottom: 18px;
    place-items: center;
    background: var(--admin-primary-soft);
    border-radius: 10px;
    font-size: 18px;
}
.stat-card h3 { margin: 0 0 5px; color: var(--admin-text); font-size: 27px; font-weight: 750; letter-spacing: -.025em; }
.stat-card p { margin: 0; color: var(--admin-text-muted); font-size: 13px; }
.stat-card .stat-caption { margin-top: 8px; font-size: 11px; }
.stat-card.is-paused { background: #fbfcfe; }
.stat-card.is-paused .stat-card-icon { color: var(--admin-warning) !important; background: var(--admin-warning-soft); }
.stat-card.is-paused h3 { color: var(--admin-warning); font-size: 18px; }

/* Tables */
.table-responsive { overflow: auto; border: 1px solid var(--admin-border); border-radius: 11px; box-shadow: none; }
.table { min-width: 720px; margin: 0; color: var(--admin-text); background: var(--admin-surface); vertical-align: middle; }
.table > :not(caption) > * > * { padding: 13px 14px; border-bottom-color: #edf0f5; }
.table thead { color: #596579; background: #f8fafc; }
.table thead th { border: 0; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-align: left; text-transform: uppercase; white-space: nowrap; }
.table tbody td { color: #344054; font-size: 13px; text-align: left; }
.table tbody tr { transition: background .14s ease; }
.table tbody tr:hover { background: #fafbff; transform: none; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .btn-group, .table td:last-child { white-space: nowrap; }
.table .btn-group { display: inline-flex; gap: 5px; flex-wrap: wrap; justify-content: flex-start; }
.table code { color: #4a5568; background: #f1f4f8; border-radius: 5px; padding: 2px 5px; }

/* Buttons */
.btn {
    min-height: 36px;
    padding: 7px 13px;
    gap: 6px;
    border: 1px solid transparent;
    border-radius: 8px;
    box-shadow: none;
    font-size: 13px;
    font-weight: 650;
    transition: background .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.btn:hover { transform: none; }
.btn:active { transform: translateY(1px); }
.btn-sm { min-height: 31px; padding: 5px 9px; font-size: 12px; }
.btn-lg { min-height: 44px; padding: 10px 18px; font-size: 14px; }
.btn-primary { color: #fff; background: var(--admin-primary); border-color: var(--admin-primary); }
.btn-primary:hover { color: #fff; background: var(--admin-primary-dark); border-color: var(--admin-primary-dark); box-shadow: 0 4px 10px rgba(79, 70, 229, .2); }
.btn-success { color: #fff; background: var(--admin-success); border-color: var(--admin-success); }
.btn-success:hover { color: #fff; background: #0f755e; border-color: #0f755e; }
.btn-danger { color: #fff; background: var(--admin-danger); border-color: var(--admin-danger); }
.btn-danger:hover { color: #fff; background: #a93640; border-color: #a93640; }
.btn-warning { color: #875207; background: #fff5db; border-color: #f2d699; }
.btn-warning:hover { color: #704204; background: #ffedbe; border-color: #e8c77e; }
.btn-info { color: var(--admin-info); background: var(--admin-info-soft); border-color: #cfe3f7; }
.btn-info:hover { color: #1f5186; background: #dfedfb; border-color: #bdd8ef; }
.btn-secondary { color: #465166; background: #f1f4f8; border-color: #dce2ea; }
.btn-secondary:hover { color: #293448; background: #e9edf3; border-color: #cfd7e2; }
.btn-light { color: #465166; background: #fff; border-color: var(--admin-border); }
.btn-outline-primary { color: var(--admin-primary); border-color: #c7c9f8; }
.btn-outline-primary:hover { color: var(--admin-primary-dark); background: var(--admin-primary-soft); border-color: #aeb2f2; }
.btn-outline-secondary { color: #536074; border-color: #d2d9e3; }
.btn-outline-secondary:hover { color: #293448; background: #f1f4f8; border-color: #c6cfdb; }
.btn-outline-danger { color: var(--admin-danger); border-color: #f0cbd0; }
.btn:disabled, .btn.disabled {
    color: #8a94a6 !important;
    background: #eef1f5 !important;
    border-color: #e0e5ec !important;
    box-shadow: none !important;
    opacity: 1;
    cursor: not-allowed;
}

/* Forms */
.form-label { margin-bottom: 7px; color: #354054; font-size: 12px; font-weight: 650; }
.form-control, .form-select {
    min-height: 40px;
    padding: 8px 11px;
    color: var(--admin-text);
    background-color: #fff;
    border: 1px solid #d8dee8;
    border-radius: 8px;
    font-size: 13px;
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.form-control::placeholder { color: #9aa4b5; }
.form-control:focus, .form-select:focus { border-color: #8d89eb; box-shadow: 0 0 0 3px rgba(79, 70, 229, .11); }
.form-control:disabled, .form-select:disabled {
    color: #7d8798;
    background-color: #f1f3f6;
    border-color: #e1e5eb;
    opacity: 1;
    cursor: not-allowed;
}
.form-control-sm, .form-select-sm { min-height: 34px; padding: 6px 9px; }
.form-text, small.text-muted { color: var(--admin-text-muted) !important; font-size: 11px; }
textarea.form-control { line-height: 1.55; }
.form-check-input:checked { background-color: var(--admin-primary); border-color: var(--admin-primary); }

/* Status and feedback */
.badge { padding: 5px 8px; gap: 4px; border-radius: 999px; box-shadow: none !important; font-size: 11px; font-weight: 650; }
.badge.bg-success { color: #0c6955 !important; background: var(--admin-success-soft) !important; }
.badge.bg-danger { color: #a8323c !important; background: var(--admin-danger-soft) !important; }
.badge.bg-warning { color: #8a5508 !important; background: var(--admin-warning-soft) !important; }
.badge.bg-info { color: #205d96 !important; background: var(--admin-info-soft) !important; }
.badge.bg-secondary { color: #5f6979 !important; background: #eef1f5 !important; }
.badge.bg-primary { color: var(--admin-primary-dark) !important; background: var(--admin-primary-soft) !important; }

.alert { padding: 12px 14px; border-width: 1px; border-radius: 10px; font-size: 13px; }
.alert-success { color: #0e6e58; background: var(--admin-success-soft); border-color: #c7eadf; }
.alert-info { color: #245b8f; background: var(--admin-info-soft); border-color: #cfe3f7; }
.alert-warning { color: #86530a; background: var(--admin-warning-soft); border-color: #f2d69c; }
.alert-danger { color: #a3333d; background: var(--admin-danger-soft); border-color: #f0ccd0; }
.alert-light { color: #536074; background: #f8fafc; border-color: var(--admin-border) !important; }

.feature-notice { display: flex; align-items: flex-start; gap: 11px; padding: 13px 14px; background: var(--admin-warning-soft); border: 1px solid #f0d598; border-radius: 10px; color: #744908; }
.feature-notice > i { margin-top: 1px; font-size: 16px; }
.feature-notice strong { display: block; margin-bottom: 2px; color: #704506; }
.feature-notice p { margin: 0; color: #8b611e; font-size: 12px; }

.empty-state { padding: 52px 24px !important; color: var(--admin-text-muted) !important; text-align: center !important; }
.empty-state i { display: block; margin-bottom: 9px; color: #a6afbd; font-size: 26px; }

/* Modal and dropdown */
.modal-backdrop.show { opacity: .35; }
.modal-content { overflow: hidden; border: 0; border-radius: 16px; box-shadow: 0 24px 70px rgba(15, 23, 42, .2); }
.modal-header { padding: 17px 21px; color: var(--admin-text); background: #fff; border-bottom: 1px solid var(--admin-border); }
.modal-header.bg-danger { color: var(--admin-danger) !important; background: var(--admin-danger-soft) !important; }
.modal-header.bg-warning { color: var(--admin-warning) !important; background: var(--admin-warning-soft) !important; }
.modal-header .btn-close { filter: none; }
.modal-title { font-size: 16px; font-weight: 700; }
.modal-body { padding: 21px; }
.modal-footer { padding: 14px 21px; background: #fbfcfe; border-top: 1px solid var(--admin-border); }
.dropdown-menu { padding: 7px; border: 1px solid var(--admin-border); border-radius: 11px; box-shadow: 0 14px 36px rgba(15, 23, 42, .14); }
.dropdown-item { padding: 8px 10px; border-radius: 7px; font-size: 13px; }
.dropdown-item:hover { background: var(--admin-primary-soft); color: var(--admin-primary-dark); }

.nav-tabs { border-bottom-color: var(--admin-border); }
.nav-tabs .nav-link { margin-bottom: -1px; padding: 9px 13px; color: var(--admin-text-muted); border: 0; border-bottom: 2px solid transparent; border-radius: 0; }
.nav-tabs .nav-link:hover { color: var(--admin-text); border-bottom-color: #cdd3de; }
.nav-tabs .nav-link.active { color: var(--admin-primary); background: transparent; border-bottom-color: var(--admin-primary); font-weight: 650; }

/* Loading and toast */
.loading-bar { position: fixed; top: 0; right: 0; left: var(--admin-sidebar-width); z-index: 1100; height: 3px; overflow: hidden; opacity: 0; pointer-events: none; transition: left .22s ease, opacity .12s ease; }
.loading-bar::after { display: block; width: 36%; height: 100%; content: ""; background: var(--admin-primary); animation: admin-loading 1s ease-in-out infinite; }
.loading-bar.is-visible { opacity: 1; }
body.sidebar-collapsed .loading-bar { left: 76px; }
@keyframes admin-loading { from { transform: translateX(-110%); } to { transform: translateX(300%); } }

.toast-stack { position: fixed; top: 86px; right: 20px; z-index: 2000; display: grid; width: min(360px, calc(100vw - 32px)); gap: 9px; }
.admin-toast { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; color: #fff; background: #263247; border-radius: 11px; box-shadow: 0 14px 32px rgba(15, 23, 42, .22); animation: toast-in .2s ease; }
.admin-toast.success { background: #146f5d; }
.admin-toast.error { background: #a83a45; }
.admin-toast.warning { background: #9a620e; }
.admin-toast i { margin-top: 1px; }
.admin-toast-content { min-width: 0; flex: 1; }
.admin-toast-message { white-space: pre-line; }
.admin-toast-close { padding: 0; color: inherit; background: transparent; border: 0; opacity: .75; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

.page-error { display: grid; min-height: 420px; place-items: center; text-align: center; }
.page-error-panel { max-width: 440px; padding: 38px; }
.page-error-icon { display: grid; width: 52px; height: 52px; margin: 0 auto 15px; place-items: center; color: var(--admin-danger); background: var(--admin-danger-soft); border-radius: 14px; font-size: 24px; }

/* Login */
body.login-page { min-height: 100vh; background: #f4f6fa; }
.login-shell { display: grid; min-height: 100vh; grid-template-columns: minmax(360px, .85fr) minmax(480px, 1.15fr); }
.login-panel { display: flex; align-items: center; justify-content: center; padding: 48px; background: #fff; }
.login-box { width: min(100%, 390px); }
.login-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 44px; }
.login-title { margin: 0 0 8px; font-size: 28px; font-weight: 750; letter-spacing: -.02em; }
.login-lead { margin: 0 0 30px; color: var(--admin-text-muted); }
.login-submit { min-height: 44px; margin-top: 6px; }
.login-aside { position: relative; display: flex; overflow: hidden; align-items: flex-end; padding: 64px; color: #fff; background: #111827; }
.login-aside::before { position: absolute; inset: -25% auto auto 15%; width: 520px; height: 520px; content: ""; background: radial-gradient(circle, rgba(99, 102, 241, .48), transparent 67%); }
.login-aside::after { position: absolute; right: -10%; bottom: -30%; width: 520px; height: 520px; content: ""; background: radial-gradient(circle, rgba(20, 134, 109, .3), transparent 67%); }
.login-aside-content { position: relative; z-index: 1; max-width: 560px; }
.login-kicker { display: inline-flex; align-items: center; gap: 7px; margin-bottom: 18px; padding: 6px 10px; color: #d9ddff; background: rgba(99, 102, 241, .2); border: 1px solid rgba(165, 180, 252, .2); border-radius: 999px; font-size: 12px; }
.login-aside h2 { margin: 0 0 14px; font-size: clamp(30px, 4vw, 48px); line-height: 1.12; letter-spacing: -.035em; }
.login-aside p { max-width: 500px; margin: 0; color: #aeb7c8; font-size: 15px; }

@media (max-width: 1199px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .content-area { padding: 22px; }
}

@media (max-width: 991px) {
    .sidebar { width: min(288px, 86vw); transform: translateX(-100%); box-shadow: 18px 0 50px rgba(15, 23, 42, .22); }
    .main-wrapper, body.sidebar-collapsed .main-wrapper { margin-left: 0; }
    .loading-bar, body.sidebar-collapsed .loading-bar { left: 0; }
    .mobile-menu-btn { display: inline-flex; width: 38px; min-width: 38px; align-items: center; justify-content: center; padding: 0; }
    .sidebar-collapse { display: none; }
    body.sidebar-collapsed .sidebar { width: min(288px, 86vw); }
    body.sidebar-collapsed .brand-copy,
    body.sidebar-collapsed .nav-section-label,
    body.sidebar-collapsed .sidebar .nav-link span { display: block; }
    body.sidebar-collapsed .sidebar-header { justify-content: flex-start; padding-inline: 18px; }
    body.sidebar-collapsed .sidebar .nav-link { justify-content: flex-start; padding-inline: 12px; }
    body.mobile-nav-open { overflow: hidden; }
    body.mobile-nav-open .sidebar { transform: translateX(0); }
    body.mobile-nav-open .sidebar-backdrop { position: fixed; inset: 0; z-index: 1030; display: block; background: rgba(15, 23, 42, .48); border: 0; }
    .login-shell { grid-template-columns: 1fr; }
    .login-aside { display: none; }
}

@media (max-width: 767px) {
    .top-navbar { min-height: 64px; padding: 10px 16px; }
    .page-title { font-size: 17px; }
    .page-description, .user-meta, .user-menu-toggle > .bi-chevron-down { display: none; }
    .content-area { padding: 16px 12px 36px; }
    .content-card { padding: 16px; border-radius: 12px; }
    .content-card > .d-flex:first-child { align-items: flex-start !important; gap: 12px; }
    .content-card > .d-flex:first-child .btn { flex: 0 0 auto; }
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-card { min-height: 132px; padding: 16px; }
    .stat-card-icon { margin-bottom: 12px; }
    .stat-card h3 { font-size: 23px; }
    .modal-dialog { margin: 10px; }
    .login-panel { padding: 28px 22px; }
    .login-brand { margin-bottom: 36px; }
}

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

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
