/* Global Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary-color: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --success-color: #10b981;
  --error-color: #ef4444;
  --warning-color: #f59e0b;
  --neutral-light: #f3f4f6;
  --neutral-medium: #d1d5db;
  --neutral-dark: #374151;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --border-radius: 8px;
  --spacing-unit: 8px;
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: #ffffff;
  color: var(--text-primary);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
}

/* Container & Layout */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: calc(var(--spacing-unit) * 2);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  padding: calc(var(--spacing-unit) * 2);
  border-bottom: 1px solid var(--neutral-medium);
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: calc(var(--spacing-unit) * 2);
}

.header h1 {
  font-size: 24px;
  font-weight: 600;
}

.header .logout-btn {
  background-color: var(--error-color);
}

/* Forms */
.form-group {
  margin-bottom: calc(var(--spacing-unit) * 2);
  display: flex;
  flex-direction: column;
}

label {
  font-weight: 500;
  margin-bottom: calc(var(--spacing-unit) * 0.5);
  font-size: 14px;
}

input[type="text"],
input[type="password"],
input[type="email"],
select,
textarea {
  padding: calc(var(--spacing-unit) * 1.5);
  border: 2px solid var(--neutral-medium);
  border-radius: var(--border-radius);
  font-size: 16px;
  font-family: inherit;
  transition: border-color 0.3s;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Buttons */
button,
.btn {
  min-height: 48px;
  min-width: 48px;
  padding: calc(var(--spacing-unit) * 1.5) calc(var(--spacing-unit) * 2);
  border: none;
  border-radius: var(--border-radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  gap: calc(var(--spacing-unit) * 0.5);
}

button:not(:disabled):hover,
.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background-color: var(--primary-color);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--primary-dark);
}

.btn-secondary {
  background-color: var(--neutral-light);
  color: var(--text-primary);
  border: 2px solid var(--neutral-medium);
}

.btn-secondary:hover:not(:disabled) {
  background-color: var(--neutral-medium);
}

.btn-success {
  background-color: var(--success-color);
  color: white;
}

.btn-success:hover:not(:disabled) {
  background-color: #059669;
}

.btn-error {
  background-color: var(--error-color);
  color: white;
}

.btn-error:hover:not(:disabled) {
  background-color: #dc2626;
}

.btn-warning {
  background-color: var(--warning-color);
  color: white;
}

.btn-warning:hover:not(:disabled) {
  background-color: #d97706;
}

.btn-block {
  width: 100%;
}

/* Forms Container */
.form-container {
  max-width: 400px;
  margin: auto;
  padding: calc(var(--spacing-unit) * 3);
  background: white;
  border-radius: var(--border-radius);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.form-title {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: calc(var(--spacing-unit) * 2);
  text-align: center;
}

.form-error {
  background-color: #fecaca;
  color: var(--error-color);
  padding: calc(var(--spacing-unit) * 1);
  border-radius: var(--border-radius);
  margin-bottom: calc(var(--spacing-unit) * 2);
  font-size: 14px;
  border-left: 4px solid var(--error-color);
}

.form-success {
  background-color: #dcfce7;
  color: var(--success-color);
  padding: calc(var(--spacing-unit) * 1);
  border-radius: var(--border-radius);
  margin-bottom: calc(var(--spacing-unit) * 2);
  font-size: 14px;
  border-left: 4px solid var(--success-color);
}

/* Grids */
.grid {
  display: grid;
  gap: calc(var(--spacing-unit) * 2);
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  width: 100%;
}

.grid.patients {
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
}

.grid.activities {
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

/* Avatar/Card */
.avatar-card,
.activity-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--spacing-unit) * 1);
  padding: calc(var(--spacing-unit) * 2);
  border: 2px solid var(--neutral-medium);
  border-radius: var(--border-radius);
  background: white;
  cursor: pointer;
  transition: all 0.3s;
  text-align: center;
}

.avatar-card:hover,
.activity-card:hover {
  border-color: var(--primary-color);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
  transform: translateY(-2px);
}

.avatar-card.selected,
.activity-card.selected {
  background-color: #eef2ff;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.avatar {
  font-size: 48px;
  line-height: 1;
}

.avatar-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  word-break: break-word;
}

.activity-name {
  font-size: 14px;
  font-weight: 600;
}

