:root {
  color-scheme: light;
  --md-sys-color-primary: #386a20;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #b8f398;
  --md-sys-color-on-primary-container: #082100;
  --md-sys-color-secondary: #55624c;
  --md-sys-color-on-secondary: #ffffff;
  --md-sys-color-secondary-container: #d9e7cb;
  --md-sys-color-on-secondary-container: #131f0d;
  --md-sys-color-tertiary-container: #bbebeb;
  --md-sys-color-on-tertiary-container: #002020;
  --md-sys-color-error: #ba1a1a;
  --md-sys-color-error-container: #ffdad6;
  --md-sys-color-on-error-container: #410002;
  --md-sys-color-surface: #f8faf4;
  --md-sys-color-surface-container: #ecefe8;
  --md-sys-color-surface-container-low: #f2f5ee;
  --md-sys-color-surface-container-high: #e6e9e2;
  --md-sys-color-surface-container-highest: #e0e4dc;
  --md-sys-color-on-surface: #191d17;
  --md-sys-color-on-surface-variant: #43483e;
  --md-sys-color-outline: #74796d;
  --md-sys-color-outline-variant: #c3c8ba;
  --md-sys-color-inverse-surface: #2e312b;
  --md-sys-color-shadow: #000000;
  --md-sys-shape-corner-small: 8px;
  --md-sys-shape-corner-medium: 12px;
  --md-sys-shape-corner-large: 16px;
  --md-sys-shape-corner-extra-large: 28px;
  --md-sys-elevation-1: 0 1px 2px rgba(25, 29, 23, 0.18), 0 1px 3px 1px rgba(25, 29, 23, 0.08);
  --md-sys-elevation-2: 0 1px 2px rgba(25, 29, 23, 0.2), 0 2px 6px 2px rgba(25, 29, 23, 0.08);
  --content-max: 1200px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--md-sys-color-surface);
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  margin: 0;
  background:
    radial-gradient(circle at 8% 0%, rgba(184, 243, 152, 0.24), transparent 30rem),
    var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font-family: Roboto, "Segoe UI", Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

button,
select {
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--md-sys-color-primary-container);
  outline-offset: 2px;
}

