:root {
    color-scheme: light;
    --background: #f4f7fb;
    --card: #ffffff;
    --text: #172033;
    --muted: #667085;
    --border: #e4e9f1;
    --accent: #3157d5;
    --ok: #087443;
    --ok-bg: #e9f8f0;
    --error: #b42318;
    --error-bg: #fff0ee;
    --warning: #98600a;
    --warning-bg: #fff7e3;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--background);
    color: var(--text);
    line-height: 1.5;
}

.container {
    width: min(1100px, calc(100% - 32px));
    margin: 56px auto;
}

.page-header { margin-bottom: 28px; }
.page-header h1 { margin: 6px 0 2px; font-size: clamp(2rem, 5vw, 3rem); letter-spacing: -0.04em; }
.page-header p { margin: 0; color: var(--muted); font-size: 1.1rem; }
.eyebrow { color: var(--accent); font-size: .78rem; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }

.card, .notice {
    margin-bottom: 18px;
    padding: 24px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 8px 28px rgba(29, 45, 75, .05);
}

.notice-error { color: var(--error); background: var(--error-bg); border-color: #ffd3cf; }
h2 { margin: 0 0 14px; font-size: 1.2rem; }
h3 { margin: 24px 0 10px; color: var(--muted); font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; }

.status-list { margin: 0; }
.status-list > div, .integration > div, .table-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 11px 0;
    border-bottom: 1px solid var(--border);
}
.status-list > div:last-child, .table-list li:last-child { border-bottom: 0; }
.status-list dt { color: var(--muted); }
.status-list dd { margin: 0; text-align: right; }
.compact > div { padding: 8px 0; }

