:root {
    --app-bg: #f4f7fb;
    --app-surface: #ffffff;
    --app-surface-soft: #f8fafc;
    --app-border: #dce3ec;
    --app-text: #1f2937;
    --app-muted: #64748b;
    --app-primary: #9400D3;
    --app-primary-dark: #7A00AF;
    --app-warning: #e1ac08;
    --app-success: #16a34a;
    --app-danger: #dc2626;
    --app-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
    --app-shadow-sm: 0 4px 12px rgba(15, 23, 42, 0.06);
}

html {
    min-height: 100%;
}

body {
    min-height: 100%;
    background: var(--app-bg);
    color: var(--app-text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
    line-height: 1.45;
}

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

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

.navbar.app-navbar {
    background: #1F0A2E !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.16);
}

.navbar-brand {
    letter-spacing: 0;
}

.app-brand-mark {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 800;
    color: #fff;
}

/* ══════════════════════════════════════════════════
   CP Nav: multi-level dropdown + sub-bar
   ══════════════════════════════════════════════════ */

.cp-nav {
    gap: 2px;
}

.cp-nav .nav-link {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 6px 12px !important;
    margin: 0;
    border: 1px solid transparent !important;
    border-radius: 6px !important;
    color: #cbd5e1 !important;
    background: transparent;
    font-size: 13px;
    font-weight: 600;
    transition: background-color 0.16s ease, color 0.16s ease, border-color 0.16s ease;
    white-space: nowrap;
}

.cp-nav .nav-link i {
    font-size: 14px;
    width: 16px;
    text-align: center;
}

.cp-nav .nav-link:hover {
    color: #fff !important;
    background: rgba(255, 255, 255, 0.1);
}

.cp-nav .nav-link.active {
    color: #fff !important;
    background: rgba(148, 0, 211, 0.28);
    border-color: rgba(187, 102, 230, 0.4) !important;
}

.cp-nav .dropdown-toggle::after {
    margin-left: 2px;
    vertical-align: 0.15em;
    border-top-width: 0.25em;
    opacity: 0.5;
}

/* Label ALWAYS visible */
.cp-nav-label {
    font-size: 13px;
    font-weight: 700;
}

/* Dropdown panel */
.cp-dropdown {
    background: #2A1040;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px !important;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.35);
    padding: 6px;
    min-width: 200px;
    animation: cpDropIn 0.15s ease-out;
}

@keyframes cpDropIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.cp-drop-item {
    display: flex !important;
    align-items: center;
    gap: 10px;
    padding: 8px 12px !important;
    color: #cbd5e1 !important;
    font-size: 13px;
    font-weight: 600;
    border-radius: 6px;
    transition: background 0.14s, color 0.14s;
}

.cp-drop-item:hover,
.cp-drop-item:focus {
    background: rgba(255, 255, 255, 0.08) !important;
    color: #fff !important;
}

.cp-drop-item.active {
    background: rgba(148, 0, 211, 0.3) !important;
    color: #fff !important;
}

.cp-drop-icon {
    width: 18px;
    text-align: center;
    font-size: 13px;
    opacity: 0.7;
    flex-shrink: 0;
}

/* ── Sub-bar: quick buttons for active group ── */
.cp-subbar {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    z-index: 1029;
    background: var(--app-surface);
    border-bottom: 1px solid var(--app-border);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
}

.cp-subbar-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    overflow-x: auto;
    scrollbar-width: thin;
}

.cp-subbar-title {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    font-weight: 800;
    color: var(--app-muted);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    white-space: nowrap;
    padding-right: 6px;
    border-right: 2px solid var(--app-border);
    margin-right: 4px;
}

.cp-subbar-title i {
    font-size: 14px;
    color: var(--app-primary);
}

.cp-subbar-btns {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
}

.cp-subbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 700;
    color: #475569;
    background: #fff;
    border: 1px solid var(--app-border);
    border-radius: 6px;
    white-space: nowrap;
    text-decoration: none;
    transition: all 0.15s ease;
}

.cp-subbar-btn i {
    font-size: 13px;
    opacity: 0.65;
}

