/* Carbon Billing 5 — Adaptive layout fix + responsive CSS
   Fixes Bootstrap 2 nested grid issues and adds mobile breakpoints.
   Does NOT change HTML templates — pure CSS overlay. */

/* ============================================================
   DESKTOP FIX: Form field layout (label + input side by side)
   Bootstrap 2 nested span4/span8 inside span6 doesn't work
   without row-fluid. Fix with flexbox.
   ============================================================ */

/* Form row: label left, field right */
.form-row.row {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    margin-bottom: 0;
    padding: 0;
}

/* Label column — see bs-compat.css .form-subgroup rules for card layout */
.form-row.row > .span4,
.form-row.row > .col-md-4 {
    flex: 0 0 auto;
    min-width: 120px;
    padding-right: 10px;
    padding-left: 10px;
    box-sizing: border-box;
}

.form-row.row > .span4 label,
.form-row.row > .col-md-4 label {
    font-size: 13px;
    font-weight: 400;
    color: #333;
    line-height: 1.4;
    margin-bottom: 0;
    white-space: normal;
    word-wrap: break-word;
    text-align: left;
}

.form-row.row > .span4,
.form-row.row > .col-md-4 {
    text-align: left;
}

.form-row.row > .span8,
.form-row.row > .col-md-8 {
    flex: 1 1 auto;
    width: auto !important;
    min-width: 0;
    padding-left: 0;
}

.form-row.row > .span8 input[type="text"],
.form-row.row > .span8 input[type="number"],
.form-row.row > .span8 input[type="email"],
.form-row.row > .span8 input[type="password"],
.form-row.row > .span8 input[type="url"],
.form-row.row > .span8 input[type="tel"],
.form-row.row > .span8 textarea,
.form-row.row > .col-md-8 input[type="text"],
.form-row.row > .col-md-8 input[type="number"],
.form-row.row > .col-md-8 input[type="email"],
.form-row.row > .col-md-8 input[type="password"],
.form-row.row > .col-md-8 input[type="url"],
.form-row.row > .col-md-8 input[type="tel"],
.form-row.row > .col-md-8 textarea {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.form-row.row > .span8 select,
.form-row.row > .col-md-8 select {
    max-width: 100%;
    box-sizing: border-box;
}

/* Checkbox fields: left-aligned */
.form-row.row > .span8 input[type="checkbox"],
.form-row.row > .col-md-8 input[type="checkbox"] {
    margin: 0 !important;
    display: inline-block;
}

/* Tab content and its rows: full width */
.row-fluid,
.tab-content {
    width: 100%;
    max-width: 100%;
}
.tab-content > .tab-pane > .row,
.tab-pane > .row {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
}

/* Form subgroups (Основные, Договор, etc.): two columns on desktop */
.row-fluid.set_height,
.row.set_height {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
}

/* Form subgroup layout — see bs-compat.css for all card styles */

/* PopupSelect + Selector icons: see bs-compat.css for main styles */

/* Balance table: make it not overflow */
#balance_table {
    width: 100% !important;
    table-layout: auto;
    font-size: 12px;
}

#balance_table td {
    white-space: nowrap;
    padding: 4px 6px !important;
}

/* Status/substatus row: inline flex */
.form-subgroup .table {
    width: 100%;
    table-layout: auto;
}

/* Fix overflow on main containers */
.container-fluid,
#content,
.content-wrapper {
    overflow-x: hidden;
}

/* Better box-sizing everywhere inside form */
.form-subgroup *,
.form-row * {
    box-sizing: border-box;
}

/* Mobile-only label: hidden on desktop */
.btn-label-mobile {
    display: none;
}

/* Toolbar (top panel): flex wrap */
.head-navbar {
    display: flex !important;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
    padding: 8px 10px !important;
    width: 100% !important;
    box-sizing: border-box;
}

/* ============================================================
   Page title centering
   ============================================================ */
.desktop-subsection-header {
    justify-content: center;
    gap: 8px;
}
.desktop-subsection-header h5 {
    margin: 0;
    font-weight: 600;
}

/* ============================================================
   CRM HelpDesk filter & table
   ============================================================ */
.bg-light select {
    height: 31px;
    font-size: 13px;
}
.bg-light input[type="text"] {
    height: 31px;
    font-size: 13px;
}
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ============================================================
   Sidebar main nav & tabs: hidden on desktop, shown on mobile
   ============================================================ */
.sidebar-main-nav {
    display: none !important;
}
.sidebar-tabs-nav {
    display: none !important;
}
.sidebar-tabs-nav .nav-link {
    font-size: 13px;
    padding: 4px 8px 4px 12px;
}
.sidebar-tabs-nav .nav-icon {
    font-size: 10px;
    opacity: 0.5;
}

/* ============================================================
   ≤1200px: Tighter layout
   ============================================================ */
@media (max-width: 1200px) {
    .form-row.row > .span4,
.form-row.row > .col-md-4 {
        flex: 0 0 160px;
        width: 160px !important;
    }

    #nav-main > li > a {
        padding-left: 8px;
        padding-right: 8px;
        font-size: 13px;
    }
}

/* ============================================================
   ≤992px: Tablet — single column subgroups, hide sidebar
   ============================================================ */
