/* ==========================================================================
   ДИЗАЙН-ТОКЕНЫ
   Единые значения вместо хардкода по файлу. Раньше в проекте было 11 разных
   скруглений и 20 разных отступов — отсюда визуальный разнобой.
   ========================================================================== */
:root {
    /* --- Отступы: шаг 4px --- */
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 20px;
    --sp-6: 24px;
    --sp-7: 28px;
    --sp-8: 32px;

    /* --- Скругления --- */
    --r-xs: 6px;
    --r-sm: 8px;
    --r-md: 12px;
    --r-lg: 16px;
    --r-xl: 20px;
    --r-full: 999px;

    /* --- Типографика ---
       Нижняя граница поднята: раньше встречались 9-10px, нечитаемые на телефоне. */
    --fs-2xs: 11px;   /* только для плотных инлайновых бейджей: на 12px они
                         перестают помещаться в строку на экране 390px и встают
                         в столбик, раздувая карточку */
    --fs-xs: 12px;    /* подписи — минимум для обычного текста */
    --fs-sm: 13px;    /* вторичный текст */
    --fs-base: 15px;  /* основной текст */
    --fs-md: 17px;    /* заметный текст, заголовки карточек */
    --fs-lg: 20px;
    --fs-xl: 24px;
    --fs-2xl: 28px;
    --fs-3xl: 36px;   /* баланс */
    --lh-tight: 1.2;
    --lh-normal: 1.5;

    /* --- Длительности анимаций --- */
    --dur-fast: 120ms;
    --dur-base: 200ms;
    --dur-slow: 320ms;
    --ease: cubic-bezier(0.4, 0, 0.2, 1);

    /* --- Слои --- */
    --z-header: 10;
    --z-tabbar: 20;
    --z-panel: 30;
    --z-modal: 50;

    --font-family: 'Inter', sans-serif;
    --tab-bar-height: 64px;
}

/* ==========================================================================
   ПАЛИТРА — тёмная тема (основная)
   Глубокий синий + золото + фиолетовый.
   Зелёный и красный зарезервированы ИСКЛЮЧИТЕЛЬНО за прибылью/убытком —
   как декоративные или категориальные цвета не используются нигде.
   ========================================================================== */
:root {
    --bg-main: #020617;
    --bg-card: #0F172A;
    --bg-surface: #1E293B;
    --text-primary: #F8FAFC;
    --text-secondary: #94A3B8;
    --border: #253449;

    /* Акцент разведён на две роли: один оттенок не может одновременно давать
       достаточный контраст и как заливка под белым текстом, и как цвет текста
       на тёмном фоне (проверено расчётом контраста WCAG). */
    --accent: #7C3AED;              /* заливка кнопок: белый текст даёт 5.7:1 */
    --accent-text: #A78BFA;         /* текст/иконки акцентом: 6.6:1 на карточке */
    --accent-soft: rgba(139, 92, 246, 0.15);
    --accent-strong: rgba(139, 92, 246, 0.35);   /* для рамок поверх soft-фона */
    --gold: #F59E0B;                /* золото — баланс, важные числа */
    --gold-soft: rgba(245, 158, 11, 0.15);

    --positive: #22C55E;
    --positive-soft: rgba(34, 197, 94, 0.15);
    --positive-strong: rgba(34, 197, 94, 0.35);
    --negative: #EF4444;
    --negative-soft: rgba(239, 68, 68, 0.15);
    --negative-strong: rgba(239, 68, 68, 0.35);

    /* Тени с синим подтоном — чтобы не выглядели грязными на синем фоне */
    --sh-sm: 0 1px 2px rgba(2, 6, 23, 0.4);
    --sh-md: 0 4px 12px rgba(2, 6, 23, 0.5);
    --sh-lg: 0 12px 32px rgba(2, 6, 23, 0.6);
}

/* --- СВЕТЛАЯ ТЕМА --- */
:root[data-theme="light"] {
    --bg-main: #F8FAFC;
    --bg-card: #FFFFFF;
    --bg-surface: #F1F5F9;
    --text-primary: #0F172A;
    --text-secondary: #64748B;
    --border: #E2E8F0;

    --accent: #7C3AED;
    --accent-text: #6D28D9;         /* на белом даёт 7.1:1 */
    --accent-soft: rgba(124, 58, 237, 0.12);
    --accent-strong: rgba(124, 58, 237, 0.3);
    /* Золото #F59E0B на белом даёт контраст ~2:1 — для текста берём затемнённое,
       иначе суммы будут нечитаемыми. */
    --gold: #B45309;
    --gold-soft: rgba(180, 83, 9, 0.12);

    --positive: #15803D;
    --positive-soft: rgba(21, 128, 61, 0.12);
    --positive-strong: rgba(21, 128, 61, 0.3);
    --negative: #DC2626;
    --negative-soft: rgba(220, 38, 38, 0.12);
    --negative-strong: rgba(220, 38, 38, 0.3);

    --sh-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --sh-md: 0 4px 12px rgba(15, 23, 42, 0.08);
    --sh-lg: 0 12px 32px rgba(15, 23, 42, 0.12);
}

/* --- ТЕМА BYBIT (чёрно-жёлтая) --- */
:root[data-theme="bybit"] {
    --bg-main: #0B0E11;
    --bg-card: #161A1E;
    --bg-surface: #1E2329;
    --text-primary: #EAECEF;
    --text-secondary: #848E9C;
    --border: #2B3139;

    --accent: #F7A600;
    --accent-text: #FFC94D;
    --accent-soft: rgba(247, 166, 0, 0.15);
    --accent-strong: rgba(247, 166, 0, 0.35);
    --gold: #F7A600;
    --gold-soft: rgba(247, 166, 0, 0.15);

    --positive: #0ECB81;
    --positive-soft: rgba(14, 203, 129, 0.15);
    --positive-strong: rgba(14, 203, 129, 0.35);
    --negative: #F6465D;
    --negative-soft: rgba(246, 70, 93, 0.15);
    --negative-strong: rgba(246, 70, 93, 0.35);

    --sh-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --sh-md: 0 4px 12px rgba(0, 0, 0, 0.5);
    --sh-lg: 0 12px 32px rgba(0, 0, 0, 0.6);
}

/* --- ТЕМА ОКЕАН (сине-бирюзовая) --- */
:root[data-theme="ocean"] {
    --bg-main: #06121F;
    --bg-card: #0C1D30;
    --bg-surface: #13293F;
    --text-primary: #E6F1FF;
    --text-secondary: #7C97B3;
    --border: #1E3A56;

    --accent: #0EA5E9;
    --accent-text: #38BDF8;
    --accent-soft: rgba(14, 165, 233, 0.15);
    --accent-strong: rgba(14, 165, 233, 0.35);
    --gold: #FBBF24;
    --gold-soft: rgba(251, 191, 36, 0.15);

    --positive: #22C55E;
    --positive-soft: rgba(34, 197, 94, 0.15);
    --positive-strong: rgba(34, 197, 94, 0.35);
    --negative: #EF4444;
    --negative-soft: rgba(239, 68, 68, 0.15);
    --negative-strong: rgba(239, 68, 68, 0.35);

    --sh-sm: 0 1px 2px rgba(2, 10, 20, 0.4);
    --sh-md: 0 4px 12px rgba(2, 10, 20, 0.5);
    --sh-lg: 0 12px 32px rgba(2, 10, 20, 0.6);
}

