:root {
    --responsive-shell-padding: clamp(14px, 2vw, 32px);
    --responsive-card-radius: 20px;
    --responsive-gap: clamp(12px, 1.2vw, 24px);
    --responsive-form-height: 46px;
    --responsive-sidebar-width: min(86vw, 320px);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    min-width: 320px;
    min-height: calc(var(--app-vh, 1vh) * 100);
    min-height: 100dvh;
    overflow-x: hidden;
}

img,
svg,
video,
canvas {
    max-width: 100%;
    height: auto;
}

pre,
code,
.code-box,
.api-code,
.token-box,
.token-text,
.mailbox-code,
.detail-mono,
.today-record-code,
.today-order-meta,
.today-order-content,
.order-content-box,
.result-content,
.error-log-box {
    max-width: 100%;
    overflow-wrap: anywhere;
}

.row > *,
[class*="col-"],
.d-flex > *,
.card,
.panel-card,
.card-custom,
.hero-card,
.user-card,
.sidebar-card,
.workspace-card,
.modal-content {
    min-width: 0;
}

.page-shell,
.dashboard-shell,
.user-container,
.verify-container,
.login-shell,
.login-box {
    width: min(100%, calc(100vw - (var(--responsive-shell-padding) * 2)));
    margin-left: auto;
    margin-right: auto;
}

.panel-card,
.card-shell,
.hero-card,
.verify-card,
.login-card,
.card-custom,
.stat-card,
.preview-card,
.sidebar-card,
.user-card,
.workspace-card,
.fold-card {
    border-radius: var(--responsive-card-radius) !important;
}

.card-body-custom,
.login-body,
.hero-body,
.card-custom .card-body,
.workspace-card > .card-body {
    padding: clamp(18px, 2vw, 32px) !important;
}

.card-custom .card-header,
.login-head,
.hero-top,
.card-header-custom {
    padding: clamp(18px, 2vw, 32px) !important;
}

.form-control,
.form-select,
.btn-login,
.btn-verify {
    min-height: var(--responsive-form-height);
}

textarea.form-control {
    min-height: 96px;
}

.btn,
.form-control,
.form-select,
.input-group,
.dropdown-menu {
    max-width: 100%;
}

.table-responsive,
.responsive-auto-wrap,
.table-shell {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-responsive table,
.responsive-auto-wrap table,
.table-shell table {
    min-width: 100%;
}

.table th,
.table td {
    vertical-align: middle;
}

.table thead th {
    white-space: nowrap;
}

.modal-dialog {
    max-width: min(var(--bs-modal-width, 760px), calc(100vw - 24px));
}

.modal-body {
    max-height: calc((var(--app-vh, 1vh) * 100) - 9rem);
    overflow-y: auto;
}

.modal-body .table-responsive,
.modal-body .responsive-auto-wrap {
    max-height: 60dvh;
}

.page-header,
.card-header-row,
.section-head,
.mailbox-panel-note,
.pagination-bar,
.pager-bar,
.hero-title-row,
.block-title {
    min-width: 0;
}

.hero-actions,
.head-actions,
.toolbar-meta,
.inline-actions,
.pager-actions,
.project-quick-actions,
.action-row {
    min-width: 0;
}

#content {
    width: auto;
    overflow-x: hidden;
}

#sidebar {
    top: 0;
    left: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.responsive-sidebar-toggle {
    position: fixed;
    right: 16px;
    bottom: max(16px, env(safe-area-inset-bottom));
    display: none;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 10px 15px;
    border: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1;
    box-shadow: 0 18px 36px rgba(37, 99, 235, 0.28);
    z-index: 1071;
}

.responsive-sidebar-toggle:hover,
.responsive-sidebar-toggle:focus {
    filter: brightness(1.04);
}

.responsive-sidebar-toggle-icon {
    font-size: 1.1rem;
    line-height: 1;
}

.responsive-sidebar-backdrop {
    position: fixed;
    inset: 0;
    display: none;
    background: rgba(15, 23, 42, 0.46);
    backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
    z-index: 1055;
}

@media (max-width: 1400px) {
    .page-shell,
    .dashboard-shell {
        max-width: calc(100vw - 32px);
    }
}

@media (max-width: 1200px) {
    .page-header,
    .hero-title-row,
    .section-head,
    .card-header-row {
        flex-direction: column;
        align-items: stretch !important;
    }

    #content {
        padding: clamp(18px, 3vw, 28px) !important;
    }

    .goods-panel,
    .workspace-grid,
    .workspace-shell,
    .today-summary-grid,
    .order-summary-grid,
    .summary-strip {
        grid-template-columns: 1fr !important;
    }

    .create-panel,
    .module-sidebar,
    .sticky-top-card {
        position: static !important;
    }
}

