/**
 * Название файла: vce-finance-md3.css
 * Описание: Стили по спецификации Google Material Design 3 для интерфейса плагина.
 *           Описывает переменные цвета поверхностей (Surfaces), Material Buttons,
 *           Outlined Text Fields, Dialogs и адаптивных стейтов (states).
 *           Полностью оптимизирован под блочную тему Twenty Twenty-Five.
 */

/* ======================================================================
   1. ПЕРЕМЕННЫЕ ЦВЕТОВ MD3 (СВЕТЛАЯ ТЕМА ПО УМОЛЧАНИЮ)
   ====================================================================== */
.vce-finance-frontend, 
.md3-dialog-container {
    --md-sys-color-primary: #3b82f6;
    --md-sys-color-on-primary: #ffffff;
    --md-sys-color-primary-container: #dbeafe;
    --md-sys-color-on-primary-container: #1e3a8a;
    --md-sys-color-surface: #f8fafc;
    --md-sys-color-surface-container: #ffffff;
    --md-sys-color-surface-container-high: #f1f5f9;
    --md-sys-color-on-surface: #0f172a;
    --md-sys-color-on-surface-variant: #64748b;
    --md-sys-color-outline: #cbd5e1;
    --md-sys-color-scrim: rgba(15, 23, 42, 0.4);
}

/* Базовые стили шорткода */
.vce-finance-frontend {
    position: relative; /* Для абсолютного позиционирования кнопки смены темы */
    --vce-bg: var(--md-sys-color-surface);
    --vce-card-bg: var(--md-sys-color-surface-container);
    --vce-text: var(--md-sys-color-on-surface);
    --vce-muted: var(--md-sys-color-on-surface-variant);
    --vce-border: var(--md-sys-color-outline);
    --vce-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);

    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--vce-bg);
    color: var(--vce-text);
    border: 1px solid var(--vce-border);
    border-radius: 12px;
    padding: 24px;
    max-width: 650px;
    margin: 20px auto;
    box-shadow: var(--vce-shadow);
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* ======================================================================
   2. ГЛОБАЛЬНАЯ ТЕМНАЯ ТЕМА (ДЛЯ ВСЕГО САЙТА И ШОРТКОДА)
   ====================================================================== */
body.vce-dark-theme {
    /* Переопределяем системные цвета темы Twenty Twenty-Five */
    --wp--preset--color--base: #0f172a !important; 
    --wp--preset--color--contrast: #f8fafc !important;
    --wp--preset--color--accent-1: #60a5fa !important;
}

/* Переопределяем цвета MD3 для плагина и модальных окон при темной теме */
body.vce-dark-theme .vce-finance-frontend,
body.vce-dark-theme .md3-dialog-container {
    --md-sys-color-primary: #60a5fa;
    --md-sys-color-on-primary: #0f172a;
    --md-sys-color-primary-container: #1e3a8a;
    --md-sys-color-on-primary-container: #dbeafe;
    --md-sys-color-surface: #0f172a;
    --md-sys-color-surface-container: #1e293b;
    --md-sys-color-surface-container-high: #334155;
    --md-sys-color-on-surface: #f8fafc;
    --md-sys-color-on-surface-variant: #94a3b8;
    --md-sys-color-outline: #475569;
    --md-sys-color-scrim: rgba(0, 0, 0, 0.6);
}

/* Корректировка теней шорткода в темном режиме */
body.vce-dark-theme .vce-finance-frontend {
    --vce-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.5);
}

/* --- КНОПКА СМЕНЫ ТЕМЫ (ИЗОЛИРОВАННАЯ И КРАСИВАЯ) --- */
#vce-theme-switcher {
    position: absolute;
    top: 24px;
    right: 24px;
    z-index: 10;
}

/* Управление иконками темы на CSS (синхронизировано с body.vce-dark-theme) */
#vce-theme-switcher .vce-sun-icon {
    display: none;
}
#vce-theme-switcher .vce-moon-icon {
    display: block;
}
body.vce-dark-theme #vce-theme-switcher .vce-sun-icon {
    display: block !important;
}
body.vce-dark-theme #vce-theme-switcher .vce-moon-icon {
    display: none !important;
}