/* --- ТЕМА НЕОН (фиолетово-розовая) --- */
:root[data-theme="neon"] {
    --bg-main: #0F0417;
    --bg-card: #1A0B2E;
    --bg-surface: #241242;
    --text-primary: #FDF4FF;
    --text-secondary: #B79ADB;
    --border: #3B1E63;

    --accent: #EC4899;
    --accent-text: #F472B6;
    --accent-soft: rgba(236, 72, 153, 0.15);
    --accent-strong: rgba(236, 72, 153, 0.35);
    --gold: #22D3EE;
    --gold-soft: rgba(34, 211, 238, 0.15);

    --positive: #34D399;
    --positive-soft: rgba(52, 211, 153, 0.15);
    --positive-strong: rgba(52, 211, 153, 0.35);
    --negative: #F43F5E;
    --negative-soft: rgba(244, 63, 94, 0.15);
    --negative-strong: rgba(244, 63, 94, 0.35);

    --sh-sm: 0 1px 2px rgba(10, 2, 20, 0.4);
    --sh-md: 0 4px 12px rgba(10, 2, 20, 0.5);
    --sh-lg: 0 12px 32px rgba(10, 2, 20, 0.6);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    position: relative;
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: var(--fs-base);
    line-height: var(--lh-normal);
    -webkit-font-smoothing: antialiased;
    padding-top: env(safe-area-inset-top);
    overflow-x: hidden;
    /* Моноширинные цифры: у Inter обычные цифры разной ширины, из-за чего суммы
       "дёргаются" при каждом обновлении цен. Для приложения про деньги это заметно. */
    font-variant-numeric: tabular-nums;
}

/* В связном тексте (разборы ИИ) пропорциональные цифры читаются лучше */
.ai-review-body,
.advice-box,
.news-item {
    font-variant-numeric: normal;
}

body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    /* Подсветка фона в тон палитре: фиолетовый -> синий -> золото.
       Зелёный/красный сюда не берём — они закреплены за прибылью/убытком. */
    background: linear-gradient(
        135deg,
        #8B5CF6 0%,
        #6366F1 25%,
        #1E3A8A 55%,
        #B45309 85%,
        #F59E0B 100%
    );
    filter: blur(90px);
    opacity: 0.22;
    z-index: -1;
    pointer-events: none;
}

:root[data-theme="light"] body::before {
    opacity: 0.1;
    filter: blur(70px);
}

/* --- LOADER --- */
.loader-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-main);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-radius: 50%;
    border-top-color: var(--accent);
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    100% {
        transform: rotate(360deg);
    }
}

/* Disable animations for users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* --- HEADER (bento) --- */
.portfolio-header {
    padding: var(--sp-5) var(--sp-4) var(--sp-4);
    background: transparent;
    border-bottom: none;
}

.balance-container {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
}

/* --- Плитки bento --- */
.bento-tile {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--sp-4);
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Главная плитка: мягкий градиент, чтобы баланс читался как акцент экрана */
.bento-balance {
    background:
        radial-gradient(120% 140% at 0% 0%, var(--accent-soft) 0%, transparent 60%),
        var(--bg-card);
}

.tile-label {
    font-size: var(--fs-2xs);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-weight: 600;
}

.tile-secondary {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    margin-top: var(--sp-1);
    letter-spacing: 0.01em;
}

/* Две узкие плитки в ряд */
.history-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-3);
}

.bento-stat {
    padding: var(--sp-3);
    gap: 2px;
}

.bento-stat .tile-value {
    font-size: var(--fs-md);
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bento-stat .tile-sub {
    font-size: var(--fs-2xs);
    font-weight: 600;
}

.tile-value.positive, .tile-sub.positive { color: var(--positive); }
.tile-value.negative, .tile-sub.negative { color: var(--negative); }

.total-balance {
    /* Баланс — золотом: главный числовой акцент экрана */
    color: var(--gold);
    font-size: var(--fs-3xl);
    font-weight: 700;
    margin: var(--sp-1) 0;
    display: flex;
    align-items: baseline;
    gap: var(--sp-1);
    letter-spacing: -0.5px;
}

.currency-label {
    font-size: var(--fs-lg);
    color: var(--text-secondary);
}

.profit-container {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
}

.profit-container.positive {
    background: var(--positive-soft);
    color: var(--positive);
}

.profit-container.negative {
    background: var(--negative-soft);
    color: var(--negative);
}

.history-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    font-size: var(--fs-xs);
}

.history-item {
    color: var(--text-secondary);
}

.history-item.positive {
    color: var(--positive);
}

.history-item.negative {
    color: var(--negative);
}

.history-sep {
    color: var(--border);
}

/* --- TAB CONTENT --- */
.tab-content {
    display: none;
    padding: 16px 16px calc(var(--tab-bar-height) + 16px);
    min-height: calc(100vh - 140px);
}

.tab-content.active {
    display: block;
}

.section-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

.section-title h2 {
    font-size: 17px;
    font-weight: 600;
}

.section-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    position: relative;
}

.add-btn {
    background: var(--accent);
    color: white;
    border: none;
    min-width: 44px;
    min-height: 44px;
    border-radius: 12px;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: all 0.2s ease;
    position: relative;
}

.add-btn svg {
    display: block;
}

.add-btn:active {
    transform: scale(0.95);
}

.add-btn:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.add-btn.spinning {
    animation: spin 1s linear;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.add-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* --- CATEGORY ACCORDION --- */
.asset-category {
    margin-bottom: 10px;
}

.category-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 14px;
    background: var(--bg-card);
    border-radius: 14px;
    border: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
    transition: background 0.15s, border-radius 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.category-header:active {
    background: var(--bg-surface);
}

.asset-category.open .category-header {
    border-radius: 14px 14px 0 0;
    border-bottom-color: transparent;
}

.category-header-left {
    display: flex;
    align-items: center;
    gap: 9px;
}

.category-emoji {
    font-size: 20px;
    line-height: 1;
    width: 28px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
}

.category-emoji svg {
    display: block;
}

.category-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
}

.category-count {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    font-weight: 500;
    margin-left: 2px;
}

.category-header-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.category-total {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
}

.category-profit-badge {
    font-size: var(--fs-xs);
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 6px;
    white-space: nowrap;
}

.category-profit-badge.positive {
    background: var(--positive-soft);
    color: var(--positive);
}

.category-profit-badge.negative {
    background: var(--negative-soft);
    color: var(--negative);
}

.category-arrow {
    color: var(--text-secondary);
    font-size: var(--fs-xs);
    transition: transform 0.22s ease;
    display: inline-block;
}

.asset-category.open .category-arrow {
    transform: rotate(180deg);
}

.category-body {
    display: none;
    flex-direction: column;
    gap: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 14px 14px;
    padding: 8px 8px 8px;
    overflow: hidden;
}

