@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@500;600&display=swap');

:root {
  --sky: #22ade0;
  --sky-deep: #0f8fc4;
  --sky-pale: #eaf7fd;
  --purple: #7c4dff;
  --magenta: #ec4899;
  --bg: #ffffff;
  --surface: #f6f9fc;
  --surface-alt: #eef4fa;
  --border: #e3ebf2;
  --ink: #0f1b2d;
  --ink-soft: #64748b;
  --good: #16a34a;
  --good-soft: #e8f8ee;
  --due: #ef4444;
  --due-soft: #fdeeee;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 2px 8px rgba(15,27,45,0.05), 0 10px 30px rgba(15,27,45,0.06);
  --shadow-hover: 0 14px 34px rgba(15,27,45,0.11);
  --brand-gradient: linear-gradient(135deg, var(--sky) 0%, var(--purple) 60%, var(--magenta) 100%);
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .display {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  letter-spacing: -0.015em;
  margin: 0;
}

.money {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  letter-spacing: -0.01em;
}

a { color: inherit; }
button, input, select { font-family: inherit; font-size: inherit; }
:focus-visible { outline: 2px solid var(--sky); outline-offset: 2px; }

/* ---------------------------------------------------------------
   Ambient background — soft drifting gradient blobs, tech-atmosphere
--------------------------------------------------------------- */
.bg-atmosphere {
  position: fixed; inset: 0;
  overflow: hidden;
  z-index: -1;
  pointer-events: none;
}
.bg-atmosphere span {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.18;
  animation: drift 26s ease-in-out infinite;
}
.bg-atmosphere span:nth-child(1) { width: 380px; height: 380px; background: var(--sky); top: -140px; left: -120px; animation-delay: 0s; }
.bg-atmosphere span:nth-child(2) { width: 340px; height: 340px; background: var(--purple); bottom: -160px; right: -120px; opacity: 0.12; animation-delay: -8s; }
.bg-atmosphere span:nth-child(3) { width: 220px; height: 220px; background: var(--magenta); top: 45%; right: 8%; opacity: 0.08; animation-delay: -14s; }

@keyframes drift {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -25px) scale(1.06); }
  66% { transform: translate(-20px, 20px) scale(0.96); }
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; } to { opacity: 1; }
}
@keyframes ringDraw {
  from { stroke-dashoffset: var(--ring-circumference); }
  to { stroke-dashoffset: var(--ring-offset); }
}
@keyframes floatLogo {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.fade-up { animation: fadeUp 0.55s cubic-bezier(0.16, 1, 0.3, 1) both; }

/* ---------------------------------------------------------------
   Top bar
--------------------------------------------------------------- */
.topbar {
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar .brand > div { min-width: 0; }
.topbar .logo-mark { height: 30px; width: auto; flex-shrink: 0; }
.topbar h1 { font-size: 18px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .sub { font-size: 11px; font-weight: 600; color: var(--sky-deep); letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap; }
.topbar .actions { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--ink-soft); flex-shrink: 0; }
.topbar .actions #userEmail {
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
  vertical-align: middle;
}
.topbar .actions button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink);
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.18s ease;
}
.topbar .actions button:hover { background: var(--sky-pale); border-color: var(--sky); color: var(--sky-deep); transform: translateY(-1px); }

/* ---------------------------------------------------------------
   Page shells
--------------------------------------------------------------- */
.shell { max-width: 900px; margin: 0 auto; padding: 40px 24px 90px; }
.center-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }

/* ---------------------------------------------------------------
   Auth card
--------------------------------------------------------------- */
.auth-card {
  width: 100%;
  max-width: 430px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 32px;
  animation: fadeUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.auth-card .crest-row { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.auth-card .logo-mark { height: 38px; width: auto; }
.auth-card h2 { font-size: 21px; }
.auth-card .eyebrow { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--sky-deep); margin-bottom: 4px; }

.tabs {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  margin-bottom: 22px;
  background: var(--surface);
}
.tabs button {
  flex: 1; border: none; background: transparent; padding: 9px 0;
  border-radius: 999px; cursor: pointer; font-size: 13px; font-weight: 500;
  color: var(--ink-soft); transition: all 0.2s ease;
}
.tabs button.active {
  background: var(--ink);
  color: #fff;
  box-shadow: 0 2px 6px rgba(15,27,45,0.2);
}

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; font-weight: 500; color: var(--ink-soft); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 11px 13px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink);
  transition: all 0.18s ease;
}
.field input:focus {
  outline: none; border-color: var(--sky); background: #fff;
  box-shadow: 0 0 0 4px rgba(34,173,224,0.14);
}
.field .hint { font-size: 11px; color: var(--ink-soft); margin-top: 5px; }

.btn-primary {
  width: 100%;
  background: var(--ink);
  color: #fff;
  border: none;
  padding: 13px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: hidden;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(15,27,45,0.25); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: default; transform: none; box-shadow: none; }

.btn-google {
  width: 100%; background: #fff; border: 1.5px solid var(--border);
  padding: 11px; border-radius: var(--radius-sm); font-weight: 500; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin-top: 10px; transition: all 0.18s ease;
}
.btn-google:hover { border-color: var(--sky); background: var(--sky-pale); transform: translateY(-1px); }

.btn-link { background: none; border: none; color: var(--sky-deep); text-decoration: none; font-weight: 500; cursor: pointer; font-size: 13px; padding: 0; border-bottom: 1px solid transparent; transition: border-color 0.15s; }
.btn-link:hover { border-color: var(--sky-deep); }

.divider { display: flex; align-items: center; gap: 10px; margin: 18px 0; color: var(--ink-soft); font-size: 12px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.msg { font-size: 13px; padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; animation: fadeUp 0.3s ease both; }
.msg.error { background: var(--due-soft); color: var(--due); }
.msg.ok { background: var(--good-soft); color: var(--good); }

.switch-row { text-align: center; margin-top: 18px; font-size: 13px; color: var(--ink-soft); }

/* ---------------------------------------------------------------
   Term picker
--------------------------------------------------------------- */
.term-picker { display: flex; gap: 8px; margin-bottom: 26px; }
.term-picker button {
  padding: 9px 18px; border-radius: 999px; border: 1.5px solid var(--border);
  background: #fff; cursor: pointer; font-size: 13px; font-weight: 500;
  transition: all 0.2s ease;
}
.term-picker button:hover { border-color: var(--sky); color: var(--sky-deep); }
.term-picker button.active {
  background: var(--ink); color: #fff; border-color: var(--ink);
  box-shadow: 0 4px 12px rgba(15,27,45,0.18);
}

/* ---------------------------------------------------------------
   Ledger / bill card — signature element: animated progress ring
--------------------------------------------------------------- */
.ledger-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 22px;
  overflow: hidden;
  transition: box-shadow 0.25s ease, transform 0.25s ease;
}
.ledger-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-2px); }

.ledger-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 24px 26px;
  border-bottom: 1px solid var(--border);
  gap: 16px;
}
.ledger-head > div:first-child { min-width: 0; flex: 1; }
.ledger-head .student-name { font-size: 20px; overflow-wrap: break-word; }
.ledger-head .student-class { font-size: 12px; color: var(--ink-soft); margin-top: 3px; }