.cp-subbar-btn:hover {
    color: var(--app-primary);
    border-color: #CB8FEA;
    background: #F8F0FD;
    text-decoration: none;
}

.cp-subbar-btn.active {
    color: #fff;
    background: var(--app-primary);
    border-color: var(--app-primary);
}

.cp-subbar-btn.active i {
    opacity: 1;
}

.app-user-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 34px;
    padding: 6px 10px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 6px;
    color: #e5e7eb;
    background: rgba(255, 255, 255, 0.06);
}

.container-bg {
    background: transparent;
}

.min-height {
    min-height: calc(100vh - 112px);
}

/* When sub-bar is present, body needs extra top margin */
.has-subbar main .container-fluid.min-height {
    padding-top: 14px;
}

main .container-fluid.min-height {
    padding-top: 14px;
    padding-bottom: 22px;
}

.card,
.admin-panel,
.message-wrapper,
.save-package-card {
    border: 1px solid var(--app-border) !important;
    border-radius: 6px !important;
    background: var(--app-surface);
    box-shadow: var(--app-shadow-sm);
}

.card-header,
.card-header-custom,
.admin-nav,
.message-header {
    background: var(--app-surface-soft) !important;
    border-bottom: 1px solid var(--app-border) !important;
}

.admin-nav,
.message-header {
    min-height: 48px;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: thin;
}

.admin-content,
.message-body {
    background: var(--app-surface);
}

.panel-title,
.header-title {
    color: var(--app-text) !important;
    font-weight: 800 !important;
    letter-spacing: 0;
}

.nav-pill-btn,
.btn-tab {
    min-height: 34px;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border-radius: 6px !important;
    border: 1px solid var(--app-border) !important;
    background: #fff !important;
    color: #334155 !important;
    font-weight: 700;
    text-decoration: none !important;
    box-shadow: none !important;
}

.nav-pill-btn:hover,
.btn-tab:hover {
    color: var(--app-primary) !important;
    border-color: #E2C2F4 !important;
    background: #F8F0FD !important;
}

.nav-pill-btn.active,
.btn-tab.active,
.nav-status-badge {
    background: var(--app-primary) !important;
    border-color: var(--app-primary) !important;
    color: #fff !important;
}

.close-link,
.btn-close-custom {
    min-width: 34px;
    min-height: 34px;
    border-radius: 6px !important;
    border: 1px solid #fecaca !important;
    background: #fff1f2 !important;
    color: var(--app-danger) !important;
}

.close-link:hover,
.btn-close-custom:hover {
    background: var(--app-danger) !important;
    color: #fff !important;
}

.table {
    margin-bottom: 0;
    color: var(--app-text);
    vertical-align: middle;
}

.table > :not(caption) > * > * {
    padding: 10px 9px;
    border-color: #e5eaf1;
}

.table thead,
.table-light {
    background: #f1f5f9 !important;
    color: #334155;
}

.table th {
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    white-space: nowrap;
}

.table-hover tbody tr:hover {
    background-color: #f8fbff;
}

.form-control,
.form-select,
.input-group-text {
    border-color: #cbd5e1;
    border-radius: 6px;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--app-primary);
    box-shadow: 0 0 0 0.18rem rgba(148, 0, 211, 0.14);
}

.input-group .form-control,
.input-group .form-select,
.input-group .input-group-text,
.input-group .btn {
    border-radius: 0;
}

.input-group > :first-child {
    border-top-left-radius: 6px !important;
    border-bottom-left-radius: 6px !important;
}

.input-group > :last-child {
    border-top-right-radius: 6px !important;
    border-bottom-right-radius: 6px !important;
}

.btn {
    border-radius: 6px;
    font-weight: 700;
}

.btn-primary {
    background: var(--app-primary);
    border-color: var(--app-primary);
}

.btn-primary:hover {
    background: var(--app-primary-dark);
    border-color: var(--app-primary-dark);
}

.btn-warning {
    background: var(--app-warning);
    border-color: var(--app-warning);
    color: #1F0A2E;
}

.btn-outline-secondary {
    border-color: #cbd5e1;
}

.badge {
    border-radius: 5px;
    font-weight: 800;
}

