/* Socorro - Monteria | Disaster Relief Coordination
   Mobile-first, high-contrast, sunlight-readable
   Target: ~5KB */

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

:root {
  /* Lost Newbs brand colors */
  --brand-coral: #F29274;
  --brand-purple: #815CFF;
  --brand-dark: #4C4F57;
  --brand-brown: #451607;
  --brand-rose: #E9A79E;

  /* Primary colors - using Lost Newbs palette */
  --primary: #F29274;
  --primary-dark: #FF947D;
  --primary-light: #FFD4AD;

  /* Emergency colors - keep original for safety */
  --success: #2E7D32;
  --success-light: #43A047;
  --warning: #F57F17;
  --warning-light: #F9A825;
  --danger: #C62828;
  --danger-light: #E53935;

  /* Base colors */
  --bg: #FFFFFF;
  --bg-alt: #F5F5F5;
  --text: #4C4F57;
  --text-secondary: #616161;
  --text-on-dark: #FFFFFF;
  --border: #E0E0E0;
  --shadow: 0 1rem 9.25rem 0.5rem rgba(0,0,0,0.059);
  --radius: 0.5rem;
  --tab-height: 56px;
  --banner-height: auto;
  --header-height: 56px;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ========== SAFETY BANNER ========== */
.safety-banner {
  background: linear-gradient(135deg, var(--danger), var(--danger-light));
  color: var(--text-on-dark);
  padding: 10px 12px;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1.4;
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: 0 3px 8px rgba(198,40,40,0.35);
  border-bottom: 2px solid var(--danger-light);
}

.safety-banner a {
  color: var(--text-on-dark);
  text-decoration: underline;
  font-weight: 700;
  text-decoration-thickness: 2px;
  text-underline-offset: 2px;
}

/* ========== HEADER ========== */
.app-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: var(--text-on-dark);
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 999;
  box-shadow: 0 2px 8px rgba(242,146,116,0.25);
}

.app-header .header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-header .header-logo {
  height: 32px;
  width: auto;
  filter: brightness(0) invert(1);
}

.app-header h1 {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.app-header .newbs-link {
  font-size: 0.65rem;
  color: rgba(255,255,255,0.9);
  text-decoration: none;
  font-weight: 500;
}

.app-header .newbs-link:hover {
  color: var(--text-on-dark);
}

/* ========== MAIN CONTENT ========== */
.app-main {
  padding-bottom: var(--tab-height);
  min-height: calc(100vh - var(--header-height) - var(--tab-height));
  min-height: calc(100dvh - var(--header-height) - var(--tab-height));
}

.view {
  display: none;
  width: 100%;
}

.view.active {
  display: block;
}

/* ========== BOTTOM TAB BAR ========== */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--tab-height);
  background: var(--bg);
  display: flex;
  border-top: 2px solid var(--border);
  z-index: 998;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
}

.tab-bar a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 4px 0;
  transition: color 0.15s, background 0.15s;
  min-height: 48px;
  border: none;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.tab-bar a .tab-icon {
  font-size: 1.4rem;
  margin-bottom: 2px;
  line-height: 1;
}

.tab-bar a.active {
  color: var(--primary);
  background: linear-gradient(180deg, rgba(242,146,116,0.12), rgba(242,146,116,0.08));
  border-top: 2px solid var(--primary);
}

.tab-bar a:active {
  background: rgba(242,146,116,0.2);
}

/* ========== MAP ========== */
.map-container {
  width: 100%;
  height: calc(100vh - var(--header-height) - var(--tab-height));
  height: calc(100dvh - var(--header-height) - var(--tab-height));
}

#map {
  width: 100%;
  height: 100%;
}

/* Leaflet popup overrides for readability */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow) !important;
}

.leaflet-popup-content {
  margin: 10px 12px !important;
  font-size: 0.85rem !important;
  line-height: 1.4 !important;
}

.popup-barrio {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 6px;
  color: var(--text);
}

.popup-needs {
  margin: 6px 0;
}