.activity-difficulty {
  font-size: 12px;
  font-weight: 500;
  padding: calc(var(--spacing-unit) * 0.5) calc(var(--spacing-unit));
  border-radius: 999px;
  background-color: var(--neutral-light);
}

.activity-difficulty.easy {
  background-color: #dcfce7;
  color: var(--success-color);
}

.activity-difficulty.medium {
  background-color: #fef3c7;
  color: var(--warning-color);
}

.activity-difficulty.hard {
  background-color: #fee2e2;
  color: var(--error-color);
}

/* Search */
.search-container {
  margin-bottom: calc(var(--spacing-unit) * 2);
  position: relative;
}

.search-input {
  width: 100%;
  padding: calc(var(--spacing-unit) * 1.5);
  font-size: 16px;
  border: 2px solid var(--neutral-medium);
  border-radius: var(--border-radius);
}

.search-input::placeholder {
  color: var(--text-secondary);
}

/* Activity Runner */
.activity-runner {
  display: flex;
  flex-direction: column;
  height: 100vh;
  gap: calc(var(--spacing-unit) * 1);
}

.activity-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(var(--spacing-unit) * 1.5);
  background-color: var(--neutral-light);
  border-radius: var(--border-radius);
}

.activity-stats {
  display: flex;
  gap: calc(var(--spacing-unit) * 2);
  font-size: 18px;
  font-weight: 600;
}

.activity-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: calc(var(--spacing-unit) * 0.5);
}

.activity-stat-value {
  font-size: 24px;
  color: var(--primary-color);
}

.activity-stat-label {
  font-size: 12px;
  color: var(--text-secondary);
}

.activity-canvas-container {
  flex: 1;
  position: relative;
  background-color: #f9fafb;
  border-radius: var(--border-radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
}

.activity-scenario {
  position: relative;
  width: 100%;
  min-height: 480px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scenario-placeholder {
  color: var(--text-secondary);
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  padding: calc(var(--spacing-unit) * 2);
  background: rgba(255, 255, 255, 0.85);
  border: 1px dashed var(--neutral-medium);
  border-radius: var(--border-radius);
}

.activity-zone {
  position: absolute;
  border: 2px dashed var(--primary-color);
  background-color: rgba(99, 102, 241, 0.05);
  opacity: 0;
  transition: all 0.2s;
  pointer-events: none;
  z-index: 40;
}

.activity-zone.active {
  background-color: rgba(99, 102, 241, 0.15);
  opacity: 1;
  border-color: var(--success-color);
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.18), 0 0 20px rgba(34, 197, 94, 0.35);
}

.activity-zone-label {
  position: absolute;
  top: -20px;
  left: 0;
  background-color: var(--primary-color);
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.draggable-object {
  position: absolute;
  width: 80px;
  height: 80px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  cursor: grab;
  transition: all 0.2s;
  border-radius: 4px;
}

.draggable-object:hover {
  transform: scale(1.1);
}

.draggable-object.dragging {
  opacity: 0.7;
  cursor: grabbing;
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.draggable-object.placed {
  opacity: 0.8;
  border: 3px solid var(--success-color);
}

.draggable-object.placed::after {
  content: "✓";
  position: absolute;
  top: -10px;
  right: -10px;
  width: 24px;
  height: 24px;
  background-color: var(--success-color);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 14px;
}

.draggable-object.invalid {
  animation: bounce 0.5s;
}

@keyframes bounce {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-10px); }
  75% { transform: translateX(10px); }
}

/* Reward Overlay */
.reward-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  animation: fadeIn 0.3s;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.reward-content {
  background: white;
  padding: calc(var(--spacing-unit) * 4);
  border-radius: var(--border-radius);
  text-align: center;
  animation: slideUp 0.5s;
}

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

.reward-title {
  font-size: 32px;
  font-weight: 700;
  color: var(--success-color);
  margin-bottom: calc(var(--spacing-unit) * 1);
}

.reward-message {
  font-size: 18px;
  color: var(--text-secondary);
  margin-bottom: calc(var(--spacing-unit) * 2);
}

.reward-emoji {
  font-size: 64px;
  margin: calc(var(--spacing-unit) * 2) 0;
  animation: bounce-emoji 0.8s infinite;
}

@keyframes bounce-emoji {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-20px); }
}

