/* ==========================================================================
   SmartSoil AI — Reusable Components CSS
   Gauges, pH Meters, Cards, Buttons, Inputs, Modals, Badges, Explainers
   ========================================================================== */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
}

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

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-600), var(--primary-700));
  color: white;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-500), var(--primary-600));
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
  color: white;
}

.btn-secondary {
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  border-color: var(--border-color);
}

.btn-secondary:hover {
  background: var(--primary-50);
  border-color: var(--primary-300);
  color: var(--primary-700);
}

[data-theme="dark"] .btn-secondary:hover {
  background: rgba(16, 185, 129, 0.1);
  color: var(--primary-300);
}

.btn-amber {
  background: linear-gradient(135deg, var(--amber-500), var(--amber-600));
  color: white;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.btn-amber:hover {
  background: linear-gradient(135deg, var(--amber-400), var(--amber-500));
  box-shadow: 0 6px 16px rgba(245, 158, 11, 0.4);
}

.btn-outline {
  background: transparent;
  border-color: var(--primary-600);
  color: var(--primary-600);
}

.btn-outline:hover {
  background: var(--primary-50);
}

[data-theme="dark"] .btn-outline:hover {
  background: rgba(16, 185, 129, 0.1);
}

.btn-lg {
  padding: 0.85rem 1.75rem;
  font-size: 1.05rem;
  border-radius: var(--radius-lg);
}

.btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: 0.82rem;
  border-radius: var(--radius-sm);
}

.btn-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: var(--radius-md);
}

/* Badges & Chips */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: capitalize;
}

.badge-good, .badge-healthy, .badge-optimal {
  background: var(--status-good-bg);
  color: var(--status-good);
  border: 1px solid rgba(16, 185, 129, 0.25);
}

.badge-warn, .badge-attention, .badge-medium {
  background: var(--status-warn-bg);
  color: var(--status-warn);
  border: 1px solid rgba(245, 158, 11, 0.25);
}

.badge-alert, .badge-critical, .badge-high {
  background: var(--status-alert-bg);
  color: var(--status-alert);
  border: 1px solid rgba(239, 68, 68, 0.25);
}

.badge-info {
  background: var(--status-info-bg);
  color: var(--status-info);
  border: 1px solid rgba(14, 165, 233, 0.25);
}

/* Form Controls */
.form-group {
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.form-control {
  width: 100%;
  padding: 0.65rem 0.95rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.95rem;
  transition: all var(--transition-fast);
}

.form-control:focus {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}

.form-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

/* Segmented Control */
.segmented-control {
  display: flex;
  background: var(--border-light);
  padding: 0.25rem;
  border-radius: var(--radius-md);
  gap: 0.25rem;
}

.segment-btn {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.segment-btn.active {
  background: var(--bg-surface);
  color: var(--primary-700);
  box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .segment-btn.active {
  color: var(--primary-400);
}

/* Circular Score Gauge */
.health-score-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  text-align: center;
}

.score-gauge-svg {
  width: 200px;
  height: 200px;
  transform: rotate(-90deg);
}

.score-gauge-bg {
  fill: none;
  stroke: var(--border-color);
  stroke-width: 14;
}

.score-gauge-fill {
  fill: none;
  stroke: var(--primary-500);
  stroke-width: 14;
  stroke-linecap: round;
  stroke-dasharray: 565.48;
  stroke-dashoffset: 565.48;
  transition: stroke-dashoffset 1.2s ease-out, stroke 0.5s ease;
}

.score-gauge-text-wrap {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.score-gauge-number {
  font-family: var(--font-heading);
  font-size: 3.2rem;
  font-weight: 800;
  line-height: 1;
  color: var(--text-primary);
}

.score-gauge-max {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 600;
}

.score-status-pill {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 0.3rem 1rem;
  border-radius: var(--radius-full);
}

/* Interactive pH Meter */
.ph-meter-card {
  padding: 1.5rem;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
}

.ph-spectrum-bar {
  height: 24px;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, 
    #ef4444 0%, /* 0-4 Very Acidic */
    #f97316 28%, /* 4-5.5 Acidic */
    #eab308 42%, /* 5.5-6.5 Moderately Acidic */
    #22c55e 50%, /* 6.5-7.5 Neutral/Optimal */
    #06b6d4 64%, /* 7.5-8.5 Moderately Alkaline */
    #3b82f6 78%, /* 8.5-10 Alkaline */
    #8b5cf6 100% /* 10-14 Strongly Alkaline */
  );
  position: relative;
  margin: 1.5rem 0 0.75rem 0;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.15);
}

.ph-needle-indicator {
  position: absolute;
  top: -10px;
  width: 4px;
  height: 44px;
  background: #0f172a;
  border-radius: 2px;
  transform: translateX(-50%);
  box-shadow: 0 0 8px rgba(0,0,0,0.4);
  transition: left 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

[data-theme="dark"] .ph-needle-indicator {
  background: #ffffff;
}

.ph-needle-indicator::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 8px solid #0f172a;
}

[data-theme="dark"] .ph-needle-indicator::after {
  border-bottom-color: #ffffff;
}

.ph-scale-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  padding: 0 4px;
}

/* Nutrient Cards & Progress Bar */
.nutrient-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.nutrient-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary-400);
}

.nutrient-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.nutrient-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.nutrient-value-display {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-primary);
}

.nutrient-unit {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: 0.2rem;
}

.nutrient-bar-track {
  width: 100%;
  height: 8px;
  background: var(--border-light);
  border-radius: var(--radius-full);
  position: relative;
  overflow: hidden;
}

.nutrient-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.8s ease;
}

.nutrient-ref-range {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

/* Problem Diagnosis Cards */
.problem-card {
  border-radius: var(--radius-md);
  padding: 1.2rem;
  background: var(--bg-surface);
  border-left: 5px solid var(--primary-500);
  border-top: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.problem-card.severity-high {
  border-left-color: var(--status-alert);
}

.problem-card.severity-medium {
  border-left-color: var(--status-warn);
}

.problem-card.severity-low {
  border-left-color: var(--status-good);
}

/* "Why?" Explainer Popover */
.why-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary-700);
  background: var(--primary-50);
  border: 1px solid var(--primary-200);
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.why-btn:hover {
  background: var(--primary-100);
  border-color: var(--primary-400);
}

[data-theme="dark"] .why-btn {
  background: rgba(16, 185, 129, 0.15);
  color: var(--primary-300);
  border-color: rgba(16, 185, 129, 0.3);
}

/* Modal Dialog */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  animation: fadeIn 0.2s ease;
}

.modal-backdrop.active {
  display: flex;
}

.modal-content {
  background: var(--bg-surface);
  border-radius: var(--radius-xl);
  max-width: 650px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--border-color);
  padding: 1.75rem;
  position: relative;
  animation: modalScale 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-close-btn {
  position: absolute;
  top: 1.25rem;
  right: 1.25rem;
  background: var(--border-light);
  border: none;
  border-radius: var(--radius-full);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
}

.modal-close-btn:hover {
  background: var(--border-color);
  color: var(--text-primary);
}

@keyframes modalScale {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* Data Quality Indicator */
.data-quality-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  font-weight: 600;
}
