:root {
    --page-bg: #f3f6fa;
    --card-bg: #ffffff;
    --border: #dce3ec;
    --shadow: 0 6px 18px rgba(23, 40, 64, 0.07);
    --text: #172033;
    --muted: #6f7d8e;
    --blue: #0d2f57;
    --blue-soft: #1f5f99;
    --teal: #2fa7b7;
    --orange: #f28c28;
    --danger: #c84b4b;
}

* {
    box-sizing: border-box;
}

html {
    background: var(--page-bg);
}

body {
    margin: 0;
    min-width: 0;
    background: var(--page-bg);
    color: var(--text);
    font-family: Arial, "Helvetica Neue", sans-serif;
    font-size: 15px;
    line-height: 1.45;
}

.analytics-shell {
    width: min(100% - 32px, 1560px);
    margin: 0 auto;
    padding: 24px 0 36px;
}

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 16px;
}

.page-header h1 {
    margin: 0 0 6px;
    color: var(--blue);
    font-size: 28px;
    font-weight: 700;
}

.page-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    color: var(--muted);
    font-size: 14px;
}

.filter-card,
.summary-card,
.chart-card,
.client-retention-card,
.notice-card,
.empty-state {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card-bg);
    box-shadow: var(--shadow);
}

.filter-card {
    margin-bottom: 16px;
    padding: 14px 16px;
}

.filter-form {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 12px;
}

.filter-form > label {
    display: grid;
    gap: 5px;
    min-width: min(100%, 230px);
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.filter-form > label:nth-of-type(1),
.filter-form > label:nth-of-type(2) {
    flex: 1 1 280px;
}

.filter-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
}

.filter-checkbox-row {
    display: flex;
    flex: 1 0 100%;
    align-items: flex-start;
    column-gap: 18px;
    row-gap: 6px;
    flex-wrap: wrap;
}

.filter-checkbox-row .filter-checkbox-with-note {
    order: 1;
}

.filter-checkbox-recalculate {
    order: 2;
    flex-basis: 100%;
}

.filter-checkbox-with-note {
    flex-wrap: wrap;
}

.filter-checkbox-with-note span {
    flex-basis: 100%;
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
    line-height: 1.25;
    padding-left: 24px;
}

.filter-checkbox input {
    width: 16px;
    height: 16px;
}

.filter-form select,
.filter-form button {
    min-height: 38px;
    border-radius: 6px;
    font: inherit;
}

.filter-form select {
    width: 100%;
    border: 1px solid #cbd5e1;
    background: #fff;
    color: var(--text);
    padding: 0 34px 0 10px;
}

.filter-form button {
    border: 1px solid var(--blue);
    background: var(--blue);
    color: #fff;
    padding: 0 18px;
    font-weight: 700;
    cursor: pointer;
}

.filter-form button:disabled,
.filter-form select:disabled {
    cursor: not-allowed;
    opacity: 0.58;
}

.notice-card {
    margin-bottom: 16px;
    padding: 12px 14px;
    color: var(--muted);
}

.notice-card-error {
    border-color: rgba(200, 75, 75, 0.38);
    color: var(--danger);
    background: #fffafa;
}

.empty-state {
    padding: 34px 28px;
    text-align: center;
}

.empty-state h2 {
    margin: 0 0 8px;
    color: var(--blue);
    font-size: 20px;
}

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

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 16px;
}

.summary-card {
    min-width: 0;
    padding: 16px 18px;
}

.summary-title {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.summary-value {
    display: block;
    color: var(--blue);
    font-size: 26px;
    line-height: 1.1;
    overflow-wrap: anywhere;
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.client-retention-card {
    margin-top: 16px;
    margin-bottom: 16px;
    padding: 18px;
}

.client-retention-header {
    margin-bottom: 12px;
}

.client-retention-header h2 {
    margin: 0 0 4px;
    color: var(--blue);
    font-size: 18px;
    font-weight: 700;
}

.client-retention-header p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.client-retention-table-wrap {
    max-width: 100%;
    overflow-x: auto;
}

.client-retention-table {
    width: 100%;
    min-width: 900px;
    border-collapse: collapse;
    color: var(--text);
    font-size: 14px;
}

.client-retention-table th,
.client-retention-table td {
    border-bottom: 1px solid var(--border);
    padding: 10px 12px;
    text-align: right;
    white-space: nowrap;
}

.client-retention-table th:first-child,
.client-retention-table td:first-child {
    text-align: left;
}

.client-retention-table thead th {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.client-retention-table tbody th {
    color: var(--blue);
    font-weight: 700;
}

.client-retention-table tbody tr:last-child th,
.client-retention-table tbody tr:last-child td {
    border-bottom: 0;
}

.chart-card {
    min-width: 0;
    padding: 18px 18px 16px;
}

.chart-card-primary {
    grid-column: 1 / -1;
}

.chart-card-header {
    min-height: 58px;
    margin-bottom: 8px;
}

.chart-card h2 {
    margin: 0 0 4px;
    color: var(--blue);
    font-size: 18px;
    font-weight: 700;
}

.chart-card p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.chart-canvas-wrap {
    position: relative;
    height: 350px;
    min-width: 0;
}

.chart-card-primary .chart-canvas-wrap {
    height: 420px;
}

.chart-canvas-wrap canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

.chart-fallback {
    color: var(--muted);
    text-align: center;
}

.chart-fallback[hidden] {
    display: none;
}

.chart-fallback:not([hidden]) {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 18px;
    border: 1px dashed var(--border);
    border-radius: 6px;
    background: #f8fafc;
}

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

    .charts-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .analytics-shell {
        width: min(100% - 20px, 1560px);
        padding-top: 16px;
    }

    .page-header h1 {
        font-size: 24px;
    }

    .filter-form,
    .filter-form > label,
    .filter-form button,
    .filter-checkbox-row,
    .filter-checkbox {
        width: 100%;
    }

    .summary-grid {
        grid-template-columns: 1fr;
    }

    .summary-value {
        font-size: 23px;
    }

    .chart-card {
        padding: 14px 12px 12px;
    }

    .chart-card-header {
        min-height: 0;
    }

    .chart-canvas-wrap,
    .chart-card-primary .chart-canvas-wrap {
        height: 320px;
    }
}
