:root {
  --brand-primary: #2f7b67;
  --brand-secondary: #3258cc;
  --brand-accent: #f2a93b;
  --on-primary: #ffffff;
  --surface: #ffffff;
  --background: #f6f8fb;
  --text: #152238;
  --muted: #5f6877;
  --border: #e1e6ef;

  --teal: #1e8f82;
  --teal-soft: #e2f3f0;
  --orange: #d97530;
  --orange-soft: #fbeadc;
  --gold: #ad7f1f;
  --gold-soft: #f8ecd2;
  --purple: #6c5da0;
  --purple-soft: #ece9f7;
  --success: #23875a;
  --success-soft: #dff3e8;
  --danger: #c33c46;
  --danger-soft: #fbe4e5;

  --shadow-sm: 0 1px 2px rgba(21, 34, 56, 0.07), 0 1px 0 rgba(21, 34, 56, 0.04);
  --shadow-md: 0 8px 24px rgba(21, 34, 56, 0.10), 0 2px 6px rgba(21, 34, 56, 0.06);

  --radius-control: 10px;
  --radius-card: 16px;
  --radius-modal: 20px;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  background: var(--background);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: transparent;
  line-height: 1.55;
}

a {
  color: var(--brand-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  width: min(1400px, calc(100vw - 32px));
  margin: 16px auto 28px;
}

.hero {
  border-radius: var(--radius-modal);
  background: var(--brand-primary);
  color: var(--on-primary);
  padding: 22px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.hero-top {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  flex-wrap: wrap;
}

.hero h1 {
  margin: 8px 0 0;
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: 1;
  letter-spacing: -0.03em;
  font-weight: 800;
}

.hero p {
  margin: 10px 0 0;
  max-width: 60ch;
  color: rgba(255, 255, 255, 0.84);
}

.school-logo {
  height: 52px;
  width: auto;
  object-fit: contain;
  background: white;
  border-radius: var(--radius-control);
  padding: 5px 12px;
  box-shadow: var(--shadow-sm);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.layout {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 20px;
  margin-top: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-head {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.card-body {
  padding: 20px;
}

.card-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.card-subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.94rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field[hidden] {
  display: none;
}

.label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.input {
  min-height: 48px;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 0 14px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.input:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-primary) 18%, transparent);
}

.button {
  min-height: 48px;
  border: none;
  border-radius: var(--radius-control);
  padding: 0 18px;
  font-weight: 700;
  color: var(--on-primary);
  background: var(--brand-primary);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 150ms ease-out, box-shadow 150ms ease-out;
}

.button:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.button.secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}

.button.soft {
  background: color-mix(in srgb, var(--brand-primary) 12%, white);
  color: var(--brand-primary);
  box-shadow: none;
}

.login-actions {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.84rem;
  text-align: center;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.helper {
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.92rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.panel {
  display: grid;
  gap: 16px;
}

.module {
  padding: 16px;
  border-radius: var(--radius-card);
  background: var(--surface);
  border: 1px solid var(--border);
}

.module h3 {
  margin: 0 0 6px;
  font-size: 1rem;
  font-weight: 700;
}

.module p {
  margin: 0;
  color: var(--muted);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  flex-wrap: wrap;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.muted-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 14px;
  color: var(--muted);
}

.alert {
  border-radius: var(--radius-control);
  padding: 14px 16px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.alert.error {
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
  background: var(--danger-soft);
  color: var(--danger);
}

.alert.success {
  border-color: color-mix(in srgb, var(--success) 35%, var(--border));
  background: var(--success-soft);
  color: var(--success);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

@media (max-width: 960px) {
  .layout,
  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }
}

.dashboard-shell {
  padding-top: 8px;
  padding-bottom: 24px;
}

.dashboard-hero {
  position: relative;
}

.hero-copy {
  display: grid;
  gap: 6px;
}

.hero-copy h1 {
  margin: 0;
}

.hero-copy p {
  margin-top: 4px;
}

.user-chip--dashboard {
  background: rgba(255, 255, 255, 0.14);
  min-width: min(100%, 340px);
}

.chip-label {
  display: block;
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 4px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.stat-card {
  border-radius: var(--radius-card);
  padding: 18px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  min-height: 128px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
}

.stat-card.brand-primary,
.stat-card.brand-secondary,
.stat-card.brand-accent,
.stat-card.role-teal,
.stat-card.role-orange,
.stat-card.role-gold,
.stat-card.role-purple {
  color: var(--on-primary);
  border-color: transparent;
}

.stat-card.brand-primary { background: var(--brand-primary); }
.stat-card.brand-secondary { background: var(--brand-secondary); }
.stat-card.brand-accent { background: var(--brand-accent); }
.stat-card.role-teal { background: var(--teal); }
.stat-card.role-orange { background: var(--orange); }
.stat-card.role-gold { background: var(--gold); }
.stat-card.role-purple { background: var(--purple); }

.stat-card.brand-primary .stat-label,
.stat-card.brand-secondary .stat-label,
.stat-card.brand-accent .stat-label,
.stat-card.role-teal .stat-label,
.stat-card.role-orange .stat-label,
.stat-card.role-gold .stat-label,
.stat-card.role-purple .stat-label {
  color: rgba(255, 255, 255, 0.78);
}

.stat-label {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-value {
  font-size: clamp(2rem, 4vw, 3rem);
  letter-spacing: -0.03em;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.dashboard-layout {
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  align-items: start;
}

.dashboard-main {
  min-height: 100%;
}

.dashboard-sidebar {
  display: grid;
  gap: 20px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--on-primary);
  background: var(--brand-primary);
}

.pill.subtle {
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
}

.list-stack {
  display: grid;
  gap: 14px;
}

.stack-list {
  display: grid;
  gap: 12px;
}

.list-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  padding: 16px;
  border-radius: var(--radius-card);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.list-item.compact {
  padding: 14px;
}

.announcement-item .item-copy,
.list-item .item-copy {
  min-width: 0;
}

.item-row {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.item-row h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.item-copy p {
  margin: 8px 0 0;
  color: var(--muted);
}

.meta-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.88rem;
}

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: var(--on-primary);
  background: var(--brand-primary);
  flex-shrink: 0;
}

.avatar.soft {
  background: var(--brand-secondary);
}

.avatar.secondary {
  background: var(--brand-accent);
}

.avatar.role-teal { background: var(--teal); }
.avatar.role-orange { background: var(--orange); }
.avatar.role-gold { background: var(--gold); }
.avatar.role-purple { background: var(--purple); }

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.chip strong {
  font-size: 0.94rem;
}

.chip span {
  color: var(--muted);
  font-size: 0.86rem;
}

.chip.role-teal { background: var(--teal-soft); border-color: transparent; color: var(--teal); }
.chip.role-orange { background: var(--orange-soft); border-color: transparent; color: var(--orange); }
.chip.role-gold { background: var(--gold-soft); border-color: transparent; color: var(--gold); }
.chip.role-purple { background: var(--purple-soft); border-color: transparent; color: var(--purple); }

.empty-state {
  padding: 20px;
  border-radius: var(--radius-card);
  border: 1px dashed var(--border);
  background: var(--surface);
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1160px) {
  .stats-grid,
  .dashboard-layout {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 960px) {
  .layout,
  .grid-2,
  .grid-3,
  .stats-grid,
  .dashboard-layout {
    grid-template-columns: 1fr;
  }

  .user-chip--dashboard {
    width: 100%;
  }
}

.impersonation-banner {
  background: #78350f;
  color: #fef3c7;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-size: 0.86rem;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 200;
}

.impersonation-stop-btn {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fef3c7;
  padding: 5px 14px;
  border-radius: 8px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.impersonation-stop-btn:hover {
  background: rgba(255,255,255,0.25);
}

/* ── School Admin Layout ───────────────────────────────────────────────────── */
.sa-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(300px, 0.6fr);
  gap: 20px;
  margin-top: 20px;
  align-items: start;
}

.sa-main { display: grid; gap: 20px; }
.sa-sidebar { display: grid; gap: 20px; }

/* Class tabs */
.class-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.class-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
}

.class-tab.active {
  background: var(--brand-primary);
  color: var(--on-primary);
  border-color: transparent;
}

.tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  background: rgba(255,255,255,0.24);
}

.class-tab:not(.active) .tab-count {
  background: color-mix(in srgb, var(--text) 8%, transparent);
}

/* Student table */
.student-table-wrap {
  overflow-x: auto;
}

.sa-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.sa-table th {
  padding: 10px 12px;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.sa-table td {
  padding: 12px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.sa-table tr:last-child td { border-bottom: none; }

.sa-table tr:hover td {
  background: var(--background);
}

.sa-student-name {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}

.avatar--sm {
  width: 36px;
  height: 36px;
  font-size: 0.78rem;
  flex-shrink: 0;
}

.sa-contact { font-size: 0.85rem; line-height: 1.5; }
.sa-contact .muted { color: var(--muted); font-size: 0.82rem; }

/* Class summary sidebar */
.class-summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.class-summary-row:last-child { border-bottom: none; }
.class-summary-row .muted { color: var(--muted); font-size: 0.88rem; }

/* Edit student button */
.btn-edit-student {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--brand-primary) 30%, var(--border));
  background: color-mix(in srgb, var(--brand-primary) 8%, white);
  color: var(--brand-primary);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.btn-edit-student:hover {
  background: color-mix(in srgb, var(--brand-primary) 14%, white);
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(21, 34, 56, 0.5);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-box {
  background: var(--surface);
  border-radius: var(--radius-modal);
  box-shadow: var(--shadow-md);
  width: min(440px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
}

.modal-box.wide {
  width: min(680px, 100%);
}

.modal-box.wide .modal-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}

.modal-box.wide .modal-body > .field.span-2,
.modal-box.wide .modal-body > #anMsg,
.modal-box.wide .modal-body > .modal-actions,
.modal-box.wide .modal-body > p {
  grid-column: 1 / -1;
}

.modal-title {
  margin: 0;
  padding: 20px 22px 16px;
  font-size: 1.1rem;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.modal-body {
  padding: 20px 22px;
  display: grid;
  gap: 16px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Utility */
.muted { color: var(--muted); }

@media (max-width: 1100px) {
  .sa-layout { grid-template-columns: 1fr; }
}

/* ── App sidebar (portal do responsável / painel da escola) ─────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-brand .school-logo {
  height: 32px;
  padding: 3px 8px;
  box-shadow: none;
  border: 1px solid var(--border);
}

.sidebar-brand-name {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

.sidebar-brand-tag {
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 2px;
}

.sidebar-nav {
  padding: 14px 10px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  border: none;
  background: none;
  font: inherit;
  text-align: left;
  width: 100%;
}

.sidebar .nav-link svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sidebar .nav-link:hover {
  background: var(--background);
  color: var(--text);
}

.sidebar .nav-link.active {
  background: color-mix(in srgb, var(--brand-primary) 12%, white);
  color: var(--brand-primary);
}

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-identity {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
}

.sidebar-avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: var(--brand-primary);
  color: var(--on-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 800;
  flex-shrink: 0;
}

.sidebar-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.main {
  flex: 1;
  min-width: 0;
  margin-left: 240px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

.page-content {
  padding: 28px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.page-content > .stats-grid {
  margin-top: 0;
}

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  .main { margin-left: 0; }
}

/* ── Identidade Visual da Escola ──────────────────────────────────────────── */
.branding-logo-row {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.branding-logo-preview {
  width: 88px;
  height: 88px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--surface);
  padding: 8px;
  flex: none;
}

.branding-color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.branding-color-input {
  padding: 4px;
  min-height: 48px;
  cursor: pointer;
}
