:root {
    --bg: #f6f8fb;
    --panel: #ffffff;
    --line: #e5e7eb;
    --text: #0f172a;
    --muted: #64748b;
    --blue: #2563eb;
    --green: #16a34a;
    --amber: #f59e0b;
    --red: #dc2626;
    --ink-soft: #334155;
    --shadow: 0 18px 40px rgba(15, 23, 42, .08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", Tahoma, sans-serif;
    letter-spacing: 0;
}

button,
input,
select {
    font: inherit;
}

button {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink-soft);
    border-radius: 7px;
    padding: .68rem .9rem;
    cursor: pointer;
    transition: border-color .18s ease, color .18s ease, background .18s ease;
}

button:hover,
button.is-active {
    border-color: var(--blue);
    color: var(--blue);
    background: #eff6ff;
}

.topbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1.5rem;
    padding: 2rem clamp(1rem, 3vw, 2.5rem) 1rem;
    border-bottom: 1px solid var(--line);
    background:
        linear-gradient(90deg, rgba(37, 99, 235, .07), transparent 42%),
        #fff;
}

.topbar h1 {
    margin: .1rem 0 .25rem;
    font-size: clamp(1.5rem, 3vw, 2.35rem);
    line-height: 1.08;
}

.topbar p {
    margin: 0;
    color: var(--muted);
}

.eyebrow {
    color: var(--blue) !important;
    font-size: .76rem;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.status-pill {
    min-width: 8rem;
    text-align: center;
    border: 1px solid var(--line);
    background: #f8fafc;
    border-radius: 7px;
    padding: .65rem .9rem;
    color: var(--muted);
}

.status-pill.is-ok {
    border-color: rgba(22, 163, 74, .35);
    background: #f0fdf4;
    color: #15803d;
}

.status-pill.is-error {
    border-color: rgba(220, 38, 38, .35);
    background: #fef2f2;
    color: var(--red);
}

.shell {
    width: min(1540px, calc(100% - 2rem));
    margin: 1rem auto 3rem;
}

.filters,
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.filters {
    padding: 1rem;
    position: sticky;
    top: 0;
    z-index: 10;
}

.period-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin-bottom: .9rem;
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(8, minmax(120px, 1fr));
    gap: .75rem;
}

label {
    display: grid;
    gap: .35rem;
    color: var(--muted);
    font-size: .78rem;
    font-weight: 700;
}

input,
select {
    width: 100%;
    min-height: 2.45rem;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    color: var(--text);
    padding: .45rem .62rem;
}

section {
    margin-top: 1rem;
}

.split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 1rem;
}

.panel {
    padding: 1rem;
    overflow: hidden;
}

.panel--warning {
    border-color: rgba(245, 158, 11, .42);
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: .8rem;
}

.section-heading h2 {
    margin: 0;
    font-size: 1rem;
}

.section-heading--inline {
    align-items: flex-start;
}

.kpi-grid,
.summary-grid,
.trio {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: .75rem;
}

.kpi,
.summary-card,
.group-card {
    min-height: 6rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: .85rem;
    background: #fff;
}

.kpi span,
.summary-card span,
.group-card span {
    display: block;
    color: var(--muted);
    font-size: .77rem;
    font-weight: 700;
}

.kpi strong,
.summary-card strong,
.group-card strong {
    display: block;
    margin-top: .5rem;
    font-size: clamp(1.25rem, 3vw, 2rem);
    line-height: 1;
}

.kpi small,
.group-card small {
    display: block;
    margin-top: .45rem;
    color: var(--muted);
}

.chart-wrap {
    position: relative;
    height: 300px;
    width: 100%;
}

.chart-wrap--tall {
    height: 420px;
}

.mini-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .5rem;
    margin-top: .75rem;
}

.mini-list div {
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: .7rem;
    color: var(--muted);
}

.funnel-list {
    display: grid;
    gap: .55rem;
}

.funnel-row {
    display: grid;
    grid-template-columns: 230px 1fr 90px 90px;
    align-items: center;
    gap: .8rem;
}

.funnel-bar {
    height: .72rem;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
}

.funnel-bar span {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--blue), var(--green));
}

.table-scroll {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
}

table {
    width: 100%;
    min-width: 900px;
    border-collapse: collapse;
    background: #fff;
}

th,
td {
    padding: .72rem .75rem;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
    font-size: .86rem;
}

th {
    background: #f8fafc;
    color: var(--muted);
    font-size: .74rem;
    text-transform: uppercase;
}

td {
    color: var(--ink-soft);
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 1.55rem;
    border-radius: 999px;
    padding: .15rem .52rem;
    background: #f1f5f9;
    color: var(--ink-soft);
    font-size: .76rem;
    font-weight: 700;
}

.badge--green { background: #dcfce7; color: #166534; }
.badge--amber { background: #fef3c7; color: #92400e; }
.badge--red { background: #fee2e2; color: #991b1b; }
.badge--blue { background: #dbeafe; color: #1d4ed8; }

.row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
}

.row-actions a,
.row-actions button {
    min-height: 2rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--blue);
    padding: .32rem .5rem;
    text-decoration: none;
    font-size: .78rem;
}

.note {
    margin: .9rem 0 0;
    padding: .8rem;
    border-left: 3px solid var(--blue);
    background: #f8fafc;
    color: var(--muted);
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: .75rem;
    margin-top: .8rem;
}

.lead-tools {
    min-width: min(260px, 100%);
}

.modal {
    position: fixed;
    inset: 0;
    display: none;
    z-index: 50;
}

.modal.is-open {
    display: block;
}

.modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, .45);
}

.modal__panel {
    position: absolute;
    inset: 4vh max(1rem, 8vw);
    overflow: auto;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 30px 80px rgba(15, 23, 42, .24);
    padding: 1.2rem;
}

.modal__close {
    float: right;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .7rem;
    margin: 1rem 0;
}

.detail-box,
.message {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: .8rem;
}

.message {
    margin-bottom: .55rem;
}

.message--USER { border-left: 4px solid var(--blue); }
.message--ASSISTANT,
.message--BOT { border-left: 4px solid var(--green); }
.message--SYSTEM { border-left: 4px solid var(--amber); }

.muted {
    color: var(--muted);
}

@media (max-width: 1100px) {
    .filter-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .kpi-grid,
    .summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 780px) {
    .topbar,
    .split {
        grid-template-columns: 1fr;
        display: grid;
    }

    .filter-grid,
    .kpi-grid,
    .summary-grid,
    .trio,
    .mini-list,
    .detail-grid {
        grid-template-columns: 1fr;
    }

    .filters {
        position: static;
    }

    .funnel-row {
        grid-template-columns: 1fr;
        gap: .35rem;
    }

    .modal__panel {
        inset: 1rem;
    }
}
