/* ============================================
   INS TB Pilot Checklist — Modern Light Theme
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap');

/* --- Design Tokens --- */
:root {
  --primary: #0d7377;
  --primary-light: #14b8a6;
  --primary-lighter: #5eead4;
  --primary-bg: #e6f7f7;
  --primary-bg-soft: #f0fdfa;
  --accent: #f97316;
  --accent-light: #fb923c;
  --accent-bg: #fff7ed;
  --bg: #f0f4f8;
  --bg-subtle: #f8fafc;
  --card: #ffffff;
  --card-hover: #fefefe;
  --text: #1e293b;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --text-dim: #cbd5e1;
  --success: #10b981;
  --success-bg: #ecfdf5;
  --success-text: #059669;
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --warning-text: #d97706;
  --error: #ef4444;
  --error-bg: #fef2f2;
  --error-text: #dc2626;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 4px 16px rgba(0,0,0,0.06);
  --shadow-md: 0 8px 30px rgba(0,0,0,0.08);
  --shadow-lg: 0 16px 50px rgba(0,0,0,0.1);
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-fast: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Subtle gradient overlay */
body::before {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background:
    radial-gradient(ellipse at 0% 0%, rgba(13,115,119,0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 100% 100%, rgba(249,115,22,0.04) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* --- App Shell --- */
#app {
  position: relative;
  z-index: 1;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* --- Progress Bar --- */
.progress-container {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 12px 20px 14px;
  border-bottom: 1px solid var(--border);
}

.progress-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.progress-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.progress-count {
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--primary);
}

.progress-track {
  width: 100%;
  height: 5px;
  background: var(--border);
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  border-radius: 10px;
  transition: width 0.6s var(--bounce);
  position: relative;
}

.progress-fill::after {
  content: '';
  position: absolute;
  right: 0;
  top: -2px;
  width: 9px;
  height: 9px;
  background: var(--primary-light);
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(20,184,166,0.5), 0 0 4px rgba(20,184,166,0.3);
}

/* --- Pages --- */
.page {
  display: none;
  flex: 1;
  padding: 20px 16px 100px;
  animation: pageIn 0.4s ease-out;
}

.page.active {
  display: flex;
  flex-direction: column;
}

@keyframes pageIn {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pageOut {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-10px); }
}

.page.slide-out {
  animation: pageOut 0.2s ease-in forwards;
}

.page.slide-in-reverse {
  animation: pageInReverse 0.35s ease-out;
}

@keyframes pageInReverse {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Welcome Page --- */
.welcome-page {
  justify-content: center;
  align-items: center;
  text-align: center;
  padding-top: 50px;
  padding-bottom: 50px;
}

.welcome-logo {
  width: 120px;
  height: auto;
  margin-bottom: 6px;
  filter: drop-shadow(0 2px 12px rgba(13,115,119,0.2));
  animation: logoFloat 3s ease-in-out infinite;
}

@keyframes logoFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.welcome-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--success-bg);
  color: var(--success-text);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 5px 14px;
  border-radius: 20px;
  margin-bottom: 20px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border: 1px solid rgba(16,185,129,0.15);
}

.welcome-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  background: var(--success);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.welcome-title {
  font-size: 1.4rem;
  font-weight: 800;
  line-height: 1.25;
  margin-bottom: 10px;
  color: var(--text);
}

.welcome-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 36px;
  max-width: 320px;
}

/* --- Cards --- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.card:hover {
  box-shadow: var(--shadow);
}

/* --- Section Headers --- */
.section-header {
  margin-bottom: 20px;
}

.section-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  font-size: 0.82rem;
  font-weight: 700;
  border-radius: 10px;
  margin-bottom: 10px;
  box-shadow: 0 3px 12px rgba(13,115,119,0.25);
}

.section-title {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.35;
  margin-bottom: 4px;
  color: var(--text);
}

.section-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* --- Form Elements --- */
.form-group {
  margin-bottom: 20px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
  line-height: 1.45;
}

.form-label .sub-label {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-top: 2px;
}

/* Text Input */
.form-input,
.form-textarea {
  width: 100%;
  background: var(--bg-subtle);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 0.92rem;
  padding: 13px 16px;
  transition: var(--transition);
  outline: none;
}