.app-shell {
  width: min(100%, var(--content-max));
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    calc(16px + env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    calc(32px + env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  display: grid;
  align-content: start;
  gap: 16px;
}

.app-header {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.title-group {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  font-size: 1.25rem;
  font-weight: 700;
  box-shadow: var(--md-sys-elevation-1);
}

h1,
h2,
h3,
h4,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 500;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

h2 {
  margin: 0 0 20px;
  font-size: 1.5rem;
  font-weight: 500;
  line-height: 1.3;
}

h3 {
  margin: 0 0 16px;
  font-size: 1.375rem;
  font-weight: 500;
  line-height: 1.35;
}

.lang-wrap {
  display: grid;
  gap: 4px;
  flex: 0 1 210px;
}

.lang-wrap label {
  padding-inline: 4px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.04em;
}

.uganda-status {
  min-height: 40px;
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 999px;
  background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.875rem;
  font-weight: 500;
}

.lamp {
  width: 10px;
  height: 10px;
  flex: 0 0 10px;
  border-radius: 50%;
}

.lamp-online {
  background: #2e7d32;
  box-shadow: 0 0 0 4px rgba(46, 125, 50, 0.16);
}

.lamp-offline {
  background: var(--md-sys-color-error);
  box-shadow: 0 0 0 4px rgba(186, 26, 26, 0.14);
}

.card {
  padding: clamp(20px, 4vw, 32px);
  border: 1px solid color-mix(in srgb, var(--md-sys-color-outline-variant) 72%, transparent);
  border-radius: var(--md-sys-shape-corner-extra-large);
  background: var(--md-sys-color-surface-container-low);
  box-shadow: var(--md-sys-elevation-1);
}

.auth-card {
  width: 100%;
  max-width: 520px;
  justify-self: center;
}

.banner {
  min-height: 48px;
  padding: 12px 16px;
  border-radius: var(--md-sys-shape-corner-medium);
  display: flex;
  align-items: center;
  font-size: 0.875rem;
  font-weight: 500;
}

.banner.offline {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}

.banner.update {
  justify-content: space-between;
  gap: 12px;
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
}

.banner.update button {
  width: auto;
  flex: 0 0 auto;
}

.tabs {
  min-height: 48px;
  margin-bottom: 24px;
  padding: 4px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  border-radius: 999px;
  background: var(--md-sys-color-surface-container-high);
}

.tab {
  min-height: 40px;
  padding: 8px 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  box-shadow: none;
}

.tab.active {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

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

input,
select,
textarea {
  width: 100%;
  min-height: 56px;
  padding: 15px 16px;
  border: 1px solid var(--md-sys-color-outline);
  border-radius: var(--md-sys-shape-corner-small);
  background: transparent;
  color: var(--md-sys-color-on-surface);
}

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

input:hover,
select:hover,
textarea:hover {
  border-color: var(--md-sys-color-on-surface);
}

input:focus,
select:focus,
textarea:focus {
  border: 2px solid var(--md-sys-color-primary);
  padding: 14px 15px;
  outline: none;
}

input::placeholder,
textarea::placeholder {
  color: var(--md-sys-color-on-surface-variant);
  opacity: 0.85;
}

.password-field {
  position: relative;
}

.password-field input {
  padding-right: 56px;
}

.password-field input:focus {
  padding-right: 55px;
}

button.password-toggle {
  position: absolute;
  top: 50%;
  right: 4px;
  width: 48px;
  min-height: 48px;
  padding: 0;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  box-shadow: none;
}

button.password-toggle:active {
  transform: translateY(-50%) scale(0.96);
}

.eye-icon {
  width: 22px;
  height: 22px;
  display: block;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5C21.27 7.61 17 4.5 12 4.5Zm0 12.5a5 5 0 1 1 0-10 5 5 0 0 1 0 10Zm0-8a3 3 0 1 0 0 6 3 3 0 0 0 0-6Z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5C21.27 7.61 17 4.5 12 4.5Zm0 12.5a5 5 0 1 1 0-10 5 5 0 0 1 0 10Zm0-8a3 3 0 1 0 0 6 3 3 0 0 0 0-6Z'/%3E%3C/svg%3E") center / contain no-repeat;
}

button {
  width: 100%;
  min-height: 48px;
  padding: 10px 24px;
  border: 0;
  border-radius: 999px;
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: var(--md-sys-elevation-1);
  transition: box-shadow 150ms ease, filter 150ms ease, transform 80ms ease;
}

button:hover {
  filter: brightness(0.96);
  box-shadow: var(--md-sys-elevation-2);
}

button:active {
  transform: scale(0.99);
  box-shadow: none;
}

button.ghost-btn {
  border: 1px solid var(--md-sys-color-outline);
  background: transparent;
  color: var(--md-sys-color-primary);
  box-shadow: none;
}

.auth-message {
  margin: 16px 0 0;
  padding: 12px 16px;
  border-radius: var(--md-sys-shape-corner-medium);
  font-size: 0.875rem;
}

.auth-message.info {
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
}

.auth-message.success {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.auth-message.error {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}

#dashboard {
  display: grid;
  gap: 16px;
}

.profile-card p {
  margin: 0 0 20px;
  color: var(--md-sys-color-on-surface-variant);
}

#students {
  display: grid;
  gap: 16px;
}

.student {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-large);
  background: var(--md-sys-color-surface);
  display: grid;
  align-content: start;
  gap: 12px;
}

.student h4 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 500;
}

.student p {
  margin: -8px 0 0;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 0.875rem;
}

.status-chip {
  width: fit-content;
  min-height: 32px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.report-status {
  margin: 0 !important;
  padding: 10px 12px;
  border-radius: var(--md-sys-shape-corner-medium);
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container) !important;
  font-size: 0.8125rem !important;
  font-weight: 600;
  line-height: 1.35;
}

.report-status[data-report-status="Completed"] {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container) !important;
}

.report-status[data-report-status="DeadLetter"] {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container) !important;
}

.hidden,
#dashboard.hidden,
.banner.hidden {
  display: none;
}

@media (max-width: 599px) {
  .app-shell {
    padding-top: calc(8px + env(safe-area-inset-top));
  }

  .uganda-status {
    position: sticky;
    top: calc(8px + env(safe-area-inset-top));
    z-index: 10;
    max-width: 100%;
    justify-self: center;
    background: color-mix(in srgb, var(--md-sys-color-surface-container-low) 92%, transparent);
    box-shadow: var(--md-sys-elevation-1);
    backdrop-filter: blur(12px);
  }

  .app-header {
    align-items: stretch;
    flex-direction: column;
  }

  .lang-wrap {
    flex-basis: auto;
  }

  .card {
    border-radius: 24px;
  }

  .banner.update {
    align-items: stretch;
    flex-direction: column;
  }

  .banner.update button {
    width: 100%;
  }
}

/* Material 3 compact/medium boundary: medium windows start at 600dp. */
@media (min-width: 600px) {
  .app-shell {
    padding-inline: max(24px, env(safe-area-inset-left));
    gap: 24px;
  }

  .uganda-status {
    justify-self: end;
    grid-row: 1;
  }

  .app-header {
    grid-row: 2;
  }

  #dashboard {
    grid-template-columns: minmax(220px, 0.36fr) minmax(0, 1fr);
    align-items: start;
    gap: 24px;
  }

  .profile-card {
    position: sticky;
    top: 24px;
  }

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

/* Material 3 expanded windows start at 840dp. */
@media (min-width: 840px) {
  .app-shell {
    padding-inline: max(32px, env(safe-area-inset-left));
  }

  .auth-card {
    max-width: 560px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