.vce-theme-btn {
    background: none;
    border: 1px solid var(--vce-border);
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 8px;
    color: var(--vce-text);
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    background-color: var(--vce-card-bg);
    transition: background-color 0.2s, border-color 0.2s;
}
.vce-theme-btn:hover {
    border-color: var(--md-sys-color-primary);
}

/* --- ВЫДЕЛЯЕМЫЙ СЧЕТ --- */
.vce-f-account-item.vce-selectable-account {
    cursor: pointer;
    border: 2px solid transparent !important;
    transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
}
.vce-f-account-item.vce-selectable-account:hover {
    background-color: var(--md-sys-color-surface-container-high);
}
.vce-f-account-item.vce-selected-active {
    border-color: var(--md-sys-color-primary) !important;
    background-color: var(--md-sys-color-primary-container) !important;
}
.vce-f-account-item.vce-selected-active .vce-acc-name {
    color: var(--md-sys-color-on-primary-container);
}

/* --- СВОРАЧИВАНИЕ ГРУПП И СТРЕЛКИ --- */
.vce-f-group {
    background: var(--vce-card-bg);
    border: 1px solid var(--vce-border);
    border-radius: 8px;
    margin-bottom: 14px;
    overflow: hidden;
    box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.05);
}

.vce-f-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    background-color: var(--vce-card-bg);
    cursor: pointer;
    user-select: none;
    border-bottom: 1px solid transparent;
    transition: background-color 0.2s;
}
.vce-f-group-header:hover {
    background-color: var(--vce-bg);
}

.vce-f-group.vce-active-group .vce-f-group-header {
    border-bottom-color: var(--vce-border);
}

.vce-f-group-title {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Сглаженная анимация поворота шеврона */
.vce-f-chevron {
    transition: transform 0.25s cubic-bezier(0.2, 0, 0, 1);
    fill: var(--vce-muted);
}
.vce-f-group:not(.vce-active-group) .vce-f-chevron {
    transform: rotate(-90deg);
}

.vce-f-accounts-list {
    padding: 0;
    margin: 0;
    list-style: none;
    min-height: 10px;
}

.vce-f-account-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid var(--vce-border);
    transition: background-color 0.15s;
    background: var(--vce-card-bg);
}
.vce-f-account-item:last-child {
    border-bottom: none;
}
.vce-f-account-item.ui-sortable-helper {
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    border-radius: 6px;
    opacity: 0.95;
}

.vce-f-acc-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.vce-drag-handle {
    cursor: grab;
    display: flex;
    align-items: center;
    color: var(--vce-border);
}
.vce-drag-handle:active {
    cursor: grabbing;
}
.vce-drag-handle svg {
    fill: currentColor;
}

.vce-acc-details {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.vce-acc-name {
    font-size: 14px;
    font-weight: 600;
}

.vce-acc-badge {
    font-size: 12px;
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 500;
    align-self: flex-start;
    text-transform: uppercase;
}

.vce-acc-right {
    text-align: right;
}

.vce-acc-balance {
    font-size: 15px;
    font-weight: 700;
}

.vce-sortable-placeholder {
    background: var(--vce-bg) !important;
    border: 2px dashed var(--vce-border) !important;
    height: 58px;
    visibility: visible !important;
}

/* --- MATERIAL DESIGN 3 КНОПКИ --- */
.md3-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    height: 40px;
    padding: 0 24px;
    border-radius: 20px;
    border: none;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.2, 0, 0, 1);
}

.md3-btn--filled {
    background-color: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
}
.md3-btn--filled:hover {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    filter: brightness(1.08);
}

.md3-btn--text {
    background: none;
    color: var(--md-sys-color-primary);
}
.md3-btn--text:hover {
    background-color: var(--md-sys-color-surface-container-high);
}