.alert {
    border-radius: 6px;
    border-width: 1px;
}

.menu-card {
    text-shadow: none !important;
    border-color: var(--app-border);
    border-radius: 6px;
    background: #fff;
    box-shadow: var(--app-shadow-sm);
}

.menu-body {
    background: #f8fafc;
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
}

.menu-icon {
    color: var(--app-primary);
}

.menu-footer {
    background: #1F0A2E !important;
    border-bottom-left-radius: 6px;
    border-bottom-right-radius: 6px;
}

.footer {
    padding: 10px 0 14px;
    background: transparent;
}

@media (max-width: 1199.98px) {
    .navbar-collapse {
        padding-top: 10px;
    }

    .cp-nav .nav-link {
        width: 100%;
        justify-content: flex-start;
        padding: 10px 12px !important;
        font-size: 14px;
    }

    .cp-nav .dropdown-toggle::after {
        margin-left: auto;
    }

    .cp-dropdown {
        background: #1A0827;
        border: none;
        border-left: 2px solid rgba(148, 0, 211, 0.4);
        border-radius: 0 !important;
        box-shadow: none;
        padding: 2px 0 2px 8px;
        margin: 0;
    }

    .cp-drop-item {
        padding: 9px 14px !important;
        font-size: 13px;
    }

    .app-user-chip {
        width: 100%;
        margin: 8px 0;
        justify-content: center;
    }

    /* Sub-bar on mobile */
    .cp-subbar {
        top: 56px;
    }

    .cp-subbar-title {
        display: none;
    }

    .cp-subbar-inner {
        padding: 5px 0;
    }

    .cp-subbar-btn {
        padding: 5px 10px;
        font-size: 12px;
    }
}

@media (max-width: 767.98px) {
    body {
        font-size: 13px;
    }

    main .container-fluid.min-height {
        padding-left: 8px;
        padding-right: 8px;
    }

    .admin-content,
    .message-body {
        padding: 12px !important;
    }

    .table > :not(caption) > * > * {
        padding: 8px 7px;
    }
}

/* ── Mobile navbar: scrollable collapsed menu ── */
@media (max-width: 1199.98px) {
    .navbar-collapse.show .navbar-nav {
        max-height: 70vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        scrollbar-color: rgba(255,255,255,0.2) transparent;
    }
    .navbar-collapse.show .navbar-nav::-webkit-scrollbar { width: 4px; }
    .navbar-collapse.show .navbar-nav::-webkit-scrollbar-thumb {
        background: rgba(255,255,255,0.2);
        border-radius: 2px;
    }
}