.reward-stats {
  background-color: var(--neutral-light);
  padding: calc(var(--spacing-unit) * 2);
  border-radius: var(--border-radius);
  margin-bottom: calc(var(--spacing-unit) * 2);
  text-align: left;
}

.reward-stat {
  display: flex;
  justify-content: space-between;
  padding: calc(var(--spacing-unit) * 0.5) 0;
  font-size: 14px;
}

.reward-actions {
  display: flex;
  gap: calc(var(--spacing-unit) * 1);
  justify-content: center;
}

.reward-actions button {
  flex: 1;
}

/* Controls */
.controls {
  display: flex;
  gap: calc(var(--spacing-unit) * 1);
  justify-content: center;
  flex-wrap: wrap;
  padding: calc(var(--spacing-unit) * 1.5);
  background-color: var(--neutral-light);
  border-radius: var(--border-radius);
}

.controls button {
  flex: 1;
  min-width: 100px;
}

/* Responsive */
@media (max-width: 768px) {
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }

  .activity-stats {
    flex-wrap: wrap;
    font-size: 14px;
  }

  .activity-header {
    padding: calc(var(--spacing-unit) * 1);
  }

  .form-container {
    max-width: 90%;
  }

  .reward-content {
    padding: calc(var(--spacing-unit) * 2);
    margin: 0 calc(var(--spacing-unit) * 1);
  }

  .reward-title {
    font-size: 24px;
  }
}

/* Loading Spinner */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid var(--neutral-medium);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: calc(var(--spacing-unit) * 1);
  min-height: 200px;
}

.loading-text {
  color: var(--text-secondary);
  font-size: 14px;
}

/* Utility Classes */
.mt-1 { margin-top: calc(var(--spacing-unit) * 1); }
.mt-2 { margin-top: calc(var(--spacing-unit) * 2); }
.mt-3 { margin-top: calc(var(--spacing-unit) * 3); }

.mb-1 { margin-bottom: calc(var(--spacing-unit) * 1); }
.mb-2 { margin-bottom: calc(var(--spacing-unit) * 2); }
.mb-3 { margin-bottom: calc(var(--spacing-unit) * 3); }

.text-center { text-align: center; }
.text-muted { color: var(--text-secondary); }
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.gap-1 { gap: calc(var(--spacing-unit) * 1); }
.gap-2 { gap: calc(var(--spacing-unit) * 2); }

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Palette System (T005) */
.palette {
  display: flex;
  flex-direction: column;
  background-color: var(--neutral-light);
  padding: calc(var(--spacing-unit) * 1);
  border-bottom: 1px solid var(--neutral-medium);
  border-radius: var(--border-radius);
}

.palette-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: calc(var(--spacing-unit) * 0.5);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.palette-container {
  display: flex;
  overflow-x: auto;
  gap: calc(var(--spacing-unit) * 1);
  padding: calc(var(--spacing-unit) * 0.5);
  border-radius: 4px;
}

.palette-item {
  width: 80px;
  height: 80px;
  border: 2px solid var(--neutral-medium);
  border-radius: 4px;
  cursor: grab;
  flex-shrink: 0;
  background-color: white;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  font-weight: bold;
  transition: all 0.2s;
}

.palette-item:hover {
  border-color: var(--primary-color);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.15);
  transform: translateY(-2px);
}

.palette-item.dragging {
  opacity: 0.5;
  border-color: var(--primary-color);
  cursor: grabbing;
}

.palette-item.placed {
  display: none;
  border-color: var(--neutral-medium);
}

/* Canvas/Lienzo System (T005) */
.activity-scenario {
  width: 100%;
  height: 100%;
  aspect-ratio: 1;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  position: relative;
  overflow: hidden;
  border-radius: 4px;
}

/* SVG Zone Overlay (T051/T052) */
.zones-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 60;
}

.zone-polygon {
  fill: rgba(59, 130, 246, 0.04);
  stroke: rgba(59, 130, 246, 0.22);
  stroke-width: 2px;
  transition: all 0.2s;
  pointer-events: none;
  vector-effect: non-scaling-stroke;
}

.activity-scenario.dragging-zones .zone-polygon {
  fill: rgba(59, 130, 246, 0.22);
  stroke: rgba(37, 99, 235, 0.98);
  stroke-width: 4px;
  filter: drop-shadow(0 0 8px rgba(37, 99, 235, 0.9));
}

