/**
 * Дашборд финмодели: общие токены — var(--sp-*) из ui-theme-v1;
 * режим PVZ-neon включается в body[data-theme="dark"].
 */

.fm-dashboard {
    --fm-radius: 1.25rem;
    --fm-gap: 1.25rem;
    --fm-transition: 0.2s ease;
    --fm-card-bg: var(--sp-surface);
    --fm-card-border: var(--sp-border);
    --fm-card-hover-shadow: var(--sp-shadow-md);
    --fm-header-bg: var(--sp-surface);
    --fm-header-border: var(--sp-border);
    --fm-title-muted: var(--sp-text-muted);
    --fm-filter-bg: var(--sp-surface-muted);
    --fm-filter-border: var(--sp-border);
    --fm-filter-active-bg: var(--sp-role-accent-soft);
    --fm-filter-active-border: var(--sp-role-accent);
    --fm-filter-text: var(--sp-text);
    --fm-chart-title: var(--sp-text-muted);
    --fm-table-header: var(--sp-text-muted);
    --fm-grid-line: var(--sp-border);
    --fm-row-hover: var(--sp-role-accent-soft);
    font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: var(--fm-gap);
}

body[data-theme="dark"] .fm-dashboard {
    --fm-page-tint: radial-gradient(ellipse 120% 80% at 10% -20%, rgba(0, 240, 255, 0.07), transparent 50%),
        radial-gradient(ellipse 100% 60% at 100% 0%, rgba(123, 97, 255, 0.09), transparent 45%);
    --fm-header-bg: rgba(255, 255, 255, 0.04);
    --fm-header-border: rgba(255, 255, 255, 0.08);
    --fm-card-bg: rgba(255, 255, 255, 0.04);
    --fm-card-border: rgba(255, 255, 255, 0.07);
    --fm-card-hover-shadow: 0 8px 28px rgba(34, 211, 238, 0.12);
    --fm-filter-bg: rgba(255, 255, 255, 0.06);
    --fm-filter-border: rgba(255, 255, 255, 0.12);
    --fm-filter-active-bg: rgba(34, 211, 238, 0.16);
    --fm-filter-active-border: #22d3ee;
    --fm-filter-text: #e2e8f0;
    --fm-chart-title: #94a3b8;
    --fm-table-header: #8899aa;
    --fm-grid-line: rgba(255, 255, 255, 0.07);
    --fm-row-hover: rgba(34, 211, 238, 0.08);
    --fm-kpi-gradient: linear-gradient(135deg, #ffffff, #22d3ee);
}

.fm-financial-shell {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    padding-inline: clamp(0.75rem, 3vw, 1.25rem);
    box-sizing: border-box;
}

@media (max-width: 768px) {
    .fm-financial-shell {
        padding-inline: clamp(0.65rem, 4vw, 1rem);
    }
}

body[data-theme="dark"] .fm-dashboard-wrap {
    background: var(--sp-bg);
    background-image: var(--fm-page-tint);
    border-radius: var(--fm-radius);
    padding: clamp(0.85rem, 2vw, 1.15rem) clamp(0.85rem, 2vw, 1.15rem) 1.25rem;
    margin: 0;
}

@media (max-width: 768px) {
    body[data-theme="dark"] .fm-dashboard-wrap {
        border-radius: 1rem;
        padding: 0.85rem clamp(0.65rem, 4vw, 1rem) 1rem;
    }
}

body[data-theme="light"] .fm-dashboard-wrap,
body:not([data-theme="dark"]) .fm-dashboard-wrap {
    margin: 0;
    padding: 0;
    background: transparent;
}

.fm-dash-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 1rem;
    background: var(--fm-header-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--fm-header-border);
    border-radius: var(--fm-radius);
    padding: 1rem 1.25rem;
    box-shadow: var(--sp-shadow-sm);
}

body[data-theme="dark"] .fm-dash-header {
    box-shadow: 0 12px 40px rgba(2, 6, 23, 0.35);
}

.fm-dash-header-main {
    flex: 1 1 240px;
    min-width: 0;
}

.fm-dash-brand {
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.25;
    color: var(--sp-text);
    margin: 0 0 0.35rem;
}