.category-body .assets-inner {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.asset-category.open .category-body {
    display: flex;
}

/* --- ASSET CARDS (single column) --- */
.assets-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.asset-card {
    background: var(--bg-card);
    border-radius: var(--r-lg);
    border: 1px solid var(--border);
    overflow: hidden;
    cursor: pointer;
    transition: border-color var(--dur-base) var(--ease),
                box-shadow var(--dur-base) var(--ease),
                transform var(--dur-fast) var(--ease);
}

.asset-card:hover {
    border-color: var(--accent);
    box-shadow: var(--sh-md);
}

/* На телефоне ховера нет — отклик даёт нажатие */
.asset-card:active {
    transform: scale(0.985);
}

/* Сетка: первая строка — название и цена, вторая — бейджи на всю ширину.
   Раньше бейджи лежали в узкой левой колонке и на экране 390px вставали
   в столбик, вытягивая карточку. */
.card-main {
    padding: var(--sp-4) var(--sp-4) 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    column-gap: var(--sp-3);
    row-gap: var(--sp-2);
}

.card-badges {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-2);
}

.card-left {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.card-right {
    flex-shrink: 0;
    text-align: right;
}

/* Иконка актива */
.asset-icon {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    flex-shrink: 0;
    color: white;
    overflow: hidden;
}

.asset-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 12px;
}

.asset-info {
    flex: 1;
    min-width: 0;
}

.asset-ticker {
    font-size: 17px;
    font-weight: 700;
}

.asset-company-name {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    margin-top: 1px;
    line-height: 1.3;
    font-weight: 400;
}

.asset-subtitle {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    margin-top: 2px;
    line-height: 1.5;
}

/* Бейдж доли в портфеле */
.allocation-badge {
    display: inline-flex;
    align-items: center;
    font-size: var(--fs-2xs);
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-surface);
    border-radius: var(--r-xs);
    padding: 2px var(--sp-2);
}

.cagr-badge {
    display: inline-flex;
    align-items: center;
    font-size: var(--fs-2xs);
    font-weight: 700;
    border-radius: var(--r-xs);
    padding: 2px var(--sp-2);
}

.cagr-badge.pos {
    background: var(--positive-soft);
    color: var(--positive);
}

.cagr-badge.neg {
    background: var(--negative-soft);
    color: var(--negative);
}

/* Бейдж источника котировки (KASE, MOEX, LBMA спот, ...) */
.price-source-badge {
    display: inline-flex;
    align-items: center;
    font-size: var(--fs-2xs);
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-surface);
    border-radius: var(--r-xs);
    padding: 2px var(--sp-2);
    opacity: 0.8;
    letter-spacing: 0.02em;
}

.asset-value {
    font-size: 17px;
    font-weight: 700;
}

.asset-profit {
    font-size: 12px;
    font-weight: 600;
    margin-top: 3px;
}

.asset-profit.positive {
    color: var(--positive);
}

.asset-profit.negative {
    color: var(--negative);
}

.asset-no-price {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 3px;
}

/* --- ALLOCATION BAR CHART --- */
.bubble-chart-container {
    padding: 10px 16px 12px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

.alloc-bar-wrap {
    display: flex;
    height: 8px;
    border-radius: 6px;
    overflow: hidden;
    gap: 2px;
    margin-bottom: 8px;
}

.alloc-bar-segment {
    border-radius: 3px;
    transition: flex 0.4s ease;
}

.alloc-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
}

.alloc-legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: var(--fs-xs);
    color: var(--text-secondary);
}

.alloc-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.alloc-legend-item span:last-child {
    font-weight: 600;
    color: var(--text-primary);
}

/* --- THEME SELECTOR --- */
.theme-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.theme-group-label {
    flex-basis: 100%;
    font-size: 12px;
    color: var(--text-secondary);
    margin: 4px 0 -2px;
}

.theme-swatch {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: inline-block;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.theme-option {
    flex: 1 1 28%;
    min-width: 88px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 8px;
    border-radius: 12px;
    border: 2px solid var(--border);
    background: var(--bg-surface);
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    font-size: var(--fs-xs);
    color: var(--text-secondary);
}

.theme-option:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.theme-option.active {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent-text);
}

.theme-option:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.theme-option .theme-emoji {
    font-size: 20px;
}

/* Sparkline */
.sparkline-wrapper {
    margin: 10px 0 0;
    height: 48px;
}

.sparkline-wrapper svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* --- LOTS SECTION --- */
.lots-section {
    padding: 8px 16px 12px;
}

.lots-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 0;
    user-select: none;
}

.lots-toggle.open .lots-arrow {
    transform: rotate(180deg);
}

.lots-arrow {
    transition: transform 0.2s;
    display: inline-block;
    font-size: var(--fs-xs);
}

.lots-list {
    display: none;
    flex-direction: column;
    gap: 4px;
    margin-top: 6px;
}

.lots-list.open {
    display: flex;
}

/* --- SWIPE TO DELETE --- */
.lot-wrapper {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    /* скруглять только здесь */
    margin-bottom: 4px;
}

/* Область под строкой лота, открывается свайпом влево.
   Две кнопки: продажа (цена известна, идёт в реализованную прибыль) и
   удаление ошибочной записи. Ширина 128px = 2 × 64px — на неё же завязан
   сдвиг строки в attachSwipeToDelete. */
.lot-actions-bg {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 128px;
    display: flex;
    cursor: pointer;
}

.lot-action {
    width: 64px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    cursor: pointer;
}

.lot-action-sell {
    background: var(--positive);
}

.lot-action-delete {
    background: var(--negative);
}

.lot-action .del-label {
    font-size: var(--fs-xs);
    font-weight: 700;
    color: white;
    letter-spacing: 0.3px;
}

/* Информация о лоте в модалке продажи */
.sell-lot-info {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 12px;
}

.sell-preview {
    margin-top: 12px;
    font-size: 13px;
    font-weight: 600;
    min-height: 18px;
}

.lot-row {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    background: var(--bg-surface);
    /* border-radius убран — у lot-row он создаёт зазоры у краёв,
       через которые пробивается красный фон */
    padding: 6px 10px;
    touch-action: pan-y;
    user-select: none;
    will-change: transform;
}

.lot-date {
    color: var(--text-secondary);
    min-width: 70px;
    cursor: pointer;
    text-decoration: underline dotted;
    text-underline-offset: 2px;
}

.lot-date-input {
    color: var(--text-secondary);
    min-width: 70px;
    background: none;
    border: none;
    font: inherit;
    font-size: 12px;
    padding: 0;
    color-scheme: dark;
}

:root[data-theme="light"] .lot-date-input {
    color-scheme: light;
}

.lot-amount {
    font-weight: 600;
    min-width: 48px;
}

.lot-price {
    color: var(--text-primary);
    flex: 1;
    text-align: right;
    font-weight: 500;
}

/* --- SKELETON LOADING --- */
@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }

    100% {
        background-position: 200% 0;
    }
}

