:root {
    --bg: #eef3f8;
    --bg-soft: #f7fafc;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --line: #dbe4ee;
    --line-strong: #cbd5e1;
    --text: #111827;
    --muted: #64748b;
    --brand: #0f766e;
    --brand-soft: #ccfbf1;
    --brand-dark: #115e59;
    --success: #15803d;
    --success-soft: #dcfce7;
    --warning: #b45309;
    --warning-soft: #fef3c7;
    --danger: #b42318;
    --danger-soft: #fee2e2;
    --info: #1d4ed8;
    --info-soft: #dbeafe;
    --shadow: 0 14px 34px rgba(15, 23, 42, 0.08);
    --shadow-soft: 0 8px 18px rgba(15, 23, 42, 0.06);
    --radius: 16px;
    --radius-sm: 10px;
}

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
    margin: 0;
    min-height: 100vh;
    overflow: hidden;
    background:
        radial-gradient(circle at top left, rgba(15, 118, 110, 0.12), transparent 34rem),
        linear-gradient(135deg, var(--bg) 0%, #f8fafc 48%, #edf5f7 100%);
    color: var(--text);
    font-family: Inter, Arial, Helvetica, sans-serif;
    font-size: 14px;
}

a { text-decoration: none; }

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-panel {
    width: min(420px, 100%);
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid rgba(219, 228, 238, 0.9);
    border-radius: 22px;
    padding: 32px;
    box-shadow: var(--shadow);
}

.login-panel h1 {
    font-size: 26px;
    margin: 0 0 8px;
    letter-spacing: -0.02em;
}

.app-shell {
    height: 100vh;
    min-height: 100vh;
    display: grid;
    grid-template-columns: 272px minmax(0, 1fr);
    overflow: hidden;
}

.app-sidebar {
    position: sticky;
    top: 0;
    z-index: 40;
    height: 100vh;
    background: rgba(255, 255, 255, 0.96);
    border-right: 1px solid rgba(203, 213, 225, 0.72);
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 10px 0 28px rgba(15, 23, 42, 0.03);
    overflow-y: auto;
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 6px 6px 18px;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--line);
}

.brand strong {
    display: block;
    line-height: 1.15;
    letter-spacing: -0.02em;
}

.brand small {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 12px;
}

.brand-mark {
    width: 44px;
    height: 44px;
    display: inline-grid;
    place-items: center;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--brand), #14b8a6);
    color: #fff;
    font-weight: 800;
    letter-spacing: 0.03em;
    box-shadow: 0 12px 20px rgba(15, 118, 110, 0.28);
}

.app-sidebar .nav {
    padding: 4px 0;
}

.app-sidebar .nav-link {
    color: #334155;
    border-radius: 12px;
    padding: 10px 12px;
    font-weight: 650;
    font-size: 13px;
    transition: background .15s ease, color .15s ease, transform .15s ease;
}

.app-sidebar .nav-link:hover {
    background: #eaf5f3;
    color: var(--brand-dark);
    transform: translateX(2px);
}

