:root{
    --bg: #f6f7fb;
    --card:#ffffff;
    --text:#0f172a;
    --muted:#64748b;
    --line:#e5e7eb;
    --shadow: 0 10px 30px rgba(15,23,42,.08);
    --primary:#2563eb;
    --good:#16a34a;
    --bad:#dc2626;
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
    margin:0;
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Noto Sans", "Apple Color Emoji","Segoe UI Emoji";
    background: var(--bg);
    color: var(--text);
    overflow-x:hidden;
}

/* Topbar */
.topbar{
    position: sticky;
    top: 0;
    z-index: 3000;
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:12px;
    padding: 12px 16px;
    background: rgba(255,255,255,.92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
}

.brand{
    display:flex;
    align-items:center;
    gap:12px;
}
.brand__logo{
    width:34px;
    height:34px;
    border-radius:12px;
    background:#fff;
    border:1px solid var(--line);
    display:flex;
    align-items:center;
    justify-content:center;
}
.brand__title{
    font-weight: 900;
    letter-spacing: -.02em;
}
.brand__subtitle{
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
}

.pill{
    padding: 8px 12px;
    border:1px solid var(--line);
    border-radius: 999px;
    background:#fff;
    color: var(--muted);
    font-weight:700;
    font-size: 12px;
}

/* Layout */
.wrap{
    max-width: 1180px; /* desktop width baseline */
    margin: 0 auto;
    padding: 16px;
}

.card{
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 14px;
    max-width:100%;
}

.card__head{
    display:flex;
    align-items:flex-start;
    justify-content:space-between;
    gap:12px;
    margin-bottom: 10px;
}
.card__head--split{
    align-items:center;
}
.card__title{
    font-weight: 900;
    letter-spacing: -.02em;
}
.card__subtitle{
    margin-top: 2px;
    color: var(--muted);
    font-size: 12px;
}
.card__actions{
    display:flex;
    align-items:center;
    gap:10px;
    flex-wrap:wrap;
}

/* Buttons */
.btn{
    border:1px solid transparent;
    background:#fff;
    color: var(--text);
    padding: 10px 12px;
    border-radius: 12px;
    font-weight: 800;
    cursor:pointer;
    user-select:none;
}
.btn:active{ transform: translateY(1px); }

.btn--primary{
    background: var(--primary);
    border-color: var(--primary);
    color:#fff;
}
.btn--ghost{
    border-color: var(--line);
    background:#fff;
}
.btn--ghost:hover{ background:#f8fafc; }

/* Controls */
.controls{ margin-bottom: 14px; }
.controls__row{
    display:grid;
    grid-template-columns: 220px 180px 180px 1fr 160px;
    gap: 12px;
    align-items:end;
}

.field{ min-width:0; }
.field__label{
    display:block;
    font-size: 12px;
    color: var(--muted);
    margin: 0 0 6px 2px;
    font-weight: 700;
}
.field__control{
    width:100%;
    appearance:none;
    -webkit-appearance:none;
    border: 1px solid var(--line);
    background:#fff;
    border-radius: 12px;
    padding: 12px 12px;
    font-weight: 800;
    color: var(--text);
    box-shadow: 0 1px 0 rgba(15,23,42,.04);
}
.field__control:focus{
    outline:none;
    border-color: rgba(37,99,235,.55);
    box-shadow: 0 0 0 4px rgba(37,99,235,.12);
}

select.field__control{
    background-image:
            linear-gradient(45deg, transparent 50%, #94a3b8 50%),
            linear-gradient(135deg, #94a3b8 50%, transparent 50%);
    background-position:
            calc(100% - 18px) calc(50% - 3px),
            calc(100% - 12px) calc(50% - 3px);
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
    padding-right: 34px;
}

.field--actions .btn{ width:100%; }

.quick{
    display:flex;
    gap: 10px;
    flex-wrap: wrap;
}
.quick .btn.btn--ghost{
    padding: 9px 12px;
    border-radius: 14px;
    border:1px solid var(--line);
    background:#fff;
    font-weight: 900;
}
.hint{
    margin-top: 6px;
    font-size: 12px;
    color: var(--muted);
}

/* KPI */
.kpi{
    display:grid;
    grid-template-columns: repeat(4, minmax(0,1fr));
    gap: 12px;
    margin-bottom: 14px;
}

.kpiTile{
    background:#fff;
    border:1px solid var(--line);
    border-radius: 18px;
    padding: 14px;
    box-shadow: 0 6px 20px rgba(15,23,42,.06);
}
.kpiTile__top{
    display:flex;
    align-items:flex-start;
    justify-content:space-between;
    gap: 10px;
    margin-bottom: 10px;
}
.kpiTile__labelRow{
    display:flex;
    align-items:center;
    gap: 8px;
    min-width:0;
}
.kpiTile__label{
    font-size: 12px;
    color: var(--muted);
    font-weight: 900;
    white-space: nowrap;
    overflow:hidden;
    text-overflow: ellipsis;
}
.kpiTile__delta{
    padding: 6px 10px;
    border-radius: 999px;
    background:#f8fafc;
    border:1px solid var(--line);
    font-weight: 900;
    font-size: 12px;
    color: var(--muted);
}
.kpiTile__delta.good{ color: var(--good); border-color: rgba(22,163,74,.25); background: rgba(22,163,74,.06); }
.kpiTile__delta.bad{ color: var(--bad); border-color: rgba(220,38,38,.25); background: rgba(220,38,38,.06); }

.kpiTile__value{
    font-size: 32px;
    font-weight: 1000;
    letter-spacing: -.03em;
}

/* Info button */
.infoBtn{
    width:22px;
    height:22px;
    border-radius:999px;
    border:1px solid var(--line);
    background:#fff;
    cursor:pointer;
    color:var(--muted);
    font-weight:1000;
    line-height:18px;
}
.infoBtn:hover{ background:#f8fafc; }

/* Grid with charts + tables */
.grid{
    display:grid;
    grid-template-columns: 1fr;
    gap: 14px;
}

/* Charts: IMPORTANT for readability */
.chart{
    width:100%;
    height: 420px; /* desktop readable */
    border-radius: 14px;
}

/* Segment buttons */
.seg{
    display:flex;
    border:1px solid var(--line);
    border-radius: 12px;
    overflow:hidden;
    background:#fff;
}
.seg__btn{
    border:0;
    background:transparent;
    padding: 9px 12px;
    font-weight: 900;
    cursor:pointer;
    color: var(--muted);
}
.seg__btn.is-active{
    background: rgba(37,99,235,.10);
    color: var(--primary);
}

/* Tables */
.tableWrap{
    width:100%;
    overflow:auto;
    border:1px solid var(--line);
    border-radius: 14px;
}
table{
    width:100%;
    border-collapse: collapse;
    background:#fff;
    min-width: 720px; /* desktop comfortable */
}
th, td{
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    font-size: 13px;
}
th{
    text-align:left;
    color: var(--muted);
    font-weight: 1000;
    background:#fbfcfe;
    position: sticky;
    top: 0;
    z-index: 1;
}
th .thWrap{
    display:flex;
    align-items:center;
    gap:8px;
}
th .thWrap .infoBtn{
    width:20px;
    height:20px;
    font-size:12px;
}

.details--hidden{ display:none; }

/* Modal */
.modal{ position:fixed; inset:0; z-index:4000; }
.modal--hidden{ display:none; }
.modal__backdrop{ position:absolute; inset:0; background: rgba(15,23,42,.35); }
.modal__card{
    position:relative;
    margin: 8vh auto 0;
    width: min(860px, calc(100vw - 24px));
    background: var(--card);
    border:1px solid var(--line);
    border-radius:16px;
    box-shadow: var(--shadow);
    padding: 12px;
}
.modal__head{
    display:flex; justify-content:space-between; align-items:center;
    gap:12px;
    border-bottom:1px solid var(--line);
    padding-bottom:10px;
    margin-bottom:10px;
}
.modal__title{ font-weight:1000; letter-spacing:-.02em; }
.modal__body{ color: var(--text); font-size: 14px; line-height: 1.5; }
.modal__body code{ background:#f1f5f9; padding:2px 6px; border-radius:8px; }
.modal__body .muted{ color: var(--muted); font-size: 12px; margin-top: 6px; }

/* Mobile */
@media (max-width: 640px){
    .wrap{ padding: 12px; max-width: 100%; }

    .controls__row{
        grid-template-columns: 1fr 1fr;
    }
    /* quick period and actions full width */
    .controls__row .field:nth-child(4),
    .controls__row .field--actions{
        grid-column: 1 / -1;
    }
    .quick .btn.btn--ghost{
        flex: 1 1 calc(50% - 10px);
        text-align:center;
        padding: 11px 10px;
    }
    .field--actions .btn--primary{
        padding: 14px 14px;
        border-radius: 14px;
        font-weight: 1000;
    }

    .kpi{
        grid-template-columns: 1fr 1fr;
    }
    .kpiTile__value{ font-size: 30px; }

    /* BIG FIX: charts readable on mobile */
    .chart{
        height: 360px;
    }

    table{ min-width: 860px; } /* table scroll ok on mobile */
}

/* ===== Typography normalization (override) ===== */
body { font-weight: 400; }

.brand__title { font-weight: 800; }
.brand__subtitle { font-weight: 500; }

.field__label { font-weight: 600; }
.field__control { font-weight: 600; }

.btn { font-weight: 650; }

.kpiTile__label { font-weight: 600; }
.kpiTile__delta { font-weight: 650; }
.kpiTile__value { font-weight: 800; }  /* было 1000 */

th { font-weight: 700; } /* было 1000 */

/* ===== Controls row: remove big empty space on desktop ===== */
.controls__row{
    /* было: 220px 180px 180px 1fr 160px */
    grid-template-columns: 240px 200px 200px auto 160px;
    align-items: end;
}

.field { min-width: 0; }

/* Quick block should not look squashed */
.quick { justify-content: flex-start; }
.quick .btn.btn--ghost { white-space: nowrap; }

@media (max-width: 1100px){
    .controls__row{
        grid-template-columns: 1fr 1fr;
    }
    .controls__row .field:nth-child(4),
    .controls__row .field--actions{
        grid-column: 1 / -1;
    }
}