* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: #F5F6FA; color: #1F2937; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; }

.topbar {
    background: #111827;
    color: white;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    gap: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,.15);
    position: sticky;
    top: 0;
    z-index: 10;
}
.brand { font-weight: 700; font-size: 18px; }
.tabs { display: flex; gap: 4px; }
.tab {
    padding: 8px 16px;
    border-radius: 8px;
    color: #9CA3AF;
    text-decoration: none;
    font-weight: 500;
    transition: background .15s, color .15s;
}
.tab:hover { background: #1F2937; color: #F3F4F6; }
.tab.active { background: #3B82F6; color: white; }

main { max-width: 1400px; margin: 0 auto; padding: 24px; }

.filter-bar {
    background: #EEF2FF;
    border: 1px solid #C7D2FE;
    border-radius: 12px;
    padding: 12px 16px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.filter-bar-label {
    font-size: 13px;
    color: #4338CA;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
}
.filter-bar-items {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}
.filter-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: white;
    border: 1px solid #A5B4FC;
    border-radius: 999px;
    text-decoration: none;
    color: #1F2937;
    font-size: 13px;
    transition: background .15s, border-color .15s;
}
.filter-badge:hover { background: #FEE2E2; border-color: #FCA5A5; }
.filter-badge-q { color: #6B7280; }
.filter-badge-v { font-weight: 600; color: #1F2937; }
.filter-badge-x { color: #EF4444; font-weight: 700; margin-left: 2px; }
.filter-reset {
    font-size: 13px;
    color: #EF4444;
    text-decoration: none;
    font-weight: 600;
    padding: 6px 10px;
    border-radius: 999px;
    transition: background .15s;
}
.filter-reset:hover { background: #FEE2E2; }

.segment-label { color: #4338CA; font-size: 14px; font-weight: 400; }

.summary h1 { margin: 0 0 16px; font-size: 24px; }
.counters { display: flex; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; }
.counter {
    background: white;
    border-radius: 12px;
    padding: 16px 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    min-width: 140px;
}
.counter .num { font-size: 28px; font-weight: 700; line-height: 1; }
.counter .lbl { font-size: 12px; color: #6B7280; margin-top: 4px; text-transform: uppercase; letter-spacing: .5px; }
.counter.ok .num { color: #10B981; }
.counter.wip .num { color: #F59E0B; }
.counter.cancel .num { color: #EF4444; }
.counter.total .num { color: #3B82F6; }

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    display: flex;
    flex-direction: column;
}
.card-head {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.qnum {
    background: #EEF2FF;
    color: #4338CA;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.card h2 { font-size: 15px; margin: 0; flex: 1 1 100%; line-height: 1.4; font-weight: 500; }
.answered { font-size: 12px; color: #6B7280; }

.chart-wrap { position: relative; height: 220px; }

.chart-legend {
    list-style: none;
    padding: 12px 0 0 0;
    margin: 0;
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
}
.chart-legend li {
    font-size: 13px;
    color: #1F2937;
}
.option-link {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 6px 8px;
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    transition: background .15s, border-color .15s;
    border: 1px solid transparent;
    cursor: pointer;
}
.option-link:hover {
    background: #F3F4F6;
}
.option-link.option-active {
    background: #DBEAFE;
    border-color: #3B82F6;
}
.option-link.option-active .legend-label { font-weight: 600; color: #1E40AF; }
.option-link.option-active .legend-count { color: #1E40AF; }
.legend-dot {
    flex-shrink: 0;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    margin-top: 3px;
}
.legend-label {
    flex: 1;
    word-break: break-word;
    overflow-wrap: anywhere;
    line-height: 1.35;
    display: flex;
    justify-content: space-between;
    gap: 8px;
}
.legend-count {
    flex-shrink: 0;
    color: #6B7280;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}
.text-block { padding: 12px 0; }
.muted { color: #6B7280; font-size: 13px; margin: 0; }

.texts, .calls {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    margin-bottom: 24px;
}
.texts h2, .calls h2 { font-size: 16px; margin: 0 0 16px; }

.text-list { list-style: none; padding: 0; margin: 0; }
.text-list li {
    padding: 12px 0;
    border-bottom: 1px solid #F3F4F6;
    display: grid;
    grid-template-columns: auto auto 1fr;
    gap: 12px;
    align-items: start;
}
.text-list li:last-child { border-bottom: 0; }
.text-qnum { font-weight: 600; color: #4338CA; font-size: 12px; padding-top: 2px; }
.text-date { font-size: 12px; color: #9CA3AF; padding-top: 2px; }
.text-body { white-space: pre-wrap; word-break: break-word; }

.calls-scroll { width: 100%; overflow-x: auto; }
.calls-table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 520px; }
.calls-table th, .calls-table td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid #F3F4F6;
}
.calls-table th { font-weight: 600; color: #6B7280; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }

/* ——— Mobile adaptivity ——— */
@media (max-width: 768px) {
    main { padding: 12px; }
    .topbar {
        padding: 10px 14px;
        gap: 10px;
        flex-wrap: wrap;
    }
    .brand { font-size: 15px; }
    .tab { padding: 6px 10px; font-size: 13px; }

    .summary h1 { font-size: 18px; line-height: 1.3; margin-bottom: 12px; }
    .segment-label { display: block; font-size: 13px; margin-top: 4px; }

    .counters { gap: 8px; margin-bottom: 16px; }
    .counter {
        padding: 10px 12px;
        min-width: 0;
        flex: 1 1 calc(50% - 4px);
    }
    .counter .num { font-size: 22px; }
    .counter .lbl { font-size: 11px; }

    .filter-bar {
        padding: 10px 12px;
        gap: 8px;
        flex-direction: column;
        align-items: flex-start;
    }
    .filter-bar-label { font-size: 11px; }
    .filter-badge { font-size: 12px; padding: 4px 8px; }
    .filter-badge-q { display: none; }

    .grid {
        grid-template-columns: 1fr;
        gap: 12px;
        margin-bottom: 24px;
    }
    .card { padding: 16px; }
    .card h2 { font-size: 14px; }
    .answered { font-size: 11px; }
    .qnum { font-size: 11px; }

    .chart-wrap { height: 200px; }

    .option-link { padding: 8px 6px; }
    .chart-legend li { font-size: 13px; }

    .texts, .calls {
        padding: 14px;
        margin-bottom: 16px;
    }
    .texts h2, .calls h2 { font-size: 15px; margin-bottom: 12px; }

    .text-list li {
        grid-template-columns: 1fr;
        gap: 4px;
        padding: 10px 0;
    }
    .text-qnum, .text-date { padding-top: 0; font-size: 11px; }

    /* Calls — стекированные карточки вместо таблицы */
    .calls-scroll { overflow-x: visible; }
    .calls-table { min-width: 0; display: block; }
    .calls-table thead { display: none; }
    .calls-table tbody, .calls-table tr, .calls-table td { display: block; width: 100%; }
    .calls-table tr {
        padding: 10px 0;
        border-bottom: 1px solid #F3F4F6;
    }
    .calls-table tr:last-child { border-bottom: 0; }
    .calls-table td {
        padding: 2px 0;
        border-bottom: 0;
    }
    .calls-table td:first-child {
        font-weight: 600;
        font-size: 15px;
        color: #1F2937;
    }
    .calls-table td:not(:first-child) {
        font-size: 13px;
        color: #4B5563;
    }
    .calls-table td:not(:first-child)::before {
        content: attr(data-label) ": ";
        color: #9CA3AF;
        font-weight: 500;
        margin-right: 4px;
    }
}