/* Плавное появление карточек */
@keyframes cardFadeIn {
    from {
        opacity: 0;
        transform: translateY(14px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.asset-card-enter {
    animation: cardFadeIn 0.28s ease both;
}

/* --- ПЕРЕКЛЮЧАТЕЛЬ ПОРТФЕЛЕЙ --- */
.portfolio-switcher {
    display: flex;
    gap: 6px;
    padding: 10px 16px 4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.portfolio-switcher::-webkit-scrollbar { display: none; }

.pf-btn {
    flex: 1;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 0;
    padding: 5px 8px;
    border-radius: 10px;
    border: 1.5px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: var(--fs-xs);
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    text-align: center;
    line-height: 1;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}
.pf-btn .pf-icon-wrap {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.pf-btn .pf-icon-wrap svg {
    width: 12px;
    height: 12px;
    stroke: currentColor;
    stroke-width: 2.2;
}
.pf-btn .pf-label {
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.pf-btn .pf-count {
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-size: var(--fs-xs);
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.pf-btn .pf-count:empty { display: none; }
.pf-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    box-shadow: 0 3px 12px var(--accent-soft);
}
.pf-btn.active .pf-count {
    background: rgba(255,255,255,0.25);
}

/* --- настройки: список портфелей --- */
.pf-settings-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 10px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
}
.pf-settings-icon {
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--text-secondary);
}
.pf-settings-icon svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
}
.pf-settings-label {
    flex: 1;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pf-delete-btn {
    width: 26px;
    height: 26px;
    border-radius: var(--r-sm);
    border: none;
    background: transparent;
    color: var(--negative);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--dur-fast) var(--ease);
    padding: 0;
    /* Иконка остаётся 26px, но область нажатия расширяется до 44px невидимым
       псевдоэлементом — иначе в кнопку тяжело попасть пальцем, а увеличение
       самой кнопки сломало бы вёрстку строки. */
    position: relative;
}

.pf-delete-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 44px;
    height: 44px;
}
.pf-delete-btn:hover { background: var(--negative-soft); }

/* --- пикер иконок портфеля --- */
.pf-icon-picker {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}
.pf-icon-pick {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1.5px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.18s;
    padding: 0;
}
.pf-icon-pick svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
}
.pf-icon-pick:hover { border-color: var(--accent); color: var(--accent-text); }
.pf-icon-pick.selected {
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
}

/* Бейдж портфеля в заголовке модала */
.portfolio-tag {
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    vertical-align: middle;
    margin-left: 6px;
}

/* --- СОРТИРОВКА --- */
.sort-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 6px 10px 10px;
    margin-top: -6px;
    margin-left: -10px;
    margin-right: -10px;
}

.sort-bar::-webkit-scrollbar { display: none; }

.sort-btn {
    flex-shrink: 0;
    padding: 6px 14px;
    border-radius: 20px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.18s;
    opacity: 0.6;
}

.sort-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    opacity: 1;
    box-shadow: 0 2px 8px var(--accent-soft);
}

.sort-btn:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.skel {
    background: linear-gradient(90deg,
            var(--bg-surface) 25%,
            var(--border) 50%,
            var(--bg-surface) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite ease-in-out;
    border-radius: 6px;
    flex-shrink: 0;
}

.skel-icon {
    width: 38px;
    height: 38px;
    border-radius: 12px;
}

.skel-line {
    height: 12px;
}

.skel-spark {
    height: 48px;
    margin: 10px 0 0;
    border-radius: 0;
}

/* --- HISTORY TAB --- */

.history-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 18px;
    padding: 14px;
    background: var(--bg-card);
    border-radius: 14px;
    border: 1px solid var(--border);
}

.hs-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.hs-label {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.2px;
    font-weight: 500;
    line-height: 1.2;
}

.hs-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-date-group {
    margin-bottom: 4px;
}

.history-date-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 600;
    margin: 8px 0 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.history-item-row {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-card);
    border-radius: 12px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    margin-bottom: 4px;
}

.hi-ticker {
    font-weight: 700;
    font-size: 14px;
    min-width: 56px;
}

.hi-mid {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.hi-detail {
    font-size: 12px;
    color: var(--text-primary);
    font-weight: 500;
}

.hi-time {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
}

.hi-price {
    font-size: 13px;
    font-weight: 600;
    text-align: right;
}

/* Кнопка продажи в списке истории. Видимая, в отличие от свайпа в карточке
   актива: свайп плохо обнаруживается, а продажа — не редкое действие. */
.hi-sell {
    background: none;
    border: none;
    color: var(--positive);
    cursor: pointer;
    opacity: 0.6;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    min-height: 28px;
}

.hi-sell svg {
    display: block;
}

.hi-sell:hover {
    opacity: 1;
    background: var(--positive-soft);
}

.hi-delete {
    background: none;
    border: none;
    color: var(--negative);
    cursor: pointer;
    font-size: 13px;
    opacity: 0.5;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    min-height: 28px;
    border-radius: 6px;
    transition: opacity 0.2s, background 0.2s;
}

.hi-delete svg {
    display: block;
}

.hi-delete:hover {
    opacity: 1;
    background: var(--negative-soft);
}

/* --- BOTTOM TAB BAR --- */
.tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--tab-bar-height);
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: stretch;
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 500;
}

.tab-btn {
    flex: 1;
    /* Без min-width:0 flex-элемент не сжимается меньше своего содержимого:
       на узких экранах (390px) длинные подписи вроде "Дивиденды" раздували
       панель, и последняя вкладка уезжала за край экрана. */
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color var(--dur-base) var(--ease);
    position: relative;
    min-height: 44px;
    padding: 0 var(--sp-1);
}

.tab-btn .tab-label {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tab-btn::after {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%) scaleX(0);
    width: 32px;
    height: 3px;
    border-radius: 0 0 4px 4px;
    background: var(--accent);
    transition: transform 0.2s ease;
}

.tab-btn.active {
    color: var(--accent-text);
}

.tab-btn.active::after {
    transform: translateX(-50%) scaleX(1);
}

.tab-btn:focus {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.tab-icon {
    font-size: 20px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tab-icon svg {
    display: block;
}

.tab-label {
    font-size: var(--fs-xs);
    font-weight: 600;
    font-family: var(--font-family);
    letter-spacing: -0.2px;
}

/* --- MODALS --- */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    z-index: 2000;
    align-items: flex-end;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    width: 100%;
    border-radius: 20px 20px 0 0;
    padding: 24px;
    animation: slideUp 0.3s ease-out;
    max-height: 90vh;
    overflow-y: auto;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }

    to {
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 28px;
    cursor: pointer;
}

.close-btn:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    margin-top: 14px;
}

.form-group input,
.form-group select {
    width: 100%;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 16px;
    font-family: var(--font-family);
}

.form-group input:focus,
.form-group select:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-color: var(--accent);
}

/* Без этого календарь-иконка в input[type=date] рендерится тёмной и почти не видна на тёмном фоне */
.form-group input[type="date"] {
    color-scheme: dark;
}

:root[data-theme="light"] .form-group input[type="date"] {
    color-scheme: light;
}

.primary-btn {
    width: 100%;
    background: var(--accent);
    color: white;
    border: none;
    padding: 14px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font-family);
    transition: opacity 0.2s;
}

.primary-btn:hover {
    opacity: 0.9;
}

.primary-btn:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.magic-btn {
    width: 100%;
    background: linear-gradient(135deg, #FF2E93 0%, #FF8000 100%);
    color: white;
    border: none;
    padding: 14px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font-family);
}

.mt-1 {
    margin-top: 20px;
}

/* --- TICKER AUTOCOMPLETE --- */
.ticker-input-wrapper {
    position: relative;
}

.ticker-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    z-index: 3000;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    margin-top: 4px;
}

