/* ============ DESIGN TOKENS ============ */
:root {
  --c-primary: #00897B;
  --c-primary-dark: #00695C;
  --c-primary-light: #4DB6AC;
  --c-primary-bg: #E0F2F1;

  --c-bg: #F5F7F6;
  --c-surface: #FFFFFF;
  --c-text: #1A1A1A;
  --c-text-secondary: #5F6368;
  --c-text-hint: #9AA0A6;
  --c-border: #DADCE0;
  --c-error: #D32F2F;
  --c-success: #2E7D32;
  --c-warning: #F57F17;

  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.12);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.16);

  --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  --container-max: 480px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font);
  font-size: clamp(0.875rem, 0.8rem + 0.4vw, 1rem);
  line-height: 1.5;
  color: var(--c-text);
  background: var(--c-bg);
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

input, textarea, button, select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

img {
  display: block;
  max-width: 100%;
}

fieldset {
  border: none;
}

a {
  color: var(--c-primary);
}

/* ============ UTILITIES ============ */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none !important;
}

/* ============ LAYOUT ============ */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
}

.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: var(--space-md);
}

/* ============ TYPOGRAPHY ============ */
h1 { font-size: clamp(1.5rem, 1.3rem + 1vw, 2rem); font-weight: 700; }
h2 { font-size: clamp(1.25rem, 1.1rem + 0.75vw, 1.5rem); font-weight: 600; }
h3 { font-size: clamp(1.1rem, 1rem + 0.5vw, 1.25rem); font-weight: 600; }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  min-height: 44px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: clamp(0.875rem, 0.85rem + 0.2vw, 1rem);
  text-decoration: none;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  -webkit-user-select: none;
  user-select: none;
}

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

.btn-primary {
  background: var(--c-primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover { background: var(--c-primary-dark); }
.btn-primary:disabled {
  background: var(--c-border);
  color: var(--c-text-hint);
  cursor: not-allowed;
  transform: none;
}

.btn-outline {
  border: 1.5px solid var(--c-primary);
  color: var(--c-primary);
  background: var(--c-surface);
}

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

.btn-ghost {
  color: var(--c-text-secondary);
  background: transparent;
}

.btn-ghost:hover { background: rgba(0,0,0,0.04); }

.btn-block { width: 100%; }

.btn-sm {
  min-height: 36px;
  padding: var(--space-xs) var(--space-md);
  font-size: 0.8125rem;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-icon:hover { background: rgba(255,255,255,0.15); }

.btn-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  color: var(--c-text);
  flex-shrink: 0;
}

.btn-back:hover { background: rgba(0,0,0,0.06); }

/* ============ FORMS ============ */
.form-label {
  display: block;
  font-weight: 600;
  font-size: clamp(0.8125rem, 0.78rem + 0.2vw, 0.9375rem);
  margin-bottom: var(--space-xs);
  color: var(--c-text);
}

.form-hint {
  font-weight: 400;
  color: var(--c-text-hint);
  font-size: 0.8125rem;
}

.form-count {
  display: block;
  text-align: right;
  margin-top: var(--space-xs);
}

.form-input {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  min-height: 44px;
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: var(--c-surface);
  font-size: 1rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(0,137,123,0.15);
}

.form-input::placeholder { color: var(--c-text-hint); }

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

.form-group {
  margin-bottom: var(--space-md);
}

/* ============ TOGGLE BUTTONS ============ */
.toggle-group {
  margin-bottom: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.toggle-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.toggle-card-label {
  font-size: clamp(0.9375rem, 0.9rem + 0.25vw, 1.0625rem);
  font-weight: 600;
  color: var(--c-text);
}

.toggle-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm);
}

.toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-sm);
  min-height: 52px;
  border-radius: var(--radius-md);
  border: 2px solid var(--c-border);
  background: var(--c-surface);
  font-size: clamp(0.875rem, 0.85rem + 0.2vw, 1rem);
  font-weight: 600;
  color: var(--c-text-secondary);
  transition: border-color 0.15s, background 0.15s, color 0.15s, transform 0.1s;
}

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