.status { display: inline-block; padding: 4px 9px; border-radius: 999px; font-size: .82rem; font-weight: 700; text-align: right; }
.status.ok { color: var(--ok); background: var(--ok-bg); }
.status.error { color: var(--error); background: var(--error-bg); }
.status.warning { color: var(--warning); background: var(--warning-bg); }
.muted { color: var(--muted); font-size: .92rem; }
.table-list { margin: 0; padding: 0; list-style: none; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: #344054; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: .75rem; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
.row-error { background: var(--error-bg); }
.notice-inline { padding: 10px 12px; border-radius: 8px; background: var(--error-bg); }
.error-text { color: var(--error); }
.warning-text { color: var(--warning); background: var(--warning-bg); }
.notice-success { color: var(--ok); background: var(--ok-bg); border-color: #b7e7cb; }

button {
    appearance: none;
    padding: 11px 17px;
    border: 0;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}
button:hover { filter: brightness(.95); }
button:disabled { cursor: wait; opacity: .55; }
.sync-actions, .phase-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.sync-actions h2, .phase-heading h2 { margin-bottom: 0; }
.sync-actions p { margin-bottom: 0; }
.sync-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.sync-phase { margin-bottom: 0; }
.sync-count { margin: 20px 0 0; font-size: 1.4rem; font-weight: 750; }
.button-secondary { background: #eef2ff; color: var(--accent); font-size: .82rem; }
.report-filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: end; }
.report-filters label { display: grid; gap: 7px; color: var(--muted); font-size: .86rem; font-weight: 650; }
.report-filters input, .report-filters select {
    width: 100%; padding: 10px 11px; border: 1px solid var(--border); border-radius: 9px;
    background: #fff; color: var(--text); font: inherit;
}
.report-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; align-items: start; }
.report-result { padding: 20px; }
.report-result .number-cell { font-size: 1.05rem; font-weight: 750; }
.detail-header, .detail-pagination { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.detail-pagination { justify-content: center; margin-top: 18px; }
.timezone-check-form { display: flex; align-items: end; gap: 12px; margin-top: 20px; }
.timezone-check-form label { display: grid; gap: 6px; color: var(--muted); font-size: .86rem; }
.timezone-check-form input { padding: 10px 11px; border: 1px solid var(--border); border-radius: 9px; font: inherit; }

@media (max-width: 520px) {
    .container { margin: 28px auto; }
    .card, .notice { padding: 19px; border-radius: 13px; }
    .integration > div { align-items: flex-start; flex-direction: column; }
    .sync-grid { grid-template-columns: 1fr; }
    .sync-actions { align-items: stretch; flex-direction: column; }
    .timezone-check-form { align-items: stretch; flex-direction: column; }
    .report-filters, .report-grid { grid-template-columns: 1fr; }
}

@media (min-width: 521px) and (max-width: 900px) {
    .report-grid { grid-template-columns: 1fr; }
}

/* Main user report */
.report-container { width: min(1500px, calc(100% - 40px)); margin: 36px auto 60px; }
.report-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 28px; margin-bottom: 24px; }
.report-header h1 { margin: 4px 0 0; font-size: clamp(2rem, 4vw, 3rem); letter-spacing: -.045em; }
.report-header p { margin: 2px 0 0; color: var(--muted); font-size: 1.08rem; }
.dashboard-nav { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.dashboard-nav a { padding: 9px 13px; border: 1px solid transparent; border-radius: 9px; color: var(--muted); font-size: .95rem; font-weight: 700; text-decoration: none; }
.dashboard-nav a:hover { color: var(--accent); background: #eef2ff; }
.dashboard-nav a.active { color: var(--accent); background: #eef2ff; border-color: #dce3ff; }
.section-intro { margin: -8px 0 18px; }
.section-intro h2 { margin-bottom: 2px; font-size: 1.35rem; }
.section-intro p { margin: 0; color: var(--muted); }
.sync-widget { display: grid; justify-items: end; gap: 7px; text-align: right; }
.main-filters { display: grid; grid-template-columns: minmax(140px, .6fr) minmax(140px, .6fr) minmax(140px, .6fr) minmax(250px, 1.1fr) minmax(380px, 1.7fr) auto; gap: 16px; align-items: end; }
.main-filters label, .filter-field { display: grid; gap: 7px; color: var(--muted); font-size: .84rem; font-weight: 700; }
.main-filters input, .main-filters select, .manual-input { width: 100%; padding: 10px 11px; border: 1px solid #d8deea; border-radius: 9px; background: #fff; color: var(--text); font: inherit; }
.main-filters small { font-weight: 400; }
.filter-label { color: var(--muted); font-size: .84rem; font-weight: 700; }
.check-select { position: relative; color: var(--text); font-weight: 500; }
.check-select summary { min-height: 44px; padding: 10px 34px 10px 11px; overflow: hidden; border: 1px solid #d8deea; border-radius: 9px; background: #fff; cursor: pointer; list-style: none; white-space: nowrap; text-overflow: ellipsis; }
.check-select summary::-webkit-details-marker { display: none; }
.check-select summary::after { content: '⌄'; position: absolute; top: 9px; right: 12px; color: var(--muted); font-size: 1rem; }
.check-select[open] summary { border-color: #91a4e8; box-shadow: 0 0 0 3px rgba(49,87,213,.08); }
.check-select-menu { position: absolute; z-index: 20; top: calc(100% + 6px); left: 0; width: max(100%, 320px); max-height: 300px; padding: 8px; overflow: auto; border: 1px solid var(--border); border-radius: 11px; background: #fff; box-shadow: 0 16px 40px rgba(23,32,51,.16); }
.source-filter .check-select-menu { width: max(100%, 460px); }
.check-select-menu label { display: flex; grid-template-columns: none; align-items: flex-start; gap: 9px; padding: 8px; border-radius: 7px; color: var(--text); cursor: pointer; font-weight: 500; }
.check-select-menu label:hover { background: #f4f6fb; }
.check-select-menu input { flex: 0 0 auto; width: 17px; height: 17px; margin: 2px 0 0; padding: 0; }
.check-select-menu span { min-width: 0; overflow-wrap: anywhere; }
.filter-actions { display: flex; gap: 8px; }
.report-toolbar, .report-card-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.report-toolbar { margin: 20px 0 10px; }
.report-toolbar p { margin: 0; }
.report-toolbar > div { display: flex; gap: 8px; }
.report-card { padding: 0; overflow: hidden; }
.report-card-heading { padding: 20px 22px 14px; }
.report-card-heading h2 { margin: 0; font-size: 1.3rem; }
.report-table-wrap { max-height: 620px; overflow: auto; border-top: 1px solid var(--border); }
.main-report-table { min-width: 1050px; }
.main-report-table thead { position: sticky; top: 0; z-index: 3; background: #f9fafc; }
.main-report-table th, .main-report-table td { text-align: right; vertical-align: middle; }
.main-report-table th:first-child, .main-report-table td:first-child { position: sticky; left: 0; z-index: 2; min-width: 230px; text-align: left; background: #fff; box-shadow: 1px 0 0 var(--border); }
.main-report-table thead th:first-child { z-index: 5; background: #f9fafc; }
.main-report-table thead tr:first-child th { text-align: center; }
.main-report-table thead tr:first-child th:first-child { text-align: left; }
.period-toggle { padding: 3px 7px; border-radius: 7px; background: transparent; color: var(--accent); font-size: .75rem; }
.period-toggle:hover, .period-toggle.active { background: #e9edff; }
.daily-heading { color: var(--accent); background: #f0f3ff; }
.main-report-table .number-cell { white-space: nowrap; font-variant-numeric: tabular-nums; }
.main-report-table .number-cell small { display: block; color: var(--muted); font-size: .72rem; font-weight: 500; }
.budget-row th, .budget-row td { background-color: #f8fafc; font-weight: 750; }
.budget-row th:first-child { background-color: #f8fafc; }
.target-ok { color: var(--ok); background: var(--ok-bg); }
.target-warn { color: var(--warning); background: #fffbf0; }
.manual-input { min-width: 105px; text-align: right; border-color: #91a4e8; box-shadow: 0 0 0 3px rgba(49,87,213,.08); }
.loading-notice::before { content: ''; display: inline-block; width: 14px; height: 14px; margin-right: 9px; border: 2px solid #c8d1e8; border-top-color: var(--accent); border-radius: 50%; animation: report-spin .75s linear infinite; vertical-align: -2px; }
.report-footer { padding: 12px 2px; text-align: right; }
.report-footer a { color: var(--muted); }
.manager-source-filters { display: grid; grid-template-columns: repeat(3, minmax(145px, .7fr)) minmax(220px, 1fr) minmax(380px, 1.6fr) auto; gap: 16px; align-items: end; }
.cohort-filters { display: grid; grid-template-columns: repeat(3, minmax(145px, .7fr)) minmax(250px, 1.1fr) minmax(380px, 1.6fr) auto; gap: 16px; align-items: end; }
.cohort-filters > label { display: grid; gap: 7px; color: var(--muted); font-size: .84rem; font-weight: 700; }
.cohort-filters input:not([type="checkbox"]), .cohort-filters select { width: 100%; padding: 10px 11px; border: 1px solid #d8deea; border-radius: 9px; background: #fff; color: var(--text); font: inherit; }
.cohort-total { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; margin-bottom: 18px; padding: 18px; border-radius: 12px; background: #eef2ff; }
.cohort-total strong { color: var(--accent); font-size: 2rem; }
.manager-source-filters > label { display: grid; gap: 7px; color: var(--muted); font-size: .84rem; font-weight: 700; }
.manager-source-filters input:not([type="checkbox"]), .manager-source-filters select { width: 100%; padding: 10px 11px; border: 1px solid #d8deea; border-radius: 9px; background: #fff; color: var(--text); font: inherit; }
#manager-source-result th:not(:first-child), #manager-source-result td:not(:first-child) { text-align: right; }
#manager-source-result tfoot { background: #f4f7fb; font-weight: 750; }
.token-dialog { width: min(430px, calc(100% - 30px)); padding: 24px; border: 1px solid var(--border); border-radius: 16px; color: var(--text); box-shadow: 0 24px 70px rgba(23,32,51,.2); }
.token-dialog::backdrop { background: rgba(23,32,51,.38); }
.token-dialog form, .token-dialog label { display: grid; gap: 14px; }
.token-dialog label { color: var(--muted); font-size: .86rem; font-weight: 700; }
.token-dialog input { width: 100%; padding: 11px; border: 1px solid var(--border); border-radius: 9px; font: inherit; }
.token-dialog h2, .token-dialog p { margin: 0; }
@keyframes report-spin { to { transform: rotate(360deg); } }

@media (max-width: 1050px) {
    .main-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .manager-source-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .cohort-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .filter-actions { grid-column: 1 / -1; }
}
@media (max-width: 650px) {
    .report-container { width: min(100% - 22px, 1500px); margin-top: 20px; }
    .report-header { flex-direction: column; }
    .dashboard-nav { align-items: stretch; flex-direction: column; }
    .sync-widget { justify-items: start; text-align: left; }
    .main-filters { grid-template-columns: 1fr; }
    .manager-source-filters { grid-template-columns: 1fr; }
    .cohort-filters { grid-template-columns: 1fr; }
    .filter-actions { grid-column: auto; }
    .check-select-menu, .source-filter .check-select-menu { position: static; width: 100%; margin-top: 6px; box-shadow: none; }
    .report-toolbar { align-items: stretch; flex-direction: column; }
    .report-toolbar > div { flex-wrap: wrap; }
}
