*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1a73e8;
  --primary-dark: #1557b0;
  --success: #0d904f;
  --danger: #d93025;
  --warning: #f9ab00;
  --bg: #f0f2f5;
  --card: #ffffff;
  --text: #1f1f1f;
  --text-light: #5f6368;
  --border: #dadce0;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

html { font-size: 16px; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

/* === HEADER === */
.header {
  background: var(--primary);
  color: #fff;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}
.header h1 { font-size: 1.1rem; font-weight: 600; }
.header-info { font-size: 0.8rem; opacity: 0.9; }
.header-actions { display: flex; gap: 8px; }

/* === SYNC BAR === */
.sync-bar {
  background: #263238;
  padding: 4px 16px;
  text-align: center;
  font-size: 0.75rem;
  z-index: 99;
  pointer-events: none;
}
.sync-bar .sync-indicator {
  pointer-events: auto;
}
.sync-indicator {
  cursor: pointer;
  user-select: none;
}
.sync-online { color: #81c784; }
.sync-offline { color: #ef9a9a; }
.sync-syncing {
  color: #90caf9;
  animation: pulse-sync 1s infinite;
}
@keyframes pulse-sync {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* === SCREENS === */
.screen { display: none; padding: 16px; max-width: 900px; margin: 0 auto; }
.screen.active { display: block; }

/* === CARDS === */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary);
}

/* === FORM ELEMENTS === */
.form-group {
  margin-bottom: 14px;
}
.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 4px;
}
.form-group .hint {
  font-size: 0.75rem;
  color: var(--text-light);
  font-weight: 400;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="search"],
select {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: #fff;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,115,232,0.15);
}

/* === FORM ROW (side by side) === */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

/* === TOGGLE BUTTONS (SIM/NAO) === */
.toggle-group {
  display: flex;
  gap: 8px;
}
.toggle-btn {
  flex: 1;
  padding: 14px 8px;
  font-size: 1rem;
  font-weight: 700;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
  user-select: none;
  -webkit-user-select: none;
}
.toggle-btn:active { transform: scale(0.97); }
.toggle-btn.selected-sim {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}
.toggle-btn.selected-nao {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.toggle-btn.selected-neutral {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* === STEPPER (numeric +/-) === */
.stepper {
  display: flex;
  align-items: center;
  gap: 4px;
}
.stepper-btn {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: #fff;
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
}
.stepper-btn:active { background: var(--bg); }
.stepper-btn.minus { color: var(--danger); }
.stepper-btn.plus { color: var(--success); }
.stepper input {
  width: 56px;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
  padding: 8px 4px;
}

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  font-size: 1rem;
  font-weight: 700;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  -webkit-user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #000; }
.btn-outline {
  background: #fff;
  color: var(--primary);
  border: 2px solid var(--primary);
}
.btn-lg {
  width: 100%;
  padding: 18px;
  font-size: 1.15rem;
}
.btn-sm { padding: 8px 16px; font-size: 0.85rem; }
.btn-header {
  padding: 8px 14px;
  font-size: 0.85rem;
  background: rgba(255,255,255,0.2);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 6px;
  cursor: pointer;
}
.btn-header:hover { background: rgba(255,255,255,0.3); }

/* === RISCO BADGE === */
.risco-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 1.4rem;
  font-weight: 900;
  color: #fff;
}
.risco-A { background: #0d904f; }
.risco-B { background: #34a853; }
.risco-C { background: #f9ab00; }
.risco-D { background: #e37400; }
.risco-E { background: #ea4335; }
.risco-F { background: #c5221f; }
.risco-G { background: #7b1fa2; }

/* === STUDENT LIST === */
.student-list { list-style: none; }
.student-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: rgba(0,0,0,0.1);
  touch-action: manipulation;
  position: relative;
  z-index: 1;
}
.student-item:active { background: #e8f0fe; }
.student-item .name { font-weight: 600; font-size: 0.95rem; }
.student-item .info { font-size: 0.8rem; color: var(--text-light); }

/* === MANAGE TURMA === */
.manage-turma-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 8px;
  margin-bottom: 6px;
}
.manage-turma-row:last-child {
  margin-bottom: 0;
}

/* === DATA NASCIMENTO NO FORMULARIO === */
.dnasc-card {
  border: 2px solid var(--warning);
  background: #fff8e1;
}

/* === RECORDS TABLE === */
.records-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.records-table th {
  background: var(--primary);
  color: #fff;
  padding: 10px 8px;
  text-align: left;
  font-weight: 600;
  position: sticky;
  top: 0;
}
.records-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}
.records-table tr:hover td { background: #e8f0fe; }

/* === CARIE GRID === */
.carie-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.carie-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: var(--bg);
  border-radius: 8px;
}
.carie-item label {
  font-size: 0.8rem;
  font-weight: 600;
  min-width: 30px;
  margin-bottom: 0;
}
.carie-item .hint {
  font-size: 0.7rem;
  color: var(--text-light);
  flex: 1;
}
.carie-item-a {
  grid-column: 1 / -1;
  background: #e8f5e9;
  border: 2px solid var(--success);
}

/* === PERIODONTAL GRID === */
.perio-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.perio-item {
  padding: 8px;
  background: var(--bg);
  border-radius: 8px;
}
.perio-item label {
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 4px;
  display: block;
}

/* === SECTION ACCORDION === */
.section-toggle {
  width: 100%;
  padding: 14px 16px;
  background: var(--card);
  border: none;
  border-bottom: 2px solid var(--primary);
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
  text-align: left;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: var(--radius) var(--radius) 0 0;
}
.section-toggle::after {
  content: '\25BC';
  font-size: 0.8rem;
  transition: transform 0.2s;
}
.section-toggle.collapsed::after { transform: rotate(-90deg); }
.section-content {
  padding: 16px;
  background: var(--card);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow);
}
.section-content.hidden { display: none; }

/* === STATS === */
.stats-row {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}
.stat-card {
  flex: 1;
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-number {
  font-size: 2rem;
  font-weight: 900;
  color: var(--primary);
}
.stat-label {
  font-size: 0.8rem;
  color: var(--text-light);
}

/* === SEARCH === */
.search-bar {
  position: relative;
  margin-bottom: 12px;
}
.search-bar input {
  padding-left: 40px;
}
.search-bar::before {
  content: '\1F50D';
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.1rem;
}

/* === ALERT === */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  font-weight: 500;
}
.alert-info { background: #e8f0fe; color: #1a73e8; }
.alert-success { background: #e6f4ea; color: #0d904f; }
.alert-warning { background: #fef7e0; color: #b06000; }

/* === PATIENT HEADER === */
.patient-header {
  background: var(--primary);
  color: #fff;
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.patient-header .name { font-size: 1.1rem; font-weight: 700; }
.patient-header .details { font-size: 0.85rem; opacity: 0.9; }

/* === FOOTER ACTIONS === */
.footer-actions {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  padding: 12px 0;
  border-top: 1px solid var(--border);
  margin-top: 16px;
}

/* === RESPONSIVE - CELULAR === */
@media (max-width: 600px) {
  html { font-size: 14px; }

  .header { padding: 8px 12px; }
  .header h1 { font-size: 0.95rem; }
  .header-info { font-size: 0.7rem; }
  .btn-header { padding: 6px 10px; font-size: 0.75rem; }

  .sync-bar { top: 44px; padding: 3px 10px; font-size: 0.7rem; }

  .screen { padding: 8px; }
  .card { padding: 12px; margin-bottom: 10px; }
  .card-title { font-size: 0.9rem; margin-bottom: 10px; padding-bottom: 6px; }

  .form-group { margin-bottom: 10px; }
  .form-group label { font-size: 0.8rem; }
  input[type="text"], input[type="number"], input[type="date"], input[type="search"], select {
    padding: 10px 12px;
    font-size: 0.9rem;
  }

  .form-row { grid-template-columns: 1fr; gap: 8px; }
  .form-row-3 { grid-template-columns: 1fr 1fr 1fr; gap: 6px; }

  .toggle-btn { padding: 10px 4px; font-size: 0.9rem; }

  .stepper-btn { width: 38px; height: 38px; font-size: 1.1rem; }
  .stepper input { width: 44px; font-size: 1rem; padding: 6px 2px; }

  .carie-grid { grid-template-columns: 1fr; gap: 6px; }
  .carie-item { padding: 6px; gap: 6px; }
  .carie-item label { font-size: 0.75rem; min-width: 24px; }
  .carie-item .hint { font-size: 0.65rem; }

  .perio-grid { grid-template-columns: 1fr; gap: 6px; }

  .section-toggle { padding: 10px 12px; font-size: 0.9rem; }
  .section-content { padding: 10px; }

  .patient-header { padding: 10px 12px; border-radius: 8px; margin-bottom: 10px; }
  .patient-header .name { font-size: 1rem !important; }
  .patient-header .details { font-size: 0.75rem; }

  .btn { padding: 12px 16px; font-size: 0.9rem; }
  .btn-lg { padding: 14px; font-size: 1rem; }
  .btn-sm { padding: 6px 12px; font-size: 0.8rem; }

  .student-item { padding: 12px; min-height: 48px; }
  .student-item .name { font-size: 0.85rem; }
  .student-item .info { font-size: 0.7rem; }
  .student-list { padding-bottom: 60px; }

  .search-bar input { padding-left: 34px; }
  .search-bar::before { left: 10px; font-size: 0.9rem; }

  .stats-row { flex-wrap: wrap; gap: 6px; }
  .stat-card { min-width: calc(33% - 4px); padding: 10px 6px; }
  .stat-number { font-size: 1.4rem; }
  .stat-label { font-size: 0.65rem; }

  .records-table { font-size: 0.75rem; }
  .records-table th { padding: 6px 4px; }
  .records-table td { padding: 8px 4px; }

  .risco-badge { width: 36px; height: 36px; font-size: 1.1rem; }

  .footer-actions { padding: 8px 0; }

  .modal-box { padding: 20px 16px; }
  .modal-icon { font-size: 2.5rem; }
  .modal-title { font-size: 1rem; }
  .modal-body { font-size: 0.85rem; }
  .modal-actions { flex-direction: column; }

  .toast { bottom: 60px; padding: 10px 18px; font-size: 0.8rem; }

  .manage-turma-row { padding: 8px 10px; }

  .tcle-badge { font-size: 0.6rem; padding: 2px 6px; margin-left: 4px; }

  .dnasc-missing { flex-direction: column; align-items: flex-start; gap: 4px; }
  .dnasc-inline-input { width: 100% !important; }

  .file-upload { padding: 20px 12px; }
  .file-upload p { font-size: 0.85rem; }

  .alert { padding: 10px 12px; font-size: 0.8rem; }
}

/* === RESPONSIVE - CELULAR MUITO PEQUENO === */
@media (max-width: 380px) {
  html { font-size: 13px; }
  .form-row-3 { grid-template-columns: 1fr 1fr; gap: 6px; }
  .header-actions { gap: 4px; }
  .btn-header { padding: 5px 8px; font-size: 0.7rem; }
  .stat-card { min-width: calc(50% - 4px); }
}

/* === EMPTY STATE === */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-light);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { font-size: 0.95rem; }

/* === SCROLLABLE TABLE === */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* === TOAST === */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #323232;
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 1000;
  animation: toast-in 0.3s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* === TCLE BADGES === */
.tcle-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 8px;
  vertical-align: middle;
}
.tcle-sim {
  background: #e6f4ea;
  color: #0d904f;
}
.tcle-nao {
  background: #fce8e6;
  color: #c5221f;
}

/* === STUDENT SEM TCLE === */
.student-sem-tcle {
  background: #fce8e6 !important;
  border-left: 4px solid var(--danger);
}
.student-sem-tcle .name {
  color: #c5221f;
}
.student-sem-tcle .info {
  color: #a03025;
}

/* === MODAL === */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal-box {
  background: #fff;
  border-radius: var(--radius);
  padding: 28px 24px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  text-align: center;
}
.modal-icon {
  font-size: 3rem;
  margin-bottom: 8px;
}
.modal-title {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--danger);
  margin-bottom: 12px;
}
.modal-body {
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.5;
  margin-bottom: 20px;
}
.modal-actions {
  display: flex;
  gap: 10px;
}

/* === FILE UPLOAD === */
.file-upload {
  border: 3px dashed var(--border);
  border-radius: var(--radius);
  padding: 30px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s;
}
.file-upload:hover, .file-upload.dragover {
  border-color: var(--primary);
  background: #e8f0fe;
}
.file-upload input { display: none; }