.ticker-dropdown-item {
    padding: 10px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.ticker-dropdown-item:last-child {
    border-bottom: none;
}

.ticker-dropdown-item:hover {
    background: var(--bg-card);
}

.dd-ticker {
    font-weight: 700;
    font-size: 14px;
    min-width: 64px;
}

.dd-name {
    font-size: 12px;
    color: var(--text-secondary);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dd-market {
    font-size: var(--fs-xs);
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 6px;
    background: var(--accent-soft);
    color: var(--accent-text);
    white-space: nowrap;
}

/* --- EXPORT BUTTON --- */
.export-btn {
    flex: 1;
    padding: 10px;
    border: 1.5px solid var(--border);
    border-radius: 12px;
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.export-btn svg {
    display: block;
}

.export-btn:hover {
    background: var(--bg-card);
    border-color: var(--accent);
}

.export-btn:active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.export-btn:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* --- FULLSCREEN ASSET DETAIL PANEL --- */
.fullscreen-panel {
    position: fixed;
    inset: 0;
    background: var(--bg-main);
    z-index: 600;
    transform: translateX(100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.fullscreen-panel.open {
    transform: translateX(0);
}

.fs-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1;
}

.fs-back {
    background: none;
    border: none;
    font-size: 22px;
    color: var(--accent-text);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 8px;
    line-height: 1;
}

.fs-back:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.fs-title {
    font-size: 17px;
    font-weight: 700;
    color: var(--text-primary);
}

.fs-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 32px;
    -webkit-overflow-scrolling: touch;
}

/* Period selector buttons */
.period-selector {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    justify-content: center;
}

.period-btn {
    padding: 8px 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.period-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.period-btn.active {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

/* Chart inside fullscreen */
.detail-chart {
    width: 100%;
    height: 180px;
    margin-bottom: 16px;
    border-radius: 14px;
    overflow: hidden;
    background: var(--bg-surface);
}

.detail-chart svg {
    display: block;
    width: 100%;
    height: 100%;
}

/* Stats grid */
.detail-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
}

.detail-stat {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 12px 14px;
    text-align: center;
}

.detail-stat .ds-label {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 4px;
}

.detail-stat .ds-value {
    font-size: 15px;
    font-weight: 700;
}

/* Lots */
.detail-lots-title {
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.detail-lot-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    background: var(--bg-card);
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 5px;
}

.detail-lot-date {
    color: var(--text-secondary);
    min-width: 70px;
}

.detail-lot-qty {
    font-weight: 600;
    min-width: 50px;
}

.detail-lot-price {
    flex: 1;
    text-align: right;
    font-weight: 500;
}

/* News section */
.detail-section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-secondary);
    margin: 18px 0 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Asset type badge */
.asset-type-badge {
    display: inline-block;
    font-size: var(--fs-xs);
    font-weight: 600;
    padding: 3px 9px;
    border-radius: 20px;
    margin-bottom: 10px;
    letter-spacing: 0.3px;
}
.asset-type-bond {
    background: rgba(255, 195, 0, 0.15);
    color: #d4a017;
    border: 1px solid rgba(255, 195, 0, 0.3);
}
.asset-type-etf {
    background: var(--accent-soft);
    color: var(--accent-text);
    border: 1px solid var(--accent-strong);
}

/* Bond / ETF info card */
.bond-info-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 12px 14px;
    margin: 10px 0 0;
}
.bond-info-title {
    font-size: var(--fs-xs);
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}
.bond-info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
}
.bond-info-row:last-child {
    border-bottom: none;
}
.bond-info-row span:first-child {
    color: var(--text-secondary);
}
.bond-info-row span:last-child {
    font-weight: 600;
}
.bond-info-highlight span:last-child {
    color: var(--positive);
}


/* Asset detail accordion */
.det-accordion {
    margin-top: 14px;
}

.det-accordion-hdr {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 12px;
    background: var(--bg-card);
    border-radius: 10px;
    cursor: pointer;
    user-select: none;
    transition: background 0.18s ease;
}

.det-accordion-hdr:hover {
    background: var(--bg-surface);
}

.det-accordion-label {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.det-accordion-label svg {
    flex-shrink: 0;
}

.det-acc-arrow-wrap {
    display: flex;
    align-items: center;
    color: var(--text-secondary);
}

.det-acc-arrow {
    transition: transform 0.28s ease;
}

.det-accordion-body {
    padding-top: 8px;
}

.news-item {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 10px 14px;
    margin-bottom: 6px;
    font-size: 13px;
    line-height: 1.45;
    color: var(--text-primary);
    border-left: 3px solid var(--accent);
}

/* Дата публикации новости */
.news-date {
    display: inline-block;
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--accent-text);
    opacity: 0.75;
    margin-right: 6px;
    vertical-align: middle;
    flex-shrink: 0;
}

.news-link {
    display: block;
    text-decoration: none;
    transition: all 0.2s ease;
}

.news-link:hover {
    background: var(--bg-surface);
    transform: translateX(2px);
}

.sentiment-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    margin: 8px 0 12px;
    border: 1px solid;
    backdrop-filter: blur(10px);
}

.sentiment-positive {
    background: var(--positive-soft);
    border-color: var(--positive-strong);
    color: var(--positive);
}

.sentiment-negative {
    background: var(--negative-soft);
    border-color: var(--negative-strong);
    color: var(--negative);
}

.sentiment-neutral {
    background: rgba(142, 142, 147, 0.12);
    border-color: rgba(142, 142, 147, 0.3);
    color: var(--text-secondary);
}

/* AI advice box */
.advice-box {
    background: linear-gradient(135deg, var(--accent-soft) 0%, var(--gold-soft) 100%);
    border: 1px solid var(--accent);
    border-radius: 14px;
    padding: 14px 16px;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-primary);
    margin-top: 8px;
    white-space: pre-wrap;
}

.advice-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-secondary);
    font-size: 13px;
    padding: 12px 0;
}

.advice-spinner {
    width: 18px;
    height: 18px;
    border: 2.5px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

.ask-ai-btn {
    width: 100%;
    padding: 13px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 14px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    margin-top: 8px;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.ask-ai-btn svg {
    display: block;
    flex-shrink: 0;
}

.ask-ai-btn:hover {
    opacity: 0.9;
}

.ask-ai-btn:disabled {
    opacity: 0.6;
}

/* --- CUSTOM RANGE SLIDER --- */
.custom-range {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    outline: none;
}

.custom-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg-card);
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.3);
}

.custom-range::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--bg-card);
}

.custom-range::-moz-range-track {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
}

/* --- TOGGLE SWITCH --- */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 28px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border);
    transition: 0.3s;
    border-radius: 28px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background-color: var(--bg-card);
    transition: 0.3s;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--accent);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(20px);
}

.toggle-switch input:focus + .toggle-slider {
    box-shadow: 0 0 0 2px var(--accent-soft);
}

/* --- SUB-TABS (внутри вкладки История) --- */
.subtab-bar {
    display: flex;
    gap: 0;
    margin: 4px 0 14px;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.subtab-bar::-webkit-scrollbar { display: none; }

.subtab-btn {
    flex: 0 0 auto;
    padding: 8px 10px;
    border: none;
    border-bottom: 2.5px solid transparent;
    border-radius: 0;
    background: transparent;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font-family);
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
    margin-bottom: -1px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.subtab-btn svg {
    display: block;
}

.subtab-btn.active {
    border-bottom-color: var(--accent);
    color: var(--accent-text);
    background: transparent;
    box-shadow: none;
}

.subtab-btn:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.subtab-content {
    display: none;
}

.subtab-content.active {
    display: block;
}

/* --- CHART PERIOD SELECTOR --- */
.chart-period-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
}