@media (max-width: 992px) {
    /* Hide left sidebar */
    .row-fluid > .span2.bs-docs-sidebar,
    .row > .col-md-2.bs-docs-sidebar {
        display: none;
    }

    /* Main content full width */
    .row-fluid > .span10,
    .row-fluid > .span7,
    .row > .col-md-10,
    .row > .col-md-7 {
        width: 100% !important;
        margin-left: 0 !important;
        padding: 0 10px !important;
        box-sizing: border-box;
    }

    /* Form subgroups: single column */
    .row-fluid.set_height > .span6.form-subgroup,
.row.set_height > .col-md-6.form-subgroup,
.row > .col-md-6.form-subgroup {
        flex: 0 0 100%;
        width: 100% !important;
        margin: 0 0 10px 0;
    }

    /* Form row: label narrower */
    .form-row.row > .span4,
.form-row.row > .col-md-4 {
        flex: 0 0 150px;
        width: 150px !important;
    }

    /* Tabs: horizontal scroll */
    #tabs {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }

    #tabs > li {
        flex-shrink: 0;
    }

    /* Tree sidebar */
    .tree-sidebar {
        width: 100% !important;
        margin-left: 0 !important;
    }

    .perms-tree-sidebar {
        width: 100% !important;
        margin-right: 0 !important;
    }

    .filter-container {
        min-width: auto !important;
    }

    /* Sgrp overrides */
    #sgrp1.span6, #sgrp2.span6,
    #sgrp3.span6, #sgrp4.span6,
    #sgrp1.col-md-6, #sgrp2.col-md-6,
    #sgrp3.col-md-6, #sgrp4.col-md-6 {
        width: 100% !important;
        margin-left: 0 !important;
    }
}

/* ============================================================
   ≤768px: Mobile landscape
   ============================================================ */
