:root {
  --green: #076223;
  --navy: #132f46;
  --bg-color: #f8fafc;
  --surface: #ffffff;
  --text-main: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --focus-ring: rgba(7, 98, 35, 0.2);
  --error: #ef4444;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Loader Overlay */
.loader-overlay {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background-color: rgba(255, 255, 255, 0.9);
  z-index: 100;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  transition: opacity 0.3s ease;
}

.loader-overlay p {
  font-weight: 600;
  color: var(--navy);
  letter-spacing: 0.5px;
  animation: simplePulse 2s ease-in-out infinite;
}

@keyframes simplePulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 1.5rem;
}

@keyframes spin { 
  0% { transform: rotate(0deg); } 
  100% { transform: rotate(360deg); } 
}

/* Main App Container */
.app-container {
  max-width: 600px;
  margin: 2rem auto;
  padding: 2rem;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
}

@media (max-width: 640px) {
  .app-container {
    margin: 0;
    min-height: 100vh;
    border-radius: 0;
    box-shadow: none;
    padding: 1.5rem;
  }
}

/* Header */
.app-header {
  text-align: center;
  margin-bottom: 2rem;
}

/* Entry Modal - Modern & Glassmorphism Design */
.entry-modal {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100vh;
  background: linear-gradient(135deg, rgba(7, 98, 35, 0.8), rgba(19, 47, 70, 0.9));
  backdrop-filter: blur(8px);
  z-index: 50;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1.5rem;
}

.entry-card {
  background: rgba(255, 255, 255, 0.95);
  padding: 3rem 2.5rem;
  border-radius: 20px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  text-align: center;
  max-width: 420px;
  width: 100%;
  animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.entry-card h2 {
  font-size: 2rem;
  color: var(--navy);
  margin-bottom: 0.5rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.entry-card p {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 2rem;
  line-height: 1.5;
}

#entryError {
  margin-bottom: 0;
  color: var(--error);
  font-weight: 500;
}

.form-control {
  width: 100%;
  padding: 1rem 1.25rem;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 1.1rem;
  font-family: inherit;
  transition: all 0.3s ease;
  background: var(--bg-color);
  color: var(--navy);
  text-align: center;
  font-weight: 600;
  letter-spacing: 1px;
}

.form-control:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 4px var(--focus-ring);
  background: #ffffff;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(30px); }
  to { opacity: 1; transform: translateY(0); }
}

.logo-container img {
  max-height: 80px;
  max-width: 100%;
  margin-bottom: 1rem;
}

.app-header h1 {
  font-size: 1.75rem;
  color: var(--navy);
  margin-bottom: 0.5rem;
  font-weight: 700;
}

.app-header p {
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Fields Container */
.fields-container {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.input-group {
  display: flex;
  flex-direction: column;
}

.input-group label {
  font-weight: 500;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
  color: var(--navy);
}

.input-control {
  width: 100%;
  box-sizing: border-box;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  transition: all 0.2s;
  background-color: var(--bg-color);
}

.input-control:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--focus-ring);
  background-color: var(--surface);
}

/* Consent Checkbox */
.consent-container {
  margin: 1.5rem 0;
  padding: 1rem;
  background-color: rgba(19, 47, 70, 0.05);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.checkbox-label {
  display: flex;
  align-items: flex-start;
  cursor: pointer;
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  border-bottom: 1px dashed rgba(19, 47, 70, 0.15);
}

.checkbox-label:last-child {
  padding-bottom: 0;
  margin-bottom: 0;
  border-bottom: none;
}

.checkbox-label input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  height: 0;
  width: 0;
}

.custom-checkbox {
  flex-shrink: 0;
  height: 20px;
  width: 20px;
  background-color: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-right: 12px;
  margin-top: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.checkbox-label input:checked ~ .custom-checkbox {
  background-color: var(--green);
  border-color: var(--green);
}

.checkbox-label input:checked ~ .custom-checkbox::after {
  content: '';
  width: 5px;
  height: 10px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

#consentText {
  font-size: 0.9rem;
  line-height: 1.4;
  color: var(--navy);
}

.req-marker.req {
  color: var(--error);
  margin-left: 4px;
}

.req-marker.opt {
  color: var(--text-muted);
  font-size: 0.85em;
  font-weight: normal;
  margin-left: 4px;
}

/* Validation Highlights */
.input-control.error {
  border-color: var(--error) !important;
  background-color: rgba(239, 68, 68, 0.05);
}

.checkbox-label.error {
  border: 1px solid var(--error);
  padding: 8px;
  border-radius: 8px;
  background-color: rgba(239, 68, 68, 0.05);
}

/* Signature Section */
.signature-section {
  margin: 2rem 0;
}

.signature-section h3 {
  font-size: 1.1rem;
  color: var(--navy);
  margin-bottom: 0.25rem;
}

.instruction-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.signature-pad-wrapper {
  border: 2px dashed var(--border);
  border-radius: 12px;
  background-color: #fff;
  overflow: hidden;
  touch-action: none; /* Crucial for drawing on mobile */
  position: relative;
  /* Maintain a good aspect ratio, allowing landscape max usage */
  width: 100%;
  height: 200px;
}

canvas#signatureCanvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.signature-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.75rem;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
}