.popup-needs span {
  display: inline-block;
  background: rgba(242,146,116,0.1);
  padding: 4px 10px;
  border-radius: 14px;
  margin: 3px 3px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid rgba(242,146,116,0.2);
}

.popup-meta {
  color: var(--text-secondary);
  font-size: 0.75rem;
  margin: 4px 0;
}

.popup-status {
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  display: inline-block;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.popup-status.open {
  background: rgba(198,40,40,0.15);
  color: var(--danger);
  border: 1px solid rgba(198,40,40,0.3);
}

.popup-status.claimed {
  background: rgba(245,127,23,0.15);
  color: var(--warning);
  border: 1px solid rgba(245,127,23,0.3);
}

.popup-status.delivered {
  background: rgba(46,125,50,0.15);
  color: var(--success);
  border: 1px solid rgba(46,125,50,0.3);
}

/* ========== FORMS ========== */
.form-view {
  padding: 16px;
  max-width: 500px;
  margin: 0 auto;
}

.form-section {
  margin-bottom: 20px;
}

.form-section h2 {
  font-size: 1.15rem;
  margin-bottom: 10px;
  color: var(--text);
  font-weight: 700;
  letter-spacing: -0.3px;
}

.form-section p {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 14px;
  line-height: 1.5;
}

/* Big checkboxes for need types */
.needs-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.need-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
  min-height: 56px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.need-checkbox:hover {
  border-color: rgba(242,146,116,0.4);
}

.need-checkbox:active {
  background: rgba(242,146,116,0.12);
}

.need-checkbox input[type="checkbox"] {
  width: 24px;
  height: 24px;
  accent-color: var(--primary);
  flex-shrink: 0;
  cursor: pointer;
}

.need-checkbox.checked {
  border-color: var(--primary);
  background: linear-gradient(135deg, rgba(242,146,116,0.1), rgba(242,146,116,0.06));
  box-shadow: 0 2px 6px rgba(242,146,116,0.15);
}

.need-checkbox .need-icon {
  font-size: 1.4rem;
  line-height: 1;
}

.need-checkbox .need-label {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}

/* Form inputs */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
  letter-spacing: -0.1px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  transition: border-color 0.15s;
  -webkit-appearance: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(242,146,116,0.15);
}

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

