:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #66758a;
  --line: #e1e7f0;
  --line-strong: #c9d4e3;
  --surface: #ffffff;
  --surface-soft: #f6f8fc;
  --surface-blue: #eff6ff;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-deep: #123a77;
  --teal: #0f9f8f;
  --amber: #b86b17;
  --red: #b42318;
  --shadow: 0 18px 50px rgba(24, 48, 88, 0.14);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background: #f3f6fa;
  font-size: 14px;
  letter-spacing: 0;
}

button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.hidden { display: none !important; }

.login-page {
  min-width: 980px;
  display: grid;
  place-items: center;
  background: #edf2f8;
}

.login-shell {
  width: 900px;
  min-height: 520px;
  display: grid;
  grid-template-columns: 1.08fr 0.92fr;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 58px;
  color: #f8fbf9;
  background: #123a77;
  position: relative;
  overflow: hidden;
}

.login-brand::after {
  content: "";
  position: absolute;
  inset: 28px;
  border: 1px solid rgba(255,255,255,.18);
  pointer-events: none;
}

.login-brand h1 { margin: 10px 0 8px; font-size: 34px; font-weight: 650; }
.login-brand p:last-child { margin: 0; color: #cbdcf5; font-size: 15px; }

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: white;
  background: var(--primary);
  border-radius: 6px;
  flex: none;
}