/* --- SEGMENTED BUTTON (MD3) --- */
.md3-segmented-button {
    display: flex;
    width: 100%;
    border: 1px solid var(--md-sys-color-outline);
    border-radius: 20px;
    overflow: hidden;
}

.md3-segment {
    flex: 1;
    background: none;
    border: none;
    border-right: 1px solid var(--md-sys-color-outline);
    padding: 12px 0;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
}
.md3-segment:last-child {
    border-right: none;
}
.md3-segment:hover {
    background-color: var(--md-sys-color-surface-container-high);
}
.md3-segment--active {
    background-color: var(--md-sys-color-primary-container) !important;
    color: var(--md-sys-color-on-primary-container) !important;
    font-weight: 600;
}

/* --- СТРУКТУРИРОВАННАЯ СЕТКА ФОРМЫ (MD3) --- */
.vce-tx-form-grid {
    display: flex;
    flex-direction: column;
    gap: 16px; /* Равномерный вертикальный отступ */
}

/* --- OUTLINED TEXT FIELDS (MD3) --- */
.md3-text-field {
    position: relative;
    width: 100%;
}

.md3-text-field__input {
    width: 100%;
    height: 56px;
    padding: 20px 16px 4px 16px;
    border-radius: 8px;
    border: 1px solid var(--md-sys-color-outline);
    background-color: var(--md-sys-color-surface-container);
    color: var(--md-sys-color-on-surface);
    font-family: inherit;
    font-size: 15px;
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.md3-text-field__input:focus {
    border-color: var(--md-sys-color-primary);
    border-width: 2px;
}

.md3-text-field__label {
    position: absolute;
    left: 16px;
    top: 6px;
    font-size: 11px;
    font-weight: 600;
    color: var(--md-sys-color-primary);
    transition: all 0.2s;
    pointer-events: none;
}

/* --- DIALOGS (MD3) --- */
.md3-dialog-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
}

.md3-dialog-scrim {
    position: absolute;
    width: 100%;
    height: 100%;
    background-color: var(--md-sys-color-scrim);
    backdrop-filter: blur(2px);
}

.md3-dialog {
    position: relative;
    background-color: var(--md-sys-color-surface-container);
    border-radius: 28px;
    width: 90%;
    max-width: 480px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    max-height: 85vh;
    animation: md3-zoom 0.25s cubic-bezier(0.2, 0, 0, 1);
}

.md3-dialog__header {
    padding: 24px 24px 16px 24px;
}
.md3-dialog__title {
    margin: 0;
    font-size: 24px;
    font-weight: 400;
    color: var(--md-sys-color-on-surface);
}

.md3-dialog__content {
    padding: 0 24px 24px 24px;
    overflow-y: auto;
}

.md3-dialog__actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 24px 24px 24px;
    border-top: 1px solid var(--vce-border);
}

.vce-acc-status-box {
    background-color: var(--md-sys-color-surface-container-high);
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 13px;
    color: var(--md-sys-color-on-surface-variant);
}

@keyframes md3-zoom {
    from {
        transform: scale(0.95);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* --- СТИЛИ ДЛЯ СПИСКА ТРАНЗАКЦИЙ --- */
.vce-tx-month-block {
    margin-bottom: 24px;
    border: 1px solid var(--vce-border);
    border-radius: 12px;
    overflow: hidden;
    background: var(--vce-card-bg);
    box-shadow: var(--vce-shadow);
}

.vce-tx-month-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    background-color: var(--md-sys-color-surface-container-high);
    border-bottom: 1px solid var(--vce-border);
}

.vce-tx-month-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--vce-text);
}

.vce-tx-month-sum {
    font-size: 15px;
    font-weight: 700;
}

.vce-net-positive {
    color: #2e7d32;
}

.vce-net-negative {
    color: #d32f2f;
}

.vce-net-neutral {
    color: var(--vce-muted);
}

.vce-tx-month-body {
    background: var(--vce-card-bg);
}