.zone-polygon:hover {
  fill: rgba(59, 130, 246, 0.15);
  stroke: rgba(59, 130, 246, 0.6);
  stroke-width: 4px;
}

.zone-polygon.active {
  fill: rgba(34, 197, 94, 0.35);
  stroke: rgba(22, 163, 74, 1);
  stroke-width: 7px;
  filter: drop-shadow(0 0 14px rgba(34, 197, 94, 1));
}

.zone-polygon.active:hover {
  fill: rgba(34, 197, 94, 0.25);
}

.zone-polygon.rejected {
  fill: rgba(239, 68, 68, 0.15);
  stroke: rgba(239, 68, 68, 0.8);
  stroke-width: 3px;
  animation: zone-shake 0.4s;
}

@keyframes zone-shake {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(239, 68, 68, 0)); }
  50% { filter: drop-shadow(0 0 8px rgba(239, 68, 68, 0.8)); }
}

/* Placed Objects (T052) */
.placed-object {
  position: absolute;
  width: 80px;
  height: 80px;
  border: 2px solid var(--success-color);
  border-radius: 4px;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  font-weight: bold;
  box-shadow: 0 4px 12px rgba(34, 197, 94, 0.2);
  animation: placed-pop 0.4s ease-out;
  z-index: 30;
  cursor: grab;
}

.placed-object.dragging {
  opacity: 0.45;
  cursor: grabbing;
}

@keyframes placed-pop {
  0% {
    transform: scale(0.8);
    opacity: 0;
  }
  70% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.placed-object::after {
  content: "✓";
  position: absolute;
  top: -10px;
  right: -10px;
  width: 24px;
  height: 24px;
  background-color: var(--success-color);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 12px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Drag Ghost/Preview (T052) */
.drag-ghost {
  position: fixed;
  pointer-events: none;
  width: 80px;
  height: 80px;
  border: 3px solid var(--primary-color);
  border-radius: 4px;
  background-color: white;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  font-weight: bold;
  box-shadow: 0 8px 16px rgba(99, 102, 241, 0.3);
  opacity: 0.95;
  z-index: 1000;
}

.drag-ghost.invalid {
  border-color: var(--error-color);
  box-shadow: 0 8px 16px rgba(239, 68, 68, 0.3);
  animation: drag-shake 0.3s;
}

@keyframes drag-shake {
  0%, 100% { transform: translateX(0) rotate(0deg); }
  25% { transform: translateX(-5px) rotate(-1deg); }
  75% { transform: translateX(5px) rotate(1deg); }
}

/* Feedback Overlays (T052) */
.rejection-feedback {
  position: absolute;
  width: 100px;
  height: 100px;
  border: 3px solid var(--error-color);
  border-radius: 50%;
  background-color: rgba(239, 68, 68, 0.1);
  pointer-events: none;
  animation: rejection-pulse 0.5s ease-out;
  z-index: 500;
}

@keyframes rejection-pulse {
  0% {
    transform: scale(0.5);
    opacity: 1;
  }
  100% {
    transform: scale(1.5);
    opacity: 0;
  }
}

.rejection-text {
  position: absolute;
  font-size: 18px;
  font-weight: 700;
  color: var(--error-color);
  pointer-events: none;
  animation: rejection-float 0.8s ease-out;
  z-index: 501;
}

@keyframes rejection-float {
  0% {
    transform: translateY(0) translateX(0);
    opacity: 1;
  }
  100% {
    transform: translateY(-40px) translateX(20px);
    opacity: 0;
  }
}

/* Confetti Container (T052) */
.confetti-container {
  position: fixed;
  pointer-events: none;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 999;
}

.confetti {
  position: absolute;
  width: 14px;
  height: 18px;
  background-color: var(--success-color);
  border-radius: 3px;
  animation: confetti-fall 4s ease-out forwards;
}

.confetti.variation-1 { background-color: var(--success-color); }
.confetti.variation-2 { background-color: #fbbf24; }
.confetti.variation-3 { background-color: #60a5fa; }
.confetti.variation-4 { background-color: #f472b6; }

@keyframes confetti-fall {
  0% {
    transform: translateY(0) translateX(0) rotate(0deg);
    opacity: 1;
  }
  100% {
    transform: translateY(110vh) translateX(var(--tx, 0px)) rotate(var(--rot, 720deg));
    opacity: 0;
  }
}