.progress-ring-wrap { position: relative; width: 74px; height: 74px; flex-shrink: 0; }
.progress-ring-wrap svg { transform: rotate(-90deg); }
.progress-ring-track { fill: none; stroke: var(--surface-alt); stroke-width: 7; }
.progress-ring-bar {
  fill: none; stroke-width: 7; stroke-linecap: round;
  animation: ringDraw 1.1s cubic-bezier(0.16, 1, 0.3, 1) both;
  animation-delay: 0.15s;
}
.progress-ring-bar.cleared { stroke: var(--good); }
.progress-ring-bar.due { stroke: url(#ringGradient); }
.progress-ring-label {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  flex-direction: column; font-family: 'Space Grotesk', sans-serif; font-weight: 600;
}
.progress-ring-label .pct { font-size: 15px; line-height: 1; }
.progress-ring-label .pct-note { font-size: 8px; font-weight: 500; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }

.ledger-rows { padding: 4px 26px; }
.ledger-row {
  display: flex; justify-content: space-between; padding: 13px 0;
  border-bottom: 1px solid var(--border); font-size: 14px;
}
.ledger-row:last-child { border-bottom: none; }
.ledger-row .label { color: var(--ink-soft); }

.ledger-total {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 26px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 15px;
}
.ledger-total .amount.due { color: var(--due); }
.ledger-total .amount.cleared { color: var(--good); }

.quote-strip {
  padding: 14px 26px;
  background: var(--sky-pale);
  border-top: 1px dashed var(--border);
  font-size: 12.5px;
  color: var(--sky-deep);
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 8px;
}
.quote-strip .quote-mark { font-family: 'Space Grotesk', sans-serif; font-size: 18px; font-style: normal; opacity: 0.5; line-height: 1; }

.empty-note { text-align: center; padding: 60px 20px; color: var(--ink-soft); }

/* ---------------------------------------------------------------
   Add-child
--------------------------------------------------------------- */
.add-child-box { margin-top: 6px; text-align: center; }
.add-child-form { max-width: 380px; margin: 14px auto 0; display: flex; gap: 8px; }
.add-child-form input {
  flex: 1; padding: 11px 13px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); text-transform: uppercase;
}
.add-child-form input:focus { outline: none; border-color: var(--sky); box-shadow: 0 0 0 4px rgba(34,173,224,0.14); }
.add-child-form button {
  padding: 11px 20px; border-radius: var(--radius-sm); border: none;
  background: var(--ink); color: #fff; cursor: pointer; font-weight: 600;
  transition: all 0.18s ease;
}
.add-child-form button:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(15,27,45,0.2); }

/* ---------------------------------------------------------------
   Admin table
--------------------------------------------------------------- */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  -webkit-overflow-scrolling: touch;
}
table.admin-table {
  width: 100%; border-collapse: collapse; background: #fff;
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
table.admin-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--ink-soft); padding: 13px 18px; background: var(--surface);
  border-bottom: 1px solid var(--border);
}
table.admin-table td { padding: 13px 18px; border-bottom: 1px solid var(--border); font-size: 14px; }
table.admin-table tr:last-child td { border-bottom: none; }
.badge { font-size: 11px; padding: 4px 10px; border-radius: 999px; font-weight: 600; }
.badge.claimed { background: var(--good-soft); color: var(--good); }
.badge.unclaimed { background: #fef3e2; color: #b7791f; }

.section-head { display: flex; justify-content: space-between; align-items: baseline; margin: 36px 0 14px; }
.section-head h2 { font-size: 18px; }
.section-head .count { font-size: 13px; color: var(--ink-soft); }

.card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px 26px;
  transition: box-shadow 0.25s ease;
}
.card:hover { box-shadow: var(--shadow-hover); }

.inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.inline-form .field { margin-bottom: 0; min-width: 170px; flex: 1; }
.inline-form .btn-primary { width: auto; padding: 11px 22px; }