.toggle-btn svg {
  opacity: 0.4;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.toggle-btn-yes.active {
  border-color: var(--c-success);
  background: #E8F5E9;
  color: var(--c-success);
}

.toggle-btn-yes.active svg { opacity: 1; }

.toggle-btn-no.active {
  border-color: var(--c-error);
  background: #FFEBEE;
  color: var(--c-error);
}

.toggle-btn-no.active svg { opacity: 1; }

.toggle-btn.active[data-value="residencial"],
.toggle-btn.active[data-value="comunitario"] {
  border-color: var(--c-primary);
  background: var(--c-primary-bg);
  color: var(--c-primary);
}

.toggle-btn.active[data-value="residencial"] svg,
.toggle-btn.active[data-value="comunitario"] svg { opacity: 1; }

/* ============ CHIPS ============ */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  min-height: 32px;
  border-radius: var(--radius-full);
  background: rgba(255,255,255,0.2);
  color: #fff;
  font-size: 0.8125rem;
  font-weight: 500;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.chip-gps { cursor: default; }

.chip-update {
  cursor: pointer;
  transition: opacity 0.15s;
}

.chip-update:active { opacity: 0.7; }

.camera-topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.gps-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c-warning);
  transition: background 0.3s;
}

.gps-dot.active { background: var(--c-success); }
.gps-dot.active { animation: pulse 2s infinite; }
.gps-dot.error { background: var(--c-error); }

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

/* ============ SCREEN: WELCOME ============ */
.welcome-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  text-align: center;
  gap: var(--space-2xl);
}

.welcome-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
}

.welcome-icon {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-lg);
  background: var(--c-primary);
  color: #fff;
  font-size: 2.5rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
}

.welcome-title {
  color: var(--c-primary-dark);
}

.welcome-desc {
  color: var(--c-text-secondary);
  font-size: clamp(0.875rem, 0.85rem + 0.2vw, 1rem);
  max-width: 320px;
  text-align: center;
}

.welcome-form {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.welcome-form .form-label {
  text-align: left;
}

.welcome-footer {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.welcome-credits,
.welcome-sponsor {
  font-size: 0.75rem;
  color: var(--c-text-hint);
}

.welcome-credits strong,
.welcome-sponsor strong {
  color: var(--c-text-secondary);
}

.flag-co {
  display: inline-block;
  vertical-align: middle;
  border-radius: 2px;
}

/* ============ SCREEN: PERMISSIONS ============ */
.permissions-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  gap: var(--space-lg);
}

.permissions-title {
  text-align: center;
}

.permissions-subtitle {
  text-align: center;
  color: var(--c-text-secondary);
  font-size: clamp(0.875rem, 0.85rem + 0.2vw, 1rem);
  max-width: 320px;
}

.permissions-list {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.permission-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  background: var(--c-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.permission-icon {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--c-primary-bg);
  color: var(--c-primary);
  border-radius: var(--radius-sm);
}

.permission-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.permission-name {
  font-weight: 600;
  font-size: clamp(0.875rem, 0.85rem + 0.2vw, 1rem);
}

.permission-desc {
  font-size: 0.8125rem;
  color: var(--c-text-secondary);
}

.permission-status {
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px var(--space-sm);
  border-radius: var(--radius-full);
}

.permission-status.granted {
  background: #E8F5E9;
  color: var(--c-success);
}

.permission-status.denied {
  background: #FFEBEE;
  color: var(--c-error);
}

.permission-status.pending {
  background: var(--c-bg);
  color: var(--c-text-hint);
}

/* ============ SCREEN: CAMERA ============ */
#screen-camera {
  background: #000;
  padding: 0;
}

.camera-topbar {
  position: absolute;
  top: var(--safe-top);
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-sm) var(--space-md);
  padding-left: calc(var(--space-md) + var(--safe-left));
  padding-right: calc(var(--space-md) + var(--safe-right));
}

.camera-viewport {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#camera-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.camera-instructions {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.6);
  padding: var(--space-lg);
  animation: fade-in 0.3s ease;
}

.camera-instructions.hidden { display: none; }

.camera-instructions-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-sm);
  color: #fff;
  max-width: 280px;
}

.camera-instructions-title {
  font-size: clamp(1rem, 0.95rem + 0.3vw, 1.125rem);
  font-weight: 600;
}

.camera-instructions-desc {
  font-size: 0.8125rem;
  color: rgba(255,255,255,0.8);
  line-height: 1.5;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.camera-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  color: rgba(255,255,255,0.7);
  text-align: center;
  padding: var(--space-md);
}

.camera-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md);
  padding-bottom: calc(var(--space-md) + var(--safe-bottom));
  padding-left: calc(var(--space-md) + var(--safe-left));
  padding-right: calc(var(--space-md) + var(--safe-right));
}

