:root {
    --app-primary: #2563eb;
    --app-primary-dark: #1d4ed8;
    --app-primary-soft: #eff6ff;
    --app-accent: #0f9488;
    --app-ink: #172033;
    --app-muted: #64748b;
    --app-panel: rgba(255, 255, 255, .94);
    --app-border: rgba(148, 163, 184, .24);
    --app-surface: #f8fafc;
    --app-radius: 12px;
    --app-shadow: 0 10px 30px rgba(15, 23, 42, .065);
    --app-shadow-hover: 0 18px 42px rgba(15, 23, 42, .11);
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    scroll-behavior: smooth;
}

body {
    background-image:
        radial-gradient(circle at 82% 4%, rgba(37, 99, 235, .09), transparent 28%),
        radial-gradient(circle at 15% 86%, rgba(13, 148, 136, .065), transparent 26%),
        linear-gradient(135deg, rgba(248, 250, 252, .97), rgba(239, 246, 255, .94)),
        url("/static/img/beijing.jpg");
    color: var(--app-ink);
    font-size: .925rem;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

::selection {
    color: #fff;
    background: rgba(37, 99, 235, .82);
}

a,
button,
input,
select,
textarea {
    -webkit-tap-highlight-color: transparent;
}

a {
    transition: color .16s ease, background-color .16s ease, border-color .16s ease;
}

button,
.btn,
.sidebar-link,
.quick-filter,
.form-control,
.form-select {
    transition: color .16s ease, background-color .16s ease, border-color .16s ease, box-shadow .16s ease, transform .16s ease;
}

:focus-visible {
    outline: 3px solid rgba(37, 99, 235, .24);
    outline-offset: 2px;
}

.app-layout {
    grid-template-columns: 252px minmax(0, 1fr);
}

body.sidebar-collapsed .app-layout {
    grid-template-columns: 80px minmax(0, 1fr);
}

.app-sidebar {
    padding: 18px 14px;
    background: rgba(255, 255, 255, .92);
    border-right-color: rgba(203, 213, 225, .62);
    box-shadow: 10px 0 36px rgba(15, 23, 42, .045);
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

.sidebar-brand {
    gap: 12px;
    margin: 0 2px 16px;
    padding: 6px 6px 18px;
}

.sidebar-brand-icon {
    width: 42px;
    height: 42px;
    color: #fff;
    font-size: 1.2rem;
    border-radius: 12px;
    background: linear-gradient(145deg, #3b82f6, #2563eb 58%, #0f9488);
    box-shadow: 0 8px 20px rgba(37, 99, 235, .24);
}

.sidebar-brand-text strong {
    color: var(--app-ink);
    font-size: .98rem;
    font-weight: 850;
}

.sidebar-brand-text small {
    margin-top: 4px;
    font-size: .66rem;
    letter-spacing: .04em;
}

.sidebar-toggle {
    min-height: 38px;
    margin-bottom: 10px;
    padding: .5rem .72rem;
    color: var(--app-muted);
    font-size: .8rem;
    font-weight: 700;
    background: #f8fafc;
}

.sidebar-toggle:hover {
    color: var(--app-primary);
    border-color: rgba(37, 99, 235, .24);
    background: var(--app-primary-soft);
}

.sidebar-section {
    padding: 15px 10px 6px;
    color: #94a3b8;
    font-size: .68rem;
    font-weight: 800;
    letter-spacing: .12em;
}

.sidebar-link {
    position: relative;
    min-height: 42px;
    gap: 11px;
    margin: 3px 0;
    padding: .66rem .75rem;
    color: #475569;
    font-size: .86rem;
    font-weight: 650;
    border: 1px solid transparent;
    border-radius: 9px;
}

.sidebar-link i {
    width: 21px;
    color: #7890aa;
    font-size: 1.05rem;
    transition: color .16s ease, transform .16s ease;
}

.sidebar-link:hover {
    color: var(--app-primary);
    background: rgba(37, 99, 235, .055);
    border-color: rgba(37, 99, 235, .07);
}

.sidebar-link:hover i {
    color: var(--app-primary);
    transform: translateY(-1px);
}

.sidebar-link.active {
    color: var(--app-primary);
    background: linear-gradient(90deg, rgba(37, 99, 235, .12), rgba(37, 99, 235, .055));
    border-color: rgba(37, 99, 235, .1);
    box-shadow: inset 3px 0 0 var(--app-primary);
}

.sidebar-link.active i {
    color: var(--app-primary);
}

.sidebar-user {
    margin-top: 18px;
    padding: 16px 8px 4px;
}

.sidebar-user > div {
    display: flex;
    align-items: center;
    min-height: 34px;
    color: #475569;
    font-size: .8rem;
    font-weight: 700;
}

body.sidebar-collapsed .sidebar-user > div {
    justify-content: center;
}

body.sidebar-collapsed .sidebar-user > div i {
    margin: 0 !important;
    font-size: 1.25rem;
}

.app-content {
    padding: 18px 26px 0;
}

.app-content-inner {
    max-width: 1540px;
}

.app-topbar {
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    padding: 0 2px;
}

.app-breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    color: var(--app-muted);
    font-size: .8rem;
}

.app-breadcrumb a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #475569;
    font-weight: 700;
    text-decoration: none;
}

.app-breadcrumb a:hover {
    color: var(--app-primary);
}

.app-breadcrumb .current {
    overflow: hidden;
    color: #94a3b8;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-topbar-meta {
    display: flex;
    align-items: center;
    gap: 9px;
    flex: 0 0 auto;
}

.app-edition-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: .32rem .65rem;
    color: #0f766e;
    font-size: .7rem;
    font-weight: 750;
    border: 1px solid rgba(13, 148, 136, .14);
    border-radius: 999px;
    background: rgba(240, 253, 250, .78);
}