@media (max-width: 991.98px) {
    body.has-responsive-sidebar {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    #sidebar {
        width: var(--responsive-sidebar-width) !important;
        height: calc(var(--app-vh, 1vh) * 100) !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        margin-left: 0 !important;
        transform: translateX(-104%);
        transition: transform 0.26s ease;
        z-index: 1060 !important;
    }

    #content {
        margin-left: 0 !important;
        max-width: 100vw !important;
        padding: 18px !important;
    }

    body.has-responsive-sidebar .responsive-sidebar-toggle {
        display: inline-flex;
    }

    body.responsive-sidebar-open #sidebar {
        transform: translateX(0);
    }

    body.has-responsive-sidebar .responsive-sidebar-backdrop {
        display: block;
    }

    body.responsive-sidebar-open .responsive-sidebar-backdrop {
        opacity: 1;
        pointer-events: auto;
    }

    body.responsive-sidebar-open {
        overflow: hidden;
    }

    .toolbar-grid,
    .filter-grid,
    .stats-grid,
    .user-card-body,
    .result-meta,
    .detail-meta-grid,
    .sidebar-nav {
        grid-template-columns: 1fr !important;
    }

    .action-row,
    .toolbar-meta,
    .hero-actions,
    .head-actions,
    .inline-actions,
    .pager-actions,
    .project-quick-actions {
        justify-content: flex-start !important;
    }

    .action-row > *,
    .toolbar-grid > *,
    .filter-grid > * {
        min-width: 0;
    }
}

@media (max-width: 767.98px) {
    .page-shell,
    .dashboard-shell,
    .user-container,
    .verify-container,
    .login-shell,
    .login-box {
        width: min(100%, calc(100vw - 24px));
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .page-shell {
        padding-top: 18px !important;
        padding-bottom: 40px !important;
    }

    .panel-card,
    .card-shell,
    .hero-card,
    .verify-card,
    .login-card,
    .card-custom,
    .stat-card,
    .preview-card,
    .sidebar-card,
    .user-card,
    .workspace-card,
    .fold-card {
        border-radius: 16px !important;
    }

    .hero-top h1,
    .hero-title {
        font-size: 1.65rem !important;
        line-height: 1.2;
    }

    .balance-value,
    .stats-card strong,
    .stat-value,
    .order-summary-card strong {
        font-size: 1.45rem !important;
    }

    .goods-panel,
    .info-item,
    .result-meta,
    .today-summary-grid,
    .order-summary-grid,
    .summary-strip,
    .stats-grid,
    .user-card-body,
    .toolbar-grid,
    .filter-grid,
    .sidebar-nav {
        grid-template-columns: 1fr !important;
        flex-direction: column;
    }

    .page-header,
    .hero-title-row,
    .card-header-row,
    .section-head,
    .user-card-head,
    .identity-wrap,
    .head-actions,
    .mailbox-panel-note,
    .pager-bar,
    .pagination-bar {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    .info-value {
        text-align: left !important;
    }

    .hero-actions,
    .head-actions,
    .toolbar-meta,
    .inline-actions,
    .pager-actions,
    .project-quick-actions,
    .action-row {
        width: 100%;
        justify-content: stretch !important;
    }

    .hero-actions .btn,
    .head-actions .btn,
    .toolbar-meta .btn,
    .inline-actions .btn,
    .pager-actions .btn,
    .project-quick-actions .btn,
    .page-header .btn,
    .action-row .btn,
    .action-row > *,
    .input-group > .btn {
        flex: 1 1 auto;
    }

    .modal-dialog {
        width: calc(100vw - 16px) !important;
        max-width: calc(100vw - 16px) !important;
        margin: 8px auto !important;
    }

    .modal-body {
        max-height: calc((var(--app-vh, 1vh) * 100) - 7rem);
    }

    .chart-wrap {
        height: 260px !important;
    }

    .error-log-box {
        height: 55dvh !important;
    }
}

@media (max-width: 575.98px) {
    .card-body-custom,
    .login-body,
    .hero-body,
    .card-custom .card-body,
    .workspace-card > .card-body {
        padding: 16px !important;
    }

    .card-custom .card-header,
    .login-head,
    .hero-top,
    .card-header-custom {
        padding: 16px !important;
    }

    .btn {
        min-height: 42px;
        white-space: normal;
    }

    .input-group {
        flex-wrap: wrap;
        gap: 8px;
    }

    .input-group > .form-control,
    .input-group > .form-select,
    .input-group > .btn {
        width: 100%;
        flex: 1 1 100%;
        border-radius: 12px !important;
    }

    .table th,
    .table td {
        padding: 0.65rem 0.75rem;
        font-size: 0.9rem;
    }

    .responsive-sidebar-toggle {
        right: 12px;
        bottom: max(12px, env(safe-area-inset-bottom));
        padding: 10px 13px;
    }
}

@media (max-width: 420px) {
    .page-shell,
    .dashboard-shell,
    .user-container,
    .verify-container,
    .login-shell,
    .login-box {
        width: min(100%, calc(100vw - 16px));
    }

    .hero-top h1,
    .hero-title {
        font-size: 1.45rem !important;
    }

    .btn,
    .form-control,
    .form-select {
        font-size: 0.92rem;
    }
}
