/* BackStage BI Analytics — fintech-grade dashboards */

.bi-page { font-family: 'Inter', system-ui, sans-serif; }

.bi-toolbar {
    display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
    padding: 16px 20px; background: #fff; border: 1px solid #e8ecf1;
    border-radius: 14px; margin-bottom: 20px; box-shadow: 0 1px 3px rgba(26,35,50,0.04);
}

.bi-toolbar .bi-field label {
    display: block; font-size: 0.68rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.06em; color: #64748b; margin-bottom: 4px;
}

.bi-toolbar input, .bi-toolbar select {
    padding: 8px 12px; border: 1px solid #e2e8f0; border-radius: 8px;
    font-size: 0.875rem; min-width: 130px; background: #fafbfc;
}

.bi-btn {
    padding: 8px 18px; border-radius: 8px; font-size: 0.875rem; font-weight: 600;
    cursor: pointer; border: none; transition: 0.2s;
}

.bi-btn--primary { background: linear-gradient(135deg, #2563eb, #1d4ed8); color: #fff; }
.bi-btn--ghost { background: transparent; color: #64748b; border: 1px solid #e2e8f0; }
.bi-btn--primary:disabled { opacity: 0.65; cursor: wait; }
.bi-toolbar--loading { opacity: 0.72; pointer-events: none; }

.bi-kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
    align-items: stretch;
}

.bi-kpi {
    background: #fff;
    border: 1px solid #e8ecf1;
    border-radius: 14px;
    padding: 16px 18px;
    position: relative;
    overflow: hidden;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.bi-kpi-label {
    font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.05em; color: #64748b; margin-bottom: 8px;
    line-height: 1.3;
}

.bi-kpi-value {
    font-size: clamp(1.05rem, 1.15vw + 0.55rem, 1.45rem);
    font-weight: 700;
    color: #1a2332;
    font-variant-numeric: tabular-nums;
    line-height: 1.15;
    white-space: nowrap;
    display: inline-flex;
    align-items: baseline;
    gap: 0.28em;
    max-width: 100%;
}

.bi-kpi-amount {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bi-kpi-currency {
    flex-shrink: 0;
    font-size: 0.82em;
    font-weight: 650;
    opacity: 0.92;
}

.bi-kpi-value--money { color: #0d9488; }

.bi-kpi-value--warn { color: #ea580c; }
.bi-kpi-value--info { color: #1d4ed8; }
.bi-kpi-value--danger { color: #dc2626; }
.bi-kpi-value--success { color: #059669; }
.bi-kpi-value--purple { color: #7c3aed; }
.bi-kpi-value--amber { color: #d97706; }

.bi-kpi--danger { border-color: #fecaca; }
.bi-kpi--success { border-color: #bbf7d0; }
.bi-kpi--purple { border-color: #e9d5ff; }
.bi-kpi--amber { border-color: #fde68a; }
.bi-kpi--critical { border-color: #fecaca; }

.bi-kpi-hint {
    margin-top: 6px;
    font-size: 0.72rem;
    line-height: 1.35;
    color: #64748b;
    font-weight: 500;
}

.bi-kpi-meta { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 0.78rem; }

.bi-delta {
    display: inline-flex; padding: 2px 8px; border-radius: 6px; font-weight: 600; font-size: 0.75rem;
}

.bi-delta--up { background: #ecfdf5; color: #059669; }
.bi-delta--down { background: #fef2f2; color: #dc2626; }
.bi-delta--flat { background: #f1f5f9; color: #64748b; }

.bi-charts {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

.bi-chart-card {
    background: #fff;
    border: 1px solid #e8ecf1;
    border-radius: 14px;
    padding: 20px;
    grid-column: span 6;
}

.bi-chart-card--wide { grid-column: span 8; }
.bi-chart-card--narrow { grid-column: span 4; }
.bi-chart-card--full { grid-column: span 12; }

@media (max-width: 1200px) {
    .bi-chart-card, .bi-chart-card--wide, .bi-chart-card--narrow { grid-column: span 12; }
}

.bi-chart-head { margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid #f1f5f9; }
.bi-chart-title { font-size: 0.9rem; font-weight: 700; color: #1a2332; }
.bi-chart-sub { font-size: 0.75rem; color: #94a3b8; margin-top: 2px; }

.bi-table-wrap { background: #fff; border: 1px solid #e8ecf1; border-radius: 14px; overflow: hidden; margin-bottom: 20px; }
.bi-table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
.bi-table th {
    padding: 10px 14px; text-align: right; font-size: 0.68rem; font-weight: 600;
    text-transform: uppercase; color: #64748b; background: #f8fafc;
}
.bi-table th:first-child { text-align: left; }
.bi-table td { padding: 11px 14px; text-align: right; border-bottom: 1px solid #f8fafc; font-variant-numeric: tabular-nums; }
.bi-table td:first-child { text-align: left; font-weight: 600; }
.bi-table .bi-total td { background: #f0fdf9; font-weight: 700; }

.org-tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 2px solid #e8ecf1; }
.org-tab {
    padding: 10px 16px; border: none; background: none; cursor: pointer;
    font-size: 0.85rem; font-weight: 600; color: #64748b; border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.org-tab.active { color: #2563eb; border-bottom-color: #2563eb; }

.org-kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.org-col { min-width: 200px; flex: 1; background: #f8fafc; border-radius: 12px; border: 1px solid #e8ecf1; max-height: 420px; display: flex; flex-direction: column; }
.org-col-head { padding: 10px 12px; font-size: 0.78rem; font-weight: 700; text-transform: uppercase; border-bottom: 1px solid #e8ecf1; background: #fff; }
.org-col-cards { padding: 8px; overflow-y: auto; flex: 1; }
.org-card { background: #fff; border: 1px solid #e8ecf1; border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; cursor: grab; font-size: 0.82rem; transition: box-shadow 0.15s, border-color 0.15s; }
.org-card--interactive:hover { border-color: #2563eb; box-shadow: 0 4px 12px rgba(37,99,235,0.12); cursor: pointer; }
.org-card.dragging { opacity: 0.5; }
.org-col.drag-over { border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,0.15); }

.kpi-chip { display: inline-flex; align-items: center; gap: 2px; padding: 3px 8px; border-radius: 20px; font-size: 0.72rem; font-weight: 600; background: #f1f5f9; color: #475569; border: 1px solid #e2e8f0; }
.kpi-chip--money { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.kpi-chip--tempo { background: #fffbeb; color: #b45309; border-color: #fde68a; }
.card-kpi-chips { margin-top: 4px; }

.mail-compose { background: #f8fafc; border: 1px solid #e8ecf1; border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.mail-thread { max-height: 280px; overflow-y: auto; }
.mail-item { padding: 12px; border-radius: 10px; margin-bottom: 8px; font-size: 0.84rem; border: 1px solid #e8ecf1; }
.mail-item--out { background: #eff6ff; }
.mail-item--in { background: #f0fdf4; }

.bi-kpi--link:hover { border-color: #2563eb; box-shadow: 0 4px 12px rgba(37,99,235,0.08); }

@media (max-width: 768px) {
    .bi-kpi-row { grid-template-columns: repeat(2, 1fr) !important; }
    .bi-charts { grid-template-columns: 1fr !important; }
    .bi-toolbar { flex-direction: column; align-items: stretch; }
    .bi-toolbar .bi-field input, .bi-toolbar .bi-field select { width: 100%; min-width: 0; }
    .org-kanban { flex-direction: column; }
    .org-col { max-height: none; min-width: 100%; }
}

@media print {
    .no-print, .fi-sidebar, .fi-topbar, .bi-toolbar { display: none !important; }
    .bi-page { padding: 0; }
    .bi-chart-card { break-inside: avoid; page-break-inside: avoid; }
}

.bi-view-tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.bi-view-tab {
    padding: 8px 16px; border-radius: 8px; border: 1px solid #cbd5e1; background: #fff;
    font-size: 0.85rem; font-weight: 600; color: #334155; cursor: pointer;
}
.bi-view-tab:hover { border-color: #93c5fd; color: #1d4ed8; background: #f8fafc; }
.bi-view-tab.active { background: #dbeafe; border-color: #60a5fa; color: #1e40af; font-weight: 700; }

.bi-perf-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.bi-perf-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 24px; }

.bi-perf-card {
    background: #fff; border: 1px solid #e8ecf1; border-radius: 14px; padding: 16px 18px;
    box-shadow: 0 1px 3px rgba(26,35,50,0.04);
}

.bi-perf-card__head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.bi-perf-card__title { font-size: 1rem; font-weight: 700; color: #1a2332; margin: 0; line-height: 1.3; }
.bi-perf-card__badge { font-size: 0.72rem; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: #f1f5f9; color: #475569; white-space: nowrap; }

.bi-perf-card__kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
.bi-perf-card__kpi-label { display: block; font-size: 0.65rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: #94a3b8; margin-bottom: 2px; }
.bi-perf-card__kpi-value { display: block; font-size: 0.95rem; font-weight: 700; color: #1e293b; }
.bi-perf-card__kpi-value--money { color: #0d9488; }

.bi-perf-card__audience { padding: 10px 12px; background: #faf5ff; border-radius: 10px; margin-bottom: 10px; border: 1px solid #e9d5ff; }
.bi-perf-card__audience-row { display: flex; gap: 12px; font-size: 0.82rem; font-weight: 600; margin-top: 4px; }

.bi-perf-card__expenses { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 10px 12px; background: #fff7ed; border-radius: 10px; margin-bottom: 10px; border: 1px solid #fed7aa; }

.bi-perf-card__contracts summary, .bi-perf-card__months summary { cursor: pointer; font-size: 0.82rem; font-weight: 600; color: #2563eb; margin-bottom: 8px; }
.bi-perf-card__contracts ul { margin: 0; padding-left: 0; list-style: none; font-size: 0.8rem; }
.bi-perf-card__contracts li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid #f1f5f9; }

.bi-perf-card__dynamics { margin-top: 10px; }
.bi-perf-card__bars { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.bi-perf-card__bar-row { display: grid; grid-template-columns: 72px 1fr 28px; gap: 8px; align-items: center; font-size: 0.75rem; }
.bi-perf-card__bar-track { height: 8px; background: #f1f5f9; border-radius: 4px; overflow: hidden; }
.bi-perf-card__bar-fill { height: 100%; background: linear-gradient(90deg, #2563eb, #60a5fa); border-radius: 4px; }
.bi-perf-card__bar-val { text-align: right; font-weight: 600; color: #475569; }

.bi-table--compact { font-size: 0.78rem; }
.bi-table--compact th, .bi-table--compact td { padding: 6px 10px; }

.bi-table--filterable .bi-table-filters th {
    background: #f8fafc;
    padding: 6px 8px;
    vertical-align: middle;
}

.bi-table--filterable .bi-table-filters input {
    width: 100%;
    min-width: 72px;
    padding: 5px 8px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 400;
    background: #fff;
    color: #0f172a;
}

.bi-table--filterable .bi-table-filters input::placeholder {
    color: #cbd5e1;
    font-weight: 400;
}

.bi-table--filterable .bi-table-filters input:focus {
    outline: none;
    border-color: #93c5fd;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.bi-pager {
    display: flex;
    align-items: center;
    gap: 8px;
}

.bi-pager--footer {
    justify-content: center;
    padding: 12px 14px;
    border-top: 1px solid #f1f5f9;
    background: #fafbfc;
}

.bi-pager.is-loading { opacity: 0.6; pointer-events: none; }

.bi-proc-top {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(260px, 320px);
    gap: 14px;
    align-items: stretch;
    margin-bottom: 20px;
}

.bi-type-widget {
    background: #fff;
    border: 1px solid #e8ecf1;
    border-radius: 14px;
    padding: 12px 14px;
    box-shadow: 0 1px 3px rgba(26, 35, 50, 0.04);
    max-height: 168px;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.bi-type-widget__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid #f1f5f9;
    flex-shrink: 0;
}

.bi-type-widget__title {
    font-size: 0.78rem;
    font-weight: 700;
    color: #1a2332;
}

.bi-type-widget__sub {
    font-size: 0.68rem;
    color: #94a3b8;
}

.bi-type-widget__list {
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 0;
}

.bi-type-widget__row {
    display: grid;
    grid-template-columns: 8px minmax(0, 1fr) auto auto auto;
    gap: 6px;
    align-items: center;
    font-size: 0.72rem;
    line-height: 1.2;
}

.bi-type-widget__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.bi-type-widget__name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #334155;
    font-weight: 600;
}

.bi-type-widget__count {
    color: #94a3b8;
    font-variant-numeric: tabular-nums;
}

.bi-type-widget__amount {
    color: #0f172a;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.bi-type-widget__share {
    color: #64748b;
    font-variant-numeric: tabular-nums;
    min-width: 36px;
    text-align: right;
}

.bi-type-widget__empty {
    font-size: 0.75rem;
    color: #94a3b8;
    text-align: center;
    padding: 12px 0;
}

@media (max-width: 960px) {
    .bi-proc-top { grid-template-columns: 1fr; }
    .bi-type-widget { max-height: none; }
}

.bi-limit-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.bi-limit-table th, .bi-limit-table td { padding: 10px 12px; border-bottom: 1px solid #f1f5f9; text-align: left; }
.bi-limit-table input { width: 100%; padding: 8px 10px; border: 1px solid #e2e8f0; border-radius: 8px; }

.bi-table--years { font-size: 0.8rem; white-space: nowrap; }
.bi-table--years th,
.bi-table--years td { padding: 9px 10px; }
.bi-table--years .bi-delta { font-size: 0.7rem; }