.app-sidebar .nav-link.active,
.app-sidebar .nav-link[aria-current="page"] {
    background: linear-gradient(135deg, var(--brand), #0d9488);
    color: #fff;
    box-shadow: 0 10px 20px rgba(15, 118, 110, 0.18);
}

.app-sidebar .nav-link.disabled {
    color: #94a3b8;
    background: transparent;
    transform: none;
}

.sidebar-footer {
    margin-top: auto;
    padding: 14px 6px 4px;
    border-top: 1px solid var(--line);
}

.app-main {
    min-width: 0;
    height: 100vh;
    padding: 28px;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    scrollbar-gutter: stable;
}

.page-header {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    margin: -8px 0 22px;
    padding: 18px 22px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(14px);
    border: 1px solid rgba(219, 228, 238, 0.85);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
}

.page-header h1 {
    font-size: 28px;
    margin: 0 0 4px;
    line-height: 1.1;
    letter-spacing: -0.035em;
}

.page-header p {
    color: var(--muted);
    margin: 0;
    max-width: 900px;
}

.metric-card,
.panel,
.stat-card {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(219, 228, 238, 0.88);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
}

.metric-card,
.stat-card {
    padding: 18px;
    min-height: 112px;
    position: relative;
    overflow: hidden;
}

.metric-card:before,
.stat-card:before {
    content: '';
    position: absolute;
    inset: 0 auto 0 0;
    width: 5px;
    background: linear-gradient(180deg, var(--brand), #14b8a6);
}

.metric-card span,
.stat-card span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 750;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.metric-card strong,
.stat-card strong {
    display: block;
    font-size: 29px;
    line-height: 1;
    letter-spacing: -0.04em;
}

.metric-card small,
.stat-card small {
    display: block;
    margin-top: 8px;
    color: var(--muted);
}

.stat-card.success:before { background: var(--success); }
.stat-card.danger:before { background: var(--danger); }
.stat-card.warning:before { background: var(--warning); }
.stat-card.info:before { background: var(--info); }

.panel {
    padding: 20px;
    margin-bottom: 18px;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    margin-bottom: 14px;
}

.panel-header h2,
.section-title {
    font-size: 18px;
    margin: 0;
    letter-spacing: -0.02em;
}

.panel-header p,
.section-subtitle {
    color: var(--muted);
    margin: 4px 0 0;
}

.table-responsive {
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    overflow: auto;
    scrollbar-gutter: stable;
}

.table-sticky-wrapper,
.panel .table-responsive:not(.table-no-freeze) {
    max-height: calc(100vh - 315px);
    overflow: auto;
}

.table-sticky-wrapper.table-tall {
    max-height: calc(100vh - 235px);
}

.table-sticky-wrapper.table-short {
    max-height: 420px;
}

table.table {
    --bs-table-bg: transparent;
    --bs-table-striped-bg: #f8fafc;
    --bs-table-hover-bg: #eef6f5;
    margin-bottom: 0;
}

table.table thead th,
.table-sticky thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #f8fafc;
    color: #475569;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 800;
    border-bottom: 1px solid var(--line-strong);
    white-space: nowrap;
}

table.table thead th:after,
.table-sticky thead th:after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 1px;
    background: var(--line-strong);
}

.table-sticky-wrapper thead th:first-child {
    border-top-left-radius: 12px;
}

.table-sticky-wrapper thead th:last-child {
    border-top-right-radius: 12px;
}

table.table tbody td {
    color: #1e293b;
    vertical-align: middle;
    border-color: #edf2f7;
}

table.table tbody tr:hover {
    background: #f8fbfb;
}

.form-control,
.form-select {
    border-color: var(--line-strong);
    border-radius: 11px;
    min-height: 39px;
}

.form-control:focus,
.form-select:focus {
    border-color: #14b8a6;
    box-shadow: 0 0 0 .2rem rgba(20, 184, 166, .16);
}

.form-label {
    color: #334155;
    font-weight: 700;
    font-size: 13px;
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--brand), #0d9488);
    border-color: var(--brand);
    box-shadow: 0 10px 16px rgba(15, 118, 110, 0.14);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--brand-dark), var(--brand));
    border-color: var(--brand-dark);
}

.badge,
.status-badge {
    border-radius: 999px;
    padding: .42rem .62rem;
    font-weight: 800;
    letter-spacing: .01em;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    font-size: 12px;
}

.status-buy,
.status-on,
.status-sent,
.status-profit {
    background: var(--success-soft);
    color: var(--success);
}

.status-watch,
.status-pending,
.status-warning {
    background: var(--warning-soft);
    color: var(--warning);
}

.status-exit,
.status-failed,
.status-loss,
.status-stop {
    background: var(--danger-soft);
    color: var(--danger);
}

.status-info,
.status-tp {
    background: var(--info-soft);
    color: var(--info);
}

.status-neutral,
.status-off,
.status-wait {
    background: #e2e8f0;
    color: #475569;
}

