.student-detail-page {
  --student-surface: var(--bg-primary, #fff);
  --student-surface-soft: var(--bg-secondary, #f5f7fb);
  --student-border: var(--border-color, #e3e7ef);
  --student-text: var(--text-primary, #172033);
  --student-muted: var(--text-muted, #667085);
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: 100%;
  min-width: 0;
  max-width: 1440px;
  margin: 0 auto;
  color: var(--student-text);
}

.student-detail-topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
}

.student-detail-back {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 0;
  background: transparent;
  color: var(--color-primary, #1f3c88);
  font-weight: 700;
  cursor: pointer;
  padding: 10px 4px;
}

.student-detail-back svg { transform: rotate(180deg); }
.student-detail-back:hover { opacity: .72; }
.student-detail-back:focus-visible,
.student-detail-tab:focus-visible,
.student-detail-copy-id:focus-visible,
.student-detail-actions > summary:focus-visible,
.student-detail-row-menu > summary:focus-visible,
.student-detail-row-details > summary:focus-visible,
.student-detail-group-link:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--color-primary, #1f3c88) 28%, transparent);
  outline-offset: 3px;
}

.student-detail-heading {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
}

.student-detail-avatar {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  background: linear-gradient(145deg, #5579d8, #1f3c88);
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(31, 60, 136, .18);
}

.student-detail-heading-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 9px;
}

.student-detail-heading h1 {
  margin: 0;
  font-size: clamp(22px, 3vw, 32px);
  line-height: 1.12;
  overflow-wrap: anywhere;
}

.student-detail-subtitle {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  color: var(--student-muted);
  font-size: 12px;
  margin-top: 4px;
}

.student-detail-copy-id {
  display: inline-grid;
  place-items: center;
  width: 27px;
  height: 27px;
  border: 1px solid var(--student-border);
  border-radius: 8px;
  background: var(--student-surface);
  color: var(--color-primary, #1f3c88);
  cursor: pointer;
}

.student-detail-header-actions,
.student-detail-inline-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.student-detail-actions,
.student-detail-row-menu { position: relative; }
.student-detail-actions > summary,
.student-detail-row-menu > summary { list-style: none; cursor: pointer; user-select: none; }
.student-detail-actions > summary::-webkit-details-marker,
.student-detail-row-menu > summary::-webkit-details-marker { display: none; }
.student-detail-actions-menu,
.student-detail-row-menu > div {
  position: absolute;
  z-index: 15;
  right: 0;
  top: calc(100% + 6px);
  display: grid;
  min-width: 210px;
  padding: 6px;
  border: 1px solid var(--student-border);
  border-radius: 12px;
  background: var(--student-surface);
  box-shadow: 0 14px 32px rgba(16, 24, 40, .15);
}
.student-detail-actions-menu button,
.student-detail-row-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--student-text);
  text-align: left;
  cursor: pointer;
}
.student-detail-actions-menu button:hover,
.student-detail-row-menu button:hover { background: var(--student-surface-soft); }

.student-detail-badge,
.student-detail-status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 11px;
  line-height: 1.2;
  font-weight: 750;
  white-space: nowrap;
}

.student-detail-badge.is-active,
.student-detail-status.is-present { color: #087a45; background: rgba(16, 185, 129, .13); }
.student-detail-badge.is-archived,
.student-detail-status.is-absent { color: #b42318; background: rgba(239, 68, 68, .12); }
.student-detail-badge.is-ungrouped,
.student-detail-status.is-unmarked { color: #475467; background: rgba(102, 112, 133, .14); }
.student-detail-badge.is-paused { color: #b54708; background: rgba(245, 158, 11, .15); }
.student-detail-status.is-late { color: #b54708; background: rgba(245, 158, 11, .15); }
.student-detail-status.is-excused { color: #175cd3; background: rgba(59, 130, 246, .13); }

.student-detail-tabs {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  border-bottom: 1px solid var(--student-border);
  scrollbar-width: thin;
}

.student-detail-tab {
  flex: 0 0 auto;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--student-muted);
  padding: 12px 16px 10px;
  font-weight: 700;
  cursor: pointer;
}

.student-detail-tab:hover { color: var(--student-text); }
.student-detail-tab.is-active { color: var(--color-primary, #1f3c88); border-bottom-color: currentColor; }
.student-detail-panel { min-width: 0; min-height: 260px; }

.student-detail-state,
.student-detail-empty,
.student-detail-error {
  min-height: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  padding: 24px;
  border: 1px dashed var(--student-border);
  border-radius: 16px;
  background: var(--student-surface-soft);
  color: var(--student-muted);
}

.student-detail-empty { min-height: 105px; }
.student-detail-empty strong,
.student-detail-error strong { color: var(--student-text); }
.student-detail-error { border-color: rgba(239, 68, 68, .35); }

.student-detail-spinner {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 3px solid var(--student-border);
  border-top-color: var(--color-primary, #1f3c88);
  animation: student-detail-spin .8s linear infinite;
}

@keyframes student-detail-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .student-detail-spinner { animation: none; } }

.student-detail-overview-grid,
.student-detail-finance-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.student-detail-card {
  min-width: 0;
  background: var(--student-surface);
  border: 1px solid var(--student-border);
  border-radius: 16px;
  padding: 17px;
  box-shadow: 0 5px 18px rgba(16, 24, 40, .045);
  margin-bottom: 14px;
}

.student-detail-card h2 {
  font-size: 15px;
  margin: 0 0 14px;
  color: var(--student-text);
}

.student-detail-card-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 13px;
}

.student-detail-card-heading h2 { margin: 0; }
.student-detail-definition { display: grid; gap: 10px; margin: 0; }
.student-detail-definition > div { display: grid; grid-template-columns: minmax(110px, .8fr) minmax(0, 1.2fr); gap: 12px; }
.student-detail-definition dt { color: var(--student-muted); }
.student-detail-definition dd { margin: 0; text-align: right; font-weight: 650; overflow-wrap: anywhere; }
.student-detail-definition.is-compact { margin-top: 14px; font-size: 12px; }

.student-detail-group-list,
.student-detail-list { display: grid; gap: 9px; }
.student-detail-group,
.student-detail-list > div {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 11px;
  background: var(--student-surface-soft);
  border-radius: 10px;
}
.student-detail-group span,
.student-detail-list span { color: var(--student-muted); font-size: 12px; text-align: right; }
.student-detail-group-link { color: var(--color-primary, #1f3c88); text-decoration: none; }
.student-detail-group-link:hover { text-decoration: underline; }

.student-detail-balance {
  font-size: clamp(25px, 4vw, 36px);
  line-height: 1;
  font-weight: 800;
  margin: 8px 0 10px;
}
.student-detail-balance.is-negative { color: #d92d20; }
.student-detail-balance.is-positive { color: #039855; }
.student-detail-balance.is-zero { color: var(--student-muted); }
.student-detail-muted { color: var(--student-muted); font-size: 12px; }

.student-detail-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 9px;
  margin-bottom: 14px;
}
.student-detail-stat {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 11px;
  border: 1px solid var(--student-border);
  border-radius: 12px;
  background: var(--student-surface);
}
.student-detail-stat span { color: var(--student-muted); font-size: 11px; }
.student-detail-stat strong { font-size: 21px; }
.student-detail-stat.is-present strong { color: #039855; }
.student-detail-stat.is-late strong { color: #dc6803; }
.student-detail-stat.is-absent strong { color: #d92d20; }
.student-detail-stat.is-excused strong { color: #175cd3; }
.student-detail-stat.is-percentage { background: color-mix(in srgb, var(--color-primary, #1f3c88) 8%, var(--student-surface)); }

.student-detail-timeline { display: grid; gap: 3px; }
.student-detail-timeline-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px 2px;
  border-bottom: 1px solid var(--student-border);
}
.student-detail-timeline-item:last-child { border-bottom: 0; }
.student-detail-timeline-item > div:nth-child(2) { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.student-detail-timeline-item > div:nth-child(2) span { color: var(--student-muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.student-detail-dot { width: 9px; height: 9px; border-radius: 50%; background: #98a2b3; }
.student-detail-dot.is-present { background: #12b76a; }
.student-detail-dot.is-late { background: #f79009; }
.student-detail-dot.is-absent { background: #f04438; }
.student-detail-dot.is-excused { background: #2e90fa; }
.student-detail-lesson-flags { display: flex; align-items: flex-end; flex-direction: column; gap: 4px; }
.student-detail-lesson-flags small,
.student-detail-note { color: var(--student-muted); font-size: 10px; display: block; margin-top: 3px; }

.student-detail-next,
.student-detail-lk {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 13px;
  padding: 12px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--color-primary, #1f3c88) 8%, var(--student-surface));
}
.student-detail-next span,
.student-detail-next small,
.student-detail-lk span { color: var(--student-muted); font-size: 11px; }
.student-detail-lk .student-detail-inline-actions { justify-content: flex-start; margin-top: 7px; }

.student-detail-notice,
.student-detail-permission-note {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 11px 13px;
  border-radius: 11px;
  margin-bottom: 14px;
  line-height: 1.45;
  font-size: 12px;
}
.student-detail-notice.is-warning { color: #93480b; border: 1px solid rgba(245, 158, 11, .35); background: rgba(245, 158, 11, .1); }
.student-detail-permission-note { color: var(--student-muted); background: var(--student-surface-soft); margin: 12px 0 0; }

.student-detail-filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr)) auto;
  align-items: end;
  gap: 10px;
  padding: 14px;
  margin-bottom: 14px;
  border: 1px solid var(--student-border);
  border-radius: 14px;
  background: var(--student-surface);
}
.student-detail-filters label { display: flex; flex-direction: column; gap: 5px; color: var(--student-muted); font-size: 11px; }
.student-detail-filter-actions { display: flex; gap: 7px; }

.student-detail-table-wrap { width: 100%; min-width: 0; overflow-x: auto; }
.student-detail-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.student-detail-table th { color: var(--student-muted); font-weight: 650; text-align: left; padding: 9px; border-bottom: 1px solid var(--student-border); }
.student-detail-table td { padding: 11px 9px; border-bottom: 1px solid var(--student-border); vertical-align: top; }
.student-detail-table tbody tr:hover { background: var(--student-surface-soft); }
.student-detail-pagination { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 15px; }
.student-detail-pagination span { color: var(--student-muted); font-size: 12px; }

.student-detail-row-details > summary,
.student-detail-row-menu > summary {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--color-primary, #1f3c88);
  font-weight: 650;
  cursor: pointer;
}
.student-detail-row-details dl { display: grid; gap: 5px; margin: 9px 0 0; }
.student-detail-row-details dl > div { display: grid; grid-template-columns: minmax(95px, .8fr) minmax(0, 1.2fr); gap: 8px; }
.student-detail-row-details dt { color: var(--student-muted); }
.student-detail-row-details dd { margin: 0; overflow-wrap: anywhere; }
.student-detail-row-menu > summary span { display: none; }

.student-detail-group-summary > div {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 9px;
}
.student-detail-group-summary section {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 11px;
  border-radius: 11px;
  background: var(--student-surface-soft);
}
.student-detail-group-summary span,
.student-detail-group-summary small { color: var(--student-muted); }

.student-detail-wallets > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
}
.student-detail-wallets > summary > span:first-child { display: flex; flex-direction: column; gap: 3px; }
.student-detail-wallets > summary small { color: var(--student-muted); font-weight: 400; }
.student-detail-wallets[open] > summary { margin-bottom: 13px; }
.student-detail-wallet-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 9px; }
.student-detail-wallet-grid > section { padding: 11px; border-radius: 11px; background: var(--student-surface-soft); }
.student-detail-wallet-grid dl { display: grid; gap: 4px; margin: 8px 0 0; }
.student-detail-wallet-grid dl > div { display: flex; justify-content: space-between; gap: 10px; }
.student-detail-wallet-grid dt { color: var(--student-muted); }
.student-detail-wallet-grid dd { margin: 0; text-align: right; }

.student-detail-finance-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 0 0 13px;
}
.student-detail-finance-summary > span {
  padding: 7px 10px;
  border-radius: 9px;
  background: var(--student-surface-soft);
  color: var(--student-muted);
  font-size: 11px;
}
.student-detail-finance-summary strong { color: var(--student-text); }

.student-detail-debt-list { display: grid; gap: 9px; }
.student-detail-debt-list > section {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 11px 12px;
  border-left: 3px solid var(--color-primary, #1f3c88);
  border-radius: 10px;
  background: var(--student-surface-soft);
}
.student-detail-debt-list > section > div { display: flex; justify-content: space-between; gap: 10px; }
.student-detail-debt-list p { margin: 0; }
.student-detail-debt-list small { color: var(--student-muted); }
.student-detail-debt-list .btn { align-self: flex-start; margin-top: 5px; }

.student-detail-history-list { display: grid; gap: 0; }
.student-detail-history-list > div { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 11px; padding: 9px 0; }
.student-detail-history-list > div > div { display: flex; flex-direction: column; gap: 3px; }
.student-detail-history-list span,
.student-detail-history-list small { color: var(--student-muted); }
.student-detail-history-marker { width: 10px; height: 10px; margin-top: 5px; border-radius: 50%; background: #2e90fa; box-shadow: 0 0 0 4px rgba(46, 144, 250, .12); }
.student-detail-history-marker.is-archive { background: #f04438; box-shadow: 0 0 0 4px rgba(240, 68, 56, .12); }
.student-detail-history-marker.is-restore { background: #12b76a; box-shadow: 0 0 0 4px rgba(18, 183, 106, .12); }

@media (max-width: 1100px) {
  .student-detail-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .student-detail-filters { grid-template-columns: repeat(2, minmax(150px, 1fr)); }
  .student-detail-filter-actions { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  .student-detail-page { gap: 13px; }
  .student-detail-topbar { grid-template-columns: minmax(0, 1fr) auto; }
  .student-detail-back { grid-column: 1 / -1; justify-self: start; }
  .student-detail-heading { min-width: 0; }
  .student-detail-header-actions { align-self: start; }
  .student-detail-overview-grid,
  .student-detail-finance-grid { grid-template-columns: 1fr; }
  .student-detail-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .student-detail-stat.is-percentage { grid-column: 1 / -1; }
  .student-detail-filters { grid-template-columns: 1fr; }
  .student-detail-filter-actions { grid-column: auto; }
  .student-detail-timeline-item { grid-template-columns: auto minmax(0, 1fr); }
  .student-detail-lesson-flags { grid-column: 2; align-items: flex-start; flex-direction: row; flex-wrap: wrap; }
  .student-detail-table thead { display: none; }
  .student-detail-table,
  .student-detail-table tbody,
  .student-detail-table tr,
  .student-detail-table td { display: block; width: 100%; }
  .student-detail-table tr { border: 1px solid var(--student-border); border-radius: 12px; padding: 7px 10px; margin-bottom: 9px; }
  .student-detail-table td { display: grid; grid-template-columns: minmax(90px, .7fr) minmax(0, 1.3fr); gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--student-border); }
  .student-detail-table td:last-child { border-bottom: 0; }
  .student-detail-table td::before { content: attr(data-label); color: var(--student-muted); font-size: 11px; }
  .student-detail-row-menu > summary span { display: inline; }
  .student-detail-row-menu > div { left: 0; right: auto; }
}

@media (max-width: 480px) {
  .student-detail-avatar { width: 42px; height: 42px; border-radius: 13px; }
  .student-detail-topbar { grid-template-columns: 1fr; }
  .student-detail-header-actions { width: 100%; justify-content: stretch; }
  .student-detail-header-actions > .btn,
  .student-detail-header-actions > details { flex: 1 1 140px; }
  .student-detail-header-actions > details > summary { justify-content: center; }
  .student-detail-actions-menu { left: auto; right: 0; max-width: calc(100vw - 32px); }
  .student-detail-card { padding: 13px; border-radius: 13px; }
  .student-detail-summary { grid-template-columns: 1fr 1fr; }
  .student-detail-definition > div { grid-template-columns: 1fr; gap: 3px; }
  .student-detail-definition dd { text-align: left; }
  .student-detail-group,
  .student-detail-list > div { flex-direction: column; }
  .student-detail-group span,
  .student-detail-list span { text-align: left; }
  .student-detail-filter-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .student-detail-pagination { gap: 6px; }
  .student-detail-pagination .btn { padding-inline: 10px; }
  .student-detail-row-details dl > div { grid-template-columns: 1fr; gap: 1px; }
}
