:root {
  color-scheme: light;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --blue-soft: #eff6ff;
  --green: #059669;
  --orange: #ea580c;
  --red: #dc2626;
  --ink: #172033;
  --muted: #667085;
  --line: #e5e7eb;
  --surface: #ffffff;
  --background: #f4f7fb;
  --shadow: 0 8px 30px rgba(24, 39, 75, 0.07);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
    "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--background);
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 100% 0, rgba(37, 99, 235, 0.08), transparent 30%),
    var(--background);
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 720px);
  min-height: 100vh;
  margin: 0 auto;
  padding:
    max(18px, env(safe-area-inset-top))
    18px
    calc(96px + env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.app-header h1,
.page-title h2,
.section-heading h2 {
  margin: 0;
}

.app-header h1 {
  font-size: 30px;
  letter-spacing: -0.04em;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 13px;
}

.icon-button {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 15px;
  color: white;
  background: var(--blue);
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.24);
  font-size: 26px;
  line-height: 1;
}

.page {
  display: none;
}

.page.active {
  display: block;
  animation: page-in 160ms ease-out;
}

@keyframes page-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 28px;
}

.backup-reminder {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 11px;
  width: 100%;
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid #fed7aa;
  border-radius: 15px;
  color: #9a3412;
  text-align: left;
  background: #fff7ed;
}

.backup-reminder > span:first-child {
  font-size: 22px;
}

.backup-reminder strong,
.backup-reminder small {
  display: block;
}

.backup-reminder small {
  margin-top: 2px;
  color: #c2410c;
  font-size: 11px;
}

.backup-reminder > span:last-child {
  font-size: 24px;
}

.summary-card {
  min-width: 0;
  padding: 17px 12px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.summary-card strong {
  display: block;
  margin-bottom: 4px;
  font-size: clamp(20px, 6vw, 27px);
  letter-spacing: -0.04em;
}

.summary-card span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-card.primary {
  color: white;
  border-color: transparent;
  background: linear-gradient(145deg, #2563eb, #3b82f6);
}

.summary-card.primary span {
  color: rgba(255, 255, 255, 0.76);
}

.section-heading,
.page-title {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin: 24px 2px 12px;
}

.page-title {
  align-items: center;
  margin-top: 0;
  margin-bottom: 18px;
}

.section-heading h2,
.page-title h2 {
  font-size: 20px;
}

.section-heading p,
.page-title p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.text-button {
  padding: 8px;
  border: 0;
  color: var(--blue);
  background: transparent;
}

.primary,
.secondary,
.danger-button {
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 13px;
  font-weight: 600;
}

.primary {
  border: 1px solid var(--blue);
  color: white;
  background: var(--blue);
}

.primary:active {
  background: var(--blue-dark);
}

.secondary {
  border: 1px solid var(--line);
  color: var(--ink);
  background: white;
}

.danger-button {
  border: 1px solid #fecaca;
  color: var(--red);
  background: #fff5f5;
}

.small {
  min-height: 38px;
  padding: 8px 13px;
  font-size: 14px;
}

.full {
  width: 100%;
}

.card-list {
  display: grid;
  gap: 11px;
}

.student-card,
.lesson-card,
.empty-state,
.settings-card {
  border: 1px solid rgba(229, 231, 235, 0.85);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.student-card {
  padding: 16px;
}

.student-card-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.student-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.student-name-row h3,
.settings-card h3 {
  margin: 0;
  font-size: 17px;
}

.status-badge {
  padding: 3px 7px;
  border-radius: 999px;
  color: var(--muted);
  background: #f2f4f7;
  font-size: 10px;
}

.student-meta {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.balance {
  flex: 0 0 auto;
  text-align: right;
}

.balance strong {
  display: block;
  color: var(--green);
  font-size: 22px;
}

.balance.warning strong {
  color: var(--orange);
}

.balance.empty strong {
  color: var(--red);
}

.balance span {
  color: var(--muted);
  font-size: 11px;
}

.progress {
  height: 6px;
  margin: 14px 0;
  overflow: hidden;
  border-radius: 999px;
  background: #eef1f5;
}

.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.progress.warning span {
  background: var(--orange);
}

.progress.empty span {
  background: var(--red);
}

.card-actions {
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.card-actions button {
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--ink);
  background: #fafafa;
  font-size: 13px;
  white-space: nowrap;
}

.card-actions button.action-primary {
  color: var(--blue);
  border-color: #bfdbfe;
  background: var(--blue-soft);
}

.lesson-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 14px;
}

.date-chip {
  width: 48px;
  padding: 7px 4px;
  border-radius: 13px;
  text-align: center;
  color: var(--blue);
  background: var(--blue-soft);
}

.date-chip strong,
.date-chip span {
  display: block;
}

.date-chip strong {
  font-size: 18px;
}

.date-chip span {
  font-size: 10px;
}

.lesson-info {
  min-width: 0;
}

.lesson-info strong,
.lesson-info span {
  display: block;
}

.lesson-info strong {
  margin-bottom: 4px;
}

.lesson-info span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lesson-units {
  text-align: right;
}

.lesson-units strong {
  display: block;
  color: var(--orange);
}

.lesson-menu {
  display: flex;
  gap: 4px;
  margin-top: 5px;
}

.lesson-menu button {
  padding: 3px 5px;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 11px;
}

.empty-state {
  padding: 30px 20px;
  text-align: center;
  color: var(--muted);
}

.empty-state strong {
  display: block;
  margin-bottom: 5px;
  color: var(--ink);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
}

.search-box input {
  width: 100%;
  height: 44px;
  border: 0;
  outline: 0;
  background: transparent;
}

.filter-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.filter-row select,
.filter-row input {
  width: 100%;
  height: 44px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--ink);
  background: white;
}

.settings-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  margin-bottom: 13px;
  padding: 17px;
}

.settings-card > button {
  grid-column: 1 / -1;
}

.settings-icon {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 13px;
  color: var(--blue);
  background: var(--blue-soft);
  font-weight: 700;
}

.settings-card p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.settings-card .backup-status {
  color: var(--blue);
}

.bottom-nav {
  position: fixed;
  z-index: 10;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  width: min(100%, 720px);
  margin: 0 auto;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(229, 231, 235, 0.85);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 -8px 30px rgba(24, 39, 75, 0.06);
  backdrop-filter: blur(18px);
}

.nav-item {
  display: grid;
  min-height: 52px;
  padding: 4px;
  place-items: center;
  border: 0;
  color: #98a2b3;
  background: transparent;
}

.nav-item span {
  font-size: 20px;
  line-height: 1;
}

.nav-item small {
  font-size: 10px;
}

.nav-item.active {
  color: var(--blue);
}

.nav-item.quick-action {
  align-content: center;
}

.nav-item.quick-action span {
  display: grid;
  width: 42px;
  height: 42px;
  margin-top: -24px;
  place-items: center;
  border: 4px solid var(--background);
  border-radius: 50%;
  color: white;
  background: var(--blue);
  box-shadow: 0 7px 18px rgba(37, 99, 235, 0.3);
  font-size: 25px;
}

dialog {
  width: min(calc(100% - 28px), 520px);
  max-height: calc(100dvh - 36px);
  padding: 20px;
  overflow-y: auto;
  border: 0;
  border-radius: 22px;
  color: var(--ink);
  background: white;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.25);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(3px);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.dialog-header h2 {
  margin: 0;
  font-size: 21px;
}

.dialog-close {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 12px;
  color: var(--muted);
  background: #f2f4f7;
  font-size: 22px;
}

form > label {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: #344054;
  font-size: 13px;
  font-weight: 600;
}

#initial-course-fields > label {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: #344054;
  font-size: 13px;
  font-weight: 600;
}