@media (max-width: 768px) {
    /* Remove content padding on mobile */
    .content-wrapper > .content {
        padding-left: 0px !important;
        padding-right: 0px !important;
    }

    /* Prevent horizontal scrolling on mobile */
    html, body {
        overflow-x: hidden !important;
        max-width: 100vw;
    }

    /* Kill Bootstrap gutter that causes horizontal overflow */
    .row, .row-fluid {
        --bs-gutter-x: 0 !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
    .row > *, .row-fluid > * {
        padding-left: 8px !important;
        padding-right: 8px !important;
    }
    .content-wrapper .content {
        padding: 0 4px !important;
    }

    /* Fixed navbar: content needs top margin to avoid overlap */
    .content-wrapper {
        margin-top: calc(3.5rem + 1px) !important;
    }

    /* Hide header nav on mobile — use sidebar instead */
    #nav-main {
        display: none !important;
    }

    /* Tabs: horizontal scroll, compact on mobile */
    #tabs {
        display: flex !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        scrollbar-width: none;
        -ms-overflow-style: none;
        border-bottom: 2px solid #dee2e6;
        margin-bottom: 8px;
        padding-bottom: 0;
    }
    #tabs::-webkit-scrollbar { display: none; }
    #tabs > li {
        flex-shrink: 0;
    }
    #tabs > li > a {
        padding: 6px 10px !important;
        font-size: 12px !important;
        white-space: nowrap;
    }

    /* Show main nav and tabs in sidebar on mobile */
    .sidebar-main-nav {
        display: block !important;
    }
    .sidebar-tabs-nav[style] {
        display: block !important;
    }

    .nav.pull-left li a div {
        font-size: 1em !important;
    }

    #feedback_button {
        display: none;
    }

    /* ─── Mobile hamburger — guaranteed visible ─── */
    .main-header .mobile-pushmenu {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        font-size: 20px;
        color: #555 !important;
        padding: 0 !important;
    }
    .main-header .mobile-pushmenu:hover,
    .main-header .mobile-pushmenu:active {
        color: #43b77a !important;
        background: rgba(0,0,0,.04);
        border-radius: 4px;
    }
    body.dark-theme .main-header .mobile-pushmenu { color: #9ca3af !important; }
    body.dark-theme .main-header .mobile-pushmenu:hover,
    body.dark-theme .main-header .mobile-pushmenu:active {
        color: #fff !important;
        background: rgba(255,255,255,.08);
    }

    /* ─── Mobile sidebar ─── */
    .main-sidebar,
    .main-sidebar .sidebar,
    .main-sidebar .sidebar-main-nav,
    .main-sidebar .nav-sidebar {
        overflow-x: hidden !important;
    }
    .main-sidebar {
        width: 250px !important;
        margin-left: -250px !important;
        transition: margin-left .3s ease-in-out;
        /* Soft gradient — teal → deep slate */
        background: linear-gradient(165deg, #2d3b3a 0%, #1f2a33 55%, #1a2028 100%) !important;
        background-image: linear-gradient(165deg, #2d3b3a 0%, #1f2a33 55%, #1a2028 100%) !important;
    }
    body.sidebar-open .main-sidebar {
        margin-left: 0 !important;
    }
    .main-sidebar .sidebar {
        padding: 0 !important;
        background: transparent !important;
        background-image: none !important;
    }
    /* Caret < on compact nav — center vertically */
    .nav-compact .nav-link > .right,
    .nav-compact .nav-link > p > .right {
        top: 50% !important;
        transform: translateY(-50%) !important;
    }
    .nav-compact .nav-item.menu-open > .nav-link > p > .right {
        transform: translateY(-50%) rotate(-90deg) !important;
    }
    /* Content — no left margin on mobile (sidebar is overlay) */
    body:not(.sidebar-open) .content-wrapper,
    body:not(.sidebar-open) .main-footer,
    body:not(.sidebar-open) .main-header {
        margin-left: 0 !important;
    }

    /* Content — no left padding on mobile */
    .container-fluid,
    .content-wrapper > .content > .container-fluid,
    section.content,
    .content {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    /* Brand: always show "СмИТ" on mobile, not section name */
    .main-sidebar .brand-link {
        padding: 10px 16px !important;
    }

    /* Hide "НАВИГАЦИЯ" header on mobile */
    .sidebar-main-nav > .nav-header {
        display: none;
    }

    /* Main nav items */
    .nav-sidebar > .nav-item > .nav-link {
        display: flex !important;
        align-items: center;
        gap: 12px;
        padding: 11px 14px !important;
        font-size: 14px;
        border-bottom: 1px solid rgba(255,255,255,.06);
        transition: background .15s;
        color: rgba(255,255,255,.82) !important;
        background: transparent !important;
        border-radius: 0 !important;
    }
    .nav-sidebar > .nav-item > .nav-link:hover {
        background: rgba(255,255,255,.06) !important;
        color: #fff !important;
    }
    .nav-sidebar > .nav-item > .nav-link:active {
        background: rgba(255,255,255,.12) !important;
    }
    .nav-sidebar > .nav-item > .nav-link > .nav-icon {
        width: 22px;
        text-align: center;
        font-size: 15px;
        flex-shrink: 0;
        opacity: .75;
        margin: 0 !important;
    }
    .nav-sidebar > .nav-item > .nav-link.active > .nav-icon {
        opacity: 1;
        color: var(--brand-primary) !important;
    }
    .nav-sidebar > .nav-item > .nav-link > p {
        margin: 0;
        flex: 1;
        min-width: 0;
        display: flex;
        align-items: center;
        justify-content: space-between;
        font-weight: 500;
    }
    /* angle-left caret — subtle */
    .nav-sidebar > .nav-item > .nav-link > p > .right {
        opacity: .4;
        font-size: .7em;
        transition: transform .2s;
    }
    .nav-sidebar > .nav-item.menu-open > .nav-link > p > .right {
        transform: rotate(-90deg);
        opacity: .7;
    }

    /* Active item highlight — override AdminLTE blue */
    .nav-sidebar > .nav-item > .nav-link.active,
    .nav-sidebar > .nav-item > .nav-link.active:hover {
        background: color-mix(in srgb, var(--brand-primary) 15%, transparent) !important;
        color: #fff !important;
        box-shadow: inset 3px 0 0 var(--brand-primary) !important;
        padding-left: 14px !important;
    }

    /* Treeview sub-items — align text with parent text */
    .nav-sidebar .nav-treeview {
        background: rgba(0,0,0,.18);
        padding: 2px 0;
    }
    .nav-sidebar .nav-treeview .nav-link {
        display: flex !important;
        align-items: center;
        gap: 12px;
        overflow: hidden;
        white-space: nowrap;
        /* 14px (parent padding-left) + 22px (icon) + 12px (gap) = 48px text offset */
        padding: 8px 14px 8px 22px !important;
        border-bottom: 1px solid rgba(255,255,255,.04);
        color: rgba(255,255,255,.7) !important;
        background: transparent !important;
    }
    .nav-sidebar .nav-treeview .nav-link:hover {
        background: rgba(255,255,255,.05) !important;
        color: #fff !important;
    }
    .nav-sidebar .nav-treeview .nav-link p {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        margin: 0;
        flex: 1;
        min-width: 0;
        font-size: 13px;
        line-height: 1.4;
        font-weight: 400;
    }
    .nav-sidebar .nav-treeview .nav-link > .nav-icon,
    .nav-sidebar .nav-treeview .nav-link > .sidebar-sub-icon {
        flex-shrink: 0;
        width: 22px;
        text-align: center;
        font-size: 11px;
        opacity: .5;
        margin: 0 !important;
    }
    .nav-sidebar .nav-treeview .nav-link.active {
        background: color-mix(in srgb, var(--brand-primary) 18%, transparent) !important;
        color: #fff !important;
    }
    .nav-sidebar .nav-treeview .nav-link.active > .nav-icon,
    .nav-sidebar .nav-treeview .nav-link.active > .sidebar-sub-icon {
        opacity: 1;
        color: var(--brand-primary) !important;
    }
    .nav-sidebar .nav-treeview .nav-link:active {
        background: rgba(255,255,255,.1) !important;
    }

    /* Compact nav tweaks — tighten padding, reduce icon margins */
    .nav-sidebar.nav-compact .nav-link {
        padding: 0.3rem 0.5rem 0.3rem 0 !important;
    }
    .nav-sidebar.nav-compact .nav-icon {
        margin-right: 0.1rem !important;
    }
    .main-sidebar .nav-treeview .nav-treeview .nav-link {
        padding-left: 0.2rem !important;
    }
    .nav-flat:not(.nav-child-indent) .nav-treeview .nav-item > .nav-link > .nav-icon {
        margin-left: 0.2rem !important;
    }

    /* No horizontal scroll anywhere (overlayScrollbars, os-content) */
    body, html,
    .os-content,
    .os-viewport,
    .content-wrapper,
    .container-fluid {
        overflow-x: hidden !important;
        max-width: 100vw !important;
    }

    /* Hide panel-left (subsection menu) inside sidebar on mobile */
    .main-sidebar .tree,
    .main-sidebar .panel-left-menu {
        display: none !important;
    }

    /* Hide recent pages in sidebar on mobile */
    .sidebar-recent-nav {
        display: none !important;
    }

    /* Mobile search bar */
    #mobile-search-bar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1040;
        background: #fff;
        padding: 8px 12px;
        box-shadow: 0 2px 8px rgba(0,0,0,.15);
    }

    #mobile-search-bar input {
        font-size: 16px; /* prevent iOS zoom on focus */
    }

    /* Help-link icons: hide on mobile (moved to navbar) */
    .help-link.group {
        display: none;
    }

    /* Hide elements marked mobile-hide */
    .mobile-hide {
        display: none !important;
    }

    /* Show mobile-only label on filter button (but hide Глобальный поиск) */
    .btn-label-mobile {
        display: inline !important;
    }
    #extend_search .btn-label-mobile {
        display: none !important;
    }

    /* Form row: tighter label */
    .form-row.row > .span4,
.form-row.row > .col-md-4 {
        flex: 0 0 130px;
        width: 130px !important;
    }

    .form-row.row > .span4 label,
.form-row.row > .col-md-4 label {
        font-size: 12px;
        line-height: 26px;
    }

    .form-row.row > .span8 input,
    .form-row.row > .span8 select,
    .form-row.row > .span8 textarea,
    .form-row.row > .col-md-8 input,
    .form-row.row > .col-md-8 select,
    .form-row.row > .col-md-8 textarea {
        font-size: 14px;
    }

    /* Toolbar buttons: ALL in 1 row, no wrapping */
    .head-navbar {
        display: flex !important;
        flex-wrap: nowrap !important;
        gap: 4px;
        align-items: center;
        overflow-x: auto;
        width: 100% !important;
        background: transparent !important;
    }
    .head-navbar .btn {
        padding: 8px 12px;
        font-size: 14px;
        flex: 0 0 auto;
        text-align: center;
        white-space: nowrap;
    }
    /* Save button: takes remaining space */
    .head-navbar .btn[name="_save"],
    .head-navbar .btn.btn-success {
        flex: 1 1 0;
        min-width: 0;
    }
    /* Delete button: inline, not full width */
    .head-navbar .btn.btn-danger {
        flex: 0 0 auto;
    }
    /* Hide text labels, icon only */
    .head-navbar .btn .btn-label { display: none; }
    /* P1-5: ensure icon stays visible inside mobile-shrunk save button */
    .head-navbar .btn.btn-success > i,
    .head-navbar .btn[name="_save"] > i {
        display: inline-block !important;
        font-size: 16px !important;
        line-height: 1 !important;
        margin: 0 !important;
    }
    .head-navbar .btn[name="_save"]::before {
        content: none;
    }
    /* Remove btn-group dropdown border rounding issues */
    .head-navbar .btn-group { flex: 0 0 auto; }

    /* Down panel: flex row */
    .down_toolbar {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
    }
    .down_toolbar .btn {
        flex: 1 1 auto;
        text-align: center;
    }

    /* Form labels: single line with ellipsis */
    .form-row.row > .span4,
    .form-row.row > .col-md-4 {
        flex: 0 0 120px !important;
        width: 120px !important;
        max-width: 120px !important;
        min-width: 0 !important;
    }
    .form-row.row > .span4 label,
    .form-row.row > .col-md-4 label {
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        display: block !important;
        max-width: 100% !important;
        font-size: 12px !important;
    }

    /* Form fields: fill remaining space */
    .form-row.row > .span8,
    .form-row.row > .col-md-8 {
        flex: 1 1 0 !important;
        min-width: 0 !important;
        max-width: 100% !important;
    }
    .form-row.row > .span8 input,
    .form-row.row > .span8 select,
    .form-row.row > .span8 textarea,
    .form-row.row > .col-md-8 input,
    .form-row.row > .col-md-8 select,
    .form-row.row > .col-md-8 textarea {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Tables: horizontal scroll */
    #result_list, #choice_list, #balance_table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .helpdesk-comments {
        height: auto !important;
        max-height: 400px;
    }

    .modal-dialog {
        margin: 10px;
    }

    /* ---- Balance table: horizontal scroll ---- */
    .acc-balance-table,
    #balance_table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        font-size: 11px;
    }

    #balance_table td,
    #balance_table th {
        padding: 3px 4px !important;
        white-space: nowrap;
    }

    /* Account fields: stack label above value */
    .acc-field-row {
        flex-wrap: wrap;
    }

    .acc-field-row > label {
        font-size: 12px;
        flex: 0 0 100%;
        margin-bottom: 2px;
    }

    .acc-field-row > .acc-field-value {
        flex: 0 0 100%;
    }

    /* ---- Status/substatus: allow full width ---- */
    .status-row select {
        max-width: 100% !important;
        min-width: 80px !important;
    }

    .status-row input.datepicker {
        max-width: 100% !important;
    }

    /* ---- Users: fix link overflow ---- */
    .form-row.row > .span8 a {
        word-break: break-all;
    }

    /* ---- Connection points & Requisites: horizontal scroll ---- */
    #conn_points_table,
    #requisites_table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    #conn_points_table th,
    #conn_points_table td,
    #requisites_table th,
    #requisites_table td {
        white-space: nowrap;
        font-size: 12px;
        padding: 4px 6px !important;
    }

    /* ---- Abonent comments: reduce max-height ---- */
    .abonents-comments-list {
        max-height: 160px !important;
    }

    /* ---- CRM Helpdesk: sections responsive ---- */
    .helpdesk-detail .field-container > .table,
    .helpdesk-detail .field-container > .table-fields {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* CRM helpdesk detail: single-column layout for 2-col key/value tables */
    .table-fields tr {
        display: flex;
        flex-wrap: wrap;
    }

    .table-fields td {
        flex: 0 0 100% !important;
        display: block !important;
        white-space: normal !important;
        border-top: none !important;
    }

    .table-fields td:nth-child(2n+1) {
        font-weight: 600;
        font-size: 11px;
        padding: 4px 6px 0 6px !important;
    }

    .table-fields td:nth-child(2n) {
        padding: 0 6px 4px 6px !important;
        border-bottom: 1px solid #eee;
    }

    /* CRM helpdesk comments: responsive */
    .helpdesk-comments-container {
        margin-top: 20px !important;
    }

    .helpdesk-comments .comments-list {
        height: auto !important;
        max-height: 250px;
    }

    .helpdesk-comments textarea {
        width: 100% !important;
        box-sizing: border-box;
    }

    .helpdesk-comments .comment-submit {
        width: 100%;
        margin-top: 6px;
    }

    /* CRM filter: stack vertically */
    .filter-container {
        flex-direction: column;
    }

    .filter-container .col-md-3 {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
        margin-bottom: 8px;
        margin-left: 0 !important;
        padding-left: 0 !important;
    }

    .filter-btn {
        width: 100%;
    }

    /* Credit/debit report: horizontal scroll + stacked filter */
    .credit-report-filter {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 4px;
    }

    .credit-report-filter .span1,
    .credit-report-filter .span2,
    .credit-report-filter .span3 {
        flex: 1 1 calc(50% - 4px) !important;
        width: auto !important;
        min-width: 0;
    }

    .credit-report-filter .span1:empty {
        display: none !important;
    }

    #credit_report {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* General: all data tables scrollable on mobile */
    .table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Prevent iOS zoom on input focus — all inputs 16px */
    input[type="text"],
    input[type="password"],
    input[type="email"],
    input[type="number"],
    input[type="tel"],
    input[type="url"],
    input[type="date"],
    input[type="datetime-local"],
    select,
    textarea {
        font-size: 16px !important;
    }

    /* Minimum touch targets (44px Apple HIG) */
    .panel-left-item {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .panel-left-link {
        padding: 10px 12px !important;
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    .nav-sidebar .nav-link {
        min-height: 44px;
        padding: 10px 12px !important;
    }

    /* Mobile subsection items: 44px touch targets */
    .mobile-subsection-item {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* Smooth scrolling for tables */
    .table,
    #result_list,
    #choice_list {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }

    /* Responsive table → card rows on mobile */
    #choice_list,
    #choice_list thead,
    #choice_list tbody,
    #choice_list tr,
    #choice_list td,
    #choice_list th {
        display: block;
    }
    #choice_list thead { display: none; }
    /* Row = card */
    #choice_list tr {
        display: grid;
        grid-template-columns: 36px 1fr auto;
        grid-template-rows: auto auto;
        align-items: center;
        padding: 8px 10px;
        margin: 0;
        gap: 0 6px;
        border-bottom: 1px solid #edf2f7;
    }
    #choice_list tr:nth-child(odd) { background: #f8fafb; }
    #choice_list tr:nth-child(even) { background: #fff; }
    #choice_list td,
    #choice_list td.actions-cell {
        padding: 0;
        border: none !important;
        font-size: 13px;
        line-height: 1.4;
        background: none !important;
        background-color: transparent !important;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    /* Kill Bootstrap table-striped on mobile */
    #choice_list.table-striped > tbody > tr:nth-of-type(odd) > * {
        background: none !important;
        --bs-table-accent-bg: transparent !important;
    }
    #choice_list td:before { display: none; }
    /* Col 1: ID — no truncation, no grey bg */
    #choice_list td:first-child {
        grid-column: 1;
        grid-row: 1;
        font-size: 12px;
        font-weight: 600;
        color: #9ca3af;
        background: transparent !important;
        overflow: visible;
        text-overflow: unset;
        white-space: nowrap;
    }
    /* Col 2: Name */
    #choice_list td:nth-child(2) {
        grid-column: 2;
        grid-row: 1;
        font-size: 14px;
        font-weight: 600;
        color: #1a202c;
        white-space: nowrap;
    }
    /* Actions: top-right */
    #choice_list td:last-child,
    #choice_list td.actions-cell {
        grid-column: 3;
        grid-row: 1 / -1;
        display: flex;
        gap: 4px;
        align-items: center;
        align-self: center;
    }
    #choice_list td:last-child a,
    #choice_list td.actions-cell a,
    #choice_list .action-btn {
        font-size: 13px;
        color: #9ca3af;
        padding: 2px;
        width: auto;
        height: auto;
        border: none;
        background: transparent;
    }
    #choice_list td:last-child a:hover { color: #43b77a; }
    /* Data columns: second row, labeled */
    #choice_list td:not(:first-child):not(:nth-child(2)):not(:last-child):not(.actions-cell) {
        grid-column: 1 / 3;
        font-size: 11px;
        color: #6b7280;
        padding: 0 0 0 36px;
        white-space: nowrap;
    }
    #choice_list td:not(:first-child):not(:nth-child(2)):not(:last-child):not(.actions-cell):before {
        display: inline;
        content: attr(data-label) ": ";
        font-weight: 600;
        color: #9ca3af;
        font-size: 10px;
        text-transform: uppercase;
        letter-spacing: .3px;
    }
    #choice_list td:empty { display: none; }
    /* result_list also truncate */
    #result_list td {
        max-width: 200px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    /* Dark theme mobile rows */
    body.dark-theme #choice_list tr:nth-child(odd) { background: #1e2228; }
    body.dark-theme #choice_list tr:nth-child(even) { background: #252930; }
    body.dark-theme #choice_list tr { border-bottom-color: #353940; }
    body.dark-theme #choice_list td:nth-child(2) { color: #e2e8f0; }
    body.dark-theme #choice_list td:last-child a { color: #6b7280; }

    /* Card body compact */
    .card-body {
        padding: 0.5rem !important;
    }

    /* Select2 mobile fix */
    .select2-container--open .select2-dropdown {
        max-width: 100vw !important;
    }

    .select2-results__options {
        max-height: 40vh !important;
    }

    /* content-wrapper: no side margin */
    .content-wrapper > .content {
        padding-left: 8px !important;
        padding-right: 8px !important;
    }

    /* Hide footer on mobile */
    .main-footer {
        display: none !important;
    }

    /* Mobile subsection bar */
    .mobile-subsection-bar {
        background: #eef1f5;
        border-bottom: 1px solid #dde1e6;
        padding: 0;
        position: relative;
        display: flex;
        align-items: center;
    }

    .mobile-subsection-current {
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 6px 12px 6px 25px;
        font-size: 13px;
        font-weight: 600;
        color: var(--brand-primary);
        text-decoration: none;
        flex: 1;
        min-width: 0;
    }
    .mobile-subsection-label {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mobile-subsection-current:hover,
    .mobile-subsection-current:focus {
        color: #2d3748;
        text-decoration: none;
    }

    .mobile-subsection-current .fa-chevron-down {
        font-size: 9px;
        opacity: .5;
        transition: transform .2s;
    }

    .mobile-subsection-bar.open .fa-chevron-down {
        transform: rotate(180deg);
    }

    .mobile-subsection-menu {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: #fff;
        border-bottom: 1px solid #dde1e6;
        box-shadow: 0 6px 20px rgba(0,0,0,.12);
        z-index: 1020;
        max-height: 60vh;
        overflow-y: auto;
        padding: 6px 8px;
    }

    .mobile-subsection-item {
        display: block;
        padding: 10px 14px;
        font-size: 14px;
        color: #4a5568;
        text-decoration: none;
        border-radius: 8px;
        margin-bottom: 2px;
        transition: background .15s;
    }

    .mobile-subsection-item:hover {
        background: #f0f2f5;
        color: #2d3748;
        text-decoration: none;
    }

    .mobile-subsection-item.active {
        background: rgba(67,183,122,.1);
        color: #276749;
        font-weight: 600;
        border-left: 3px solid #43b77a;
        padding-left: 11px;
    }

    .mobile-subsection-item:last-child {
        margin-bottom: 0;
    }
}

