:root {
    --po-bg: #f4f6f9;
    --po-bg-elev: #ffffff;
    --po-border: #e2e8f0;
    --po-text: #1e293b;
    --po-muted: #64748b;
    --po-accent: #2563eb;
    --po-accent-soft: rgba(37, 99, 235, 0.12);
    --po-green: #059669;
    --po-up: #059669;
    --po-down: #dc2626;
    --po-radius: 16px;
    --po-font: "Montserrat", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    --po-pad-x: 16px;
    --po-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 16px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--po-bg);
    color: var(--po-text);
    font-family: var(--po-font);
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

.po-body {
    min-height: 100%;
    min-height: 100dvh;
    overflow-x: hidden;
}

.po-wrap {
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px var(--po-pad-x) 32px;
    padding-left: max(var(--po-pad-x), env(safe-area-inset-left));
    padding-right: max(var(--po-pad-x), env(safe-area-inset-right));
    padding-bottom: max(32px, env(safe-area-inset-bottom));
}

.po-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}

.po-brand-name {
    font-size: clamp(1.6rem, 4vw, 2.1rem);
    font-weight: 700;
    letter-spacing: 0.04em;
    line-height: 1.1;
}

.po-brand-sub {
    color: var(--po-muted);
    margin-top: 4px;
    font-size: 0.92rem;
}

.po-updated {
    color: var(--po-muted);
    font-size: 0.85rem;
}

.po-period { margin-bottom: 18px; }

.po-presets,
.po-grain {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.po-presets button,
.po-grain button,
.po-apply {
    appearance: none;
    border: 1px solid var(--po-border);
    background: var(--po-bg-elev);
    color: var(--po-text);
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 0.88rem;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.po-presets button.is-active,
.po-grain button.is-active,
.po-apply {
    background: var(--po-accent);
    border-color: var(--po-accent);
    color: #fff;
}

.po-custom {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-top: 12px;
}

.po-custom label {
    color: var(--po-muted);
    font-size: 0.88rem;
    display: flex;
    gap: 6px;
    align-items: center;
}

.po-custom input[type="date"] {
    background: var(--po-bg-elev);
    border: 1px solid var(--po-border);
    color: var(--po-text);
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 1rem; /* избегает зума iOS */
    max-width: 100%;
}

.po-kpis {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    margin-bottom: 14px;
}

.po-kpi-wide { max-width: 100%; }

.po-channel-breakdown {
    list-style: none;
    margin: 16px 0 0;
    padding: 14px 0 0;
    border-top: 1px solid var(--po-border);
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.po-channel-breakdown li {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.po-ch-name {
    color: var(--po-muted);
    font-size: 0.82rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

.po-ch-icon {
    width: 20px;
    height: 20px;
    border-radius: 5px;
    object-fit: contain;
    flex: 0 0 auto;
    background: #fff;
    border: 1px solid var(--po-border);
}

.po-ch-value {
    font-size: 1.25rem;
    font-weight: 650;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px;
}

.po-ch-delta {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--po-muted);
}

.po-ch-delta.is-up { color: var(--po-up); }
.po-ch-delta.is-down { color: var(--po-down); }

.po-card {
    background: var(--po-bg-elev);
    border: 1px solid var(--po-border);
    border-radius: var(--po-radius);
    box-shadow: var(--po-shadow);
    padding: 18px;
    min-width: 0;
}

.po-kpi-label {
    color: var(--po-muted);
    font-size: 0.9rem;
}

.po-kpi-value {
    font-size: clamp(2rem, 6vw, 2.8rem);
    font-weight: 700;
    margin-top: 6px;
    line-height: 1.1;
    word-break: break-word;
}

.po-kpi-delta {
    margin-top: 8px;
    font-size: 0.9rem;
    color: var(--po-muted);
}

.po-kpi-delta.is-up { color: var(--po-up); }
.po-kpi-delta.is-down { color: var(--po-down); }

.po-grid {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 14px;
    margin-bottom: 14px;
}

.po-card-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
}

.po-card-hint {
    margin: 4px 0 12px;
    color: var(--po-muted);
    font-size: 0.82rem;
}

.po-chart-box {
    position: relative;
    width: 100%;
    max-width: 100%;
}

.po-chart-bar { height: 280px; }
.po-chart-donut { height: 240px; }
.po-chart-line { height: 300px; }

.po-legend {
    list-style: none;
    margin: 12px 0 0;
    padding: 0;
    display: grid;
    gap: 6px;
}

.po-legend li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 0.88rem;
    color: var(--po-muted);
}

.po-legend .swatch {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 8px;
}

.po-daily {
    margin-bottom: 14px;
}

.po-daily-head {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 4px;
}

.po-footnote {
    margin: 14px 0 0;
    color: var(--po-muted);
    font-size: 0.8rem;
}

.po-error {
    margin-top: 12px;
    color: var(--po-down);
    font-size: 0.9rem;
}

/* Планшет / узкий десктоп */
@media (max-width: 800px) {
    :root { --po-pad-x: 12px; }

    .po-kpis,
    .po-grid {
        grid-template-columns: 1fr;
    }

    .po-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        margin-bottom: 14px;
    }

    .po-updated {
        width: 100%;
        line-height: 1.35;
    }

    .po-presets {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        margin: 0 calc(-1 * var(--po-pad-x));
        padding: 2px var(--po-pad-x) 6px;
        gap: 8px;
    }

    .po-presets::-webkit-scrollbar { display: none; }

    .po-presets button,
    .po-grain button,
    .po-apply {
        flex: 0 0 auto;
        min-height: 40px;
        padding: 10px 14px;
        font-size: 0.86rem;
    }

    .po-channel-breakdown {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .po-channel-breakdown li {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .po-custom {
        flex-direction: column;
        align-items: stretch;
    }

    .po-custom label {
        width: 100%;
        justify-content: space-between;
    }

    .po-custom input[type="date"] {
        flex: 1;
        min-width: 0;
        min-height: 44px;
        padding: 10px 12px;
    }

    .po-apply {
        width: 100%;
        min-height: 44px;
    }

    .po-card {
        padding: 14px;
        border-radius: 14px;
    }

    .po-kpi-label { font-size: 0.82rem; }
    .po-kpi-value { font-size: clamp(1.75rem, 9vw, 2.3rem); }
    .po-kpi-delta { font-size: 0.8rem; line-height: 1.35; }

    .po-daily-head {
        flex-direction: column;
        align-items: stretch;
    }

    .po-grain {
        width: 100%;
    }

    .po-grain button {
        flex: 1 1 0;
        text-align: center;
        justify-content: center;
    }

    .po-chart-bar { height: 220px; }
    .po-chart-donut { height: 220px; }
    .po-chart-line { height: 240px; }

    .po-wrap { padding-top: 14px; padding-bottom: max(28px, env(safe-area-inset-bottom)); }
}

/* Телефон */
@media (max-width: 480px) {
    :root { --po-pad-x: 10px; }

    .po-brand-name {
        font-size: 1.45rem;
        letter-spacing: 0.03em;
    }

    .po-brand-sub { font-size: 0.82rem; }

    .po-kpis {
        gap: 10px;
    }

    .po-grid {
        gap: 10px;
    }

    .po-card-title { font-size: 1rem; }

    .po-chart-bar { height: 200px; }
    .po-chart-donut { height: 200px; }
    .po-chart-line { height: 220px; }

    .po-legend li { font-size: 0.82rem; }
}

/* Очень узкий экран: KPI в одну колонку */
@media (max-width: 360px) {
    .po-kpis {
        grid-template-columns: 1fr;
    }
}