.chart-period-bar::-webkit-scrollbar { display: none; }

.period-btn {
    flex-shrink: 0;
    flex: 1;
    min-width: 44px;
    min-height: 36px;
    padding: 7px 8px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 700;
    font-family: var(--font-family);
    cursor: pointer;
    transition: background 0.18s, border-color 0.18s, color 0.18s;
}

.period-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.period-btn:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* --- CHART BENCHMARK SELECTOR --- */
.chart-benchmark-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
}

.bench-btn {
    flex: 1;
    min-height: 32px;
    padding: 6px 8px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 700;
    font-family: var(--font-family);
    cursor: pointer;
    transition: background 0.18s, border-color 0.18s, color 0.18s;
}

.bench-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.bench-btn:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* --- CHART LEGEND (видна при активном сравнении с эталоном) --- */
.chart-legend {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin: -4px 0 12px;
    font-size: var(--fs-xs);
    color: var(--text-secondary);
}

.chart-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.chart-legend-dot {
    display: inline-block;
    width: 14px;
    height: 2px;
    background: var(--positive);
    border-radius: 1px;
}

.chart-legend-dot--dashed {
    background: repeating-linear-gradient(90deg, var(--text-secondary) 0 4px, transparent 4px 7px);
}

/* --- PORTFOLIO CHART WRAPPER --- */
.portfolio-chart-wrap {
    position: relative;
    background: var(--bg-card);
    border-radius: 16px;
    border: 1px solid var(--border);
    overflow: hidden;
    min-height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
}

.portfolio-chart-svg {
    width: 100%;
    height: 220px;
    display: block;
}

/* SVG chart elements */
.chart-grid-line {
    stroke: var(--border);
    stroke-width: 0.7;
    stroke-dasharray: 3, 3;
}

.chart-axis-line {
    stroke: var(--border);
    stroke-width: 1;
}

.chart-axis-label {
    fill: var(--text-secondary);
    font-size: var(--fs-xs);
    font-family: var(--font-family);
}

/* Прозрачные хитзоны (hover-цели) */
.chart-hit {
    cursor: crosshair;
}

/* --- CHART TOOLTIP --- */
.chart-tooltip {
    position: absolute;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 7px 11px;
    pointer-events: none;
    z-index: 10;
    min-width: 110px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
}

.ct-date {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    margin-bottom: 2px;
    font-weight: 500;
}

.ct-value {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
}

/* --- CHART PLACEHOLDER --- */
.chart-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 32px 20px;
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.6;
    gap: 8px;
}

/* --- CHART STATS ROW (под графиком) --- */
.chart-stats-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    gap: 8px;
    margin-bottom: 12px;
}

.chart-stat {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 10px 6px;
    text-align: center;
    border: 1px solid var(--border);
}

.cs-label {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 4px;
    font-weight: 600;
}

.cs-value {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.3;
}

/* ===== ВКЛАДКА НАЛОГИ ===== */
.tax-card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
}

.tax-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.tax-card-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-text);
    flex-shrink: 0;
}

.tax-card-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
}

.tax-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.tax-row:last-of-type {
    border-bottom: none;
}

.tax-label {
    font-size: 13px;
    color: var(--text-secondary);
    flex: 1;
}

.tax-rate {
    font-size: 14px;
    font-weight: 700;
    color: var(--accent-text);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    white-space: nowrap;
}

.tax-hint {
    font-size: var(--fs-xs);
    font-weight: 400;
    color: var(--text-secondary);
    margin-top: 2px;
}

.tax-exempt {
    margin-top: 10px;
    padding: 8px 10px;
    background: var(--positive-soft);
    border-radius: 8px;
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
    display: flex;
    gap: 6px;
    align-items: flex-start;
}

.exempt-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #30D158;
    flex-shrink: 0;
}

.tax-info-row {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 7px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.tax-info-row:last-child {
    border-bottom: none;
}

.tax-info-bullet {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-text);
    flex-shrink: 0;
}

/* Блок напоминаний */
.tax-reminders {
    margin-bottom: 14px;
}

.tax-reminders-title {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.tax-reminder-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-card);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
}

.tri-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.tri-icon svg {
    width: 20px;
    height: 20px;
}

.tri-body {
    flex: 1;
    min-width: 0;
}

.tri-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.tri-date {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
}

.tri-days {
    flex-shrink: 0;
}

.tax-badge {
    display: inline-block;
    padding: 4px 9px;
    border-radius: 20px;
    font-size: var(--fs-xs);
    font-weight: 700;
}

.tax-badge.urgent {
    background: var(--negative-soft);
    color: #FF453A;
}

.tax-badge.warn {
    background: rgba(255, 159, 10, 0.18);
    color: #FF9F0A;
}

.tax-badge.ok {
    background: var(--positive-soft);
    color: #30D158;
}

/* ===== P&L OVERVIEW GRID ===== */
.pnl-overview {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 16px;
}

.pnl-ov-card {
    background: var(--bg-card);
    border: 1.5px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    cursor: pointer;
    transition: border-color 0.18s, box-shadow 0.18s;
    -webkit-tap-highlight-color: transparent;
}

.pnl-ov-card:hover {
    border-color: var(--accent);
    box-shadow: 0 2px 8px var(--accent-soft);
}

.pnl-ov-card.active {
    border-color: var(--accent);
    background: var(--accent-soft);
}

.pnl-ov-period {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 4px;
}

.pnl-ov-value {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
}

.pnl-ov-pct {
    font-size: var(--fs-xs);
    font-weight: 600;
    margin-top: 2px;
    opacity: 0.85;
}

/* ===== РИСК-АНАЛИТИКА ===== */

.risk-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 16px;
    color: var(--text-secondary);
    font-size: 14px;
    gap: 4px;
}

.risk-no-data {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 48px 24px 32px;
    color: var(--text-secondary);
    font-size: 14px;
    gap: 8px;
    line-height: 1.5;
}

.risk-no-data-hint {
    font-size: 12px;
    opacity: 0.7;
    max-width: 260px;
}

