:root {
  --teal: #005859;
  --teal-dark: #003f40;
  --mint: #dceff0;
  --orange: #c66a17;
  --red: #c62828;
  --green: #2e7d32;
  --ink: #173133;
  --muted: #68797a;
  --line: #dde5e5;
  --surface: #ffffff;
  --canvas: #f3f6f5;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(0,88,89,.035) 25%, transparent 25%) 0 0/24px 24px,
    var(--canvas);
  font-family: "Segoe UI", "Trebuchet MS", sans-serif;
}
button, input { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.topbar {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(16px, 4vw, 56px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 8px;
  display: grid; place-items: center;
  color: white; background: var(--teal); font-weight: 800;
}
.brand strong, .brand span { display: block; }
.brand strong { color: var(--teal); font-size: 15px; letter-spacing: 1.2px; }
.brand span { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tabs { display: flex; align-self: stretch; }
.tab {
  border: 0; border-bottom: 3px solid transparent;
  background: transparent; color: var(--muted);
  padding: 0 18px; font-weight: 700;
}
.tab.active { color: var(--teal); border-bottom-color: var(--teal); }

main { width: min(1180px, calc(100% - 32px)); margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }
body.person-only .tabs { display: none; }
body.person-only main { width: min(760px, calc(100% - 32px)); }
.person-page { margin: 34px auto; }
.person-page-heading { display: flex; align-items: center; gap: 16px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.person-page-heading .eyebrow { color: var(--teal); margin-bottom: 6px; }
.person-page-heading h1 { margin: 0 0 5px; font-size: 26px; line-height: 1.15; }
.person-page-heading p:last-child { margin: 0; color: var(--muted); font-size: 13px; }
.person-page-courses { margin-top: 24px; }
.person-page-courses h2 { margin: 0; font-size: 18px; }
.person-page .modal-courses { margin-top: 12px; }
.empty-state h1 { margin: 0 0 8px; font-size: 22px; }
.empty-state p { margin: 0; }
.qr-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.qr-item { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: white; text-align: center; break-inside: avoid; }
.qr-item strong, .qr-item span { display: block; }
.qr-item strong { font-size: 14px; }
.qr-item span { margin-top: 4px; color: var(--muted); font-size: 11px; }
.qr-code { width: 152px; height: 152px; display: grid; place-items: center; }
.qr-code img, .qr-code canvas { width: 144px; height: 144px; }
.qr-item a { color: var(--teal); font-size: 12px; font-weight: 700; }
.admin-head-actions { display: flex; gap: 8px; }
.supervisor-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 20px 0 12px; }
.supervisor-toolbar .filters { margin: 0; flex-wrap: wrap; }
.supervisor-toolbar .search-box { min-width: 240px; }
.supervisor-list { display: grid; }
.supervisor-card { display: grid; grid-template-columns: minmax(0, 1fr) 132px; gap: 16px; align-items: start; padding: 16px; border-bottom: 1px solid var(--line); background: white; }
.supervisor-person { display: flex; align-items: center; gap: 12px; }
.supervisor-person h2 { margin: 0 0 3px; font-size: 15px; }
.supervisor-person p { margin: 0; color: var(--muted); font-size: 12px; }
.supervisor-summary { display: flex; align-items: center; gap: 8px; margin: 12px 0; }
.supervisor-summary strong { font-size: 12px; }
.supervisor-courses summary { color: var(--teal); cursor: pointer; font-size: 12px; font-weight: 800; }
.supervisor-courses .modal-courses { margin-top: 9px; }
.supervisor-qr { display: grid; justify-items: center; gap: 4px; }
.supervisor-qr .qr-code { width: 112px; height: 112px; }
.supervisor-qr .qr-code img, .supervisor-qr .qr-code canvas { width: 104px; height: 104px; }
.supervisor-qr > span { color: var(--muted); font-size: 10px; }
.hero {
  min-height: 190px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 38px 40px 30px;
  margin: 24px 0 18px;
  background: linear-gradient(115deg, #003f40 0%, #005859 70%, #187b79 100%);
  color: white;
  border-radius: 8px;
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: ""; width: 260px; height: 260px;
  border: 38px solid rgba(255,255,255,.055);
  border-radius: 50%; position: absolute; right: -80px; top: -120px;
}
.hero > * { position: relative; z-index: 1; }
.eyebrow { margin: 0 0 8px; font-size: 11px; font-weight: 800; letter-spacing: 1.4px; }
.hero h1 { margin: 0; font-size: clamp(28px, 5vw, 43px); line-height: 1.05; }
.hero p:last-child { margin: 10px 0 0; color: rgba(255,255,255,.78); }
.search-box {
  height: 46px; min-width: 280px;
  display: flex; align-items: center; gap: 8px;
  background: white; color: #7e9191;
  border: 1px solid var(--line); border-radius: 6px;
  padding: 0 13px;
}
.search-box.full { width: 100%; margin-bottom: 12px; }
.search-box input { width: 100%; border: 0; outline: 0; color: var(--ink); background: transparent; }
.hero .search-box { border: 0; }

.filters {
  display: flex; gap: 8px; margin-bottom: 16px;
  overflow: hidden;
  padding: 0; border: 0; box-shadow: none;
}
.filter {
  flex: none; height: 38px; border: 1px solid var(--line); border-radius: 6px;
  background: white; color: var(--muted); padding: 0 12px; font-weight: 700;
}
.filter b {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px;
  margin-left: 5px; border-radius: 11px; background: #edf2f1;
}
.filter.active { background: var(--teal); border-color: var(--teal); color: white; }
.filter.active b { background: rgba(255,255,255,.16); color: white; }

.people-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.person-card {
  min-width: 0; border: 1px solid var(--line); border-radius: 8px;
  background: white; overflow: hidden;
  transition: transform .18s ease, box-shadow .18s ease;
}
.person-card:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(27,65,66,.10); }
.person-main { display: flex; gap: 12px; padding: 15px; align-items: center; }
.avatar {
  flex: none; width: 72px; height: 72px; border-radius: 50%;
  overflow: hidden; border: 3px solid white;
  box-shadow: 0 0 0 1px #d5dfdf;
  background: #dceff0;
}
.avatar img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: center 35%;
}
.avatar.large { width: 92px; height: 92px; }
.person-info { min-width: 0; }
.person-info h3 { margin: 0 0 3px; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-info p { margin: 0; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cs-tag { display: inline-block; margin-top: 7px; color: var(--teal); font-size: 11px; font-weight: 800; }
.card-statuses { border-top: 1px solid var(--line); padding: 10px 15px 12px; }
.status-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 5px 0; font-size: 12px; }
.status-row span:first-child { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-pill { flex: none; padding: 4px 7px; border-radius: 12px; font-size: 10px; font-weight: 800; }
.status-pill.proximo { background: #fff1d6; color: #9a5b10; }
.status-pill.vencido { background: #fde2e2; color: var(--red); }
.status-pill.concluido { background: #dff1e3; color: var(--green); }
.status-pill.sem-status { background: #edf2f1; color: #5e7070; }
.card-open { width: 100%; border: 0; border-top: 1px solid var(--line); background: #fafcfc; color: var(--teal); padding: 9px; font-size: 12px; font-weight: 800; }
.empty-state { padding: 70px 20px; text-align: center; color: var(--muted); }

.login-panel { min-height: calc(100vh - 72px); display: grid; place-items: center; }
.login-card {
  width: min(390px, 100%); padding: 34px;
  border: 1px solid var(--line); border-radius: 8px; background: white;
  box-shadow: 0 18px 50px rgba(35,72,73,.10);
}
.lock-icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; background: var(--mint); color: var(--teal); margin-bottom: 18px; }
.login-card h2 { margin: 0 0 22px; }
.login-card label { display: block; color: var(--muted); font-size: 12px; font-weight: 800; margin-top: 14px; }
.login-card input {
  display: block; width: 100%; height: 44px; margin-top: 7px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 6px; outline: none;
}
.login-card input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0,88,89,.08); }
.form-error { min-height: 18px; color: var(--red); font-size: 12px; }
.primary-btn, .secondary-btn {
  min-height: 44px; border-radius: 6px; padding: 0 18px; font-weight: 800;
}
.primary-btn { border: 0; background: var(--teal); color: white; }
.primary-btn:hover { background: var(--teal-dark); }
.secondary-btn { border: 1px solid var(--line); background: white; color: var(--teal); }
.login-card .primary-btn { width: 100%; margin-top: 4px; }

.admin-head { display: flex; align-items: center; justify-content: space-between; padding: 28px 0 18px; }
.admin-head h1 { margin: 0; }
.import-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}
.import-box strong { color: var(--teal); }
.import-box p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.import-btn {
  flex: none;
  min-height: 40px;
  display: inline-grid;
  place-items: center;
  border-radius: 6px;
  padding: 0 12px;
  background: var(--teal);
  color: white;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}
.import-btn input { display: none; }
.admin-actions { display: flex; gap: 8px; flex: none; }
.new-person-form {
  grid-template-columns: 120px minmax(180px, 1fr) minmax(180px, 1fr) auto auto;
  align-items: end;
  gap: 10px;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}
.new-person-form:not(.hidden) { display: grid; }
.new-person-form label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 11px; font-weight: 800; }
.new-person-form input { height: 40px; border: 1px solid var(--line); border-radius: 6px; padding: 0 10px; }
.admin-layout { display: grid; grid-template-columns: 310px minmax(0, 1fr); gap: 14px; min-height: 560px; }
.admin-list { border: 1px solid var(--line); border-radius: 8px; background: white; padding: 12px; }
.admin-person {
  width: 100%; display: flex; align-items: center; gap: 10px;
  border: 0; border-bottom: 1px solid #edf1f1; background: white;
  text-align: left; padding: 9px 6px; color: var(--ink);
}
.admin-person.active { background: #edf6f6; border-radius: 6px; }
.admin-person .avatar { width: 48px; height: 48px; }
.admin-person div { min-width: 0; }
.admin-person strong, .admin-person span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.admin-person strong { font-size: 13px; }
.admin-person span { color: var(--muted); font-size: 10px; margin-top: 2px; }
.editor-panel { border: 1px solid var(--line); border-radius: 8px; background: white; padding: 20px; }
.editor-empty { height: 100%; min-height: 440px; display: grid; place-items: center; color: var(--muted); }
.editor-person { display: flex; align-items: center; gap: 14px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.editor-person h2 { margin: 0 0 4px; }
.editor-person p { margin: 0; color: var(--muted); font-size: 13px; }
.photo-editor { display: grid; grid-template-columns: 92px minmax(180px, 1fr); gap: 10px; align-items: center; }
.photo-drop-zone {
  min-height: 82px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  border: 1px dashed #94aaa9;
  border-radius: 8px;
  padding: 10px;
  background: #f7faf9;
  cursor: pointer;
}
.photo-drop-zone.dragging { border-color: var(--teal); background: #edf6f6; }
.photo-drop-zone strong { color: var(--teal); font-size: 12px; }
.photo-drop-zone span { color: var(--muted); font-size: 11px; }
.photo-drop-zone input { display: none; }
.remove-photo-btn { grid-column: 2; justify-self: start; border: 0; background: transparent; color: var(--red); padding: 0; font-size: 11px; font-weight: 800; }
.person-fields { min-width: 0; flex: 1; }
.person-fields label { display: block; margin-bottom: 8px; color: var(--muted); font-size: 11px; font-weight: 800; }
.person-fields input { width: 100%; height: 38px; margin-top: 5px; border: 1px solid var(--line); border-radius: 6px; padding: 0 9px; color: var(--ink); }
.course-editor { display: grid; gap: 10px; margin: 16px 0; }
.course-edit-row {
  display: grid; grid-template-columns: minmax(180px, 1fr) 150px 150px;
  align-items: end; gap: 10px; padding: 12px; background: #f8faf9; border: 1px solid #edf1f1; border-radius: 6px;
}
.course-edit-row label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 11px; font-weight: 800; }
.course-name { color: var(--ink); font-size: 13px; font-weight: 800; min-height: 38px; display: flex; align-items: center; }
.course-edit-row input, .course-edit-row select { height: 38px; border: 1px solid var(--line); border-radius: 5px; background: white; padding: 0 8px; color: var(--ink); }
.save-btn { width: 100%; }

.modal { position: fixed; inset: 0; z-index: 50; display: none; align-items: end; justify-content: center; }
.modal.open { display: flex; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(10,38,39,.55); backdrop-filter: blur(3px); }
.modal-card { position: relative; z-index: 1; width: min(620px, calc(100% - 24px)); max-height: 88vh; overflow-y: auto; background: white; border-radius: 8px 8px 0 0; padding: 22px; margin-bottom: 0; }
.icon-btn { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 50%; background: white; font-size: 21px; }
.modal-close { position: absolute; right: 16px; top: 16px; }
.modal-person { display: flex; align-items: center; gap: 14px; padding-right: 48px; }
.modal-person h2 { margin: 0 0 4px; }
.modal-person p { margin: 0; color: var(--muted); font-size: 13px; }
.modal-courses { display: grid; gap: 8px; margin-top: 18px; }
.modal-course { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 6px; }
.modal-course strong { display: block; font-size: 13px; }
.modal-course small { display: block; color: var(--muted); margin-top: 4px; }
.qr-wrap { margin-top: 16px; display: grid; justify-items: center; border-top: 1px solid var(--line); padding-top: 14px; }
.qr-wrap p { margin: 8px 0 0; color: var(--muted); font-size: 11px; }

.toast { position: fixed; right: 18px; bottom: 18px; z-index: 80; transform: translateY(100px); opacity: 0; background: var(--ink); color: white; border-radius: 6px; padding: 12px 16px; transition: .25s ease; }
.toast.show { transform: translateY(0); opacity: 1; }

@media (max-width: 900px) {
  .people-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-layout { grid-template-columns: 250px minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .topbar { height: 62px; padding: 0 12px; }
  .brand span { display: none; }
  .brand-mark { width: 34px; height: 34px; }
  .tabs { margin-left: auto; }
  .tab { padding: 0 9px; font-size: 12px; }
  main { width: calc(100% - 20px); }
  .hero { min-height: 220px; align-items: flex-start; flex-direction: column; justify-content: flex-end; padding: 24px 18px 18px; margin: 10px 0 12px; }
  .hero-actions, .hero-actions .search-box { width: 100%; min-width: 0; }
  .hero h1 { font-size: 29px; }
  .hero p:last-child { font-size: 13px; }
  .people-grid { grid-template-columns: 1fr; }
  .person-page { margin: 22px auto; }
  .person-page-heading { align-items: flex-start; gap: 12px; }
  .person-page-heading .avatar.large { width: 72px; height: 72px; }
  .person-page-heading h1 { font-size: 21px; }
  .admin-head { align-items: flex-start; flex-direction: column; gap: 10px; }
  .admin-head-actions { width: 100%; }
  .admin-head-actions button { flex: 1; }
  .supervisor-toolbar { align-items: stretch; flex-direction: column; }
  .supervisor-toolbar .search-box { min-width: 0; }
  .supervisor-card { grid-template-columns: minmax(0, 1fr) 86px; gap: 8px; padding: 12px 6px; }
  .supervisor-card .avatar { width: 52px; height: 52px; }
  .supervisor-person { gap: 8px; }
  .supervisor-person h2 { font-size: 13px; }
  .supervisor-person p { font-size: 10px; }
  .supervisor-summary { align-items: flex-start; flex-direction: column; gap: 5px; }
  .supervisor-qr .qr-code { width: 84px; height: 84px; }
  .supervisor-qr .qr-code img, .supervisor-qr .qr-code canvas { width: 80px; height: 80px; }
  .supervisor-courses .modal-course { padding: 8px; }
  .person-card { display: block; }
  .person-main { padding: 12px; }
  .filters { margin-bottom: 10px; flex-wrap: wrap; overflow: hidden; }
  .login-panel { min-height: calc(100vh - 62px); align-items: start; padding-top: 26px; }
  .login-card { padding: 24px 18px; }
  .admin-head { padding: 18px 0 12px; }
  .admin-layout { display: block; min-height: 0; }
  .import-box { align-items: flex-start; flex-direction: column; }
  .admin-actions { width: 100%; }
  .admin-actions .secondary-btn, .admin-actions .import-btn { flex: 1; }
  .new-person-form:not(.hidden) { grid-template-columns: 1fr; }
  .admin-list { margin-bottom: 10px; max-height: 230px; overflow-y: auto; }
  .editor-panel { padding: 12px; }
  .editor-empty { min-height: 260px; }
  .editor-person { align-items: flex-start; }
  .photo-editor { width: 100%; grid-template-columns: 76px minmax(0, 1fr); }
  .person-fields { width: 100%; }
  .course-edit-row { grid-template-columns: 1fr; }
  .course-name { min-height: 24px; }
  .modal-card { width: 100%; max-height: 92vh; }
}

@media print {
  body { background: white; }
  .topbar, #adminLoginPanel, .supervisor-toolbar, .admin-head { display: none !important; }
  main { width: 100%; }
  .supervisor-card { grid-template-columns: minmax(0, 1fr) 112px; padding: 8px; }
  .supervisor-courses > .modal-courses { display: grid !important; }
  .supervisor-courses summary { display: none; }
}