.price-up,
.text-profit { color: var(--success) !important; font-weight: 800; }
.price-down,
.text-loss { color: var(--danger) !important; font-weight: 800; }
.text-muted-strong { color: var(--muted); font-weight: 700; }

.stock-code {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 54px;
    padding: 6px 9px;
    border-radius: 10px;
    background: #eef6f5;
    color: var(--brand-dark);
    font-weight: 850;
    letter-spacing: .02em;
}

.empty-state {
    padding: 26px;
    text-align: center;
    color: var(--muted);
    background: var(--surface-soft);
    border-radius: 14px;
}

.action-stack {
    display: inline-flex;
    justify-content: flex-end;
    gap: 6px;
    flex-wrap: wrap;
}

.progress-mini {
    height: 7px;
    border-radius: 999px;
    background: #e2e8f0;
    overflow: hidden;
    min-width: 90px;
}

.progress-mini > span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--brand), #14b8a6);
}

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

.small-note {
    color: var(--muted);
    font-size: 12px;
}

.nowrap { white-space: nowrap; }

.error-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    text-align: center;
}

@media (max-width: 992px) {
    body { overflow: auto; }
    .app-shell {
        grid-template-columns: 1fr;
        height: auto;
        overflow: visible;
    }
    .app-sidebar {
        position: sticky;
        top: 0;
        height: auto;
        max-height: 55vh;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }
    .app-sidebar .nav {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px;
    }
    .sidebar-footer { margin-top: 10px; }
    .app-main {
        height: auto;
        min-height: calc(100vh - 120px);
        overflow: visible;
        padding: 18px;
    }
    .page-header {
        top: 0;
        flex-direction: column;
        padding: 18px;
    }
    .table-sticky-wrapper,
    .panel .table-responsive:not(.table-no-freeze) {
        max-height: 65vh;
    }
}

@media (max-width: 576px) {
    body { font-size: 13px; }
    .app-sidebar .nav { grid-template-columns: 1fr; }
    .metric-card strong,
    .stat-card strong { font-size: 24px; }
    .panel { padding: 14px; }
}

/* Sidebar hide/show toggle */
.app-shell,
.app-sidebar,
.app-main {
    transition: grid-template-columns .22s ease, transform .22s ease, opacity .18s ease, padding .18s ease;
}

.sidebar-toggle-button {
    position: fixed;
    top: 18px;
    left: 224px;
    z-index: 90;
    min-width: 40px;
    height: 40px;
    border: 1px solid rgba(203, 213, 225, 0.85);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.94);
    color: #334155;
    box-shadow: 0 10px 22px rgba(15, 23, 42, 0.12);
    font-weight: 850;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    backdrop-filter: blur(12px);
}

.sidebar-toggle-button:hover {
    background: #eef6f5;
    color: var(--brand-dark);
    border-color: rgba(15, 118, 110, 0.28);
}

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

body.sidebar-collapsed .app-sidebar {
    transform: translateX(-112%);
    opacity: 0;
    pointer-events: none;
    padding-left: 0;
    padding-right: 0;
    border-right: 0;
    box-shadow: none;
    overflow: hidden;
}