.form-input:focus,
.form-textarea:focus {
  border-color: var(--primary-light);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(20,184,166,0.12);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-dim);
}

.form-textarea {
  min-height: 88px;
  resize: vertical;
  line-height: 1.55;
}

/* Number Input */
.form-input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.form-input[type="number"]::-webkit-inner-spin-button,
.form-input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

/* --- Toggle Buttons (Sim/Não) --- */
.toggle-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.toggle-btn {
  flex: 1;
  min-width: 80px;
  padding: 13px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  color: var(--text-muted);
  font-family: 'Inter', sans-serif;
  font-size: 0.88rem;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  user-select: none;
  -webkit-user-select: none;
  position: relative;
  overflow: hidden;
}

.toggle-btn:active {
  transform: scale(0.97);
}

.toggle-btn.selected {
  border-color: var(--primary);
  background: var(--primary-bg);
  color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary), 0 3px 12px rgba(13,115,119,0.15);
}

.toggle-btn.selected-no {
  border-color: var(--error);
  background: var(--error-bg);
  color: var(--error-text);
  box-shadow: 0 0 0 1px var(--error), 0 3px 12px rgba(239,68,68,0.1);
}

.toggle-btn.selected-warning {
  border-color: var(--warning);
  background: var(--warning-bg);
  color: var(--warning-text);
  box-shadow: 0 0 0 1px var(--warning), 0 3px 12px rgba(245,158,11,0.15);
}

/* Three-option toggle */
.toggle-group.three-options .toggle-btn {
  min-width: 0;
  flex: 1;
  font-size: 0.78rem;
  padding: 11px 8px;
}

/* --- Radio Cards --- */
.radio-group {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.radio-card {
  padding: 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  user-select: none;
  -webkit-user-select: none;
}

.radio-card:active {
  transform: scale(0.97);
}

.radio-card.selected {
  border-color: var(--primary);
  background: var(--primary-bg);
  box-shadow: 0 3px 12px rgba(13,115,119,0.15);
}

.radio-card .radio-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
}

.radio-card.selected .radio-value {
  color: var(--primary);
}

.radio-card .radio-label {
  font-size: 0.68rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* --- Conditional Fields (slide down) --- */
.conditional-field {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease, opacity 0.3s ease, margin 0.3s ease;
  opacity: 0;
  margin-top: 0;
}

.conditional-field.visible {
  max-height: 300px;
  opacity: 1;
  margin-top: 12px;
}

/* --- Divider --- */
.divider {
  height: 1px;
  background: var(--border-light);
  margin: 18px 0;
}

/* --- Navigation Buttons --- */
.nav-buttons {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 99;
  display: flex;
  gap: 10px;
  padding: 14px 16px;
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  max-width: 480px;
  margin: 0 auto;
}

.btn {
  flex: 1;
  padding: 15px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: 'Inter', sans-serif;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
  overflow: hidden;
}

.btn:active {
  transform: scale(0.97);
}

.btn-secondary {
  background: var(--bg);
  color: var(--text-muted);
  border: 2px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border-light);
  color: var(--text);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  box-shadow: 0 4px 14px rgba(13,115,119,0.3);
}

.btn-primary:hover {
  box-shadow: 0 6px 20px rgba(13,115,119,0.4);
}

.btn-accent {
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  color: #fff;
  box-shadow: 0 4px 14px rgba(249,115,22,0.3);
}

.btn-start {
  padding: 16px 36px;
  font-size: 1rem;
  font-weight: 700;
  border-radius: 14px;
  min-width: 200px;
}

.btn-icon {
  font-size: 1.05rem;
}

.btn-dashboard-link:hover {
  background: var(--primary-bg) !important;
  border-color: var(--primary-light) !important;
  color: var(--primary) !important;
}

/* Ripple effect */
.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(13,115,119,0.15);
  transform: scale(0);
  animation: rippleAnim 0.6s ease-out;
  pointer-events: none;
}

@keyframes rippleAnim {
  to { transform: scale(4); opacity: 0; }
}

