/* ── App Layout ──────────────────────────────────────────────────────────── */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    background: #131828;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 24px 0;
    flex-shrink: 0;
    z-index: 10;
    height: 100vh;
    min-height: 0;
}
[data-theme="light"] .sidebar {
    background: #ffffff;
}

.sidebar > .logo,
.sidebar > .theme-toggle,
.sidebar > .user-block {
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 20px 24px;
    border-bottom: 1px solid var(--border);
}

.sidebar .logo svg {
    filter: drop-shadow(0 2px 6px var(--primary-glow));
}

.logo-tag {
    font-size: var(--text-3xs);
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), #0284c7);
    color: #fff;
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    margin-left: auto;
    /* Push to right */
    letter-spacing: .5px;
    box-shadow: 0 2px 8px var(--primary-glow);
}

.logo .logo-tsk {
    font-size: var(--text-xl);
}

.logo .logo-group {
    font-size: var(--text-xl);
}

.nav-menu {
    flex: 1 1 auto;
    min-height: 0;
    padding: 16px 0;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.25) transparent;
}

.nav-menu::-webkit-scrollbar {
    width: 6px;
}

.nav-menu::-webkit-scrollbar-track {
    background: transparent;
}

.nav-menu::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.25);
    border-radius: var(--radius-xs);
}

.nav-menu::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.45);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--text-muted);
    font-size: var(--text-sm);
    font-weight: 500;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    position: relative;
    margin: 1px 8px;
    border-radius: var(--radius-sm);
    max-height: 44px;
}

/* Отключаем transition на пунктах/шевроне до первого кадра — чтобы
   восстановленное из localStorage свёрнутое состояние не «схлопывалось»
   анимацией при загрузке. JS добавляет .anim-ready на .nav-menu. */
.nav-menu:not(.anim-ready) .nav-item,
.nav-menu:not(.anim-ready) .nav-section-chevron {
    transition: none !important;
}

.nav-item:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
}

.nav-item.active {
    color: #fff;
    background: linear-gradient(90deg, rgba(14, 165, 233, 0.28), rgba(14, 165, 233, 0.08));
    border-left-color: var(--primary);
    box-shadow: inset 0 0 0 1px rgba(14, 165, 233, 0.25), 0 4px 14px rgba(14, 165, 233, 0.18);
    font-weight: 600;
}
.nav-item.active i {
    color: var(--primary);
    filter: drop-shadow(0 0 6px rgba(14, 165, 233, 0.55));
}
[data-theme="light"] .nav-item.active {
    color: var(--primary);
    background: linear-gradient(90deg, rgba(2, 132, 199, 0.15), rgba(2, 132, 199, 0.04));
    box-shadow: inset 0 0 0 1px rgba(2, 132, 199, 0.18), 0 4px 14px rgba(2, 132, 199, 0.12);
}

/* Nav count badge */
.nav-count-badge {
    margin-left: auto;
    font-size: var(--text-3xs); font-weight: 700;
    background: var(--primary); color: #fff;
    padding: 1px 7px; border-radius: var(--radius-sm);
    min-width: 18px; text-align: center;
    line-height: 16px;
    box-shadow: 0 2px 6px rgba(14, 165, 233, 0.3);
}

.nav-item i {
    width: 16px;
    height: 16px;
}

.nav-section {
    position: relative;
    margin: 16px 8px 2px;
    padding: 8px 12px 6px;
    font-size: var(--text-3xs);
    font-weight: 700;
    letter-spacing: 1.2px;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 8px;
    border-radius: var(--radius-sm);
    transition: color 0.15s ease, background 0.15s ease;
}

/* Hairline-разделитель над каждой группой (кроме самой первой) */
.nav-section::before {
    content: '';
    position: absolute;
    top: -9px;
    left: 4px;
    right: 4px;
    height: 1px;
    background: var(--border);
}

.nav-menu > .nav-section:first-child {
    margin-top: 4px;
}

.nav-menu > .nav-section:first-child::before {
    display: none;
}

.nav-section .nav-section-icon {
    width: 13px;
    height: 13px;
    color: var(--primary);
    opacity: 0.75;
    flex-shrink: 0;
}

/* Метка-заголовок прижимает счётчик+шеврон вправо */
.nav-section-label {
    margin-right: auto;
}