body.sidebar-collapsed .sidebar-toggle-button {
    left: 18px;
    min-width: 96px;
    padding: 0 14px;
    justify-content: center;
    background: linear-gradient(135deg, var(--brand), #0d9488);
    color: #fff;
    border-color: rgba(15, 118, 110, 0.18);
}

body.sidebar-collapsed .page-header {
    padding-left: 118px;
}

@media (max-width: 992px) {
    .sidebar-toggle-button {
        top: 12px;
        left: 12px;
        min-width: 94px;
        padding: 0 12px;
    }

    body:not(.sidebar-collapsed) .sidebar-toggle-button {
        background: linear-gradient(135deg, var(--brand), #0d9488);
        color: #fff;
    }

    body.sidebar-collapsed .app-sidebar {
        display: none;
    }

    body.sidebar-collapsed .page-header,
    body:not(.sidebar-collapsed) .page-header {
        padding-left: 112px;
    }
}

/* Sidebar toggle v5: visible inline hide button + floating restore button */
.brand {
    position: relative;
}

.brand-text {
    min-width: 0;
    flex: 1 1 auto;
}

.sidebar-inline-toggle,
.sidebar-restore-toggle {
    border: 1px solid rgba(203, 213, 225, 0.9);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.94);
    color: #334155;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.10);
    font-weight: 850;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    cursor: pointer;
    transition: background .15s ease, color .15s ease, border-color .15s ease, transform .15s ease;
}

.sidebar-inline-toggle {
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    margin-left: auto;
    font-size: 22px;
}

.sidebar-inline-toggle:hover,
.sidebar-restore-toggle:hover {
    background: #eef6f5;
    color: var(--brand-dark);
    border-color: rgba(15, 118, 110, 0.35);
    transform: translateY(-1px);
}

.sidebar-restore-toggle {
    display: none;
    position: fixed;
    top: 18px;
    left: 18px;
    z-index: 120;
    min-width: 96px;
    height: 40px;
    padding: 0 14px;
    backdrop-filter: blur(12px);
    background: linear-gradient(135deg, var(--brand), #0d9488);
    color: #fff;
    border-color: rgba(15, 118, 110, 0.18);
}

body.sidebar-collapsed .sidebar-restore-toggle {
    display: inline-flex;
}

body.sidebar-collapsed .sidebar-inline-toggle {
    display: none;
}

/* Hide older floating button if it was injected by an older cached script */
.sidebar-toggle-button {
    display: none !important;
}

/* Keep only one active menu item visually strong */
.app-sidebar .nav-link.active[aria-current="page"] {
    background: linear-gradient(135deg, var(--brand), #0d9488);
    color: #fff;
}

@media (max-width: 992px) {
    .sidebar-restore-toggle {
        top: 12px;
        left: 12px;
    }

    .sidebar-inline-toggle {
        width: 38px;
        height: 38px;
    }
}

/* Top user menu v6 */
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 80;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin: -8px 0 16px;
    padding: 10px 14px;
    min-height: 58px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(14px);
    border: 1px solid rgba(219, 228, 238, 0.88);
    border-radius: 16px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.07);
}

.topbar-left,
.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.topbar-menu-toggle {
    min-width: 94px;
    height: 38px;
    border: 1px solid rgba(203, 213, 225, 0.9);
    border-radius: 999px;
    background: #ffffff;
    color: #334155;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
    font-weight: 850;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    cursor: pointer;
    transition: background .15s ease, color .15s ease, border-color .15s ease, transform .15s ease;
}

.topbar-menu-toggle:hover {
    background: #eef6f5;
    color: var(--brand-dark);
    border-color: rgba(15, 118, 110, 0.35);
    transform: translateY(-1px);
}

.topbar-menu-icon {
    font-size: 20px;
    line-height: 1;
}

.topbar-context {
    min-width: 0;
}

.topbar-context strong,
.user-meta strong,
.user-dropdown-header strong {
    display: block;
    line-height: 1.1;
    color: #0f172a;
}

.topbar-context small,
.user-meta small,
.user-dropdown-header small {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-top: 2px;
}

.user-menu-toggle {
    min-height: 40px;
    border: 1px solid rgba(203, 213, 225, 0.9);
    border-radius: 999px;
    background: #ffffff;
    color: #334155;
    padding: 5px 10px 5px 5px;
    display: inline-flex;
    align-items: center;
    gap: 9px;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease, transform .15s ease;
}

.user-menu-toggle:hover,
.user-menu-toggle[aria-expanded="true"] {
    background: #eef6f5;
    border-color: rgba(15, 118, 110, 0.35);
    transform: translateY(-1px);
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    background: linear-gradient(135deg, var(--brand), #14b8a6);
    color: #ffffff;
    font-weight: 900;
    font-size: 12px;
    letter-spacing: .02em;
}

.user-avatar-lg {
    width: 42px;
    height: 42px;
    font-size: 14px;
}

.user-meta {
    min-width: 0;
    text-align: left;
    max-width: 190px;
}

.user-meta strong,
.user-meta small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-menu-caret {
    color: var(--muted);
    font-size: 11px;
}

.user-dropdown {
    min-width: 250px;
    border: 1px solid rgba(219, 228, 238, 0.95);
    border-radius: 14px;
    padding: 8px;
}

.user-dropdown-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
}

.user-dropdown .dropdown-item {
    border-radius: 10px;
    padding: 9px 10px;
}

/* App header now uses topbar; page header freezes below it. */
.page-header {
    top: 74px;
}

/* Use topbar button as the main restore button; keep old floating restore hidden. */
.sidebar-restore-toggle {
    display: none !important;
}

body.sidebar-collapsed .topbar-menu-toggle {
    background: linear-gradient(135deg, var(--brand), #0d9488);
    border-color: rgba(15, 118, 110, 0.18);
    color: #fff;
}

body.sidebar-collapsed .page-header {
    padding-left: 22px;
}

@media (max-width: 992px) {
    .app-topbar {
        margin: 0 0 14px;
        border-radius: 14px;
    }

    .page-header {
        top: 72px;
    }

    body.sidebar-collapsed .page-header,
    body:not(.sidebar-collapsed) .page-header {
        padding-left: 18px;
    }

    .topbar-context {
        display: none;
    }
}

@media (max-width: 576px) {
    .app-topbar {
        gap: 8px;
        padding: 9px;
    }

    .topbar-menu-toggle {
        min-width: 44px;
        width: 44px;
        padding: 0;
    }

    .topbar-menu-text,
    .user-meta,
    .user-menu-caret {
        display: none;
    }

    .user-menu-toggle {
        padding: 4px;
    }
}

/* User management v7 */
.role-check-list {
    display: grid;
    gap: 10px;
}

.role-check-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface-soft);
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease, transform .15s ease;
}