.loading { text-align: center; padding: 44px; color: var(--ink-soft); font-size: 14px; }
.loading::after {
  content: ''; display: block; width: 22px; height: 22px; margin: 14px auto 0;
  border: 2.5px solid var(--surface-alt); border-top-color: var(--sky); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.clickable-row { cursor: pointer; transition: background 0.15s ease; }
.clickable-row:hover { background: var(--sky-pale); }

/* ---------------------------------------------------------------
   Modal
--------------------------------------------------------------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,27,45,0.5);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 100;
  animation: fadeIn 0.2s ease both;
}
.modal-box {
  background: #fff; border-radius: var(--radius); max-width: 640px; width: 100%;
  max-height: 85vh; overflow-y: auto; box-shadow: 0 24px 60px rgba(15,27,45,0.25);
  animation: fadeUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.modal-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 24px 28px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: #fff;
}
.modal-close { background: var(--surface); border: none; cursor: pointer; font-size: 18px; color: var(--ink-soft); line-height: 1; padding: 8px 11px; border-radius: 999px; transition: all 0.15s ease; }
.modal-close:hover { background: var(--due-soft); color: var(--due); }
.modal-body { padding: 24px 28px; }
.modal-section { margin-bottom: 24px; }
.modal-section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--sky-deep); font-weight: 600; margin-bottom: 10px; }
.detail-row { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.detail-row span:first-child { min-width: 0; overflow-wrap: break-word; }
.detail-row:last-child { border-bottom: none; }

@media (max-width: 560px) {
  .shell { padding: 22px 14px 70px; }

  /* Top bar: stack cleanly, truncate long text instead of overflowing */
  .topbar { padding: 10px 14px; }
  .topbar .brand { gap: 8px; }
  .topbar .logo-mark { height: 26px; }
  .topbar h1 { font-size: 14px; max-width: 40vw; }
  .topbar .sub { font-size: 9px; }
  .topbar .actions { gap: 8px; }
  .topbar .actions #userEmail { max-width: 90px; font-size: 11px; }
  .topbar .actions button { padding: 7px 12px; font-size: 12px; }

  .ledger-head { flex-direction: row; align-items: center; padding: 18px 16px; gap: 10px; }
  .ledger-head .student-name { font-size: 16px; }
  .progress-ring-wrap { width: 58px; height: 58px; }
  .progress-ring-wrap svg { width: 58px; height: 58px; }
  .progress-ring-label .pct { font-size: 12px; }
  .progress-ring-label .pct-note { font-size: 7px; }
  .ledger-rows { padding: 2px 16px; }
  .ledger-row { padding: 10px 0; font-size: 13px; }
  .ledger-total { padding: 14px 16px; font-size: 13px; flex-direction: column; align-items: flex-start; gap: 6px; }
  .quote-strip { padding: 12px 16px; font-size: 11.5px; }

  .term-picker { gap: 6px; margin-bottom: 20px; }
  .term-picker button { padding: 7px 12px; font-size: 12px; }

  .inline-form { flex-direction: column; align-items: stretch; }
  .inline-form .field { min-width: 0; width: 100%; }
  .inline-form .btn-primary { width: 100%; }
  .add-child-form { flex-direction: column; }
  .card { padding: 16px 16px; }
  .section-head { margin: 26px 0 12px; }
  .section-head h2 { font-size: 15px; }

  /* Admin table -> stacked cards on mobile, no horizontal scrolling needed */
  .table-scroll { overflow-x: visible; box-shadow: none; border-radius: 0; }
  table.admin-table thead { display: none; }
  table.admin-table, table.admin-table tbody, table.admin-table tr, table.admin-table td { display: block; width: 100%; }
  table.admin-table { border: none; box-shadow: none; }
  table.admin-table tr {
    background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm);
    margin-bottom: 12px; padding: 4px 14px; box-shadow: var(--shadow);
  }
  table.admin-table td {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 0; border-bottom: 1px solid var(--border); text-align: right; font-size: 13px;
  }
  table.admin-table td:last-child { border-bottom: none; }
  table.admin-table td::before {
    content: attr(data-label);
    font-size: 11px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.04em; color: var(--ink-soft); text-align: left;
  }
  table.admin-table td.loading { display: block; text-align: center; padding: 30px 0; }
  table.admin-table td.loading::before { content: none; }

  /* Modal: full-width sheet instead of a floating box, comfortable padding */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-box { max-width: 100%; width: 100%; max-height: 92vh; border-radius: 20px 20px 0 0; }
  .modal-head { padding: 18px 18px; }
  .modal-head h2 { font-size: 16px; }
  .modal-body { padding: 18px 18px; }
  .modal-section { margin-bottom: 20px; }
  .detail-row { font-size: 13px; padding: 8px 0; }
}