/* Dark theme: mobile subsection bar */
body.dark-theme .mobile-subsection-bar {
    background: #1e222a;
    border-color: #3a3f47;
}
body.dark-theme .mobile-subsection-current {
    color: #7ecfbb;
}
body.dark-theme .mobile-subsection-current:hover,
body.dark-theme .mobile-subsection-current:focus {
    color: #a0d8cc;
}
body.dark-theme .mobile-subsection-menu {
    background: #22262e;
    border-color: #3a3f47;
    box-shadow: 0 6px 20px rgba(0,0,0,.4);
}
body.dark-theme .mobile-subsection-item {
    color: #c8ccd4;
}
body.dark-theme .mobile-subsection-item:hover {
    background: #2a2e37;
    color: #e2e8f0;
}
body.dark-theme .mobile-subsection-item.active {
    background: color-mix(in srgb, var(--brand-primary) 15%, transparent);
    color: #7ecfbb;
    border-left-color: var(--brand-primary);
}

/* ============================================================
   ≤480px: Mobile portrait — stacked label + field
   ============================================================ */
@media (max-width: 480px) {
    #nav-main > li > a {
        padding: 4px 4px !important;
        font-size: 11px;
    }

    .nav.pull-left li a div {
        font-size: 0.85em !important;
    }

    /* Stack label above field */
    .form-row.row {
        flex-wrap: wrap !important;
    }

    .form-row.row > .span4,
    .form-row.row > .col-md-4 {
        flex: 0 0 100%;
        width: 100% !important;
        padding-right: 0;
    }

    .form-row.row > .span4 label,
    .form-row.row > .col-md-4 label {
        font-weight: 600;
        color: #555;
        font-size: 12px;
        line-height: 20px;
    }

    .form-row.row > .span8,
    .form-row.row > .col-md-8 {
        flex: 0 0 100%;
        width: 100% !important;
    }

    .form-row.row > .span8 input,
    .form-row.row > .span8 select,
    .form-row.row > .col-md-8 select {
        font-size: 16px;
        padding: 6px;
    }

    /* ---- Toolbar: flexbox wrap ---- */
    .head-navbar {
        display: flex !important;
        flex-wrap: wrap;
        gap: 4px !important;
        padding: 6px 8px !important;
    }

    .head-navbar .btn {
        margin-bottom: 0;
        text-align: center;
        padding: 5px 6px;
        font-size: 11px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Row 1: Save + Add Abonent — each 50% */
    .head-navbar > #butt_save {
        flex: 1 1 calc(50% - 4px);
        order: 1;
    }

    .head-navbar > .btn-group:first-of-type {
        flex: 1 1 calc(50% - 4px);
        display: flex;
        order: 2;
    }

    .head-navbar > .btn-group:first-of-type .btn {
        flex: 1;
    }

    .head-navbar > .btn-group:first-of-type .dropdown-toggle {
        flex: 0 0 auto;
        width: auto;
    }

    /* Row 2: Delete + Block + Disconnect — each 33% */
    .head-navbar > #delete_btn,
    .head-navbar > #restore_btn {
        flex: 1 1 calc(33.33% - 4px);
        order: 3;
    }

    .head-navbar > a[name="_restore"] {
        flex: 1 1 calc(33.33% - 4px);
        order: 3;
    }

    /* Block/Unblock/Disconnect buttons — in row 2 */
    .head-navbar > a[href*="block_status"] {
        flex: 1 1 calc(33.33% - 4px);
        order: 4;
    }

    /* Extend search (filter) — full row */
    #extend_search {
        flex: 1 1 100%;
        order: 10;
    }

    /* Hidden inline search (replaced by mobile navbar search) */
    #qf-search-block {
        display: none !important;
    }

    /* Print/Export/Folder dropdowns hidden via .mobile-hide */
    /* Other btn-groups (print) */
    .head-navbar > .btn-group.mobile-hide {
        display: none !important;
    }

    /* ---- Folder toolbar: horizontal scroll ---- */
    .folder-toolbar {
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        gap: 4px !important;
        padding-bottom: 4px;
    }

    .folder-toolbar .badge {
        font-size: .65rem !important;
        padding: .15rem .4rem !important;
        flex-shrink: 0;
    }

    .folder-toolbar .chip-btn {
        font-size: .68rem !important;
        padding: .15rem .45rem !important;
        flex-shrink: 0;
    }

    .folder-toolbar .dropdown .btn {
        font-size: .68rem !important;
        padding: .15rem .45rem !important;
    }

    .folder-toolbar form {
        flex-shrink: 0;
    }

    .folder-toolbar form input.form-control {
        width: 100px !important;
        font-size: 12px;
    }

    .folder-toolbar .form-select {
        font-size: 11px;
        padding: .1rem .15rem;
        width: 3.5em !important;
    }

    /* ---- Search page toolbar ---- */
    .search-toolbar {
        flex-wrap: wrap !important;
        gap: 4px !important;
    }

    .search-toolbar .badge {
        font-size: .65rem !important;
        padding: .15rem .4rem !important;
    }

    .search-toolbar form.input-group {
        width: 100% !important;
        order: 10;
        flex-shrink: 1 !important;
    }

    .filter-row {
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        gap: 4px !important;
        padding-bottom: 4px;
    }

    .filter-row .chip-btn {
        font-size: .68rem;
        padding: 2px 6px;
        flex-shrink: 0;
    }

    .filter-row .filter-select {
        max-width: 130px !important;
        font-size: 12px;
        flex-shrink: 0;
    }

    /* ---- General ---- */
    #tabs > li > a {
        padding: 6px 8px !important;
        font-size: 12px;
    }

    div.sub_grp {
        width: 100% !important;
        float: none !important;
        margin-right: 0;
    }

    div.sub_grp:nth-child(even) {
        float: none !important;
        right: auto;
    }

    .selector-icons {
        display: inline-flex;
        margin-top: 0;
    }

    .select2-container {
        width: 100% !important;
    }

    .modal {
        width: auto !important;
        margin: 10px !important;
        left: 0 !important;
        right: 0 !important;
    }

    /* Card titles smaller */
    .card-header .card-title {
        font-size: .85rem;
    }

    /* Table compact */
    .folder-table th,
    .folder-table td {
        font-size: .75rem !important;
        padding: .2rem .3rem !important;
    }

    /* Data table font */
    #choice_list th,
    #choice_list td {
        font-size: 12px !important;
        padding: 4px 6px !important;
    }

    /* Icon-only toolbar buttons at ≤480px (moved from ≤380px) */
    .head-navbar .btn .btn-label {
        display: none;
    }

    .head-navbar .btn {
        padding: 6px 10px;
        font-size: 14px;
    }

    /* Down panel buttons: full width stack */
    .down_toolbar .btn {
        font-size: 13px;
        padding: 8px 12px;
        min-height: 44px;
    }

    /* Modal full-width */
    .modal-dialog {
        margin: 5px !important;
        max-width: calc(100vw - 10px) !important;
    }

    /* Desktop subsection header hidden on phones */
    .desktop-subsection-header {
        display: none !important;
    }
}