.risk-data-warn {
    margin: 16px 16px 0;
    padding: 10px 14px;
    background: color-mix(in srgb, #FFD60A 12%, transparent);
    border-left: 3px solid #FFD60A;
    border-radius: 8px;
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.risk-section-title {
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    padding: 18px 16px 8px;
}

.risk-metric-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 4px 16px 0;
}

.risk-card {
    background: var(--bg-card);
    border-radius: 14px;
    padding: 14px 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.risk-card-label {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1.2;
    /* Кнопка «?» прижимается к правому краю карточки: у метрик разной длины
       названия, и без space-between значок прыгал бы вслед за текстом. */
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.risk-card-value {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.1;
}

.risk-card-value.risk-green  { color: var(--positive); }
.risk-card-value.risk-yellow { color: #FFD60A; }
.risk-card-value.risk-red    { color: var(--negative); }
.risk-card-value.risk-muted  { color: var(--text-secondary); }

.asset-risk-empty {
    background: var(--bg-card);
    border-radius: 14px;
    padding: 14px;
    color: var(--text-secondary);
    font-size: var(--fs-sm);
    line-height: 1.5;
}

.asset-risk-note {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    line-height: 1.45;
    margin-top: 10px;
}

.risk-card-hint {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    margin-top: 2px;
    line-height: 1.3;
}

/* ===== ПОДСКАЗКИ ПО МЕТРИКАМ («?» в кружке) ===== */

.metric-help {
    position: relative;
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}

/* Сам кружок маленький, чтобы не спорить с цифрой, но пальцем в него надо
   попадать — расширяем область нажатия невидимой зоной до ~40px. */
.metric-help::before {
    content: '';
    position: absolute;
    inset: -11px;
}

.metric-help:hover,
.metric-help.active {
    color: var(--accent-text);
    border-color: var(--accent);
}

.metric-help:focus { outline: none; }

/* Внутри сплошного текста (а не заголовка карточки) кружку нужен воздух слева
   и выравнивание по базовой линии строки. */
.asset-risk-note .metric-help,
.risk-section-title .metric-help {
    margin: 0 3px;
    vertical-align: -4px;
}

.metric-tip {
    position: fixed;
    z-index: 3000;
    max-width: min(290px, calc(100vw - 24px));
    padding: 11px 13px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: 13px;
    line-height: 1.45;
    box-shadow: var(--sh-md);
    /* Прячем через visibility, а не display:none: JS замеряет размеры подсказки
       ДО показа, чтобы прижать её к краю экрана и не дать вылезти за границы. */
    visibility: hidden;
    opacity: 0;
    transform: translateY(-4px);
    pointer-events: none;
    transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}

.metric-tip.visible {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.risk-conc-wrap {
    padding: 0 16px 20px;
}

.risk-conc-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 10px;
}

.risk-conc-val {
    font-size: 20px;
    font-weight: 700;
}

.risk-conc-desc {
    font-size: 12px;
    color: var(--text-secondary);
}

.risk-conc-bar-track {
    height: 8px;
    background: var(--bg-surface);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 12px;
}

.risk-conc-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}

.risk-conc-assets {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.risk-conc-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.risk-conc-ticker {
    font-weight: 600;
    min-width: 52px;
}

.risk-conc-bar-mini-track {
    flex: 1;
    height: 5px;
    background: var(--bg-surface);
    border-radius: 3px;
    overflow: hidden;
}

.risk-conc-bar-mini {
    height: 100%;
    border-radius: 3px;
    background: var(--accent);
    transition: width 0.5s ease;
}

.risk-conc-pct {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 38px;
    text-align: right;
}

/* --- КОРРЕЛЯЦИОННАЯ МАТРИЦА --- */
.corr-heatmap-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 10px;
}

.corr-heatmap-table {
    border-collapse: collapse;
    font-size: 11px;
}

.corr-heatmap-table th {
    padding: 4px 6px;
    color: var(--text-secondary);
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
}

.corr-heatmap-table th:first-child {
    text-align: right;
    padding-right: 8px;
}

.corr-heatmap-table td {
    text-align: center;
    font-weight: 600;
    border: 2px solid var(--bg-card);
    border-radius: 4px;
    transition: background 0.2s;
}

.corr-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.corr-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.corr-legend-swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 3px;
    opacity: 0.75;
}

.corr-legend-swatch--neutral {
    background: var(--border);
    opacity: 1;
}

.corr-excluded-note {
    font-size: 11px;
    color: var(--text-secondary);
    text-align: center;
}

/* ===== ИИ ОБЗОР ПОРТФЕЛЯ ===== */

.ai-review-wrap {
    margin: 8px 0 24px;
}

.ai-review-trigger {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 10%, var(--bg-card)), var(--bg-card));
    border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
    border-radius: 14px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 600;
    text-align: left;
    transition: border-color 0.2s, background 0.2s;
}

.ai-review-trigger:hover,
.ai-review-trigger:active {
    border-color: color-mix(in srgb, var(--accent) 55%, transparent);
    background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 16%, var(--bg-card)), var(--bg-card));
}

.ai-review-trigger-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: color-mix(in srgb, var(--accent) 18%, transparent);
    border-radius: 10px;
    color: var(--accent-text);
    flex-shrink: 0;
}

.ai-review-trigger-hint {
    font-size: var(--fs-xs);
    font-weight: 400;
    color: var(--text-secondary);
    display: block;
    margin-top: 2px;
}

.ai-review-trigger > span:not(.ai-review-trigger-icon):not(.ai-review-trigger-hint) {
    flex: 1;
}

/* Когда карточка открыта — прячем кнопку-триггер */
.ai-review-wrap.open .ai-review-trigger {
    display: none;
}

.ai-review-card {
    background: var(--bg-card);
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.ai-review-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 10px;
    border-bottom: 1px solid var(--border);
}

.ai-review-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 700;
    color: var(--accent-text);
}

.ai-review-ts {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
}

.ai-review-body {
    padding: 14px 16px;
    font-size: 14px;
    line-height: 1.65;
    color: var(--text-primary);
    white-space: pre-line;
}

/* Свёрнутое состояние: карточка ИИ-обзора занимает примерно тот же объём,
   что и карточка актива, а не разрастается стеной текста на весь экран.
   Раскрывается по кнопке "Показать полностью". */
.ai-review-body-wrap {
    position: relative;
    max-height: 168px;
    overflow: hidden;
    transition: max-height 0.25s var(--ease);
}

.ai-review-body-wrap.expanded {
    max-height: 4000px; /* с запасом — реального контента столько не бывает */
}

.ai-review-body-wrap:not(.expanded)::after {
    content: '';
    position: absolute;
    left: 0; right: 0; bottom: 0;
    height: 48px;
    background: linear-gradient(to bottom, transparent, var(--bg-card));
    pointer-events: none;
}

.ai-review-expand-btn {
    display: none;
    width: 100%;
    padding: 10px 16px;
    background: transparent;
    border: none;
    border-top: 1px solid var(--border);
    color: var(--accent-text);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
}

.ai-review-expand-btn.visible {
    display: block;
}

.ai-review-body.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 36px 16px;
    gap: 10px;
    color: var(--text-secondary);
    font-size: 13px;
}

.ai-review-refresh {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0 16px 14px;
    padding: 8px 14px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

.ai-review-refresh:hover {
    border-color: var(--accent);
    color: var(--accent-text);
}

/* ===== P&L ПО ПЕРИОДАМ ===== */
.pnl-period-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
    padding: 4px;
    background: var(--bg-card);
    border-radius: 12px;
}

.pnl-period-btn {
    flex: 1;
    padding: 8px 4px;
    border: none;
    border-radius: 9px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.18s ease;
}

.pnl-period-btn.active {
    background: var(--accent);
    color: #fff;
}

.pnl-period-btn:focus { outline: none; }

.pnl-card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 20px;
    border: 1px solid var(--border);
    margin-bottom: 10px;
}

.pnl-card.pnl-pos { border-left: 4px solid var(--positive); }
.pnl-card.pnl-neg { border-left: 4px solid var(--negative); }

.pnl-card-period {
    font-size: var(--fs-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.pnl-card-change {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.5px;
    line-height: 1.1;
}

.pnl-card-pct {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 16px;
}

.pnl-card-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.pnl-meta-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 13px;
    font-weight: 600;
}

.pnl-meta-label {
    font-size: var(--fs-xs);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-secondary);
}