.app-topbar-user {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #334155;
    font-size: .78rem;
    font-weight: 750;
}

.app-topbar-avatar {
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--app-primary);
    border: 1px solid rgba(37, 99, 235, .12);
    border-radius: 9px;
    background: rgba(37, 99, 235, .08);
}

.app-content-inner > .d-flex.justify-content-between.align-items-center.mb-4 {
    margin-bottom: 1.35rem !important;
}

body [class$="-page-icon"] {
    width: 48px;
    height: 48px;
    color: #fff;
    font-size: 22px;
    border: 1px solid rgba(255, 255, 255, .7);
    border-radius: 13px;
    background: linear-gradient(145deg, #3b82f6, #2563eb 60%, #0f9488);
    box-shadow: 0 9px 22px rgba(37, 99, 235, .2);
}

.app-content-inner h2 {
    color: #162033;
    font-size: clamp(1.35rem, 2vw, 1.65rem);
    font-weight: 800;
    letter-spacing: -.01em;
}

.app-content-inner h2 + .text-muted {
    font-size: .79rem;
}

.card {
    border-color: var(--app-border) !important;
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow) !important;
}

.card-header {
    border-bottom-color: var(--app-border) !important;
}

body [class$="-card-header"] {
    padding: 14px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, .12);
    border-radius: var(--app-radius) var(--app-radius) 0 0;
    background: linear-gradient(115deg, #1e4fbf, #2563eb 58%, #0f827a);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .12);
}

body [class*="-header-sub"] {
    font-weight: 500;
    opacity: .76;
}

body [class*="-count-badge"] {
    backdrop-filter: blur(8px);
}

.stat-card,
.metric-card,
.inv-stat {
    border: 1px solid var(--app-border) !important;
    border-radius: var(--app-radius) !important;
    background: rgba(255, 255, 255, .93);
    box-shadow: var(--app-shadow);
}

.stat-card {
    min-height: 138px;
}

.stat-card::after,
.metric-card::after {
    content: "";
    position: absolute;
    right: -34px;
    bottom: -46px;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(37, 99, 235, .055), transparent 68%);
    pointer-events: none;
}

.stat-value,
.metric-value,
.inv-stat-value {
    font-variant-numeric: tabular-nums;
    letter-spacing: -.025em;
}

.stat-icon,
.metric-icon,
.inv-stat-icon {
    border: 1px solid rgba(37, 99, 235, .08);
    border-radius: 11px;
}

.btn {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: .46rem .85rem;
    font-size: .82rem;
    font-weight: 700;
    border-radius: 8px;
}

.btn-sm {
    min-height: 32px;
    padding: .32rem .65rem;
    font-size: .76rem;
    border-radius: 7px;
}

.btn-lg {
    min-height: 46px;
    padding: .65rem 1.25rem;
    font-size: .92rem;
}