/* --- Toast Notification --- */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--primary);
  color: #fff;
  padding: 10px 24px;
  border-radius: 30px;
  font-size: 0.78rem;
  font-weight: 600;
  z-index: 200;
  opacity: 0;
  transition: all 0.35s var(--bounce);
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(13,115,119,0.3);
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* --- Review Page --- */
.review-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-xs);
}

.review-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.review-card-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--primary);
}

.review-edit-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  transition: var(--transition);
}

.review-edit-btn:active {
  transform: scale(0.95);
  background: var(--border-light);
}

.review-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 5px 0;
  gap: 12px;
}

.review-item + .review-item {
  border-top: 1px solid var(--border-light);
}

.review-item-label {
  font-size: 0.72rem;
  color: var(--text-light);
  flex-shrink: 0;
  max-width: 55%;
  line-height: 1.4;
}

.review-item-value {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  text-align: right;
  word-break: break-word;
}

.review-item-value.empty {
  color: var(--text-dim);
  font-style: italic;
  font-weight: 400;
}

/* --- Success Page --- */
.success-page {
  justify-content: center;
  align-items: center;
  text-align: center;
}

.success-icon {
  width: 80px;
  height: 80px;
  background: var(--success-bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  margin-bottom: 20px;
  animation: successPop 0.5s var(--bounce);
  border: 2px solid rgba(16,185,129,0.2);
}

@keyframes successPop {
  from { transform: scale(0); }
  to { transform: scale(1); }
}

.success-title {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text);
}

.success-text {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 30px;
}

/* --- Admin Panel --- */
.admin-fab {
  position: fixed;
  bottom: 80px;
  right: 16px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text-light);
  font-size: 1.15rem;
  cursor: pointer;
  z-index: 98;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  box-shadow: var(--shadow);
}

.admin-fab:hover {
  background: var(--primary-bg);
  color: var(--primary);
  border-color: var(--primary-light);
}

.admin-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 300;
  display: none;
  align-items: flex-end;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.admin-overlay.open {
  display: flex;
}

.admin-panel {
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 20px 16px;
  overflow-y: auto;
  animation: slideUp 0.35s ease-out;
  box-shadow: var(--shadow-lg);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.admin-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.admin-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg);
  border: none;
  color: var(--text-muted);
  font-size: 1.05rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.admin-close:hover {
  background: var(--border);
  color: var(--text);
}

.admin-password {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}

.admin-password .form-input {
  flex: 1;
}

.admin-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.admin-btn {
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text-muted);
  font-family: 'Inter', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
}

.admin-btn:hover {
  background: var(--border-light);
  color: var(--text);
}

.admin-btn.download-all {
  background: var(--primary-bg);
  border-color: var(--primary-light);
  color: var(--primary);
}

.admin-btn.delete-btn {
  background: var(--error-bg);
  border-color: rgba(239,68,68,0.3);
  color: var(--error-text);
}

.submission-card {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 10px;
}

.submission-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.submission-facility {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}

.submission-date {
  font-size: 0.68rem;
  color: var(--text-light);
}

.submission-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.submission-actions .admin-btn {
  padding: 7px 12px;
  font-size: 0.7rem;
}

.admin-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-light);
  font-size: 0.82rem;
}

/* --- Sub-question numbering --- */
.sub-q-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
  line-height: 1.5;
}

.sub-q-number {
  color: var(--primary);
  font-weight: 700;
  margin-right: 4px;
}

/* --- Validation Error --- */
.form-input.error,
.form-textarea.error {
  border-color: var(--error);
  box-shadow: 0 0 0 3px var(--error-bg);
}

.error-message {
  font-size: 0.7rem;
  color: var(--error-text);
  margin-top: 4px;
  display: none;
}

.error-message.visible {
  display: block;
}

/* --- Utility --- */
.hidden {
  display: none !important;
}

.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }

/* --- Mobile Safe Area --- */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .nav-buttons {
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 4px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-light);
}

/* --- Desktop adjustment --- */
@media (min-width: 481px) {
  body {
    display: flex;
    justify-content: center;
  }

  #app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    background: var(--card);
  }

  .nav-buttons {
    max-width: 480px;
    left: 50%;
    transform: translateX(-50%);
  }
}