body[data-theme="dark"] .fm-dash-brand {
    background: linear-gradient(135deg, #22d3ee, #a78bfa);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.fm-dash-meta {
    font-size: 0.8rem;
    color: var(--fm-title-muted);
    margin: 0;
}

.fm-dash-header-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.75rem;
    flex: 1 1 280px;
}

.fm-dash-nav-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-end;
    width: 100%;
}

.fm-dash-nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0.45rem 1rem;
    border-radius: 999px;
    font-size: 0.875rem;
    font-weight: 500;
    border: 1px solid var(--sp-border);
    background: var(--sp-surface-muted);
    color: var(--sp-text);
    text-decoration: none;
    transition: background var(--fm-transition), border-color var(--fm-transition), color var(--fm-transition);
}

body[data-theme="dark"] .fm-dash-nav-btn {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.12);
    color: #e5e7eb;
}

.fm-dash-nav-btn:hover {
    border-color: var(--sp-role-accent);
    background: var(--sp-role-accent-soft);
    color: var(--sp-text);
}

body[data-theme="dark"] .fm-dash-nav-btn:hover {
    border-color: #22d3ee;
    background: rgba(34, 211, 238, 0.14);
    color: #fff;
}

.fm-dash-nav-btn-primary {
    border-color: transparent;
    background: linear-gradient(135deg, #22d3ee, #7b61ff);
    color: #041018;
    font-weight: 600;
}

.fm-dash-nav-btn-primary:hover {
    color: #041018;
    filter: brightness(1.05);
}

.fm-dash-back {
    font-size: 0.8rem;
    color: var(--sp-role-accent);
    text-decoration: none;
    margin-bottom: 0.25rem;
}

.fm-dash-back:hover {
    filter: brightness(1.08);
    text-decoration: underline;
}

.fm-dash-filters {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: flex-end;
    width: 100%;
}

.fm-dash-filter-btn {
    background: var(--fm-filter-bg);
    border: 1px solid var(--fm-filter-border);
    color: var(--fm-filter-text);
    padding: 0.5rem 1rem;
    border-radius: 999px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all var(--fm-transition);
    white-space: nowrap;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    opacity: 0.92;
}

.fm-dash-filter-btn.active,
.fm-dash-filter-btn:hover {
    background: var(--fm-filter-active-bg);
    border-color: var(--fm-filter-active-border);
    opacity: 1;
}

body[data-theme="dark"] .fm-dash-filter-btn.active,
body[data-theme="dark"] .fm-dash-filter-btn:hover {
    color: #fff;
}

/* KPI */
.fm-dash-kpi-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.95rem;
}

.fm-dash-kpi-card {
    background: var(--fm-card-bg);
    backdrop-filter: blur(6px);
    border: 1px solid var(--fm-card-border);
    border-radius: var(--fm-radius);
    padding: 1.15rem;
    transition: transform var(--fm-transition), box-shadow var(--fm-transition), border-color var(--fm-transition);
    min-width: 0;
}

.fm-dash-kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--fm-card-hover-shadow);
    border-color: var(--fm-filter-active-border);
}

.fm-dash-kpi-title {
    font-size: 0.8rem;
    color: var(--fm-title-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.45rem;
    line-height: 1.35;
}

.fm-dash-kpi-value {
    font-size: 1.85rem;
    font-weight: 700;
    line-height: 1.15;
    color: var(--sp-text);
    word-break: break-word;
}

body[data-theme="dark"] .fm-dash-kpi-value {
    background: var(--fm-kpi-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.fm-dash-kpi-change {
    font-size: 0.8rem;
    margin-top: 0.35rem;
    color: var(--sp-success-500);
}

.fm-dash-kpi-change.negative {
    color: var(--sp-danger-500);
}

/* Charts */
.fm-dash-charts-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: var(--fm-gap);
}

.fm-dash-chart-box {
    background: var(--fm-card-bg);
    backdrop-filter: blur(6px);
    border: 1px solid var(--fm-card-border);
    border-radius: var(--fm-radius);
    padding: 1.1rem 1rem;
    display: flex;
    flex-direction: column;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    height: 350px;
}

.fm-dash-chart-box canvas {
    flex: 1 1 auto;
    width: 100% !important;
    height: auto !important;
    min-height: 0;
}

.fm-dash-section-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--fm-chart-title);
}

.fm-dash-performers {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--fm-gap);
}

