:root {
  color-scheme: light;
  --bg: #f7f7f4;
  --surface: #ffffff;
  --text: #18202a;
  --muted: #667085;
  --line: #dde3ea;
  --focus: #1f6feb;
  --time: #5b5fc7;
  --school: #0b74b9;
  --positive: #137a3a;
  --positive-bg: #e8f6ed;
  --negative: #b42318;
  --negative-bg: #fff0ed;
  --trade: #9a5b00;
  --shadow: 0 10px 30px rgba(24, 32, 42, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  width: 100%;
  max-width: 100%;
  height: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

button,
input,
textarea {
  font: inherit;
  max-width: 100%;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 45%, transparent);
  outline-offset: 3px;
}

.offline-banner {
  position: fixed;
  z-index: 50;
  top: env(safe-area-inset-top);
  left: 0;
  right: 0;
  max-width: 100vw;
  padding: 10px 16px;
  background: #1f2937;
  color: white;
  text-align: center;
  font-size: 0.9rem;
}

.login-shell {
  height: 100vh;
  height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(24px + env(safe-area-inset-top)) 18px calc(24px + env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.login-card {
  width: min(420px, 100%);
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 26px;
}

.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #20294f;
  color: white;
  font-weight: 800;
  margin-bottom: 18px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.login-card h1 {
  margin-bottom: 8px;
  font-size: 2rem;
}

.login-card p {
  color: var(--muted);
}

.stack {
  display: grid;
  gap: 14px;
}

.compact {
  gap: 10px;
}

label,
.modal-field {
  display: grid;
  gap: 7px;
  color: #344054;
  font-size: 0.95rem;
  font-weight: 650;
}

input,
textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 12px 13px;
  background: #fff;
  color: var(--text);
}

textarea {
  min-height: 110px;
  resize: vertical;
}

.app-shell {
  height: 100vh;
  height: 100dvh;
  width: min(100%, 720px);
  max-width: 100%;
  padding: calc(18px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-left)) calc(92px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-right));
  margin: 0 auto;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.screen-header {
  padding: 10px 2px 16px;
}

.screen-header p {
  margin-bottom: 2px;
  color: var(--muted);
  font-weight: 700;
}

.screen-header h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 8vw, 3.2rem);
  line-height: 1;
  letter-spacing: 0;
}

.balance-panel,
.settings-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.balance-panel {
  display: grid;
  gap: 10px;
  place-items: center;
  min-height: 150px;
  padding: 26px 18px;
  margin-bottom: 18px;
}

.balance-panel span {
  color: var(--muted);
  font-weight: 750;
}