/* ── Responsive tables on mobile ── */
@media (max-width: 575px) {
    .table-responsive-stack tr { display: block; border-bottom: 2px solid #e5eaf4; }
    .table-responsive-stack td { display: flex; justify-content: space-between; padding: 6px 8px; border: none; }
    .table-responsive-stack td::before { content: attr(data-label); font-weight: 700; color: #64748b; flex-shrink: 0; margin-right: 8px; }
}

/* ── Better focus for accessibility ── */
:focus-visible {
    outline: 2px solid var(--app-primary);
    outline-offset: 2px;
}

/* ── Smooth scrolling ── */
html { scroll-behavior: smooth; }

/* ── Navbar fits on medium desktops (1200–1599px): tighter items, user name hidden ── */
@media (min-width: 1200px) and (max-width: 1599.98px) {
    .cp-nav { gap: 0; }
    .cp-nav .nav-link { padding: 6px 8px !important; gap: 5px; }
    .cp-nav-label { font-size: 12.5px; }
    .app-user-chip small { display: none; }
}

/* ── Touch-friendly controls on phones ── */
@media (max-width: 575.98px) {
    .btn, .form-control, .form-select { min-height: 40px; }
    .btn-sm { min-height: 34px; }
}

/* ── Dashboard header link: no underline ── */
a.dash-welcome, a.dash-welcome:hover { text-decoration: none; }

/* ── Respect reduced-motion preference ── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
    .reveal { opacity: 1 !important; transform: none !important; }
}
@media (min-width: 1200px) and (max-width: 1439.98px) {
    .cp-nav .dropdown-toggle::after { display: none; }
    .app-brand-mark span { font-size: 1.05rem; }
}

/* ══════════════════════════════════════════════════
   MoExpress brand: тёмно-фиолетовый #9400D3 поверх Bootstrap 5.2
   ══════════════════════════════════════════════════ */
:root {
    --brand: #9400D3;
    --brand-dark: #7A00AF;
    --brand-deep: #1F0A2E;
    --brand-soft: #F8F0FD;
    --bs-primary: #9400D3;
    --bs-primary-rgb: 148, 0, 211;
    --bs-link-color: #9400D3;
    --bs-link-hover-color: #7A00AF;
}
.app-brand-icon { color: #D9A3F5; }
.navbar.app-navbar { background: linear-gradient(90deg, #1F0A2E 0%, #2D0A47 100%) !important; }
.btn-primary {
    --bs-btn-bg: #9400D3; --bs-btn-border-color: #9400D3;
    --bs-btn-hover-bg: #7A00AF; --bs-btn-hover-border-color: #7A00AF;
    --bs-btn-active-bg: #6A0099; --bs-btn-active-border-color: #6A0099;
    --bs-btn-disabled-bg: #9400D3; --bs-btn-disabled-border-color: #9400D3;
    --bs-btn-focus-shadow-rgb: 148, 0, 211;
}
.btn-outline-primary {
    --bs-btn-color: #9400D3; --bs-btn-border-color: #9400D3;
    --bs-btn-hover-bg: #9400D3; --bs-btn-hover-border-color: #9400D3;
    --bs-btn-active-bg: #7A00AF; --bs-btn-active-border-color: #7A00AF;
    --bs-btn-disabled-color: #9400D3; --bs-btn-disabled-border-color: #9400D3;
    --bs-btn-focus-shadow-rgb: 148, 0, 211;
}
.btn-link { --bs-btn-color: #9400D3; --bs-btn-hover-color: #7A00AF; }
.form-control:focus, .form-select:focus { border-color: #CB8FEA; box-shadow: 0 0 0 .2rem rgba(148, 0, 211, .18); }
.form-check-input:checked { background-color: #9400D3; border-color: #9400D3; }
.form-check-input:focus { border-color: #CB8FEA; box-shadow: 0 0 0 .2rem rgba(148, 0, 211, .18); }
.pagination { --bs-pagination-color: #9400D3; --bs-pagination-hover-color: #7A00AF; --bs-pagination-focus-color: #7A00AF;
    --bs-pagination-active-bg: #9400D3; --bs-pagination-active-border-color: #9400D3; --bs-pagination-focus-box-shadow: 0 0 0 .2rem rgba(148, 0, 211, .18); }
.nav-pills { --bs-nav-pills-link-active-bg: #9400D3; }
.nav { --bs-nav-link-color: #9400D3; --bs-nav-link-hover-color: #7A00AF; }
.list-group { --bs-list-group-active-bg: #9400D3; --bs-list-group-active-border-color: #9400D3; }
.dropdown-menu { --bs-dropdown-link-active-bg: #9400D3; }
.progress { --bs-progress-bar-bg: #9400D3; }
.alert-primary { --bs-alert-color: #5A0082; --bs-alert-bg: #F3E3FB; --bs-alert-border-color: #DDB3F2; }
.table-primary { --bs-table-bg: #F3E3FB; --bs-table-border-color: #DDB3F2; }
.text-bg-primary { color: #fff !important; background-color: #9400D3 !important; }
.bg-primary { background-color: rgba(148, 0, 211, var(--bs-bg-opacity, 1)) !important; }
.text-primary { color: rgba(148, 0, 211, var(--bs-text-opacity, 1)) !important; }
.border-primary { border-color: rgba(148, 0, 211, var(--bs-border-opacity, 1)) !important; }
.link-primary { color: #9400D3 !important; }
.link-primary:hover, .link-primary:focus { color: #7A00AF !important; }
.bg-primary-subtle { background-color: #F3E3FB !important; }
.app-brand-logo { height: 34px; width: auto; display: block; }
@media (max-width: 575.98px) { .app-brand-logo { height: 30px; } }