.brand-mark svg { width: 20px; height: 20px; }
.brand-mark-large { width: 52px; height: 52px; background: #dbeafe; color: var(--primary-deep); margin-bottom: 90px; }
.brand-mark-large svg { width: 26px; height: 26px; }
.brand-kicker, .section-kicker { letter-spacing: 0; font-size: 11px; font-weight: 700; }
.brand-kicker { color: #a9c5ee !important; }

.login-panel { padding: 58px 52px; display: flex; flex-direction: column; justify-content: center; }
.login-heading { margin-bottom: 28px; }
.login-heading .section-kicker { color: var(--primary); margin: 0 0 8px; }
.login-heading h2 { margin: 0; font-size: 25px; }
.login-form { display: grid; gap: 10px; }
.login-form label { color: #455149; font-size: 13px; font-weight: 600; margin-top: 4px; }
.input-with-icon { position: relative; }
.input-with-icon svg { position: absolute; width: 17px; left: 13px; top: 12px; color: #79847d; }
.input-with-icon input {
  width: 100%; height: 42px; padding: 0 12px 0 40px;
  border: 1px solid var(--line-strong); border-radius: 5px; outline: none;
}
.input-with-icon input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.primary-button {
  height: 44px; margin-top: 18px; border: 0; border-radius: 5px; color: white;
  background: var(--primary); display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 650;
}
.primary-button:hover { background: var(--primary-dark); }
.primary-button svg { width: 18px; }
.login-error { display: flex; align-items: center; gap: 8px; background: #fff2f0; color: var(--red); padding: 10px 12px; border-left: 3px solid var(--red); margin-bottom: 16px; }
.login-error svg { width: 17px; }

.dashboard-page { min-width: 1180px; }
.app-shell { min-height: 100vh; }
.topbar {
  height: 64px; padding: 0 28px; display: flex; align-items: center; justify-content: space-between;
  background: rgba(255,255,255,.97); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
  box-shadow: 0 1px 8px rgba(37, 58, 91, .04);
}
.brand-lockup { display: flex; gap: 12px; align-items: center; }
.brand-lockup strong { display: block; font-size: 16px; }
.brand-lockup span { display: block; color: var(--muted); font-size: 11px; margin-top: 3px; }
.topbar-meta { display: flex; align-items: center; gap: 17px; color: var(--muted); font-size: 12px; }
.topbar-meta form { margin: 0; }
.user-name { color: var(--ink); font-weight: 650; }
.sync-badge { display: flex; align-items: center; gap: 7px; color: #43536a; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 3px rgba(184,107,23,.12); }
.sync-badge.ready .status-dot { background: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.sync-badge.error .status-dot { background: var(--red); box-shadow: 0 0 0 3px rgba(180,35,24,.12); }
.icon-button { width: 34px; height: 34px; border: 0; border-radius: 5px; background: transparent; color: #536278; display: grid; place-items: center; }
.icon-button:hover { background: var(--surface-soft); color: var(--ink); }
.icon-button svg { width: 17px; height: 17px; }
.icon-button.bordered { border: 1px solid var(--line-strong); background: white; }

.dashboard-main { max-width: 1580px; margin: 0 auto; padding: 22px 28px 48px; }
.filter-band { min-height: 58px; display: flex; align-items: center; gap: 22px; padding: 8px 0 18px; border-bottom: 1px solid var(--line); }
.filter-group { display: flex; align-items: center; gap: 10px; }
.filter-group.grow { flex: 1; }
.filter-label { color: var(--muted); font-size: 12px; font-weight: 650; white-space: nowrap; }
.segmented { display: inline-grid; grid-auto-flow: column; border: 1px solid var(--line-strong); border-radius: 5px; overflow: hidden; background: white; }
.segmented button { height: 34px; padding: 0 14px; border: 0; border-right: 1px solid var(--line); background: white; color: #52647b; }
.segmented button:last-child { border-right: 0; }
.segmented button:hover { background: var(--surface-soft); }
.segmented button.active { background: var(--primary); color: white; }
select, input[type="date"] { height: 34px; padding: 0 30px 0 10px; border: 1px solid var(--line-strong); background: white; color: var(--ink); border-radius: 5px; outline: none; }
select:focus, input[type="date"]:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.custom-dates { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.compact-button { height: 34px; padding: 0 12px; border: 1px solid var(--primary); color: var(--primary); background: white; border-radius: 5px; font-weight: 650; }
.compact-button:hover { background: var(--surface-blue); }
.active-filters { display: flex; align-items: center; gap: 8px; padding: 14px 0 0; }
.back-button { height: 30px; padding: 0 11px; border: 1px solid var(--line-strong); border-radius: 5px; background: white; color: #43536a; display: inline-flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 650; }
.back-button:hover { border-color: #9eb9e6; background: var(--surface-blue); color: var(--primary-dark); }
.back-button svg { width: 15px; height: 15px; }
.filter-chip { display: inline-flex; align-items: center; gap: 7px; height: 28px; padding: 0 8px 0 10px; border: 1px solid #bfd3f5; background: var(--surface-blue); color: var(--primary-dark); border-radius: 4px; font-size: 12px; }
.filter-chip button { border: 0; background: transparent; padding: 0; display: grid; color: inherit; }
.filter-chip svg { width: 14px; height: 14px; }

.kpi-strip { display: grid; grid-template-columns: 1.15fr 1fr 1fr 1fr; margin-top: 10px; background: white; border: 1px solid var(--line); }
.kpi-item { min-height: 128px; padding: 24px 28px; border-right: 1px solid var(--line); display: flex; flex-direction: column; justify-content: center; }
.kpi-item:last-child { border-right: 0; }
.kpi-item span { color: var(--muted); font-size: 12px; font-weight: 650; }
.kpi-item strong { font-size: 29px; line-height: 1.2; margin: 9px 0 7px; font-variant-numeric: tabular-nums; }
.kpi-item small { color: #7a857f; font-size: 11px; }
.primary-kpi { background: var(--primary-deep); color: white; }
.primary-kpi span, .primary-kpi small { color: #c8daf4; }

.trend-section { background: white; margin-top: 18px; padding: 22px 26px 16px; border-top: 3px solid var(--primary); border-bottom: 1px solid var(--line-strong); }
.section-heading-row { display: flex; justify-content: space-between; align-items: flex-start; }
.section-heading-row .section-kicker { color: var(--primary); margin: 0 0 5px; }
.section-heading-row h2 { font-size: 18px; margin: 0; }
.chart-legend { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; }
.chart-legend .legend-token, .chart-legend .legend-request { width: 18px; height: 3px; display: inline-block; margin-left: 12px; }
.timezone-note { padding-right: 10px; border-right: 1px solid var(--line); color: #52647b; }
.legend-token { background: var(--primary); }
.legend-request { background: var(--teal); }
.trend-chart { height: 320px; width: 100%; }

.ranking-section { background: white; margin-top: 18px; border-top: 1px solid var(--line-strong); border-bottom: 1px solid var(--line-strong); }
.ranking-toolbar { min-height: 60px; padding: 0 22px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.tabs { display: flex; align-self: stretch; }
.tabs button { padding: 0 17px; border: 0; border-bottom: 3px solid transparent; background: transparent; color: #627188; font-weight: 650; }
.tabs button:hover { color: var(--ink); }
.tabs button.active { color: var(--primary-dark); border-bottom-color: var(--primary); }
.ranking-total { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.table-status { display: none; padding: 16px 22px; color: var(--muted); border-bottom: 1px solid var(--line); }
.table-status.visible { display: block; }
.table-wrap { min-height: 340px; overflow: visible; }
.ranking-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.ranking-table th { height: 44px; padding: 0 10px; color: #6d7b90; background: #f6f8fc; border-bottom: 1px solid var(--line); text-align: right; font-size: 11px; font-weight: 700; position: sticky; top: 64px; z-index: 8; }
.ranking-table th:first-child, .ranking-table th:nth-child(2), .ranking-table[data-tab="employees"] th:nth-child(3) { text-align: left; }
.ranking-table td { height: 56px; padding: 7px 13px; border-bottom: 1px solid #edf1f6; text-align: right; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking-table td:first-child, .ranking-table td:nth-child(2), .ranking-table[data-tab="employees"] td:nth-child(3) { text-align: left; }
.ranking-table tbody tr.clickable { cursor: pointer; }
.ranking-table tbody tr:hover { background: #f5f8fd; }
.sort-button { width: 100%; height: 44px; padding: 0 3px; border: 0; background: transparent; color: inherit; display: flex; align-items: center; justify-content: flex-end; gap: 5px; font-size: inherit; font-weight: inherit; }
.ranking-table th:first-child .sort-button, .ranking-table th:nth-child(2) .sort-button, .ranking-table[data-tab="employees"] th:nth-child(3) .sort-button { justify-content: flex-start; }
.sort-button:hover, .sort-button.active { color: var(--primary-dark); }
.sort-button svg { width: 13px; height: 13px; flex: none; }
.rank-cell { color: var(--muted); font-weight: 700; }
.rank-top { color: var(--amber); }
.identity { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar { width: 30px; height: 30px; flex: none; display: grid; place-items: center; border-radius: 5px; background: #e7effc; color: var(--primary-dark); font-size: 12px; font-weight: 700; }
.avatar.unmapped { background: #fff1df; color: #9b570e; }
.identity-text { min-width: 0; }
.identity-text strong, .identity-text span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.identity-text strong { font-size: 13px; }
.identity-text span { font-size: 10px; color: var(--muted); margin-top: 3px; }
.metric-main { color: #18345f; font-weight: 700; }
.metric-bar { height: 3px; margin-top: 5px; margin-left: auto; max-width: 120px; background: #e4eaf3; }
.metric-bar span { display: block; height: 100%; background: var(--primary); }
.peak-time { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.peak-time strong { color: var(--ink); font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.peak-time span { color: var(--muted); font-size: 10px; }
.cost { color: var(--amber); }
.empty-row td { text-align: center !important; color: var(--muted); height: 220px; }
.table-footer { min-height: 50px; display: flex; align-items: center; justify-content: space-between; padding: 0 22px; color: var(--muted); font-size: 12px; background: #fafbfd; }

.sync-overlay { position: fixed; inset: 0; background: rgba(237,242,248,.92); z-index: 50; display: grid; place-items: center; }
.sync-dialog { width: 480px; padding: 42px; background: white; border: 1px solid var(--line-strong); box-shadow: var(--shadow); text-align: center; }
.sync-icon { width: 48px; height: 48px; display: grid; place-items: center; margin: 0 auto 22px; background: var(--surface-blue); color: var(--primary); border-radius: 6px; }
.sync-icon svg { width: 24px; }
.sync-dialog .section-kicker { color: var(--primary); margin: 0 0 7px; }
.sync-dialog h2 { margin: 0 0 10px; font-size: 21px; }
.sync-dialog p { color: var(--muted); line-height: 1.6; }
.progress-track { height: 8px; margin: 24px 0 10px; background: #e4eaf3; overflow: hidden; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--primary); transition: width .35s ease; }
.sync-dialog strong { color: var(--primary-dark); font-variant-numeric: tabular-nums; }
.toast { position: fixed; right: 24px; bottom: 24px; max-width: 420px; padding: 12px 16px; background: #18345f; color: white; box-shadow: var(--shadow); border-radius: 5px; z-index: 60; }
.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