.btn-primary {
  width: 100%;
  background-color: var(--green);
  color: #fff;
  box-shadow: 0 4px 6px rgba(7, 98, 35, 0.2);
}

.btn-primary:hover {
  background-color: #054f1c;
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  background-color: var(--text-muted);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-secondary {
  background-color: var(--border);
  color: var(--text-main);
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
}

.btn-secondary:hover {
  background-color: #d1d5db;
}

/* Status Messages */
.status-message {
  padding: 1rem;
  border-radius: 8px;
  margin-bottom: 1.5rem;
  font-weight: 500;
  text-align: center;
}

.status-message.error {
  background-color: rgba(239, 68, 68, 0.1);
  color: var(--error);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.status-message.warning {
  background-color: #fffbeb;
  color: #92400e;
  border: 1px solid #fcd34d;
}

.status-message.warning .btn {
  margin-top: 0.75rem;
}

/* Location check panel (shown when the form is blocked) */
.location-panel {
  padding: 1.25rem;
  border-radius: 12px;
  margin-bottom: 1.5rem;
  background-color: rgba(239, 68, 68, 0.06);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.location-panel-title {
  font-weight: 600;
  color: var(--error);
  margin-bottom: 0.5rem;
}

.location-panel-detail {
  color: var(--text-main);
  margin-bottom: 0.75rem;
}

.location-tips {
  margin: 0 0 1.25rem 1.25rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.location-tips li + li {
  margin-top: 0.35rem;
}

/* Success View Animation */
.success-view {
  text-align: center;
  padding: 3rem 1rem;
}

.success-view h2 {
  color: var(--green);
  margin: 1.5rem 0 0.5rem;
}

.success-view p {
  color: var(--text-muted);
}

.checkmark-circle {
  width: 80px;
  height: 80px;
  position: relative;
  display: inline-block;
}

.checkmark-circle .background {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--green);
  position: absolute;
}

.checkmark-circle .checkmark {
  border-radius: 5px;
}

.checkmark-circle .checkmark.draw:after {
  animation-duration: 800ms;
  animation-timing-function: ease;
  animation-name: checkmark;
  transform: scaleX(-1) rotate(135deg);
  animation-fill-mode: forwards;
}

.checkmark-circle .checkmark:after {
  opacity: 1;
  height: 40px;
  width: 20px;
  transform-origin: left top;
  border-right: 4px solid white;
  border-top: 4px solid white;
  content: '';
  left: 20px;
  top: 40px;
  position: absolute;
}

/* Verified Mode */
.verified-entry {
  text-align: center;
  padding: 1rem 0;
}

.verified-entry .input-group {
  max-width: 320px;
  margin: 0 auto;
}

.verified-entry .input-group label {
  font-size: 1rem;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 0.5rem;
}

.verified-input {
  text-align: center;
  font-size: 1.5rem !important;
  font-weight: 700;
  letter-spacing: 2px;
  padding: 1rem 1.25rem !important;
  border: 2px solid var(--border) !important;
  border-radius: 12px !important;
}

.verified-input:focus {
  border-color: var(--green) !important;
  box-shadow: 0 0 0 4px var(--focus-ring) !important;
}

/* Live digit counter & progress fill pill (Amber -> Green) */
.digit-counter,
.valid-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background-color: #f1f5f9;
  color: #475569;
  white-space: nowrap;
  letter-spacing: 0.2px;
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #e2e8f0;
  min-width: 86px;
  transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease, transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s;
}

.pill-progress-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0%;
  background: rgba(251, 191, 36, 0.45);
  transition: width 0.2s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s ease;
  z-index: 0;
  border-radius: 999px;
}

.pill-text {
  position: relative;
  z-index: 1;
  transition: color 0.2s ease;
}

.digit-counter.valid,
.valid-badge.valid {
  background-color: #dcfce7 !important;
  border-color: #bbf7d0 !important;
  color: #15803d !important;
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(21, 128, 61, 0.18);
  transform: scale(1.04);
}

.digit-counter.valid .pill-progress-fill,
.valid-badge.valid .pill-progress-fill {
  background: #dcfce7 !important;
}

.digit-counter.searching,
.valid-badge.searching {
  background-color: #fef3c7 !important;
  border-color: #fde68a !important;
  color: #92400e !important;
}

/* Modern search shimmer on active input */
.input-control.is-searching {
  pointer-events: none;
  border-color: #cbd5e1 !important;
  color: #334155 !important;
  background-color: #e2e8f0 !important;
  background-image: linear-gradient(
    90deg,
    #e2e8f0 0%,
    #e2e8f0 35%,
    #cbd5e1 42%,
    #ffffff 50%,
    #cbd5e1 58%,
    #e2e8f0 65%,
    #e2e8f0 100%
  ) !important;
  background-repeat: no-repeat !important;
  background-size: 200% 100% !important;
  animation: searchShimmer 1.4s cubic-bezier(0.4, 0, 0.2, 1) infinite !important;
  box-shadow: 0 0 0 3px rgba(19, 47, 70, 0.08);
}

/* Skeleton shimmer on downstream form fields while lookup is searching */
.input-control.skeleton-loading,
select.input-control.skeleton-loading {
  pointer-events: none;
  border-color: #cbd5e1 !important;
  color: transparent !important;
  background-color: #e2e8f0 !important;
  background-image: linear-gradient(
    90deg,
    #e2e8f0 0%,
    #e2e8f0 35%,
    #cbd5e1 42%,
    #ffffff 50%,
    #cbd5e1 58%,
    #e2e8f0 65%,
    #e2e8f0 100%
  ) !important;
  background-repeat: no-repeat !important;
  background-size: 200% 100% !important;
  animation: searchShimmer 1.4s cubic-bezier(0.4, 0, 0.2, 1) infinite !important;
}

.input-control.skeleton-loading::placeholder {
  color: transparent !important;
}

@keyframes searchShimmer {
  0% {
    background-position: 130% 0;
  }
  100% {
    background-position: -30% 0;
  }
}

.field-readonly {
  background-color: #f1f5f9 !important;
  color: var(--text-muted) !important;
  cursor: not-allowed !important;
  border-color: transparent !important;
  pointer-events: none;
}

.verified-expanded {
  animation: expandIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  margin-top: 1.25rem;
}

@keyframes expandIn {
  from { opacity: 0; transform: translateY(-10px); max-height: 0; }
  to { opacity: 1; transform: translateY(0); max-height: 2000px; }
}

@keyframes checkmark {
  0% { height: 0; width: 0; opacity: 1; }
  20% { height: 0; width: 20px; opacity: 1; }
  40% { height: 40px; width: 20px; opacity: 1; }
  100% { height: 40px; width: 20px; opacity: 1; }
}

/* Dropdown Select Styling — matches text inputs */
select.input-control {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  padding-right: 2.5rem;
  cursor: pointer;
}

select.input-control:focus {
  cursor: pointer;
}

/* Disabled fields (Strict mode — before lookup) */
.input-control:disabled,
select.input-control:disabled {
  background-color: #f1f5f9 !important;
  color: #94a3b8 !important;
  cursor: not-allowed !important;
  border-color: #e2e8f0 !important;
  opacity: 0.7;
}

/* Read-only select dropdowns (after prefill) */
select.input-control.field-readonly {
  background-color: #f1f5f9 !important;
  color: var(--text-muted) !important;
  cursor: not-allowed !important;
  border-color: transparent !important;
  pointer-events: none;
  background-image: none;
}

/* Info Card — informational text section with link support */
.info-card {
  padding: 0.875rem 1rem;
  background-color: rgba(7, 98, 35, 0.04);
  border-left: 3px solid var(--green);
  border-radius: 0 8px 8px 0;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--navy);
}

.info-card a {
  color: var(--green);
  text-decoration: underline;
  font-weight: 500;
  transition: color 0.2s;
}

.info-card a:hover {
  color: #054f1c;
}

/* Conditional Group — show/hide sections based on dropdown answers */
.condition-group {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.4s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.3s ease,
              margin 0.3s ease;
  margin-top: 0;
  margin-bottom: 0;
}

.condition-group.visible {
  max-height: 2000px;
  opacity: 1;
  margin-top: 1.25rem;
  margin-bottom: 0;
}

.condition-group-inner {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1rem;
  background-color: rgba(19, 47, 70, 0.02);
  border: 1px solid rgba(19, 47, 70, 0.08);
  border-left: 3px solid var(--green);
  border-radius: 0 10px 10px 0;
}

/* Links in FormDescription */
.app-header p a {
  color: var(--green);
  text-decoration: underline;
  font-weight: 500;
}

.app-header p a:hover {
  color: #054f1c;
}