.role-check-item:hover {
    border-color: rgba(15, 118, 110, 0.35);
    background: #eef6f5;
    transform: translateY(-1px);
}

.role-check-item strong {
    display: block;
    color: var(--text);
    line-height: 1.1;
}

.role-check-item small {
    display: block;
    color: var(--muted);
    margin-top: 3px;
}

.app-sidebar .brand {
    padding-right: 6px;
}

/* Menu flow grouping v9 */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 4px 0 10px;
}

.nav-section {
    display: grid;
    gap: 5px;
}

.nav-section-title {
    padding: 7px 10px 4px;
    color: #64748b;
    font-size: 10px;
    font-weight: 900;
    letter-spacing: 0.11em;
    text-transform: uppercase;
    line-height: 1.2;
}

.nav-section + .nav-section {
    border-top: 1px solid rgba(226, 232, 240, 0.88);
    padding-top: 10px;
}

.app-sidebar .sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    min-height: 38px;
    margin: 0;
}

.app-sidebar .sidebar-nav .nav-link.active,
.app-sidebar .sidebar-nav .nav-link[aria-current="page"] {
    transform: none;
}

body.sidebar-collapsed .sidebar-nav,
body.sidebar-collapsed .sidebar-footer,
body.sidebar-collapsed .brand {
    pointer-events: none;
}

@media (max-width: 992px) {
    .sidebar-nav {
        gap: 10px;
    }

    .nav-section + .nav-section {
        padding-top: 8px;
    }
}

/* Collapsible sidebar submenu v10 */
.nav-section-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border: 0;
    background: transparent;
    padding: 7px 10px 4px;
    color: #64748b;
    font-size: 10px;
    font-weight: 900;
    letter-spacing: 0.11em;
    text-transform: uppercase;
    line-height: 1.2;
    border-radius: 10px;
    cursor: pointer;
    text-align: left;
}