.btn-primary {
    border-color: var(--app-primary);
    background: linear-gradient(135deg, #3478f6, var(--app-primary));
    box-shadow: 0 6px 16px rgba(37, 99, 235, .16);
}

.btn-primary:hover,
.btn-primary:focus {
    border-color: var(--app-primary-dark);
    background: linear-gradient(135deg, var(--app-primary), var(--app-primary-dark));
    box-shadow: 0 9px 22px rgba(37, 99, 235, .24);
    transform: translateY(-1px);
}

.btn-outline-primary {
    color: var(--app-primary);
    border-color: rgba(37, 99, 235, .3);
    background: rgba(255, 255, 255, .66);
}

.btn-outline-primary:hover,
.btn-outline-primary:focus {
    color: #fff;
    border-color: var(--app-primary);
    background: var(--app-primary);
}

.btn-outline-secondary {
    color: #52637a;
    border-color: #d5dfeb;
    background: rgba(255, 255, 255, .66);
}

.btn-outline-secondary:hover,
.btn-outline-secondary:focus {
    color: #26364d;
    border-color: #b8c6d8;
    background: #f1f5f9;
}

.btn-outline-success {
    color: #047857;
    border-color: rgba(5, 150, 105, .28);
    background: rgba(255, 255, 255, .66);
}

.btn-dark {
    border-color: #1e293b;
    background: linear-gradient(135deg, #334155, #172033);
}

body [class*="-btn-submit"],
body [class*="-btn-add"] {
    border-radius: 9px;
    background: linear-gradient(135deg, #059669, #0f9488);
    box-shadow: 0 9px 22px rgba(5, 150, 105, .22);
}

.form-label {
    color: #52637a;
    font-size: .8rem;
}

.form-control,
.form-select,
.input-group-text {
    min-height: 40px;
    color: var(--app-ink);
    font-size: .84rem;
    border-color: #d8e1ec;
    border-radius: 8px;
    background-color: rgba(255, 255, 255, .88);
}

.form-control-sm,
.input-group-sm .form-control,
.input-group-sm .input-group-text {
    min-height: 33px;
}

.input-group-lg .form-control,
.input-group-lg .input-group-text {
    min-height: 48px;
}

.form-control::placeholder {
    color: #a1afbf;
}

.form-control:hover,
.form-select:hover {
    border-color: #bdccde;
}

.form-control:focus,
.form-select:focus {
    border-color: #82adf8;
    background-color: #fff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .105);
}

.input-group-text {
    color: #8191a5;
    background-color: #f4f7fb;
}

.form-check-input {
    border-color: #bdc9d8;
}

.form-check-input:checked {
    border-color: var(--app-primary);
    background-color: var(--app-primary);
}

.table {
    --bs-table-hover-bg: rgba(37, 99, 235, .035);
    font-size: .83rem;
}

.table > thead > tr > th {
    color: #697b91;
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .02em;
    background: #f7f9fc;
    border-bottom-color: #e2e8f0;
}

.table > tbody > tr > td {
    border-color: #edf1f6;
}

.table > tbody > tr {
    transition: background-color .14s ease, box-shadow .14s ease;
}

.table-responsive {
    scrollbar-width: thin;
    scrollbar-color: #c4d0df #f8fafc;
    -webkit-overflow-scrolling: touch;
}

.table-responsive::-webkit-scrollbar {
    height: 8px;
}

.table-responsive::-webkit-scrollbar-thumb {
    border: 2px solid #f8fafc;
    border-radius: 999px;
    background: #c4d0df;
}

.badge {
    padding: .38em .62em;
    font-size: .72rem;
    font-weight: 700;
    border: 1px solid transparent;
    border-radius: 7px;
}

.badge.bg-success {
    color: #047857;
    border-color: rgba(5, 150, 105, .12);
    background: #e8f8f1 !important;
}

.badge.bg-secondary {
    color: #52637a;
    border-color: rgba(100, 116, 139, .1);
    background: #edf2f7 !important;
}

.quick-filter {
    min-height: 34px;
    padding: .4rem .75rem;
    font-size: .77rem;
    font-weight: 650;
    background: rgba(255, 255, 255, .76);
}

.quick-filter.active {
    box-shadow: 0 4px 12px rgba(37, 99, 235, .09);
}

.alert {
    position: relative;
    padding: .8rem 2.6rem .8rem 1rem;
    font-size: .82rem;
    border: 1px solid transparent;
    border-radius: 10px;
    box-shadow: 0 8px 22px rgba(15, 23, 42, .055);
}

.alert-info {
    color: #24539d;
    border-color: #dbeafe;
    background: rgba(239, 246, 255, .96);
}

.alert-warning {
    color: #8a5410;
    border-color: #fde9bd;
    background: rgba(255, 251, 235, .96);
}

.app-flash {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.app-flash > i {
    flex: 0 0 auto;
}

.app-flash .btn-close {
    position: absolute;
    top: 50%;
    right: 12px;
    padding: 0;
    font-size: .72rem;
    transform: translateY(-50%);
}

.modal-content {
    overflow: hidden;
    border: 1px solid var(--app-border);
    border-radius: 14px !important;
    box-shadow: 0 26px 70px rgba(15, 23, 42, .2);
}

.modal-header,
.modal-footer {
    border-color: #e7edf4;
}

.modal-backdrop.show {
    opacity: .42;
}

.pagination {
    gap: 4px;
}

.page-link {
    min-width: 34px;
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    color: #52637a;
    font-size: .78rem;
    border: 1px solid #dce4ee;
    border-radius: 8px !important;
}

.page-item.active .page-link {
    border-color: var(--app-primary);
    background: var(--app-primary);
    box-shadow: 0 5px 12px rgba(37, 99, 235, .2);
}

.app-footer {
    margin-top: 32px !important;
    margin-bottom: 20px !important;
    font-size: .7rem !important;
    opacity: .75;
}

.login-shell {
    min-height: calc(100vh - 90px);
}

.login-panel {
    border-radius: 20px;
    box-shadow: 0 30px 90px rgba(15, 23, 42, .18);
}

.login-brand-panel {
    background:
        radial-gradient(circle at 84% 12%, rgba(34, 211, 238, .2), transparent 32%),
        linear-gradient(145deg, rgba(15, 45, 105, .98), rgba(18, 93, 130, .95) 58%, rgba(7, 114, 105, .96)),
        linear-gradient(90deg, rgba(255, 255, 255, .1) 1px, transparent 1px),
        linear-gradient(rgba(255, 255, 255, .08) 1px, transparent 1px);
    background-size: auto, auto, 34px 34px, 34px 34px;
}

.login-brand-title {
    letter-spacing: .02em;
}

.login-form-kicker {
    letter-spacing: .14em;
}

.login-form .form-control,
.login-form .input-group-text {
    min-height: 48px;
}

.login-form .input-group:focus-within .input-group-text {
    border-color: #82adf8;
}

.lg-password-toggle {
    min-width: 46px;
    color: #8191a5;
    border: 1px solid #d8e1ec;
    border-left: 0;
    border-radius: 0 8px 8px 0;
    background: #f8fafc;
}

.lg-password-toggle:hover,
.lg-password-toggle:focus {
    color: var(--app-primary);
    background: #fff;
}

.login-form .form-control.lg-password-input {
    border-right: 0;
    border-radius: 0;
}

.auth-body .app-footer {
    display: none;
}

body {
    overflow-x: hidden;
    background-image:
        radial-gradient(circle at 82% 4%, rgba(37, 99, 235, .07), transparent 28%),
        radial-gradient(circle at 15% 86%, rgba(13, 148, 136, .045), transparent 26%),
        linear-gradient(135deg, rgba(248, 250, 252, .985), rgba(239, 246, 255, .975)),
        url("/static/img/beijing.jpg");
}

.app-topbar {
    padding: 6px 11px;
    border: 1px solid rgba(203, 213, 225, .48);
    border-radius: 11px;
    background: rgba(255, 255, 255, .48);
    backdrop-filter: blur(10px);
}

.stat-card,
.metric-card {
    min-height: 124px;
}

.stat-card .card-body,
.metric-card .card-body,
.db-stat-card .card-body {
    padding: 17px 18px;
}

.stat-value,
.metric-value {
    font-size: clamp(1.4rem, 2vw, 2rem);
}

.stat-card .stat-icon,
.metric-card .metric-icon {
    width: 38px;
    height: 38px;
}

body .inv-card-header {
    color: var(--app-ink);
    border-bottom: 1px solid #e5ebf2;
    background: linear-gradient(90deg, #f8faff, #f2f8fc) !important;
    box-shadow: none;
}

.inv-card-header .inv-cat-badge {
    color: #1d4ed8;
    background: #eaf2ff;
}

.inv-card-header .inv-cat-count {
    color: #52637a;
    background: #e8eef6;
}

.inv-card-header .inv-cat-value {
    color: #64748b;
}

.inv-table td {
    padding-top: .68rem;
    padding-bottom: .68rem;
}

.inv-batch-text {
    overflow-wrap: anywhere;
}

@media (max-width: 760px) {
    .app-topbar {
        padding: 4px 8px;
        background: rgba(255, 255, 255, .6);
    }

    .card.stat-card,
    .card.metric-card {
        min-height: 118px;
    }

    .stat-card .card-body,
    .metric-card .card-body,
    .db-stat-card .card-body {
        padding: 13px;
    }

    .stat-card .stat-icon,
    .metric-card .metric-icon {
        width: 32px;
        height: 32px;
        font-size: .85rem;
    }

    .stat-card .stat-value,
    .metric-card .metric-value {
        font-size: clamp(1.05rem, 5.2vw, 1.45rem);
        overflow-wrap: anywhere;
    }

    .stat-card .text-muted.small,
    .metric-card .text-muted.small {
        font-size: .68rem;
    }

    .metric-card .rp-metric-label,
    .stat-card h6 {
        font-size: .7rem !important;
    }

    .inv-card-header .inv-cat-value {
        width: 100%;
    }
}

@media (max-width: 1080px) {
    .app-layout {
        grid-template-columns: 80px minmax(0, 1fr);
    }

    .app-content {
        padding: 16px 18px 0;
    }

    .app-topbar {
        margin-bottom: 16px;
    }
}

@media (max-width: 760px) {
    body {
        font-size: .875rem;
        background-attachment: scroll;
    }

    .app-content {
        padding: 66px 12px 0;
    }

    .app-topbar {
        min-height: 34px;
        margin-bottom: 14px;
    }

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

    .app-breadcrumb {
        font-size: .75rem;
    }

    .app-content-inner > .d-flex.justify-content-between.align-items-center.mb-4 {
        align-items: flex-start !important;
        gap: 14px !important;
    }

    .app-content-inner > .d-flex.justify-content-between.align-items-center.mb-4 > .d-flex:last-child:not(:first-child) {
        width: 100%;
    }

    .app-content-inner > .d-flex.justify-content-between.align-items-center.mb-4 > .d-flex:last-child:not(:first-child) .btn {
        flex: 1 1 auto;
    }

    body [class$="-page-icon"] {
        width: 42px;
        height: 42px;
        font-size: 19px;
        border-radius: 11px;
    }

    .app-content-inner h2 {
        font-size: 1.25rem;
    }

    .app-content-inner h2 + .text-muted {
        max-width: 270px;
        font-size: .74rem;
        line-height: 1.45;
    }

    .card {
        border-radius: 11px;
    }

    body [class$="-card-header"] {
        align-items: flex-start;
        padding: 13px 15px;
        border-radius: 11px 11px 0 0;
    }

    body [class*="-header-sub"] {
        display: block;
        margin: 3px 0 0 !important;
        font-size: .7rem;
        line-height: 1.4;
    }

    .card-body.p-4 {
        padding: 1rem !important;
    }

    .stat-card {
        min-height: 126px;
    }

    .stat-value {
        font-size: clamp(1.35rem, 6vw, 1.85rem);
    }

    .btn {
        min-height: 40px;
    }

    .btn-sm {
        min-height: 34px;
    }

    .table {
        font-size: .79rem;
    }

    .table > thead > tr > th {
        font-size: .7rem;
    }

    .login-shell {
        padding-top: 0;
    }

    .login-panel {
        border-radius: 16px;
    }

    .login-brand-panel {
        min-height: 232px;
        padding: 30px 26px;
    }

    .login-brand-mark {
        width: 58px;
        height: 58px;
        margin-bottom: 18px;
        font-size: 26px;
    }

    .login-brand-title {
        font-size: 36px;
    }

    .login-brand-line {
        margin-top: 20px;
    }

    .login-form-panel {
        padding: 30px 24px 26px;
    }

    .login-form-head {
        margin-bottom: 26px;
    }

    .login-form-head h1 {
        font-size: 27px;
    }

    .app-footer {
        margin-top: 24px !important;
    }
}

@media (max-width: 420px) {
    .app-content-inner > .d-flex.justify-content-between.align-items-center.mb-4 > .d-flex:last-child:not(:first-child) .btn {
        flex-basis: calc(50% - 5px);
    }

    .app-content-inner > .d-flex.justify-content-between.align-items-center.mb-4 > .d-flex:last-child:not(:first-child) .db-user-pill {
        display: none;
    }
}

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

@media print {
    .app-sidebar,
    .app-topbar,
    .mobile-sidebar-trigger,
    .sidebar-backdrop,
    .app-footer {
        display: none !important;
    }

    .app-layout,
    body.sidebar-collapsed .app-layout {
        display: block;
    }

    .app-content {
        padding: 0;
    }

    .card {
        box-shadow: none !important;
    }
}
