:root {
  color-scheme: light dark;
  --app-bg: var(--tg-theme-bg-color, #0e1621);
  --surface: var(--tg-theme-secondary-bg-color, #17212b);
  --surface-raised: color-mix(in srgb, var(--surface) 86%, white 14%);
  --surface-soft: color-mix(in srgb, var(--surface) 91%, var(--app-bg) 9%);
  --text: var(--tg-theme-text-color, #f4f7fa);
  --muted: var(--tg-theme-hint-color, #7f9bb1);
  --accent: var(--tg-theme-button-color, #2aabee);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #63b9f4);
  --line: color-mix(in srgb, var(--muted) 20%, transparent);
  --success: #45d39f;
  --warning: #f0aa56;
  --danger: #ed7272;
  --shadow: 0 8px 30px rgba(0, 0, 0, .16);
  --safe-top: max(0px, var(--tg-safe-area-inset-top, 0px));
  --content-safe-top: max(0px, var(--tg-content-safe-area-inset-top, 0px));
  --safe-bottom: max(12px, var(--tg-safe-area-inset-bottom, 0px));
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--app-bg);
  scroll-behavior: smooth;
}

body {
  min-width: 280px;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 92% 2%, color-mix(in srgb, var(--accent) 9%, transparent) 0, transparent 28rem),
    var(--app-bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app-shell {
  width: min(100%, 720px);
  min-height: 100vh;
  margin: 0 auto;
  padding-bottom: var(--safe-bottom);
}

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: calc(66px + var(--safe-top) + var(--content-safe-top));
  padding: calc(10px + var(--safe-top) + var(--content-safe-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .08);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.brand-mark {
  display: grid;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(145deg, color-mix(in srgb, var(--accent) 74%, white 26%), var(--accent));
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 28%, transparent);
  color: var(--accent-text);
}

.brand-copy {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 2px;
}

.brand-copy strong {
  overflow: hidden;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-copy span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live-dot {
  width: 9px;
  height: 9px;
  margin-right: 4px;
  border: 2px solid color-mix(in srgb, var(--success) 25%, var(--surface));
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 11%, transparent);
}

main {
  width: 100%;
  padding: 21px 14px 32px;
}

.view[hidden],
[hidden] {
  display: none !important;
}

.intro-row,
.section-heading,
.employee-main,
.employee-value,
.detail-heading,
.money-row,
.metric-row,
.state-actions {
  display: flex;
  align-items: center;
}

.intro-row {
  justify-content: space-between;
  gap: 12px;
  margin: 0 2px 15px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .095em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(24px, 7vw, 31px);
  line-height: 1.08;
  letter-spacing: -.035em;
}

h2 {
  margin-bottom: 3px;
  font-size: 19px;
  line-height: 1.2;
  letter-spacing: -.015em;
}

h3 {
  margin-bottom: 0;
  font-size: 15px;
  line-height: 1.25;
}

.icon-button,
.back-button,
.clear-search,
.month-tab,
.employee-card,
.state-button {
  border: 0;
  cursor: pointer;
}

.icon-button {
  display: grid;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  color: var(--muted);
}

.icon-button:active svg,
.is-refreshing svg {
  animation: rotate .65s linear infinite;
}

.month-tabs {
  display: flex;
  gap: 7px;
  margin: 0 -14px 17px;
  padding: 2px 14px 4px;
  overflow-x: auto;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}

.month-tabs:empty {
  display: none;
}

.month-tabs::-webkit-scrollbar {
  display: none;
}

.month-tab {
  min-height: 36px;
  padding: 7px 15px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
  scroll-snap-align: center;
  transition: transform .15s ease, background-color .15s ease, color .15s ease;
}

.month-tab[aria-selected="true"] {
  border-color: transparent;
  background: var(--accent);
  box-shadow: 0 5px 16px color-mix(in srgb, var(--accent) 25%, transparent);
  color: var(--accent-text);
}

.month-tab:active,
.employee-card:active,
.state-button:active,
.back-button:active {
  transform: scale(.985);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin-bottom: 25px;
}

.summary-card {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.summary-card.primary {
  position: relative;
  grid-column: 1 / -1;
  min-height: 112px;
  overflow: hidden;
  padding: 17px;
  border-color: color-mix(in srgb, var(--accent) 25%, transparent);
  background:
    linear-gradient(125deg, color-mix(in srgb, var(--accent) 18%, var(--surface)), var(--surface) 72%);
}

.summary-card.primary::after {
  position: absolute;
  top: -42px;
  right: -32px;
  width: 142px;
  height: 142px;
  border: 24px solid color-mix(in srgb, var(--accent) 8%, transparent);
  border-radius: 50%;
  content: "";
}

.summary-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.summary-card.primary .summary-label {
  color: color-mix(in srgb, var(--text) 67%, var(--muted));
}

.summary-value {
  position: relative;
  z-index: 1;
  display: block;
  overflow: hidden;
  font-size: 24px;
  font-weight: 800;
  line-height: 1.12;
  letter-spacing: -.035em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-card.primary .summary-value {
  max-width: 84%;
  margin-top: 6px;
  font-size: clamp(29px, 9vw, 38px);
}

.summary-note {
  position: relative;
  z-index: 1;
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
}

.section-heading {
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin: 0 2px 12px;
}

.section-caption {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 12px;
}

.count-pill {
  min-width: 30px;
  padding: 5px 9px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 43px;
  margin-bottom: 10px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  color: var(--muted);
}

.search-box:focus-within {
  border-color: color-mix(in srgb, var(--accent) 65%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 10%, transparent);
  color: var(--accent);
}

.search-box input {
  min-width: 0;
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
}

.search-box input::placeholder {
  color: var(--muted);
  opacity: .78;
}

.search-box input::-webkit-search-cancel-button {
  display: none;
}

.clear-search {
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 50%;
  background: color-mix(in srgb, var(--muted) 22%, transparent);
  color: var(--text);
  font-size: 18px;
  line-height: 22px;
}

.employees-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.employee-card {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 11px;
  min-height: 77px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .08);
  color: var(--text);
  text-align: left;
  transition: transform .12s ease, border-color .15s ease, background-color .15s ease;
}

@media (hover: hover) {
  .employee-card:hover {
    border-color: color-mix(in srgb, var(--accent) 48%, transparent);
    background: var(--surface-raised);
  }
}

.avatar {
  display: grid;
  position: relative;
  flex: 0 0 45px;
  width: 45px;
  height: 45px;
  place-items: center;
  border-radius: 14px;
  background: var(--avatar-color, var(--accent));
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .02em;
}

.avatar .crown {
  position: absolute;
  top: -7px;
  right: -7px;
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: #754fc8;
  font-size: 11px;
}

.employee-main {
  min-width: 0;
  flex: 1;
  align-items: flex-start;
  flex-direction: column;
  gap: 4px;
}

.employee-name {
  display: block;
  width: 100%;
  overflow: hidden;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.employee-meta {
  display: block;
  width: 100%;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.employee-value {
  flex: 0 0 auto;
  align-items: flex-end;
  flex-direction: column;
  gap: 5px;
}

.employee-total {
  max-width: 125px;
  overflow: hidden;
  color: var(--link);
  font-size: 13px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kpi-badge,
.role-badge,
.verdict-badge {
  display: inline-flex;
  align-items: center;
  min-height: 21px;
  padding: 3px 7px;
  border-radius: 7px;
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.tone-good {
  background: color-mix(in srgb, var(--success) 16%, transparent);
  color: var(--success);
}

.tone-warn {
  background: color-mix(in srgb, var(--warning) 17%, transparent);
  color: var(--warning);
}

.tone-bad {
  background: color-mix(in srgb, var(--danger) 16%, transparent);
  color: var(--danger);
}

.tone-neutral {
  background: color-mix(in srgb, var(--muted) 15%, transparent);
  color: var(--muted);
}

.chevron {
  flex: 0 0 15px;
  color: var(--muted);
  opacity: .7;
}

.state-region:empty {
  display: none;
}

.state-card,
.inline-empty {
  display: flex;
  min-height: 230px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 28px 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--muted);
  text-align: center;
}

.state-card strong,
.inline-empty strong {
  margin: 7px 0 5px;
  color: var(--text);
  font-size: 15px;
}

.state-card p,
.inline-empty span {
  max-width: 310px;
  margin-bottom: 0;
  font-size: 13px;
  line-height: 1.45;
}

.state-icon,
.empty-icon {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  border-radius: 17px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  font-size: 24px;
}

.state-actions {
  gap: 8px;
  justify-content: center;
  margin-top: 17px;
}

.state-button {
  min-height: 38px;
  padding: 8px 16px;
  border-radius: 11px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 13px;
  font-weight: 700;
}

.state-button.secondary {
  border: 1px solid var(--line);
  background: var(--surface-raised);
  color: var(--text);
}

.inline-empty {
  min-height: 190px;
}

.skeleton-wrap {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.skeleton {
  position: relative;
  overflow: hidden;
  border-radius: 16px;
  background: var(--surface);
}

.skeleton::after {
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--text) 8%, transparent), transparent);
  content: "";
  animation: shimmer 1.2s infinite;
}

.skeleton-summary {
  height: 112px;
  margin-bottom: 2px;
}

.skeleton-row {
  height: 76px;
}

.back-button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 34px;
  margin: -4px 0 12px -4px;
  padding: 5px 7px 5px 2px;
  border-radius: 9px;
  background: transparent;
  color: var(--link);
  font-size: 13px;
  font-weight: 650;
  transition: transform .12s ease, background-color .15s ease;
}

.back-button:hover {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.detail-view {
  max-width: 620px;
  margin: 0 auto;
}

.detail-profile {
  position: relative;
  overflow: hidden;
  margin-bottom: 10px;
  padding: 18px;
  border: 1px solid color-mix(in srgb, var(--accent) 24%, var(--line));
  border-radius: 19px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 15%, var(--surface)), var(--surface) 70%);
  box-shadow: var(--shadow);
}

.detail-profile.is-lead {
  border-color: color-mix(in srgb, #9875e7 35%, transparent);
  background: linear-gradient(135deg, color-mix(in srgb, #754fc8 22%, var(--surface)), var(--surface) 72%);
}

.detail-heading {
  align-items: flex-start;
  gap: 12px;
}

.detail-heading .avatar {
  flex-basis: 52px;
  width: 52px;
  height: 52px;
  border-radius: 16px;
  font-size: 16px;
}

.detail-name {
  min-width: 0;
  flex: 1;
  padding-top: 2px;
}

.detail-name h1 {
  overflow-wrap: anywhere;
  font-size: 22px;
  line-height: 1.15;
}

.detail-name p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.role-badge {
  margin-top: 9px;
  background: color-mix(in srgb, #9875e7 20%, transparent);
  color: color-mix(in srgb, #a98df0 82%, var(--text));
}

.detail-total {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  margin-top: 19px;
  padding-top: 15px;
  border-top: 1px solid var(--line);
}

.detail-total span {
  color: var(--muted);
  font-size: 12px;
}

.detail-total strong {
  font-size: clamp(24px, 7vw, 31px);
  line-height: 1;
  letter-spacing: -.035em;
  white-space: nowrap;
}

.detail-kpi {
  margin-top: 14px;
}

.progress-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 11px;
}

.progress-label b {
  color: var(--text);
}

.progress-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 17%, transparent);
}

.progress-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--success));
  transition: width .4s ease;
}

.detail-card {
  margin-top: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--surface);
  box-shadow: 0 5px 20px rgba(0, 0, 0, .09);
}

.card-title {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 13px;
}

.card-icon {
  display: grid;
  width: 31px;
  height: 31px;
  place-items: center;
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 13%, transparent);
  color: var(--accent);
  font-size: 15px;
}

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

.payout {
  min-width: 0;
  padding: 12px;
  border-radius: 13px;
  background: var(--surface-soft);
}

.payout span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 11px;
}

.payout strong {
  display: block;
  overflow: hidden;
  color: var(--link);
  font-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.payout small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.25;
}

.money-list,
.metrics-list {
  border-radius: 13px;
  background: var(--surface-soft);
}

.money-row,
.metric-row {
  min-height: 42px;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 11px;
  border-bottom: 1px solid var(--line);
}

.money-row:last-child,
.metric-row:last-child {
  border-bottom: 0;
}

.money-row span,
.metric-row span:first-child {
  color: var(--muted);
  font-size: 12px;
}

.money-row strong,
.metric-row strong {
  font-size: 13px;
  text-align: right;
}

.money-row.total-row {
  min-height: 49px;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.money-row.total-row span,
.money-row.total-row strong {
  color: var(--text);
  font-size: 14px;
}

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

.metric-tile {
  min-width: 0;
  padding: 12px;
  border-radius: 13px;
  background: var(--surface-soft);
}

.metric-tile span {
  display: block;
  min-height: 28px;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.25;
}

.metric-tile strong {
  display: block;
  overflow: hidden;
  font-size: 17px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lead-score {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  padding: 13px;
  border-radius: 13px;
  background: color-mix(in srgb, #754fc8 13%, var(--surface-soft));
}

.lead-score span {
  color: var(--muted);
  font-size: 12px;
}

.lead-score strong {
  font-size: 23px;
}

.verdict-badge {
  max-width: 54%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.comment-card p {
  margin-bottom: 0;
  color: color-mix(in srgb, var(--text) 86%, var(--muted));
  font-size: 13px;
  line-height: 1.55;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@keyframes shimmer {
  100% { transform: translateX(100%); }
}

@keyframes rotate {
  to { transform: rotate(360deg); }
}

@media (min-width: 600px) {
  main {
    padding-right: 20px;
    padding-left: 20px;
  }

  .month-tabs {
    margin-right: -20px;
    margin-left: -20px;
    padding-right: 20px;
    padding-left: 20px;
  }

  .employees-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 340px) {
  main {
    padding-right: 10px;
    padding-left: 10px;
  }

  .app-header {
    padding-right: 12px;
    padding-left: 12px;
  }

  .month-tabs {
    margin-right: -10px;
    margin-left: -10px;
    padding-right: 10px;
    padding-left: 10px;
  }

  .summary-card,
  .detail-card {
    padding: 12px;
  }

  .employee-card {
    gap: 8px;
    padding: 10px;
  }

  .avatar {
    flex-basis: 40px;
    width: 40px;
    height: 40px;
  }

  .employee-total {
    max-width: 102px;
    font-size: 12px;
  }

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

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