.nav-section-toggle:hover {
    color: #0f766e;
    background: rgba(15, 118, 110, 0.06);
}

.nav-section-toggle:focus-visible {
    outline: 3px solid rgba(20, 184, 166, 0.25);
    outline-offset: 2px;
}

.nav-section-chevron {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 999px;
    color: #94a3b8;
    transition: transform .15s ease, background .15s ease, color .15s ease;
    font-size: 14px;
    line-height: 1;
}

.nav-section-toggle:hover .nav-section-chevron {
    background: rgba(15, 118, 110, 0.10);
    color: #0f766e;
}

.nav-section-items {
    display: grid;
    gap: 5px;
}

.nav-section.nav-section-collapsed .nav-section-items {
    display: none;
}

.nav-section.nav-section-collapsed .nav-section-chevron {
    transform: rotate(-90deg);
}

.nav-section.has-active > .nav-section-toggle {
    color: #0f766e;
}

.nav-section.has-active > .nav-section-toggle .nav-section-chevron {
    color: #0f766e;
    background: rgba(15, 118, 110, 0.10);
}

body.sidebar-collapsed .nav-section-toggle {
    pointer-events: none;
}

/* Flexible mobile layout v26 ------------------------------------------------- */
:root {
    --tia-topbar-h: 66px;
    --tia-page-header-h: 0px;
}

html,
body {
    max-width: 100%;
}

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

.app-main,
.panel,
.metric-card,
.stat-card,
.table-responsive,
.table-sticky-wrapper,
.card,
.alert {
    min-width: 0;
}

