:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --button: var(--tg-theme-button-color, #2481cc);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --accent-green: #34c759;
  --accent-red: #ff3b30;
  --accent-orange: #ff9500;
  --accent-blue: #007aff;
  --surface: var(--secondary-bg);
  --divider: rgba(128,128,128,0.15);
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ── */
header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--secondary-bg);
  padding: 10px 16px;
  display: flex;
  gap: 8px;
  align-items: center;
  border-bottom: 1px solid var(--divider);
}

#branch-select,
#month-select,
#year-select {
  flex: 1;
  padding: 7px 8px;
  border: 1px solid var(--divider);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
}

#branch-select { flex: 2; }

/* ── Tab nav ── */
.tabs {
  display: flex;
  background: var(--secondary-bg);
  padding: 0 8px;
  border-bottom: 1px solid var(--divider);
}

.tab-btn {
  flex: 1;
  padding: 11px 4px;
  border: none;
  background: transparent;
  color: var(--hint);
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn.active {
  color: var(--button);
  border-bottom-color: var(--button);
  font-weight: 600;
}

/* ── Tab content ── */
.tab-content { display: none; padding: 16px; }
.tab-content.active { display: block; }

/* ── Section heading ── */
.section-heading {
  font-size: 11px;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 0 4px;
  margin: 20px 0 8px;
}
.section-heading:first-child { margin-top: 0; }

/* ── Stat grid (big numbers) ── */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.stat-grid.single { grid-template-columns: 1fr; }

.stat-tile {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
}

.stat-tile .tile-label {
  font-size: 12px;
  color: var(--hint);
  margin-bottom: 6px;
}

.stat-tile .tile-value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1;
}

.stat-tile .tile-value.green { color: var(--accent-green); }
.stat-tile .tile-value.red   { color: var(--accent-red); }
.stat-tile .tile-value.orange{ color: var(--accent-orange); }
.stat-tile .tile-value.blue  { color: var(--accent-blue); }

.stat-tile .tile-sub {
  font-size: 11px;
  color: var(--hint);
  margin-top: 4px;
}

/* ── List card ── */
.list-card {
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}

.list-card-header {
  padding: 12px 14px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--divider);
}

.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--divider);
}

.list-row:last-child { border-bottom: none; }

.list-row .row-label { color: var(--text); font-size: 14px; }
.list-row .row-value { font-weight: 600; font-size: 14px; }

/* ── Revenue hero ── */
.revenue-hero {
  background: var(--button);
  border-radius: var(--radius);
  padding: 20px 16px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.revenue-hero .hero-label {
  font-size: 13px;
  color: rgba(255,255,255,0.75);
  margin-bottom: 6px;
}

.revenue-hero .hero-value {
  font-size: 26px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.5px;
}

.revenue-hero .hero-badge {
  font-size: 13px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(255,255,255,0.2);
  color: #fff;
}

/* ── Badge (inline) ── */
.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 10px;
  margin-left: 6px;
  font-weight: 600;
}
.badge-up   { background: rgba(52,199,89,0.15);  color: var(--accent-green); }
.badge-down { background: rgba(255,59,48,0.15);   color: var(--accent-red); }

/* ── Trainer rows ── */
.trainer-row {
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 8px;
  overflow: hidden;
  cursor: pointer;
}

.trainer-header {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  gap: 10px;
}

.chevron {
  color: var(--hint);
  font-size: 11px;
  transition: transform 0.2s;
  display: inline-block;
  flex-shrink: 0;
}
.trainer-row.expanded .chevron { transform: rotate(90deg); }

.trainer-name { flex: 1; font-weight: 600; font-size: 15px; }

.trainer-summary {
  font-size: 13px;
  color: var(--hint);
  text-align: right;
}

.trainer-breakdown {
  display: none;
  padding: 0 14px 12px;
  border-top: 1px solid var(--divider);
}
.trainer-row.expanded .trainer-breakdown { display: block; }

.breakdown-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 12px;
  color: var(--hint);
  border-bottom: 1px solid var(--divider);
}
.breakdown-row:last-child { border-bottom: none; }

/* Trainer total bar */
.trainer-total-bar {
  background: var(--button);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.trainer-total-bar .bar-label { font-size: 13px; color: rgba(255,255,255,0.8); }
.trainer-total-bar .bar-value { font-size: 20px; font-weight: 700; color: #fff; }

/* ── Days toggle ── */
.days-toggle {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
}

.toggle-btn {
  padding: 5px 14px;
  border: 1px solid var(--divider);
  border-radius: 20px;
  background: var(--bg);
  color: var(--hint);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}
.toggle-btn.active {
  background: var(--button);
  color: var(--button-text);
  border-color: var(--button);
  font-weight: 600;
}

/* ── Member rows ── */
.member-list { background: var(--surface); border-radius: var(--radius); overflow: hidden; }

.member-row {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  gap: 10px;
  border-bottom: 1px solid var(--divider);
}
.member-row:last-child { border-bottom: none; }

.member-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--button);
  color: var(--button-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.member-info { flex: 1; min-width: 0; }
.member-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member-detail { font-size: 12px; color: var(--hint); margin-top: 1px; }

.member-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 10px;
  flex-shrink: 0;
  white-space: nowrap;
}
.member-badge.warn  { background: rgba(255,149,0,0.15);  color: var(--accent-orange); }
.member-badge.danger{ background: rgba(255,59,48,0.15);   color: var(--accent-red); }
.member-badge.info  { background: rgba(0,122,255,0.15);   color: var(--accent-blue); }

/* Members section header row */
.members-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  margin-top: 20px;
}
.members-section-header:first-child { margin-top: 0; }
.members-section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Skeleton ── */
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}
.skeleton {
  background: linear-gradient(90deg, var(--secondary-bg) 25%, rgba(128,128,128,0.1) 50%, var(--secondary-bg) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  height: 60px;
  border-radius: var(--radius);
  margin-bottom: 10px;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: rgba(0,0,0,0.8);
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 9999;
  transition: transform 0.25s ease;
  white-space: nowrap;
  backdrop-filter: blur(8px);
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ── Empty ── */
.empty-state {
  text-align: center;
  color: var(--hint);
  padding: 32px 16px;
  font-size: 14px;
}

/* ── Login ── */
#login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 32px 20px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border-radius: 20px;
  padding: 28px 24px;
}

.login-card h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
}

.login-card .login-sub {
  font-size: 13px;
  color: var(--hint);
  margin-bottom: 24px;
}

.login-field {
  margin-bottom: 14px;
}

.login-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 6px;
}

.login-field input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--divider);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  transition: border-color 0.15s;
}

.login-field input:focus {
  outline: none;
  border-color: var(--button);
}

.login-error {
  display: none;
  font-size: 13px;
  color: var(--accent-red);
  text-align: center;
  margin-bottom: 14px;
  padding: 8px 12px;
  background: rgba(255,59,48,0.08);
  border-radius: 8px;
}

.login-btn {
  width: 100%;
  padding: 13px;
  background: var(--button);
  color: var(--button-text);
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s;
  margin-top: 4px;
}
.login-btn:active { opacity: 0.85; }
.login-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Rate row (set PT session price) ── */
.rate-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid var(--divider);
  margin-top: 4px;
}
.rate-input {
  flex: 1;
  padding: 6px 10px;
  border: 1.5px solid var(--button);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
.rate-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.rate-btn.primary { background: var(--button); color: var(--button-text); }
.rate-btn.secondary { background: var(--secondary-bg); color: var(--hint); }