/* ============================================================
   ≤380px: Very small phones — icon-only toolbar buttons
   ============================================================ */
@media (max-width: 380px) {
    /* On very small screens, keep Глобальный поиск hidden */
    #extend_search .btn-label-mobile {
        display: none !important;
    }

    /* Even tighter on very small phones */
    .mobile-subsection-current {
        font-size: 12px;
        padding: 6px 10px;
    }
}

/* ============================================================
   Settings sections: mobile responsive
   ============================================================ */

/* VpnConst tabs + file_config tabs: horizontal scroll on mobile */
#vpn-tabs,
#config-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
#vpn-tabs::-webkit-scrollbar,
#config-tabs::-webkit-scrollbar { display: none; }

#vpn-tabs .nav-item,
#config-tabs .nav-item {
    flex-shrink: 0;
}

/* file_config: config groups responsive */
.file-config-group {
    min-height: auto !important;
}

/* interface_settings + permission_settings: stack on mobile */
@media (max-width: 768px) {
    /* Settings flex layouts: stack vertically */
    .d-flex.gap-3 {
        flex-direction: column !important;
    }

    /* Trees: full width */
    .filetree {
        font-size: 12px !important;
    }

    /* Permission checkboxes panel: full width */
    .perms-options {
        min-width: auto !important;
        width: 100% !important;
    }

    /* Folder tree: full width */
    .folders-tree {
        font-size: 13px;
    }

    .folders-tree ul {
        padding-left: 15px !important;
    }

    /* VpnConst tabs: smaller text */
    #vpn-tabs .nav-link,
    #config-tabs .nav-link {
        font-size: 12px;
        padding: 6px 10px;
        white-space: nowrap;
    }

    /* config groups: single column */
    .file-config-group {
        margin-left: 0 !important;
        min-height: auto !important;
    }

    /* Settings form inputs: full width */
    .file-config-group input[type="text"],
    .file-config-group input[type="number"],
    .file-config-group select {
        max-width: 100% !important;
        width: 100% !important;
    }

    /* interface_settings table: horizontal scroll */
    #choice_list {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    #choice_list th,
    #choice_list td {
        white-space: nowrap;
        font-size: 12px !important;
    }

    /* close_period / unblock: form fields full width */
    .settings-field-row input,
    .settings-field-row select {
        max-width: 100% !important;
        width: 100% !important;
    }
}