.table-responsive,
.table-sticky-wrapper,
.panel .table-responsive:not(.table-no-freeze) {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.table-responsive > table,
.table-sticky-wrapper > table {
    margin-bottom: 0;
}

.mobile-sidebar-backdrop {
    display: none;
}

@media (min-width: 993px) {
    .app-main {
        overflow-y: auto;
        overflow-x: hidden;
    }
}

@media (max-width: 992px) {
    body {
        overflow-x: hidden !important;
        overflow-y: auto !important;
        background: #eef3f8;
    }

    .app-shell {
        display: block !important;
        min-height: 100dvh;
        height: auto !important;
        overflow: visible !important;
        grid-template-columns: 1fr !important;
    }

    .app-main {
        width: 100% !important;
        min-height: 100dvh !important;
        height: auto !important;
        overflow: visible !important;
        padding: calc(var(--tia-topbar-h) + 12px) 12px 22px !important;
    }

    .app-topbar {
        position: fixed !important;
        top: 8px !important;
        left: 8px !important;
        right: 8px !important;
        z-index: 1200 !important;
        min-height: 54px !important;
        margin: 0 !important;
        padding: 8px 10px !important;
        border-radius: 16px !important;
        gap: 8px !important;
        max-width: calc(100vw - 16px) !important;
    }

    .topbar-left,
    .topbar-right {
        min-width: 0 !important;
        flex: 0 1 auto;
    }

    .topbar-context {
        display: none !important;
    }

    .topbar-menu-toggle {
        min-width: 44px !important;
        width: 44px !important;
        height: 40px !important;
        padding: 0 !important;
        flex: 0 0 auto !important;
    }

    .topbar-menu-text,
    .user-meta,
    .user-menu-caret {
        display: none !important;
    }

    .user-menu-toggle {
        min-height: 40px !important;
        padding: 4px !important;
        flex: 0 0 auto !important;
    }

    .user-dropdown {
        min-width: min(280px, calc(100vw - 24px)) !important;
    }

    .app-sidebar {
        position: fixed !important;
        inset: 0 auto 0 0 !important;
        z-index: 1300 !important;
        width: min(86vw, 320px) !important;
        height: 100dvh !important;
        max-height: none !important;
        padding: 16px 14px !important;
        border-right: 1px solid rgba(203, 213, 225, 0.9) !important;
        border-bottom: 0 !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        transform: translateX(-105%) !important;
        opacity: 1 !important;
        pointer-events: none !important;
        box-shadow: 16px 0 34px rgba(15, 23, 42, 0.22) !important;
        transition: transform .22s ease !important;
    }

    body:not(.sidebar-collapsed) .app-sidebar,
    body.mobile-menu-open .app-sidebar {
        transform: translateX(0) !important;
        pointer-events: auto !important;
    }

    body.sidebar-collapsed .app-sidebar {
        display: flex !important;
        transform: translateX(-105%) !important;
        pointer-events: none !important;
        padding: 16px 14px !important;
        opacity: 1 !important;
    }

    body.mobile-menu-open .mobile-sidebar-backdrop,
    body:not(.sidebar-collapsed) .mobile-sidebar-backdrop {
        display: block !important;
        position: fixed !important;
        inset: 0 !important;
        z-index: 1250 !important;
        background: rgba(15, 23, 42, 0.42) !important;
        border: 0 !important;
        padding: 0 !important;
    }

    .sidebar-restore-toggle,
    .sidebar-inline-toggle,
    .sidebar-toggle-button {
        display: none !important;
    }

    .brand {
        margin-bottom: 8px !important;
        padding-bottom: 14px !important;
    }

    .sidebar-nav {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
    }

    .app-sidebar .nav,
    .app-sidebar .sidebar-nav .nav-section-items {
        display: grid !important;
        grid-template-columns: 1fr !important;
    }

    .app-sidebar .nav-link {
        min-height: 42px !important;
        font-size: 14px !important;
    }

    .page-header {
        position: sticky !important;
        top: calc(var(--tia-topbar-h) + 8px) !important;
        z-index: 1100 !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 10px !important;
        margin: 0 0 14px !important;
        padding: 14px !important;
        border-radius: 16px !important;
        max-width: 100% !important;
    }

    body.sidebar-collapsed .page-header,
    body:not(.sidebar-collapsed) .page-header {
        padding-left: 14px !important;
    }

    .page-header h1 {
        font-size: clamp(20px, 6vw, 26px) !important;
        line-height: 1.12 !important;
        word-break: break-word;
    }

    .page-header p {
        font-size: 13px !important;
    }

    .page-header > div,
    .page-header .d-flex,
    .page-header form {
        max-width: 100% !important;
        flex-wrap: wrap !important;
    }

    .page-header .btn,
    .page-header button,
    .page-header a.btn,
    .page-header form .form-control,
    .page-header form .form-select {
        width: 100%;
    }

    .row {
        --bs-gutter-x: .75rem;
        --bs-gutter-y: .75rem;
    }

    .row > [class*="col-"] {
        min-width: 0;
    }

    .metric-card,
    .stat-card,
    .panel {
        border-radius: 16px !important;
    }

    .metric-card,
    .stat-card {
        min-height: auto !important;
        padding: 15px !important;
    }

    .metric-card strong,
    .stat-card strong {
        font-size: clamp(21px, 7vw, 28px) !important;
        overflow-wrap: anywhere;
    }

    .panel {
        padding: 14px !important;
        margin-bottom: 14px !important;
    }

    .help-grid,
    .checklist-grid,
    .status-grid,
    .glossary-grid,
    .quick-grid,
    .summary-grid,
    .dashboard-grid,
    .metric-grid,
    .stat-grid {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    .table-sticky-wrapper,
    .table-responsive,
    .panel .table-responsive:not(.table-no-freeze) {
        max-height: 68dvh !important;
        border-radius: 14px !important;
        overflow-x: auto !important;
        overflow-y: auto !important;
    }

    table.table {
        font-size: 12.5px !important;
    }

    table.table th,
    table.table td {
        padding: 8px 9px !important;
        white-space: nowrap;
        vertical-align: middle;
    }

    .table-sticky-wrapper thead th,
    .table-responsive thead th,
    .table-sticky thead th {
        position: sticky !important;
        top: 0 !important;
        z-index: 8 !important;
        background: #f8fafc !important;
        box-shadow: 0 1px 0 rgba(203, 213, 225, 0.85) !important;
    }

    .form-control,
    .form-select,
    .btn {
        min-height: 40px;
    }

    .btn-group,
    .btn-toolbar {
        flex-wrap: wrap !important;
        gap: 6px !important;
    }

    .dropdown-menu {
        max-width: calc(100vw - 24px);
    }
}

@media (max-width: 576px) {
    .app-main {
        padding-left: 10px !important;
        padding-right: 10px !important;
    }

    .app-topbar {
        left: 6px !important;
        right: 6px !important;
        top: 6px !important;
        max-width: calc(100vw - 12px) !important;
    }

    .page-header {
        top: 68px !important;
        padding: 12px !important;
    }

    .panel {
        padding: 12px !important;
    }

    .table-sticky-wrapper,
    .table-responsive,
    .panel .table-responsive:not(.table-no-freeze) {
        margin-left: -2px;
        margin-right: -2px;
    }

    .card-body {
        padding: 14px !important;
    }
}


/* Mobile drawer menu scroll fix v27 --------------------------------------- */
@media (max-width: 992px) {
    body.mobile-menu-open,
    body.mobile-menu-open html {
        overflow: hidden !important;
    }

    body.mobile-menu-open .app-sidebar,
    body:not(.sidebar-collapsed) .app-sidebar {
        display: grid !important;
        grid-template-rows: auto minmax(0, 1fr) auto !important;
        align-content: stretch !important;
        gap: 10px !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)) !important;
        overflow: hidden !important;
    }

    body.mobile-menu-open .app-sidebar *,
    body:not(.sidebar-collapsed) .app-sidebar * {
        pointer-events: auto !important;
    }

    .app-sidebar .brand {
        position: sticky !important;
        top: 0 !important;
        z-index: 2 !important;
        flex: 0 0 auto !important;
        margin: 0 !important;
        padding: 6px 6px 12px !important;
        background: rgba(255, 255, 255, 0.98) !important;
        backdrop-filter: blur(12px) !important;
    }

    .app-sidebar .sidebar-nav {
        min-height: 0 !important;
        max-height: none !important;
        height: auto !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain !important;
        padding: 2px 3px 18px !important;
        margin: 0 -3px !important;
        scrollbar-gutter: stable !important;
    }

    .app-sidebar .sidebar-footer {
        position: sticky !important;
        bottom: 0 !important;
        z-index: 2 !important;
        flex: 0 0 auto !important;
        margin: 0 !important;
        padding: 10px 6px 2px !important;
        background: rgba(255, 255, 255, 0.98) !important;
        backdrop-filter: blur(12px) !important;
    }

    .app-sidebar .nav-section {
        min-width: 0 !important;
    }

    .app-sidebar .nav-section-toggle {
        min-height: 38px !important;
        padding: 9px 10px !important;
        touch-action: manipulation !important;
    }

    .app-sidebar .nav-section-items {
        max-height: none !important;
        overflow: visible !important;
        padding-bottom: 2px !important;
    }

    .app-sidebar .nav-link {
        width: 100% !important;
        min-height: 44px !important;
        white-space: normal !important;
        line-height: 1.25 !important;
        padding: 10px 12px !important;
    }

    .app-sidebar .nav-link .menu-text,
    .app-sidebar .nav-link span:last-child {
        min-width: 0 !important;
        overflow-wrap: anywhere !important;
    }

    .app-sidebar .nav-section.has-active > .nav-section-items {
        display: grid !important;
    }
}

@media (max-width: 576px) {
    body.mobile-menu-open .app-sidebar,
    body:not(.sidebar-collapsed) .app-sidebar {
        width: min(94vw, 360px) !important;
    }

    .app-sidebar .brand-mark {
        width: 38px !important;
        height: 38px !important;
        border-radius: 12px !important;
    }

    .app-sidebar .brand strong {
        font-size: 14px !important;
    }

    .app-sidebar .brand small {
        font-size: 11px !important;
    }
}