/* Lucide-шеврон сворачивания */
.nav-section-chevron {
    width: 14px;
    height: 14px;
    opacity: 0.5;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.nav-section:hover .nav-section-chevron {
    opacity: 0.8;
}

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

/* Счётчик пунктов на свёрнутой группе (показывается из JS) */
.nav-section-count {
    display: none;
    font-size: var(--text-4xs);
    font-weight: 700;
    letter-spacing: 0;
    color: var(--text-muted);
    background: rgba(148, 163, 184, 0.18);
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    line-height: 14px;
    min-width: 16px;
    text-align: center;
}

/* Подсветка группы, в которой находится активный пункт */
.nav-section.has-active {
    color: var(--text);
}

.nav-section.has-active .nav-section-label {
    color: var(--primary);
}

.nav-section.has-active .nav-section-icon {
    opacity: 1;
}

.nav-section:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.04);
}

[data-theme="light"] .nav-section:hover {
    background: rgba(2, 6, 23, 0.035);
}

/* Свёрнутая группа: пункты схлопываются по высоте/прозрачности (анимация),
   а не исчезают мгновенно. overflow:hidden только на свёрнутых — чтобы
   не обрезать свечение активного пункта в раскрытом состоянии. */
.nav-item.in-collapsed-section {
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-top: 0;
    margin-bottom: 0;
    overflow: hidden;
    pointer-events: none;
}

.user-block {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

.avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: var(--text-base);
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 2px 10px rgba(14, 165, 233, 0.3);
}

.user-avatar-mini {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-3xs);
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.avatar-sm {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-2xs);
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.user-info {
    flex: 1;
}

.username {
    display: block;
    font-size: var(--text-sm);
    font-weight: 600;
}

.role {
    display: block;
    font-size: var(--text-2xs);
    color: var(--text-muted);
}

.logout-icon {
    width: 16px;
    height: 16px;
    cursor: pointer;
    color: var(--text-muted);
    transition: color .2s;
}

.logout-icon:hover {
    color: var(--danger);
}

/* ── Main Content ────────────────────────────────────────────────────────── */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Top Bar ─────────────────────────────────────────────────────────────── */
.top-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 32px;
    background: #131828;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 5;
    position: relative;
}
[data-theme="light"] .top-bar {
    background: #ffffff;
}

/* ── Rates Banner ──────────────────────────────────────────────────────── */
/* ── Rates Popup ─────────────────────────────────────────────────────────── */
.rates-popup-wrap {
    position: relative;
}
.rates-trigger {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 12px; border-radius: var(--radius-sm);
    background: var(--glass-bg); border: 1px solid var(--border);
    color: var(--text-muted); cursor: pointer;
    transition: all 0.2s; font-size: var(--text-xs); font-weight: 600;
    font-family: inherit;
}
.rates-trigger:hover {
    border-color: var(--primary); color: var(--primary);
    background: rgba(14, 165, 233, 0.06);
    box-shadow: 0 2px 8px rgba(14, 165, 233, 0.1);
}
.rates-trigger-label { font-weight: 700; }

.rates-dropdown {
    display: none; position: fixed;
    width: 340px; z-index: 3000;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius); padding: 0;
    box-shadow: var(--shadow-xl), 0 0 1px rgba(255, 255, 255, 0.1);
    animation: ratesDropIn 0.2s ease;
    overflow: visible;
    isolation: isolate;
}
.rates-dropdown.open { display: block; }
@keyframes ratesDropIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.rates-dropdown-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px 10px; border-bottom: 1px solid var(--border);
    font-size: var(--text-sm); font-weight: 700; color: var(--text);
}
.rates-dropdown-meta {
    font-size: var(--text-3xs); font-weight: 500; color: var(--text-muted);
}

.rates-dropdown-list {
    padding: 8px;
    display: flex; flex-direction: column; gap: 4px;
}

.rate-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 10px; border-radius: var(--radius-sm);
    transition: background 0.15s;
}
.rate-row:hover { background: rgba(14, 165, 233, 0.04); }

.rate-row-left {
    display: flex; align-items: center; gap: 8px;
}
.rate-sym {
    font-size: var(--text-lg); font-weight: 700; color: var(--primary);
    width: 22px; text-align: center;
}
.rate-code {
    font-weight: 700; color: var(--text); font-size: var(--text-sm);
}