@media (max-width: 480px) {
    /* VpnConst/config: even smaller tabs */
    #vpn-tabs .nav-link,
    #config-tabs .nav-link {
        font-size: 11px;
        padding: 5px 8px;
    }

    /* interface_settings: compact table */
    #choice_list select {
        font-size: 11px !important;
        width: 120px !important;
    }

    #choice_list input[type="number"] {
        width: 50px !important;
    }
}

/* ============================================================
   Print
   ============================================================ */
@media print {
    .bs-docs-sidebar,
    #feedback_button,
    .head-navbar,
    .down_toolbar,
    #top-alerts,
    #tabs, hr,
    .btn, .btn-group,
    #qf-search-block {
        display: none !important;
    }

    .row-fluid > .span10,
    .row-fluid > .span7,
    .row > .col-md-10,
    .row > .col-md-7 {
        width: 100% !important;
        margin-left: 0 !important;
    }

    .form-subgroup {
        border: 1px solid #ccc !important;
        page-break-inside: avoid;
    }

    input, select, textarea {
        border: none !important;
        box-shadow: none !important;
    }
}

/* ============================================================
   SIDEBAR: Icon + text styles (all screen sizes)
   ============================================================ */

/* Soft gradient on sidebar background */
.main-sidebar {
    background: linear-gradient(165deg, #2d3b3a 0%, #1f2a33 55%, #1a2028 100%);
}
.main-sidebar .sidebar {
    background: transparent;
}

/* Flat nav — no margins */
.nav-flat {
    margin: 0;
}

/* Treeview — no extra left padding on the container */
.main-sidebar .nav-treeview {
    padding-left: 0;
}

/* Treeview items: teal accent color */
.main-sidebar .nav-treeview > .nav-item > .nav-link {
    color: #3fbc97 !important;
}

/* ─── Desktop overrides for "Абоненты" section (menu == 'Abonents') ─── */
@media (min-width: 768px) {
    body.section-abonents .nav-sidebar.nav-compact .nav-link {
        padding: 0.3rem 0.5rem 0.3rem 0 !important;
    }
    body.section-abonents .nav-sidebar.nav-compact .nav-icon {
        margin-right: 0.1rem !important;
    }
    body.section-abonents .main-sidebar .nav-treeview .nav-treeview .nav-link {
        padding-left: 0.2rem !important;
    }
    body.section-abonents .nav-flat:not(.nav-child-indent) .nav-treeview .nav-item > .nav-link > .nav-icon {
        margin-left: 0.2rem !important;
    }
    /* No horizontal scroll on desktop Abonents section */
    body.section-abonents,
    body.section-abonents html,
    body.section-abonents .os-content,
    body.section-abonents .os-viewport,
    body.section-abonents .content-wrapper,
    body.section-abonents .container-fluid {
        overflow-x: hidden !important;
        max-width: 100vw !important;
    }
}

/* Sidebar treeview items: truncate long text, center icon+text */
.nav-sidebar .nav-treeview .nav-link {
    display: flex !important;
    align-items: center;
    gap: 6px;
    overflow: hidden;
    white-space: nowrap;
}
.nav-sidebar .nav-treeview .nav-link p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin: 0;
    flex: 1;
    min-width: 0;
}
.nav-sidebar .nav-treeview .nav-link .sidebar-sub-icon {
    flex-shrink: 0;
    width: 18px;
    text-align: center;
    font-size: 11px;
    opacity: .65;
}
.nav-sidebar .nav-treeview .nav-link:hover .sidebar-sub-icon,
.nav-sidebar .nav-treeview .nav-link.active .sidebar-sub-icon {
    opacity: 1;
}
