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

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-alt: #eef1f5;
  --border: #d8dde4;
  --text: #1a2332;
  --text-muted: #5f6d7e;
  --primary: #1b6b4a;
  --primary-hover: #145536;
  --primary-light: #e8f5ee;
  --danger: #c0392b;
  --danger-light: #fdecea;
  --warning: #e67e22;
  --warning-light: #fef5e7;
  --success: #27ae60;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* ========== Login ========== */
.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: linear-gradient(145deg, #1a2332 0%, #1b6b4a 100%);
}
.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 2rem 1.5rem;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}
.login-card h1 {
  font-size: 1.25rem;
  margin-bottom: 0.25rem;
  color: var(--primary);
}
.login-card .subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}
.login-card .error-msg {
  background: var(--danger-light);
  color: var(--danger);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  margin-bottom: 1rem;
  display: none;
}
.login-card .error-msg.show { display: block; }

/* ========== Forms ========== */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: var(--font);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-alt); color: var(--text); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #a93226; }
.btn-block { width: 100%; }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.8rem; }

/* ========== App Shell ========== */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}
.top-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}
.top-bar h1 {
  font-size: 1.1rem;
  color: var(--primary);
  white-space: nowrap;
}
.top-bar-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.top-bar-actions button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1.3rem;
  padding: 0.25rem;
}

.main-content {
  flex: 1;
  padding: 1rem;
  padding-bottom: calc(4.5rem + var(--safe-bottom));
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: var(--safe-bottom);
  z-index: 100;
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.5rem 0.25rem;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.65rem;
  font-weight: 600;
  transition: color 0.15s;
}
.bottom-nav a.active { color: var(--primary); }
.bottom-nav a svg { width: 22px; height: 22px; }

/* ========== Cards ========== */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 1rem;
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: box-shadow 0.15s;
}
.card:hover { box-shadow: var(--shadow-lg); }
.card-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
}
.card-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.card-meta {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}
.card-tag {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 100px;
  font-weight: 600;
}
.tag-active { background: var(--primary-light); color: var(--primary); }
.tag-completed { background: var(--surface-alt); color: var(--text-muted); }
.tag-due { background: var(--warning-light); color: var(--warning); }
.tag-overdue { background: var(--danger-light); color: var(--danger); }
.tag-photos { background: var(--surface-alt); color: var(--text-muted); }

/* ========== Search Bar ========== */
.search-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.search-bar input {
  flex: 1;
  padding: 0.6rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-family: var(--font);
}
.search-bar input:focus {
  outline: none;
  border-color: var(--primary);
}

/* Filter row */
.filter-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 0.25rem;
}
.filter-chip {
  padding: 0.35rem 0.75rem;
  border-radius: 100px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.filter-chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ========== Section Headers ========== */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.section-header h2 {
  font-size: 1.15rem;
}

/* ========== Detail View ========== */
.detail-header {
  margin-bottom: 1rem;
}
.detail-header h2 {
  font-size: 1.25rem;
  margin-bottom: 0.25rem;
}
.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.detail-row:last-child { border-bottom: none; }
.detail-label {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
}
.detail-value { text-align: right; }

/* ========== Photo Grid ========== */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.photo-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius);
  cursor: pointer;
  transition: opacity 0.15s;
}
.photo-grid img:hover { opacity: 0.85; }

/* Photo lightbox */
.photo-lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.photo-lightbox img {
  max-width: 100%;
  max-height: 90dvh;
  border-radius: var(--radius);
}
.photo-lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  font-size: 1.5rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
}

/* Upload area */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s;
  margin-top: 0.75rem;
}
.upload-area:hover { border-color: var(--primary); }
.upload-area input { display: none; }

/* ========== Map ========== */
.map-container {
  height: calc(100dvh - 8rem - var(--safe-bottom));
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--border);
}
.map-container .leaflet-container {
  height: 100%;
  width: 100%;
}

/* ========== Alerts ========== */
.alert-banner {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.85rem;
  font-weight: 600;
}
.alert-warning { background: var(--warning-light); color: var(--warning); }
.alert-info { background: var(--primary-light); color: var(--primary); }

/* ========== Empty State ========== */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 0.75rem;
  opacity: 0.4;
}
.empty-state p { font-size: 0.9rem; }

/* ========== Loading ========== */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-center {
  display: flex;
  justify-content: center;
  padding: 3rem;
}

/* ========== Back link ========== */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 1rem;
}
.back-link:hover { color: var(--primary); }

/* ========== Toast ========== */
.toast {
  position: fixed;
  bottom: calc(5rem + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text);
  color: #fff;
  padding: 0.6rem 1.25rem;
  border-radius: 100px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  opacity: 0;
  transition: transform 0.3s, opacity 0.3s;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ========== Desktop tweaks ========== */
@media (min-width: 768px) {
  .main-content { padding: 1.5rem 2rem; }
  .photo-grid { grid-template-columns: repeat(4, 1fr); }
  .form-row { grid-template-columns: 1fr 1fr 1fr; }
}
