:root {
  --tg-bg: #ffffff;
  --tg-secondary-bg: #f2f4f7;
  --tg-text: #111214;
  --tg-hint: #6f7480;
  --tg-link: #2a6df4;
  --tg-button: #2a6df4;
  --tg-button-text: #ffffff;
  --tg-header-bg: #ffffff;
  --tg-accent: #2a6df4;

  --pos: #1f9d55;
  --neg: #dd4a4a;
  --line: rgba(17, 18, 20, 0.08);
  --shadow: 0 8px 24px rgba(17, 18, 20, 0.08);
  --radius: 18px;
}

html[data-theme="dark"] {
  --tg-bg: #131417;
  --tg-secondary-bg: #1e2025;
  --tg-text: #f2f3f5;
  --tg-hint: #9aa0ab;
  --tg-link: #6da6ff;
  --tg-button: #3d7bf6;
  --tg-button-text: #ffffff;
  --tg-header-bg: #131417;
  --tg-accent: #6da6ff;

  --pos: #4fd48a;
  --neg: #ff7a7a;
  --line: rgba(255, 255, 255, 0.09);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--tg-bg);
  color: var(--tg-text);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

h1,
h2 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.02em;
}

h1 {
  font-size: 20px;
}

h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--tg-hint);
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(28px + env(safe-area-inset-bottom));
  min-height: 100dvh;
}

/* ---------- boot ---------- */

.boot {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tg-bg);
  z-index: 50;
}

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--tg-button);
  animation: spin 0.8s linear infinite;
}

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

/* ---------- topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 2px 18px;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 650;
  font-size: 17px;
  color: var(--tg-button-text);
  background: var(--tg-button);
  flex: none;
}

.avatar.sm {
  width: 34px;
  height: 34px;
  font-size: 14px;
}

.who {
  min-width: 0;
  flex: 1;
}

.who .name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.who .handle {
  color: var(--tg-hint);
  font-size: 13px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--tg-secondary-bg);
  display: grid;
  place-items: center;
  font-size: 18px;
  cursor: pointer;
  flex: none;
}

.icon-btn:active {
  transform: scale(0.96);
}

/* ---------- balance ---------- */

.balance-card {
  position: relative;
  overflow: hidden;
  border-radius: 24px;
  padding: 22px;
  color: var(--tg-button-text);
  background:
    radial-gradient(120% 120% at 8% 0%, rgba(255, 255, 255, 0.3), transparent 55%),
    radial-gradient(120% 120% at 100% 110%, rgba(255, 255, 255, 0.16), transparent 60%),
    var(--tg-button);
  box-shadow: var(--shadow);
  margin-bottom: 22px;
}

.balance-label {
  font-size: 13px;
  opacity: 0.85;
  letter-spacing: 0.02em;
}

.balance-value {
  font-size: 46px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin: 4px 0 16px;
  font-variant-numeric: tabular-nums;
}

.balance-row {
  display: flex;
  gap: 10px;
}

/* ---------- buttons ---------- */

.btn {
  border: 0;
  border-radius: 14px;
  padding: 11px 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.06s ease, opacity 0.15s ease;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn:active {
  transform: scale(0.97);
}

.btn.primary {
  background: var(--tg-button);
  color: var(--tg-button-text);
}

.balance-card .btn.primary {
  background: rgba(255, 255, 255, 0.95);
  color: var(--tg-button);
}

.balance-card .btn.ghost {
  background: rgba(255, 255, 255, 0.16);
  color: var(--tg-button-text);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.btn.ghost {
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  border: 1px solid var(--line);
}

.btn.danger {
  background: transparent;
  color: var(--neg);
  border: 1px solid var(--line);
}

.btn.small {
  min-height: 36px;
  padding: 7px 12px;
  font-size: 13px;
  border-radius: 11px;
}

.btn.block {
  width: 100%;
}

.btn[disabled] {
  opacity: 0.45;
  pointer-events: none;
}

/* ---------- structure ---------- */

.block {
  margin-bottom: 22px;
}

.block > h2 {
  margin-bottom: 10px;
  padding-left: 2px;
}

.screen-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0 18px;
}

.screen-head h1 {
  flex: 1;
}

.screen-head .icon-btn.back {
  font-size: 24px;
  line-height: 1;
}

.label {
  display: block;
  font-size: 13px;
  color: var(--tg-hint);
  margin-bottom: 8px;
  padding-left: 2px;
}

.input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--tg-secondary-bg);
  border-radius: 14px;
  padding: 12px 14px;
  min-height: 46px;
  outline: none;
  transition: border-color 0.15s ease;
}

.input:focus {
  border-color: var(--tg-button);
}

.input.amount {
  font-size: 26px;
  font-weight: 650;
  text-align: center;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  padding: 14px;
}

.hint {
  color: var(--tg-hint);
  font-size: 13px;
  margin: 10px 2px 0;
}

/* ---------- transactions ---------- */

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

.tx {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 15px;
  background: var(--tg-secondary-bg);
}

.tx-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 700;
  flex: none;
  background: rgba(31, 157, 85, 0.14);
  color: var(--pos);
}

.tx.neg .tx-icon {
  background: rgba(221, 74, 74, 0.14);
  color: var(--neg);
}

.tx-main {
  flex: 1;
  min-width: 0;
}

.tx-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-sub {
  color: var(--tg-hint);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-amount {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--pos);
  flex: none;
}

.tx.neg .tx-amount {
  color: var(--neg);
}

/* ---------- user list ---------- */

.user-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
  width: 100%;
}

.user-row:active {
  background: var(--tg-secondary-bg);
}

.user-row .name {
  font-weight: 600;
}