.vce-tx-day-block {
    border-bottom: 1px solid var(--vce-border);
}
.vce-tx-day-block:last-child {
    border-bottom: none;
}

.vce-tx-day-header {
    padding: 10px 18px;
    font-size: 13px;
    font-weight: 600;
    color: var(--vce-muted);
    background: var(--vce-bg);
    border-bottom: 1px solid var(--vce-border);
}

.vce-tx-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.vce-tx-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid var(--vce-border);
}
.vce-tx-item:last-child {
    border-bottom: none;
}

.vce-tx-left {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.vce-tx-category {
    font-size: 14px;
    font-weight: 500;
    color: var(--vce-text);
}

.vce-tx-meta {
    font-size: 12px;
    color: var(--vce-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}

.vce-tx-time {
    font-size: 12px;
}

.vce-tx-account-badge {
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.vce-tx-right {
    text-align: right;
    display: flex;
    align-items: baseline;
    gap: 3px;
}

.vce-tx-amount {
    font-size: 14px;
    font-weight: 700;
}

.vce-tx-positive {
    color: #2e7d32;
}

.vce-tx-negative {
    color: #d32f2f;
}

.vce-tx-transfer-neutral {
    color: var(--vce-muted);
}

.vce-tx-currency-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--vce-muted);
}

/* --- ВАЛИДАЦИЯ ПЕРЕВОДОВ (ОШИБКИ) --- */
.vce-field-invalid .md3-text-field__input {
    border-color: #d32f2f !important;
    border-width: 2px !important;
    color: #d32f2f !important;
}

.vce-field-invalid .md3-text-field__label {
    color: #d32f2f !important;
}

/* --- СТИЛИ ДЛЯ ОГРАНИЧЕНИЯ ДОСТУПА --- */
.vce-no-access-container {
    text-align: center;
    padding: 60px 30px !important;
    background-color: var(--vce-card-bg);
    border-radius: 16px !important;
    border: 1px solid var(--vce-border);
    box-shadow: var(--vce-shadow);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 250px;
}

.vce-no-access-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    max-width: 400px;
    margin: 0 auto;
}

.vce-no-access-icon {
    color: var(--md-sys-color-primary);
    background: var(--md-sys-color-primary-container);
    padding: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    transition: transform 0.3s ease;
}
.vce-no-access-icon:hover {
    transform: scale(1.05);
}

.vce-no-access-title {
    font-size: 20px;
    font-weight: 700;
    margin: 0;
    color: var(--vce-text);
}

.vce-no-access-desc {
    font-size: 14px;
    color: var(--vce-muted);
    margin: 0;
    line-height: 1.5;
}

/* --- WIDGET INCOME & EXPENSES CHART STYLES --- */
#vce-ie-widget {
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

#vce-ie-chart-container {
    cursor: crosshair;
    user-select: none;
    -webkit-user-select: none;
}

/* Tooltip card styled with Material Design 3 surface tokens and glassmorphism */
.vce-chart-tooltip-card {
    background: var(--vce-card-bg) !important;
    border: 1px solid var(--vce-border) !important;
    border-radius: 8px;
    padding: 10px 14px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
    color: var(--vce-text) !important;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    pointer-events: none;
    font-family: inherit;
    min-width: 160px;
    box-sizing: border-box;
}

.vce-tooltip-date {
    font-size: 11px;
    text-transform: uppercase;
    font-weight: 700;
    color: var(--vce-muted) !important;
    border-bottom: 1px solid var(--vce-border);
    padding-bottom: 6px;
    margin-bottom: 6px;
    letter-spacing: 0.5px;
}

.vce-tooltip-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    margin-top: 4px;
}

.vce-tooltip-row strong {
    font-weight: 700;
}

/* SVG Chart Elements Styling */
#vce-ie-chart-container svg {
    display: block;
    width: 100%;
    height: 100%;
}

#vce-ie-chart-container svg text {
    fill: var(--vce-muted);
    font-family: inherit;
    font-weight: 500;
}