.btn-capture {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: transparent;
  padding: 4px;
  transition: transform 0.1s;
}

.btn-capture:active { transform: scale(0.92); }

.btn-capture-inner {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #fff;
  transition: background 0.15s;
}

.btn-capture:active .btn-capture-inner { background: var(--c-primary-light); }

/* ============ SCREEN: DATA ============ */
#screen-data {
  background: var(--c-bg);
}

.screen-header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
}

.screen-title {
  flex: 1;
}

.photo-preview {
  position: relative;
  margin-bottom: var(--space-lg);
}

.photo-preview img {
  width: 100%;
  object-fit: contain;
  border-radius: var(--radius-md);
  background: var(--c-bg);
}

.photo-preview .btn {
  position: absolute;
  bottom: var(--space-sm);
  right: var(--space-sm);
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.data-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  padding-bottom: var(--space-xl);
}

/* ============ SCREEN: SUMMARY ============ */
.summary-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  text-align: center;
  gap: var(--space-lg);
}

.checkmark-wrap {
  width: 72px;
  height: 72px;
}

.checkmark {
  width: 72px;
  height: 72px;
}

.checkmark-circle {
  stroke-dasharray: 157;
  stroke-dashoffset: 157;
  stroke-width: 2;
  stroke: var(--c-success);
  animation: circle-draw 0.5s ease forwards;
}

.checkmark-check {
  stroke-dasharray: 48;
  stroke-dashoffset: 48;
  stroke-width: 3;
  stroke: var(--c-success);
  stroke-linecap: round;
  stroke-linejoin: round;
  animation: check-draw 0.3s 0.4s ease forwards;
}

@keyframes circle-draw {
  to { stroke-dashoffset: 0; }
}

@keyframes check-draw {
  to { stroke-dashoffset: 0; }
}

.summary-title {
  color: var(--c-success);
}

.summary-status {
  color: var(--c-text-secondary);
  font-size: clamp(0.8125rem, 0.78rem + 0.2vw, 0.9375rem);
}

.summary-img {
  width: 100%;
  max-width: 280px;
  object-fit: cover;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.summary-card {
  width: 100%;
  background: var(--c-surface);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  text-align: left;
  box-shadow: var(--shadow-sm);
}

.summary-card dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--space-xs) var(--space-md);
  font-size: 0.875rem;
}

.summary-card dt {
  color: var(--c-text-secondary);
  font-weight: 500;
}

.summary-card dd {
  font-weight: 600;
}

/* ============ QUEUE BADGE ============ */
.queue-badge {
  position: fixed;
  bottom: calc(var(--space-md) + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  padding: var(--space-xs) var(--space-md);
  background: var(--c-warning);
  color: #fff;
  font-size: 0.8125rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-md);
  animation: slide-up 0.3s ease;
}

@keyframes slide-up {
  from { transform: translateX(-50%) translateY(20px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* ============ TOAST ============ */
.toast {
  position: fixed;
  top: calc(var(--space-md) + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  padding: var(--space-sm) var(--space-lg);
  background: var(--c-text);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  white-space: nowrap;
  animation: toast-in 0.3s ease;
}

.toast.toast-success { background: var(--c-success); }
.toast.toast-error { background: var(--c-error); }
.toast.toast-warning { background: var(--c-warning); }

@keyframes toast-in {
  from { transform: translateX(-50%) translateY(-20px); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* ============ LOADING OVERLAY ============ */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  background: rgba(0,0,0,0.5);
  color: #fff;
  font-weight: 500;
}

/* ============ SPINNER ============ */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.spinner-lg {
  width: 40px;
  height: 40px;
  border-width: 3px;
}

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

/* ============ MODAL ============ */
.modal {
  border: none;
  border-radius: var(--radius-md);
  padding: 0;
  max-width: 360px;
  width: calc(100% - var(--space-xl) * 2);
  box-shadow: var(--shadow-lg);
}

.modal::backdrop {
  background: rgba(0,0,0,0.4);
}

.modal-content {
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.modal-title {
  font-size: 1.125rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
}

/* ============ TABLET (768px+) ============ */
@media (min-width: 768px) {
  :root {
    --container-max: 540px;
  }
}

/* ============ DESKTOP (1024px+) ============ */
@media (min-width: 1024px) {
  :root {
    --container-max: 600px;
  }
}