.fm-dash-list-card {
    background: var(--fm-card-bg);
    backdrop-filter: blur(6px);
    border: 1px solid var(--fm-card-border);
    border-radius: var(--fm-radius);
    padding: 1.1rem;
    width: 100%;
    box-sizing: border-box;
}

.fm-dash-point-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--fm-card-border);
    gap: 0.6rem;
}

.fm-dash-point-item:last-child {
    border-bottom: none;
}

.fm-dash-point-name {
    font-weight: 500;
    color: var(--sp-text);
    word-break: break-word;
}

.fm-dash-margin {
    font-weight: 700;
    white-space: nowrap;
}

.fm-dash-positive {
    color: var(--sp-success-500);
}

.fm-dash-negative {
    color: var(--sp-danger-500);
}

.fm-dash-table-wrap {
    background: var(--fm-card-bg);
    backdrop-filter: blur(6px);
    border: 1px solid var(--fm-card-border);
    border-radius: var(--fm-radius);
    padding: 1.1rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    box-sizing: border-box;
}

.fm-dash-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    min-width: 700px;
}

.fm-dash-table th {
    text-align: left;
    padding: 0.65rem 0.85rem;
    color: var(--fm-table-header);
    font-weight: 500;
    border-bottom: 1px solid var(--fm-grid-line);
}

.fm-dash-table td {
    padding: 0.65rem 0.85rem;
    border-bottom: 1px solid var(--fm-grid-line);
    color: var(--sp-text);
}

.fm-dash-table tbody tr:hover td {
    background: var(--fm-row-hover);
}

.fm-bindings-toolbar .form-label {
    color: var(--fm-table-header);
}

.fm-bindings-sort {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    font-weight: 500;
    color: var(--fm-table-header);
    cursor: pointer;
    text-align: left;
}

.fm-bindings-sort:hover {
    color: var(--sp-primary-500);
}

.fm-bindings-sort.is-active {
    color: var(--sp-primary-600);
}

.fm-bindings-sort.is-active::after {
    content: " \25B2";
    font-size: 0.65em;
}

.fm-bindings-sort.is-active.is-desc::after {
    content: " \25BC";
}