.rate-row-right {
    display: flex; align-items: center; gap: 10px; font-size: var(--text-xs);
}
.rate-nbk {
    color: var(--text); font-weight: 600; font-size: var(--text-sm);
}
.rate-buy { color: var(--success); font-size: var(--text-2xs); min-width: 58px; }
.rate-sell { color: var(--danger); font-size: var(--text-2xs); min-width: 58px; }
.rate-header { padding: 2px 10px 6px; }
.rate-col-label { font-size: var(--text-4xs); font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; min-width: 58px; }
.rate-header .rate-nbk { font-size: var(--text-4xs); font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

/* Light theme */
[data-theme="light"] .rates-dropdown {
    background: #ffffff;
    border-color: rgba(203, 213, 225, 0.6);
    box-shadow: 0 16px 48px rgba(15, 23, 42, 0.15);
}

.rate-diff {
    font-size: var(--text-3xs);
    font-weight: 600;
    padding: 1px 5px;
    border-radius: var(--radius-xs);
    margin-left: 4px;
}

.rate-diff.up {
    color: var(--success);
    background: rgba(34, 197, 94, 0.1);
}

.rate-diff.down {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

.badge-discount {
    display: inline-block;
    font-size: var(--text-2xs);
    font-weight: 600;
    padding: 1px 6px;
    border-radius: var(--radius-xs);
    color: var(--success);
    background: rgba(34, 197, 94, 0.12);
    margin-left: 6px;
}

/* Calculation params section */
.calc-params-section {
    margin-top: 8px;
}

.calc-params-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    color: var(--text-secondary);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.calc-params-toggle:hover {
    background: var(--surface3);
    color: var(--text);
}

.calc-params-toggle .calc-chevron {
    margin-left: auto;
    transition: transform 0.2s;
}

.calc-params-toggle.open .calc-chevron {
    transform: rotate(180deg);
}

.calc-params-body {
    padding: 10px 0 0;
}

.calc-info-hint {
    font-size: var(--text-2xs);
    color: var(--text-muted);
    padding: 6px 10px;
    background: var(--surface2);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--primary);
}

.calc-price-breakdown {
    font-size: var(--text-2xs);
    color: var(--text-secondary);
    margin-top: 2px;
}

.calc-margin-badge {
    display: inline-block;
    font-size: var(--text-3xs);
    font-weight: 600;
    padding: 1px 5px;
    border-radius: var(--radius-xs);
    margin-left: 4px;
}

.calc-margin-badge.good {
    color: var(--success);
    background: rgba(34, 197, 94, 0.1);
}

.calc-margin-badge.warn {
    color: var(--warning);
    background: rgba(245, 158, 11, 0.1);
}

.calc-margin-badge.bad {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 7px 12px;
    width: 240px;
    transition: border-color 0.15s, box-shadow 0.15s;
    margin-left: auto;
}

.search-box:focus-within {
    border-color: var(--primary);
    box-shadow: var(--shadow-focus);
}

.search-box i {
    width: 15px;
    height: 15px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.search-box input {
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-size: var(--text-sm);
    width: 100%;
    min-width: 0;
}

.search-kbd {
    flex-shrink: 0;
    font-family: inherit;
    font-size: var(--text-3xs);
    font-weight: 600;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    padding: 1px 6px;
    letter-spacing: 0.5px;
}
[data-theme="light"] .search-kbd {
    background: rgba(15, 23, 42, 0.04);
}

/* Topbar section title — название текущего раздела */
.topbar-section-title {
    font-size: var(--text-base);
    font-weight: 600;
    color: var(--text);
    margin-right: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.top-actions {
    display: flex;
    gap: 8px;
}

/* ── Content Header ──────────────────────────────────────────────────────── */
.content-header {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 32px 32px 24px;
    /* More breathing room */
    flex-shrink: 0;
    flex-wrap: wrap;
}

.header-text h1 {
    font-size: var(--text-xl);
    font-weight: 700;
}

.header-text p {
    color: var(--text-muted);
    font-size: var(--text-xs);
    margin-top: 2px;
}

.stats-cards {
    display: flex;
    gap: 12px;
    margin-left: auto;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 18px;
    text-align: center;
    transition: border-color var(--transition-fast);
}

.stat-card:hover {
    border-color: rgba(14, 165, 233, 0.3);
}

.stat-active {
    border-color: rgba(14, 165, 233, .3);
}

.stat-done {
    border-color: rgba(16, 185, 129, .3);
}

.stat-value {
    display: block;
    font-size: var(--text-2xl);
    font-weight: 700;
    line-height: 1;
}

.stat-label {
    display: block;
    font-size: var(--text-3xs);
    color: var(--text-muted);
    margin-top: 2px;
}

/* ── Content Header Adjustments ─────────────────────────────── */
#pageSubtitle {
    margin-bottom: 0;
}