.form-group .hint {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.form-group .char-count {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-align: right;
  margin-top: 4px;
  font-weight: 600;
}

/* ========== BUTTONS ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 24px;
  font-size: 1rem;
  font-weight: 700;
  font-family: inherit;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  text-align: center;
  width: 100%;
}

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

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

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: var(--text-on-dark);
  box-shadow: 0 2px 8px rgba(242,146,116,0.25);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  box-shadow: 0 4px 12px rgba(242,146,116,0.35);
}

.btn-success {
  background: linear-gradient(135deg, var(--success), var(--success-light));
  color: var(--text-on-dark);
  box-shadow: 0 2px 8px rgba(46,125,50,0.25);
}

.btn-success:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--success-light), var(--success));
  box-shadow: 0 4px 12px rgba(46,125,50,0.35);
}

.btn-warning {
  background: linear-gradient(135deg, var(--warning), var(--warning-light));
  color: var(--text);
  box-shadow: 0 2px 8px rgba(245,127,23,0.25);
}

.btn-warning:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--warning-light), var(--warning));
  box-shadow: 0 4px 12px rgba(245,127,23,0.35);
}

.btn-danger {
  background: linear-gradient(135deg, var(--danger), var(--danger-light));
  color: var(--text-on-dark);
  box-shadow: 0 2px 8px rgba(198,40,40,0.25);
}

.btn-danger:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--danger-light), var(--danger));
  box-shadow: 0 4px 12px rgba(198,40,40,0.35);
}

.btn-outline {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
  font-weight: 700;
}

.btn-outline:hover:not(:disabled) {
  background: rgba(242,146,116,0.12);
  border-color: var(--primary-dark);
}

.btn-sm {
  min-height: 36px;
  padding: 8px 16px;
  font-size: 0.85rem;
  width: auto;
}

/* ========== CARDS ========== */
.card {
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.card:hover {
  border-color: rgba(242,146,116,0.3);
  box-shadow: 0 3px 10px rgba(242,146,116,0.15);
}

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

.card-header h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

/* ========== SAFETY WARNING BOX ========== */
.safety-box {
  background: linear-gradient(135deg, #FFF3E0, #FFE8CC);
  border: 3px solid var(--warning);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
  box-shadow: 0 3px 10px rgba(245,127,23,0.15);
}

.safety-box h3 {
  color: var(--warning);
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.safety-box ul {
  list-style: none;
  padding: 0;
}

.safety-box li {
  font-size: 0.875rem;
  padding: 6px 0;
  padding-left: 26px;
  position: relative;
  line-height: 1.5;
  font-weight: 500;
}

.safety-box li::before {
  content: "\26A0\FE0F";
  position: absolute;
  left: 0;
  font-size: 1.1rem;
}

/* ========== PRIVACY NOTE ========== */
.privacy-note {
  background: linear-gradient(135deg, #F9F9F9, var(--bg-alt));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 0.825rem;
  color: var(--text-secondary);
  margin-top: 16px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  line-height: 1.5;
}

.privacy-note::before {
  content: "\1F512";
  flex-shrink: 0;
  font-size: 1.1rem;
}

.privacy-note a {
  color: var(--primary);
  font-weight: 600;
  text-decoration: underline;
}

/* ========== GPS / LOCATION ========== */
.gps-section {
  text-align: center;
  padding: 12px 0;
}

.gps-accuracy {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 8px;
  font-weight: 600;
}

.gps-accuracy.good {
  color: var(--success);
  font-weight: 700;
}
.gps-accuracy.fair {
  color: var(--warning);
  font-weight: 700;
}
.gps-accuracy.poor {
  color: var(--danger);
  font-weight: 700;
}

.or-divider {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 20px 0;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.or-divider::before,
.or-divider::after {
  content: "";
  flex: 1;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}

/* ========== TOAST NOTIFICATIONS ========== */
.toast-container {
  position: fixed;
  bottom: calc(var(--tab-height) + 12px);
  right: 12px;
  left: 12px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--text);
  color: var(--text-on-dark);
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  pointer-events: auto;
  animation: toastIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.3;
}

.toast.removing {
  animation: toastOut 0.25s ease-in forwards;
}

.toast.success {
  background: linear-gradient(135deg, var(--success), var(--success-light));
}
.toast.error {
  background: linear-gradient(135deg, var(--danger), var(--danger-light));
}
.toast.warning {
  background: linear-gradient(135deg, var(--warning), var(--warning-light));
  color: var(--text);
}
.toast.info {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
}

@keyframes toastIn {
  0% {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes toastOut {
  0% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(10px) scale(0.95);
  }
}

/* ========== LOADING SPINNER (Squiggly/bouncy per AI.md) ========== */
.spinner-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.85);
  z-index: 9990;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
}

.spinner-overlay.active {
  display: flex;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 5px solid rgba(242,146,116,0.2);
  border-top-color: var(--primary);
  border-bottom-color: var(--primary);
  border-radius: 50%;
  animation: squigglySpin 1s cubic-bezier(0.68, -0.55, 0.27, 1.55) infinite;
}

.spinner-inner {
  width: 26px;
  height: 26px;
  border: 4px solid rgba(255,148,125,0.3);
  border-top-color: var(--primary-dark);
  border-bottom-color: var(--primary-dark);
  border-radius: 50%;
  animation: squigglySpin 0.7s cubic-bezier(0.68, -0.55, 0.27, 1.55) infinite reverse;
  position: absolute;
}

.spinner-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.spinner-text {
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 700;
  letter-spacing: 0.3px;
}

@keyframes squigglySpin {
  0%   { transform: rotate(0deg) scale(1); }
  25%  { transform: rotate(90deg) scale(1.1); }
  50%  { transform: rotate(180deg) scale(1); }
  75%  { transform: rotate(270deg) scale(1.1); }
  100% { transform: rotate(360deg) scale(1); }
}

/* ========== REQUEST ID DISPLAY ========== */
.request-id {
  background: linear-gradient(135deg, rgba(242,146,116,0.08), rgba(242,146,116,0.05));
  border: 2px dashed var(--primary);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  margin: 20px 0;
  box-shadow: 0 2px 6px rgba(242,146,116,0.1);
}

.request-id .id-label {
  font-size: 0.8rem;
  color: var(--text);
  margin-bottom: 6px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.request-id .id-value {
  font-size: 1.4rem;
  font-weight: 700;
  font-family: monospace;
  color: var(--primary);
  letter-spacing: 2px;
}

/* ========== DELIVERY COMPLETION FORM ========== */
.delivery-form {
  padding: 16px;
}

/* ========== FOOTER ========== */
.app-footer {
  text-align: center;
  padding: 24px 16px;
  padding-bottom: calc(var(--tab-height) + 24px);
  font-size: 0.8rem;
  color: var(--text-secondary);
  border-top: 2px solid var(--border);
  background: linear-gradient(180deg, var(--bg), var(--bg-alt));
  line-height: 1.6;
}

.app-footer a {
  color: var(--primary);
  font-weight: 600;
}

.social-links {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 12px;
}

.social-links a {
  color: var(--primary);
  font-weight: 600;
  transition: color 0.2s, transform 0.2s;
  display: inline-block;
}

.social-links a:hover {
  color: var(--primary-dark);
  transform: translateY(-2px);
}

/* ========== OFFLINE INDICATOR ========== */
.offline-bar {
  background: linear-gradient(135deg, var(--text), #666);
  color: var(--text-on-dark);
  text-align: center;
  padding: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  display: none;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  letter-spacing: 0.3px;
}

.offline-bar.visible {
  display: block;
}

/* ========== RESPONSIVE ========== */
@media (min-width: 600px) {
  .needs-grid {
    grid-template-columns: 1fr 1fr 1fr 1fr;
  }

  .form-view {
    max-width: 600px;
    padding: 24px;
  }

  .toast-container {
    left: auto;
    max-width: 400px;
  }

  .app-header h1 {
    font-size: 1.25rem;
  }

  .safety-banner {
    font-size: 0.9rem;
    padding: 12px;
  }

  .card {
    padding: 18px;
  }
}

@media (max-width: 360px) {
  .app-header h1 {
    font-size: 1rem;
  }

  .tab-bar a {
    font-size: 0.65rem;
  }

  .app-header .contribute-text {
    display: none;
  }
}

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

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

/* ========== CONTRIBUTE LINK ========== */
.app-header .header-right {
  display: flex;
  align-items: center;
}

.app-header .contribute-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius);
  background: rgba(255,255,255,0.15);
  color: var(--text-on-dark);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 700;
  transition: background 0.2s, transform 0.2s;
  -webkit-tap-highlight-color: transparent;
  border: 1px solid rgba(255,255,255,0.2);
}

.app-header .contribute-link:hover {
  background: rgba(255,255,255,0.2);
  color: var(--text-on-dark);
  text-decoration: none;
  transform: translateY(-1px);
}

.app-header .gitlab-logo {
  height: 20px;
  width: 20px;
  filter: brightness(0) invert(1);
}

.app-header .contribute-text {
  white-space: nowrap;
}

/* ========== CHARACTER COUNTER ========== */
.char-count {
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-align: right;
  margin-top: 4px;
}

/* ========== LOCATION DESCRIPTION ========== */
.popup-location-desc {
  font-size: 0.8rem;
  color: var(--text);
  margin: 6px 0;
  padding: 6px 8px;
  background: rgba(242,146,116,0.08);
  border-left: 3px solid var(--primary);
  border-radius: 4px;
  line-height: 1.4;
}