.fm-mp-table-cell {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    width: 100%;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.fm-mp-table-cell .fm-mp-badge {
    width: 36px;
    height: 36px;
    font-size: 1rem;
    font-weight: 700;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.fm-mp-table-icon {
    object-fit: contain;
    border-radius: 6px;
    vertical-align: middle;
}

.fm-dash-alert-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 0.45rem;
    vertical-align: middle;
}

.fm-dash-alert-dot.warn {
    background: var(--sp-warning-500);
}

.fm-dash-alert-dot.danger {
    background: var(--sp-danger-500);
}

/* CFO портфельный дэшборд */
.fm-dash-period-row {
    justify-content: flex-end;
    width: 100%;
}

.fm-pl-period-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.fm-pl-range {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.fm-pl-range input[type="month"] {
    width: 8.5rem;
}

.fm-cfo-kpi-strip {
    grid-template-columns: repeat(7, 1fr);
}

.fm-cfo-panels-row {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: var(--fm-gap);
}

.fm-dash-action-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
}

.fm-dash-action-card {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0.55rem 1rem;
    border-radius: 0.85rem;
    border: 1px solid var(--fm-card-border);
    background: var(--fm-filter-bg);
    color: var(--sp-text);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: border-color var(--fm-transition), background var(--fm-transition);
}

.fm-dash-action-card:hover {
    border-color: var(--fm-filter-active-border);
    background: var(--fm-filter-active-bg);
    color: var(--sp-text);
}

.fm-cfo-dashboard.is-loading .fm-skeleton-target {
    color: transparent !important;
    background: linear-gradient(90deg, var(--fm-filter-bg) 25%, var(--fm-card-border) 50%, var(--fm-filter-bg) 75%);
    background-size: 200% 100%;
    animation: fm-skeleton-shimmer 1.2s ease-in-out infinite;
    border-radius: 0.35rem;
    min-height: 1.5rem;
}

.fm-cfo-dashboard.is-loading .fm-skeleton-list {
    opacity: 0.45;
}

@keyframes fm-skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.fm-dash-kpi-change.negative {
    color: var(--sp-danger-500) !important;
}

@media (max-width: 1400px) {
    .fm-cfo-kpi-strip {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 992px) {
    .fm-cfo-panels-row {
        grid-template-columns: 1fr;
    }
}

/* Страницы владельца «Отчёты», «Смены» — KPI как на портфеле финмодели */
.owner-reports-kpi-shell.fm-dashboard,
.owner-shifts-kpi-shell.fm-dashboard {
    max-width: 100%;
    margin: 0;
    width: 100%;
}

.owner-reports-kpi-shell .fm-dash-kpi-grid,
.owner-shifts-kpi-shell .fm-dash-kpi-grid {
    grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 1199px) {
    .owner-reports-kpi-shell .fm-dash-kpi-grid,
    .owner-shifts-kpi-shell .fm-dash-kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 479px) {
    .owner-reports-kpi-shell .fm-dash-kpi-grid,
    .owner-shifts-kpi-shell .fm-dash-kpi-grid {
        grid-template-columns: 1fr;
    }
}

.owner-reports-kpi-shell .fm-dash-kpi-change.text-muted,
.owner-shifts-kpi-shell .fm-dash-kpi-change.text-muted {
    color: var(--fm-title-muted) !important;
}

.fm-dash-footer {
    display: flex;
    justify-content: space-between;
    color: var(--fm-title-muted);
    font-size: 0.75rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

@media (max-width: 1200px) {
    .fm-dash-kpi-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .fm-dashboard {
        gap: 0.9rem;
    }

    .fm-dash-header {
        padding: 0.85rem 1rem;
        flex-direction: column;
        align-items: stretch;
    }

    .fm-dash-header-actions {
        align-items: stretch;
    }

    .fm-dash-nav-row,
    .fm-dash-filters {
        justify-content: flex-start;
    }

    .fm-dash-kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.65rem;
    }

    .fm-dash-kpi-card {
        padding: 0.9rem;
    }

    .fm-dash-kpi-value {
        font-size: 1.5rem;
    }

    .fm-dash-charts-row {
        grid-template-columns: 1fr;
        gap: 0.9rem;
    }

    .fm-dash-performers {
        grid-template-columns: 1fr;
        gap: 0.9rem;
    }

    .fm-dash-chart-box {
        height: 280px;
    }

    .fm-dash-table th,
    .fm-dash-table td {
        padding: 0.5rem 0.55rem;
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .fm-dash-kpi-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .fm-dash-kpi-value {
        font-size: 1.65rem;
    }

    .fm-dash-filter-btn {
        padding: 0.42rem 0.85rem;
        font-size: 0.8rem;
        min-height: 40px;
    }

    .fm-dash-section-title {
        font-size: 0.88rem;
    }

    .fm-dash-chart-box {
        height: 220px;
        padding: 0.85rem;
    }

    .fm-dash-footer {
        font-size: 0.68rem;
    }

    .fm-dash-nav-btn {
        min-height: 40px;
        font-size: 0.8rem;
        flex: 1 1 calc(50% - 0.25rem);
        justify-content: center;
    }

    .fm-dash-nav-row {
        width: 100%;
    }
}

.fm-recalc-modal {
    border-radius: 1rem;
    background: var(--fm-card-bg, var(--sp-surface));
}

.fm-recalc-ring {
    position: relative;
    width: 4.5rem;
    height: 4.5rem;
    margin-left: auto;
    margin-right: auto;
}

.fm-recalc-ring::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 3px solid color-mix(in srgb, var(--sp-role-accent, #0ea5e9) 18%, transparent);
    border-top-color: var(--sp-role-accent, #0ea5e9);
    animation: fm-recalc-spin 0.9s linear infinite;
}

.fm-recalc-ring-inner {
    position: absolute;
    inset: 0.55rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: color-mix(in srgb, var(--sp-role-accent, #0ea5e9) 12%, var(--sp-surface));
    color: var(--sp-role-accent, #0ea5e9);
    font-size: 1.35rem;
}

.fm-recalc-progress {
    height: 0.45rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--sp-border, #dee2e6) 70%, transparent);
}

.fm-recalc-progress .progress-bar {
    border-radius: 999px;
}

@keyframes fm-recalc-spin {
    to {
        transform: rotate(360deg);
    }
}