.user-row .handle {
  color: var(--tg-hint);
  font-size: 12.5px;
}

.user-row .grow {
  flex: 1;
  min-width: 0;
}

.user-row .balance {
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

/* ---------- teacher student list ---------- */

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.section-head h2 {
  margin: 0;
}

.head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 10px 0 2px;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip-btn {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  min-height: 34px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--tg-text);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.chip-btn.active {
  background: var(--tg-button);
  border-color: var(--tg-button);
  color: var(--tg-button-text);
}

.chip-count {
  font-size: 11.5px;
  opacity: 0.65;
  font-variant-numeric: tabular-nums;
}

.class-tag {
  color: var(--tg-text);
  font-weight: 600;
}

.pending-item {
  margin-bottom: 10px;
}

.pending-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: -4px;
}

.pending-actions .class-select {
  flex: 1;
  min-width: 0;
  min-height: 36px;
  padding: 6px 10px;
  font-size: 13px;
}

.class-manage-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.class-manage-row .grow {
  flex: 1;
  min-width: 0;
}

.class-manage-row .name {
  font-weight: 600;
}

.class-manage-row .handle {
  color: var(--tg-hint);
  font-size: 12.5px;
}

.class-manage {
  margin-bottom: 8px;
}

.grid-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
}

.student-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 6px 6px 6px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
}

.student-main {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.student-main:active {
  opacity: 0.6;
}

.student-main .grow {
  flex: 1;
  min-width: 0;
}

.student-main .name,
.student-main .handle {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.student-main .name {
  font-weight: 600;
}

.student-main .handle {
  color: var(--tg-hint);
  font-size: 12.5px;
}

.student-main .balance {
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.quick {
  display: flex;
  align-items: center;
  gap: 6px;
}

.quick-btn {
  width: 46px;
  height: 40px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  font-weight: 700;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: transform 0.06s ease, opacity 0.15s ease;
}

.quick-btn.plus {
  background: var(--tg-button);
  border-color: var(--tg-button);
  color: var(--tg-button-text);
}

.quick-btn:active {
  transform: scale(0.95);
}

.quick-btn[disabled] {
  opacity: 0.45;
  pointer-events: none;
}

.picked {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--tg-button);
  background: rgba(42, 109, 244, 0.08);
}

.picked .grow {
  flex: 1;
  min-width: 0;
}

.chip {
  display: inline-block;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--tg-secondary-bg);
  color: var(--tg-hint);
}

.chip.teacher {
  background: rgba(42, 109, 244, 0.14);
  color: var(--tg-accent);
}

.chip.pending {
  background: rgba(240, 170, 30, 0.16);
  color: #b57a00;
}

.chip.removed,
.chip.rejected {
  background: rgba(221, 74, 74, 0.14);
  color: var(--neg);
}

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: var(--tg-secondary-bg);
  margin-bottom: 16px;
}

.tab {
  flex: 1;
  border: 0;
  background: transparent;
  border-radius: 11px;
  padding: 9px 6px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--tg-hint);
  cursor: pointer;
}

.tab.active {
  background: var(--tg-bg);
  color: var(--tg-text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

/* ---------- cards ---------- */

.card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 15px;
  background: var(--tg-secondary-bg);
  margin-bottom: 8px;
}

.card .grow {
  flex: 1;
  min-width: 0;
}

.card .name {
  font-weight: 600;
}

.card .handle {
  color: var(--tg-hint);
  font-size: 12.5px;
}

.actions {
  display: flex;
  gap: 8px;
}

/* ---------- empty / loader ---------- */

.empty {
  text-align: center;
  color: var(--tg-hint);
  padding: 34px 16px;
  font-size: 14px;
}

.empty strong {
  display: block;
  color: var(--tg-text);
  margin-bottom: 4px;
  font-size: 15px;
}

.empty.small {
  padding: 16px;
}

.loader {
  width: 22px;
  height: 22px;
  margin: 26px auto;
  border-radius: 50%;
  border: 2.5px solid var(--line);
  border-top-color: var(--tg-button);
  animation: spin 0.8s linear infinite;
}

.skeleton-list {
  display: block;
  min-height: 60px;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  max-width: min(90vw, 420px);
  background: var(--tg-text);
  color: var(--tg-bg);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 80;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- sheet ---------- */

.sheet-root {
  position: fixed;
  inset: 0;
  z-index: 70;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  background: var(--tg-bg);
  border-radius: 22px 22px 0 0;
  padding: 10px 18px calc(20px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
  max-height: 88dvh;
  overflow-y: auto;
}

.sheet-root.open .sheet-backdrop {
  opacity: 1;
}

.sheet-root.open .sheet {
  transform: translateY(0);
}

.sheet-grabber {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
  margin: 2px auto 14px;
}

.sheet h2 {
  color: var(--tg-text);
  text-transform: none;
  letter-spacing: -0.01em;
  font-size: 18px;
  margin-bottom: 4px;
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

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

.sheet-head .grow {
  flex: 1;
  min-width: 0;
}

.sheet-head .handle {
  color: var(--tg-hint);
  font-size: 13px;
}

.sheet .label {
  margin-top: 0;
}

.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 18px;
}

.sheet-actions .btn {
  width: 100%;
}

.balance-line {
  display: flex;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--tg-secondary-bg);
  font-weight: 600;
  margin-bottom: 18px;
}

.textarea {
  min-height: 78px;
  resize: vertical;
}

.fatal {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 26vh 24px 0;
  gap: 12px;
}

.fatal .emoji {
  font-size: 40px;
}

.fatal p {
  color: var(--tg-hint);
  margin: 0;
  max-width: 34ch;
}