.pnl-no-data, .pnl-error, .pnl-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 36px 16px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
    gap: 6px;
}

.pnl-error { color: var(--negative); }

.pnl-disclaimer {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    line-height: 1.4;
    padding: 0 2px;
}

.pnl-disclaimer svg { flex-shrink: 0; margin-top: 1px; }

/* ===== КАЛЬКУЛЯТОР ИПН ===== */
.tax-calc-section {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 16px;
    border: 1px solid var(--border);
    margin-bottom: 14px;
}

.tax-calc-hdr {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
}

.tax-calc-hint {
    font-size: var(--fs-xs);
    font-weight: 500;
    color: var(--text-secondary);
    margin-left: auto;
}

.tax-calc-btn {
    width: 100%;
    padding: 11px 16px;
    border: none;
    border-radius: 12px;
    background: var(--accent);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    transition: opacity 0.18s ease;
}

.tax-calc-btn:disabled { opacity: 0.6; cursor: default; }
.tax-calc-btn:hover:not(:disabled) { opacity: 0.88; }

.tax-calc-assets {
    margin-top: 14px;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.tax-asset-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    gap: 8px;
}

.tax-asset-row:last-child { border-bottom: none; }

.tax-asset-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.tax-asset-ticker {
    font-weight: 700;
    font-size: 13px;
}

.tax-asset-type {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.tax-asset-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    font-weight: 600;
}

.tax-calc-total {
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}

.tax-total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
    gap: 8px;
}

.tax-total-row:last-child { border-bottom: none; }

.tax-total-main {
    font-weight: 700;
    font-size: 14px;
    background: var(--bg-surface);
}

/* =========================================================
   Ребаланс портфеля (rebalance-plan subtab)
   ========================================================= */

.rbp-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 12px;
}

.rbp-card-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.rbp-hint {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 14px;
    line-height: 1.5;
}

.rbp-asset-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--divider);
}
.rbp-asset-row:last-child { border-bottom: none; }

.rbp-asset-info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.rbp-asset-ticker {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.rbp-asset-cur-pct {
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border-radius: 6px;
    padding: 2px 6px;
}

.rbp-target-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.rbp-target-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.rbp-target-input {
    width: 60px;
    padding: 5px 7px;
    border-radius: 8px;
    border: 1.5px solid var(--divider);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    text-align: right;
    -webkit-appearance: none;
}
.rbp-target-input:focus {
    outline: none;
    border-color: var(--accent);
}

.rbp-pct-sign {
    font-size: 13px;
    color: var(--text-secondary);
}

.rbp-total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0 4px;
    margin-top: 4px;
    border-top: 1px solid var(--divider);
}

.rbp-total-label {
    font-size: 13px;
    color: var(--text-secondary);
}

.rbp-total-val {
    font-size: 14px;
    font-weight: 700;
}
.rbp-total-val.ok   { color: var(--positive); }
.rbp-total-val.warn { color: var(--negative); }

.rbp-extra-row {
    margin-top: 12px;
}

.rbp-extra-label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.rbp-extra-inputs {
    display: flex;
    gap: 8px;
}

.rbp-extra-input {
    flex: 1;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1.5px solid var(--divider);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
}
.rbp-extra-input:focus { outline: none; border-color: var(--accent); }

.rbp-extra-select {
    padding: 8px 10px;
    border-radius: 10px;
    border: 1.5px solid var(--divider);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    -webkit-appearance: none;
}

.rbp-run-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    margin-top: 14px;
    padding: 12px;
    border-radius: 12px;
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: opacity .15s;
}
.rbp-run-btn:disabled { opacity: .5; pointer-events: none; }
.rbp-run-btn:active   { opacity: .8; }

.rbp-optimize-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    margin-bottom: 12px;
    padding: 10px;
    border-radius: 12px;
    border: 1px solid var(--accent);
    background: var(--accent-soft);
    color: var(--accent-text);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: opacity .15s;
}
.rbp-optimize-btn:disabled { opacity: .5; pointer-events: none; }
.rbp-optimize-btn:active   { opacity: .8; }

.rbp-optimize-note {
    font-size: 12px;
    color: var(--text-secondary);
    margin: -6px 0 12px;
    line-height: 1.4;
}
.rbp-optimize-note:empty { display: none; }

.rbp-objective-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.rbp-objective-label {
    font-size: 12px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.rbp-objective-toggle {
    display: flex;
    flex: 1;
    gap: 4px;
    padding: 3px;
    background: var(--bg-surface);
    border-radius: 10px;
}

.rbp-objective-btn {
    flex: 1;
    padding: 6px 4px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.18s ease;
}

.rbp-objective-btn.active {
    background: var(--accent);
    color: #fff;
}

.rbp-objective-btn:focus { outline: none; }

.rbp-loading {
    text-align: center;
    padding: 24px;
    color: var(--text-secondary);
    font-size: 13px;
}
.rbp-empty {
    text-align: center;
    padding: 24px;
    color: var(--text-secondary);
    font-size: 14px;
}

.rbp-result-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 14px;
    margin-bottom: 12px;
}

.rbp-summary {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 10px 12px;
    margin-bottom: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.rbp-summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: var(--text-secondary);
}
.rbp-summary-row.total-row {
    border-top: 1px solid var(--divider);
    padding-top: 6px;
    margin-top: 2px;
    color: var(--text-primary);
    font-weight: 600;
}
.rbp-summary-val { font-weight: 600; color: var(--text-primary); }
.rbp-summary-val.positive { color: var(--positive); }
.rbp-summary-val.negative { color: var(--negative); }

.rbp-result-row {
    padding: 10px 0;
    border-bottom: 1px solid var(--divider);
}
.rbp-result-row:last-child { border-bottom: none; }

.rbp-result-top {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.rbp-result-ticker {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    flex: 1;
}

.rbp-result-action {
    font-size: 12px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 8px;
}
.rbp-buy  { background: var(--positive-soft); color: var(--positive); }
.rbp-sell { background: var(--negative-soft);  color: var(--negative); }
.rbp-hold { background: var(--bg-secondary);  color: var(--text-secondary); }

.rbp-result-amount {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    flex-shrink: 0;
}

.rbp-bars {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 6px;
}
.rbp-bar-row {
    display: flex;
    align-items: center;
    gap: 6px;
}
.rbp-bar-label {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    width: 30px;
    flex-shrink: 0;
    text-align: right;
}
.rbp-bar-track {
    flex: 1;
    height: 8px;
    background: var(--bg-secondary);
    border-radius: 4px;
    overflow: hidden;
}
.rbp-bar-fill.current {
    height: 100%;
    background: var(--accent);
    border-radius: 4px;
    transition: width .4s ease;
}
.rbp-bar-fill.target {
    height: 100%;
    background: rgba(255,255,255,.3);
    border-radius: 4px;
    transition: width .4s ease;
}
.rbp-bar-pct {
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    width: 38px;
    text-align: right;
    flex-shrink: 0;
}

.rbp-drift {
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 6px;
    display: inline-block;
}
.rbp-drift.overweight  { background: var(--negative-soft);  color: var(--negative); }
.rbp-drift.underweight { background: var(--positive-soft);  color: var(--positive); }
.rbp-drift.balanced    { background: var(--bg-secondary);  color: var(--text-secondary); }