#vce-ie-chart-container svg line {
    transition: stroke 0.3s ease;
}

#vce-ie-chart-container svg path {
    transition: stroke-width 0.15s ease;
}

/* Loading spinner animation */
.vce-chart-loading .spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--vce-border);
    border-top-color: var(--md-sys-color-primary);
    border-radius: 50%;
    animation: vce-spin 0.8s linear infinite;
}

@keyframes vce-spin {
    to { transform: rotate(360deg); }
}

/* --- NET WORTH WIDGET & SETTINGS DRAW ER --- */
.vce-frontend-widget {
    margin-bottom: 24px;
}
.vce-frontend-widget:last-child {
    margin-bottom: 0;
}

#vce-nw-widget {
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.vce-widget-settings-btn {
    transition: transform 0.3s ease, color 0.2s ease;
}
.vce-widget-settings-btn:hover {
    transform: rotate(45deg);
    color: var(--md-sys-color-primary) !important;
}

.vce-widget-settings-drawer {
    border-color: var(--vce-border) !important;
    background-color: var(--md-sys-color-surface-container-high) !important;
    transition: all 0.3s cubic-bezier(0.2, 0, 0, 1);
}

#vce-nw-chart-container {
    cursor: crosshair;
    user-select: none;
    -webkit-user-select: none;
}

#vce-nw-chart-container svg {
    display: block;
    width: 100%;
    height: 100%;
}

#vce-nw-chart-container svg text {
    fill: var(--vce-muted);
    font-family: inherit;
    font-weight: 500;
}

/* Input elements inside the widget settings drawer */
#vce-nw-widget-start-date {
    border: 1px solid var(--vce-border) !important;
    background-color: var(--vce-card-bg) !important;
    color: var(--vce-text) !important;
    outline: none;
    transition: border-color 0.2s ease;
}
#vce-nw-widget-start-date:focus {
    border-color: var(--md-sys-color-primary) !important;
}

/* --- CRYPTOCURRENCY ACCOUNT STYLES --- */
#vce-crypto-chart-container {
    cursor: crosshair;
    user-select: none;
    -webkit-user-select: none;
}

#vce-crypto-chart-container svg {
    display: block;
    width: 100%;
    height: 100%;
}

#vce-crypto-chart-container svg text {
    fill: var(--vce-muted);
    font-family: inherit;
    font-weight: 500;
}

/* Portfolio Table */
.vce-crypto-portfolio-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

.vce-crypto-portfolio-table th {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--vce-muted);
    border-bottom: 1px solid var(--vce-border);
    padding: 8px 4px;
}

.vce-crypto-portfolio-table td {
    padding: 12px 4px;
    color: var(--vce-text);
    border-bottom: 1px solid var(--vce-border);
}

.vce-crypto-portfolio-table tr:last-child td {
    border-bottom: none;
}

/* Neutral transaction color for swap operations */
.vce-tx-transfer-neutral {
    color: var(--vce-muted) !important;
}

/* Responsive grid for crypto summary cards */
.vce-crypto-summary-card {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.vce-crypto-summary-card > div {
    padding: 16px;
    background: var(--vce-card-bg);
    border: 1px solid var(--vce-border);
    border-radius: 12px;
    box-shadow: var(--vce-shadow);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* Style for the primary total balance summary card */
.vce-crypto-summary-card > div:last-child {
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    border-color: transparent;
}

/* Ensure nice datepicker styling for crypto charts */
#vce-crypto-chart-start-date {
    border: 1px solid var(--vce-border) !important;
    background-color: var(--vce-card-bg) !important;
    color: var(--vce-text) !important;
    outline: none;
    transition: border-color 0.2s ease;
}

#vce-crypto-chart-start-date:focus {
    border-color: var(--md-sys-color-primary) !important;
}

#vce-crypto-last-updated {
    font-size: 11px;
    font-weight: 500;
    color: var(--vce-muted);
    align-self: center;
}