form input,
form select,
form textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid #d0d5dd;
  border-radius: 12px;
  outline: none;
  color: var(--ink);
  background: white;
  font-size: 16px;
  font-weight: 400;
}

.search-box input,
.filter-row select,
.filter-row input {
  font-size: 16px;
}

form input:focus,
form select:focus,
form textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

textarea {
  resize: vertical;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-grid label {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: #344054;
  font-size: 13px;
  font-weight: 600;
}

.form-hint,
.dialog-subtitle {
  margin: -3px 0 14px;
  color: var(--muted);
  font-size: 12px;
}

.form-hint.warning {
  color: var(--orange);
}

.detail-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}

.detail-summary div {
  padding: 12px 8px;
  border-radius: 13px;
  text-align: center;
  background: #f8fafc;
}

.detail-summary strong,
.detail-summary span {
  display: block;
}

.detail-summary strong {
  font-size: 19px;
}

.detail-summary span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}

.detail-section h3 {
  margin: 18px 0 9px;
  font-size: 15px;
}

.course-balance-list {
  display: grid;
  gap: 8px;
  margin: 14px 0 18px;
}

.course-balance-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fafcff;
}

.course-balance-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.course-balance-main h4 {
  margin: 0;
  font-size: 14px;
}

.course-balance-main p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.course-balance-main strong {
  color: var(--green);
  font-size: 19px;
}

.course-balance-actions {
  display: flex;
  gap: 5px;
  margin-top: 9px;
}

.course-balance-actions button {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: white;
  font-size: 11px;
}

.course-label {
  color: var(--blue);
  font-style: normal;
}

.detail-entry {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.detail-entry p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.detail-entry .positive {
  color: var(--green);
}

.detail-entry .negative {
  color: var(--orange);
}

.detail-entry-actions {
  flex: 0 0 auto;
  text-align: right;
}

.detail-entry-actions button {
  margin-top: 4px;
  padding: 2px 4px;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 11px;
}

.toast {
  position: fixed;
  z-index: 100;
  right: 18px;
  bottom: calc(92px + env(safe-area-inset-bottom));
  left: 18px;
  width: fit-content;
  max-width: calc(100% - 36px);
  margin: auto;
  padding: 11px 16px;
  border-radius: 12px;
  color: white;
  background: rgba(15, 23, 42, 0.92);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.2);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.hidden {
  display: none !important;
}

@media (max-width: 390px) {
  .app-shell {
    padding-right: 13px;
    padding-left: 13px;
  }

  .student-card-main {
    align-items: flex-start;
  }

  .form-grid {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .filter-row {
    grid-template-columns: 1fr 1fr;
  }

  .filter-row input {
    grid-column: 1 / -1;
  }
}

@media (min-width: 721px) {
  .bottom-nav {
    bottom: 14px;
    border: 1px solid var(--line);
    border-radius: 22px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