.balance-panel strong {
  font-size: clamp(2.6rem, 15vw, 5rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.time-accent {
  border-top: 5px solid var(--time);
}

.school-accent {
  border-top: 5px solid var(--school);
}

.quick-grid,
.school-grid {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

.quick-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.school-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.wide {
  grid-column: 1 / -1;
}

.adjust,
.wide-action,
.primary-button,
.secondary-button,
.danger-button,
.ghost-button {
  min-height: 48px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 800;
}

.adjust {
  min-height: 72px;
  font-size: 1.45rem;
}

.positive {
  color: var(--positive);
  background: var(--positive-bg);
  border-color: #abefc6;
}

.negative {
  color: var(--negative);
  background: var(--negative-bg);
  border-color: #fecdca;
}

.wide-action,
.primary-button {
  width: 100%;
  background: #20294f;
  color: white;
  border-color: #20294f;
}

.time-action {
  background: var(--time);
  border-color: var(--time);
  margin-bottom: 24px;
}

.custom-time-action {
  background: #ffffff;
  color: var(--time);
  border-color: color-mix(in srgb, var(--time) 42%, #ffffff);
  margin-bottom: 10px;
}

.trade-action {
  background: #b76e00;
  border-color: #b76e00;
  margin-bottom: 24px;
}

.secondary-button {
  background: #eef4ff;
  color: #1849a9;
  border-color: #b2ccff;
}

.danger-button {
  background: var(--negative);
  color: white;
  border-color: var(--negative);
}

.ghost-button,
.text-button,
.danger-link {
  background: transparent;
  color: #344054;
  border: 1px solid var(--line);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 750;
}

.text-button,
.danger-link {
  border-color: transparent;
  color: #475467;
  padding-inline: 4px;
}

.danger-link {
  color: var(--negative);
  margin-top: 12px;
}

.danger-text {
  color: var(--negative);
}

.school-date-box {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.school-date-box > span {
  color: var(--muted);
  font-weight: 750;
}

.date-control {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  gap: 8px;
}

.date-control button {
  min-height: 52px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  font-weight: 850;
}

.activity-section {
  margin-top: 4px;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  min-width: 0;
}

.section-heading h2 {
  margin: 0;
  font-size: 1.15rem;
}

.activity-group {
  margin-bottom: 16px;
}

.activity-group h3 {
  margin: 18px 0 8px;
  color: #475467;
  font-size: 0.98rem;
}

.activity-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  min-width: 0;
}

.activity-main {
  width: 100%;
  min-width: 0;
  display: grid;
  gap: 4px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.activity-title {
  font-size: 1.12rem;
  font-weight: 850;
  min-width: 0;
  overflow-wrap: anywhere;
}

.activity-meta,
.activity-reason,
.user-row span,
.muted {
  color: var(--muted);
}

.activity-reason {
  line-height: 1.35;
  min-width: 0;
  overflow-wrap: anywhere;
}

.activity-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 6px;
}

.positive-text {
  color: var(--positive);
}

.negative-text {
  color: var(--negative);
}

.special-text {
  color: var(--trade);
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 8px max(10px, env(safe-area-inset-left)) calc(8px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-right));
  background: #ffffff;
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 22px rgba(24, 32, 42, 0.08);
  transform: translate3d(0, 0, 0);
  -webkit-transform: translate3d(0, 0, 0);
  contain: layout paint;
  will-change: transform;
}

.nav-button {
  min-height: 58px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #667085;
  display: grid;
  place-items: center;
  gap: 3px;
  font-size: 0.82rem;
  font-weight: 850;
}

.nav-button.active {
  background: #eef4ff;
  color: #1849a9;
}

.nav-icon {
  width: 22px;
  height: 22px;
  display: block;
  background: currentColor;
  -webkit-mask-position: center;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-size: contain;
  mask-position: center;
  mask-repeat: no-repeat;
  mask-size: contain;
}

.icon-clock {
  -webkit-mask-image: url("/icons/ui/clock.svg");
  mask-image: url("/icons/ui/clock.svg");
}

.icon-school {
  -webkit-mask-image: url("/icons/ui/school.svg");
  mask-image: url("/icons/ui/school.svg");
}

.icon-settings {
  -webkit-mask-image: url("/icons/ui/settings.svg");
  mask-image: url("/icons/ui/settings.svg");
}

.settings-card {
  padding: 16px;
  margin-bottom: 14px;
}

.settings-card h2 {
  margin-bottom: 12px;
  font-size: 1.15rem;
}

.settings-card h3 {
  margin: 10px 0 0;
}

.checkbox-row {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.checkbox-row input {
  width: auto;
}

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.user-row:last-child {
  border-bottom: 0;
}

.user-row div {
  display: grid;
  gap: 3px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: end center;
  padding: 12px max(12px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: rgba(15, 23, 42, 0.45);
  overflow-x: hidden;
}

.modal {
  width: min(520px, 100%);
  max-width: 100%;
  max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow-y: auto;
  background: var(--surface);
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.28);
}

.modal h2 {
  margin-bottom: 12px;
}

.modal-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(120px, 100%), 1fr));
  gap: 10px;
  margin-top: 18px;
}

.segmented-field {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  border: 0;
  padding: 0;
  margin: 0 0 14px;
}

.segmented-field legend {
  grid-column: 1 / -1;
  margin-bottom: 7px;
  color: #344054;
  font-size: 0.95rem;
  font-weight: 650;
}

.segment-option {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #475467;
  font-weight: 850;
}

.segment-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segment-option.selected:first-of-type {
  color: var(--positive);
  background: var(--positive-bg);
  border-color: #abefc6;
}

.segment-option.selected:last-of-type {
  color: var(--negative);
  background: var(--negative-bg);
  border-color: #fecdca;
}

.apply-stepper {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
  margin-top: 14px;
}

.apply-minutes-field {
  min-width: 0;
  grid-column: 1 / -1;
  grid-row: 1;
}

.step-button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: #344054;
  font-weight: 900;
}

@media (min-width: 560px) {
  .apply-stepper {
    grid-template-columns: 52px 52px minmax(0, 1fr) 52px 52px;
  }

  .apply-minutes-field {
    grid-column: auto;
    grid-row: auto;
  }
}

.transaction-detail {
  display: grid;
  gap: 6px;
}

.form-error,
.status-message.error {
  color: var(--negative);
  min-height: 1.2em;
}

.status-message {
  color: var(--positive);
}

.empty-state {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.55);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

@media (min-width: 720px) {
  .bottom-nav {
    left: 50%;
    width: 720px;
    transform: translateX(-50%);
    -webkit-transform: translateX(-50%);
    border-inline: 1px solid var(--line);
  }
}
