/* FarmCapture — mobile-first PWA */

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--c-bg);
  overflow-x: hidden;
}

/* ====== Auth cover (sign-in gate) ====== */
.auth-cover {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  background:
    radial-gradient(circle at 20% 10%, rgba(255,255,255,0.08), transparent 50%),
    radial-gradient(circle at 90% 90%, rgba(0,0,0,0.2), transparent 50%),
    linear-gradient(135deg, var(--c-primary-d), #14401a 80%);
  overflow: auto;
}

.auth-cover-card {
  width: 100%;
  max-width: 420px;
  background: var(--c-surface);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
  box-shadow: 0 24px 64px rgba(0,0,0,0.32), 0 8px 16px rgba(0,0,0,0.18);
}

.auth-cover-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-5);
}

.auth-cover-brand .brand-mark { width: 28px; height: 28px; }
.auth-cover-brand .brand-name {
  font-weight: 700;
  font-size: var(--fs-lg);
}

.auth-cover-headline {
  margin: 0 0 var(--sp-2);
  font-size: var(--fs-xl);
  letter-spacing: -0.01em;
}

.auth-cover-sub {
  margin: 0 0 var(--sp-5);
  color: var(--c-text-2);
  line-height: 1.5;
}

.auth-cover-form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}

.auth-cover-form input[type="email"] {
  padding: var(--sp-3) var(--sp-4);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  font-size: var(--fs-md);
  font-family: inherit;
  min-height: var(--touch-min);
}

.auth-cover-form input:focus {
  outline: 2px solid var(--c-primary);
  outline-offset: -1px;
}

.auth-cover-form .btn-primary {
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-md);
  font-weight: 600;
  min-height: 48px;
  border-radius: var(--r-md);
}

.auth-cover-form .btn-primary[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}

.auth-cover-hint {
  font-size: var(--fs-sm);
  color: var(--c-text-2);
  margin: 0 0 var(--sp-4);
  line-height: 1.5;
}

.auth-cover-foot {
  font-size: var(--fs-xs);
  color: var(--c-text-3);
  margin: 0;
  padding-top: var(--sp-3);
  border-top: 1px solid var(--c-border);
}

.auth-loading {
  position: fixed;
  inset: 0;
  z-index: 2001;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  background: var(--c-bg);
  color: var(--c-text-2);
}

.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--c-border);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

body.signed-out .auth-cover { display: flex; }
body.auth-loading-active .auth-loading { display: flex; }
body.auth-loading-active .auth-cover { display: none; }

body.signed-out .topbar,
body.signed-out main,
body.signed-out .tabbar,
body.auth-loading-active .topbar,
body.auth-loading-active main,
body.auth-loading-active .tabbar { display: none !important; }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: env(safe-area-inset-top, 0) var(--sp-4) 0;
  height: calc(56px + env(safe-area-inset-top, 0));
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.brand-mark {
  width: 24px;
  height: 24px;
  background:
    radial-gradient(circle at 30% 30%, var(--c-primary) 30%, transparent 31%),
    radial-gradient(circle at 70% 70%, var(--c-accent) 30%, transparent 31%),
    var(--c-primary-l);
  border-radius: 50%;
}

.brand-name {
  font-weight: 700;
  font-size: var(--fs-md);
  letter-spacing: -0.01em;
}

.sync-indicator {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-xs);
  color: var(--c-text-2);
}

.sync-indicator .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c-offline);
  box-shadow: 0 0 0 0 currentColor;
}

.sync-indicator.online .dot { background: var(--c-online); }
.sync-indicator.syncing .dot {
  background: var(--c-syncing);
  animation: pulse 1.2s ease-in-out infinite;
}

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

/* Tab bar */
.tabbar {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--c-surface);
  border-top: 1px solid var(--c-border);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--sp-2) 0 var(--sp-3);
  font-size: var(--fs-xs);
  color: var(--c-text-3);
  min-height: var(--touch-min);
  position: relative;
}

.tab.active {
  color: var(--c-primary);
}

.tab .badge {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  margin-left: 4px;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  border-radius: var(--r-pill);
  background: var(--c-accent);
  color: white;
  vertical-align: middle;
}

.tab .badge:empty { display: none; }

/* Main / panels */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.tab-panel {
  display: none;
  padding: var(--sp-4);
  padding-bottom: var(--sp-8);
}

.tab-panel.active {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.section-title {
  font-size: var(--fs-md);
  font-weight: 600;
  margin: 0;
  color: var(--c-text-2);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  font-size: var(--fs-xs);
}

/* Session bar */
.session-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--sp-3) var(--sp-4);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
}

.session-label-eyebrow {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-text-3);
  margin-bottom: 2px;
}

.session-label {
  font-weight: 600;
  font-size: var(--fs-md);
}

/* GPS card */
.gps-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: var(--sp-4);
}

.gps-status-row {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
}

.gps-pulse {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--c-text-3);
  position: relative;
}

.gps-card.fix .gps-pulse {
  background: var(--c-online);
}

.gps-card.fix .gps-pulse::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--c-online);
  opacity: 0.4;
  animation: ping 1.6s ease-out infinite;
}

@keyframes ping {
  0% { transform: scale(0.6); opacity: 0.6; }
  100% { transform: scale(1.6); opacity: 0; }
}

.gps-status {
  font-size: var(--fs-sm);
  color: var(--c-text-2);
  font-weight: 500;
}

.gps-coords {
  font-family: var(--font-mono);
  font-size: var(--fs-lg);
  font-weight: 600;
  margin-bottom: 2px;
}

.gps-meta {
  font-size: var(--fs-xs);
  color: var(--c-text-3);
}

/* Capture button */
.capture-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) 0;
}

.capture-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--c-primary), var(--c-primary-d));
  color: white;
  font-weight: 700;
  font-size: var(--fs-md);
  letter-spacing: 0.02em;
  box-shadow:
    0 12px 24px rgba(46, 125, 50, 0.3),
    0 4px 8px rgba(46, 125, 50, 0.2),
    inset 0 -4px 8px rgba(0, 0, 0, 0.1),
    inset 0 2px 4px rgba(255, 255, 255, 0.2);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.1s ease, box-shadow 0.2s ease;
}

.capture-button:active {
  transform: scale(0.97);
  box-shadow:
    0 4px 8px rgba(46, 125, 50, 0.3),
    inset 0 4px 8px rgba(0, 0, 0, 0.15);
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-text,
.btn-danger,
.btn-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-sm);
  font-weight: 600;
  font-size: var(--fs-sm);
  min-height: var(--touch-min);
  transition: background 0.15s ease, transform 0.05s ease;
}

.btn-primary {
  background: var(--c-primary);
  color: white;
}
.btn-primary:active { background: var(--c-primary-d); transform: translateY(1px); }

.btn-secondary {
  background: var(--c-surface);
  color: var(--c-text);
  border: 1px solid var(--c-border);
}
.btn-secondary:active { background: var(--c-surface-2); }

.btn-text {
  background: transparent;
  color: var(--c-text-2);
}
.btn-text:active { background: var(--c-surface-2); }

.btn-danger {
  background: var(--c-danger);
  color: white;
}
.btn-danger:active { filter: brightness(0.9); }

.btn-link {
  background: transparent;
  color: var(--c-primary);
  padding: var(--sp-2);
  font-weight: 500;
  min-height: 32px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--c-text-2);
}
.icon-btn:active { background: var(--c-surface-2); }

/* Recent list */
.recent-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.recent-item {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-3);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  align-items: center;
}

.recent-thumb {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  border-radius: var(--r-sm);
  background: var(--c-surface-2);
  object-fit: cover;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--c-text-3);
}

.recent-thumb svg {
  width: 24px;
  height: 24px;
}

.recent-meta {
  flex: 1;
  min-width: 0;
}

.recent-title {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-sub {
  font-size: var(--fs-xs);
  color: var(--c-text-3);
  font-family: var(--font-mono);
}

.recent-status {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: var(--r-pill);
  flex-shrink: 0;
}

.recent-status.pending  { background: #fef3c7; color: #92400e; }
.recent-status.synced   { background: #d1fae5; color: #065f46; }

@media (prefers-color-scheme: dark) {
  .recent-status.pending { background: #422006; color: #fbbf24; }
  .recent-status.synced  { background: #022c22; color: #6ee7b7; }
}

.empty-state {
  text-align: center;
  padding: var(--sp-6) var(--sp-4);
  color: var(--c-text-3);
  font-size: var(--fs-sm);
  background: var(--c-surface);
  border: 1px dashed var(--c-border);
  border-radius: var(--r-md);
}

/* Sessions list (queue tab) */
.queue-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sessions-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.session-group {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  overflow: hidden;
}

.session-group-header {
  padding: var(--sp-3) var(--sp-4);
  background: var(--c-surface-2);
  border-bottom: 1px solid var(--c-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.session-group-title {
  font-weight: 600;
}

.session-group-count {
  font-size: var(--fs-xs);
  color: var(--c-text-3);
}

.session-group-body {
  display: flex;
  flex-direction: column;
}

.session-group-body .recent-item {
  border: none;
  border-radius: 0;
  border-bottom: 1px solid var(--c-border);
}

.session-group-body .recent-item:last-child { border-bottom: none; }

/* Settings */
.setting {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-4) 0;
  border-bottom: 1px solid var(--c-border);
}

.setting:last-of-type { border-bottom: none; }

.setting label {
  font-weight: 600;
  font-size: var(--fs-sm);
}

.setting input[type="text"],
.setting input[type="email"] {
  padding: var(--sp-3);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  font-size: var(--fs-md);
}

.setting input:focus {
  outline: 2px solid var(--c-primary);
  outline-offset: -1px;
}

.hint {
  font-size: var(--fs-xs);
  color: var(--c-text-3);
  line-height: 1.4;
  margin: 0;
}

.setting.danger .btn-danger {
  align-self: flex-start;
}

/* Auth block */
.auth-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
}
.auth-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  color: var(--c-text-1);
  border-radius: 999px;
  padding: var(--sp-1) var(--sp-3);
  font-size: var(--fs-sm);
  font-weight: 500;
}
.auth-pill::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2e7d32;
}
#sendMagicBtn { align-self: flex-start; }
#sendMagicBtn[disabled] { opacity: 0.6; cursor: not-allowed; }

.footer-note {
  text-align: center;
  margin-top: var(--sp-6);
  color: var(--c-text-3);
  font-size: var(--fs-xs);
}

/* Modal */
dialog {
  border: none;
  padding: 0;
  background: var(--c-surface);
  color: var(--c-text);
  border-radius: var(--r-lg);
  max-width: 92vw;
  width: 480px;
  box-shadow: var(--shadow-lg);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}

dialog form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-4);
  max-height: 90vh;
  overflow-y: auto;
}

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

.modal-header h3 { margin: 0; font-size: var(--fs-lg); }

#capturePreview {
  width: 100%;
  max-height: 280px;
  object-fit: cover;
  border-radius: var(--r-sm);
  background: var(--c-surface-2);
}

.modal-gps {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--c-text-2);
  background: var(--c-surface-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
}

.gps-source-pill {
  display: inline-block;
  font-family: inherit;
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 999px;
  margin-left: 4px;
  vertical-align: middle;
}

.gps-source-pill.exif {
  background: rgba(46, 125, 50, 0.12);
  color: #2e7d32;
}

.gps-source-pill.live {
  background: rgba(2, 119, 189, 0.12);
  color: #0277bd;
}

dialog form label {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  font-size: var(--fs-sm);
  font-weight: 500;
}

dialog form textarea,
dialog form input[type="text"],
dialog form select {
  padding: var(--sp-3);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  font-size: var(--fs-md);
  font-family: inherit;
  resize: vertical;
}

dialog form textarea:focus,
dialog form input:focus,
dialog form select:focus {
  outline: 2px solid var(--c-primary);
  outline-offset: -1px;
}

.voice-section {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.voice-label {
  font-size: var(--fs-sm);
  font-weight: 500;
}

.voice-controls {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.voice-icon {
  color: var(--c-danger);
  font-size: 14px;
}

.voice-controls.recording .voice-icon {
  animation: pulse 1s infinite;
}

.voice-status {
  font-size: var(--fs-xs);
  color: var(--c-text-3);
  font-family: var(--font-mono);
}

#voicePreview {
  width: 100%;
  height: 36px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
  margin-top: var(--sp-2);
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom, 0));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--c-text);
  color: var(--c-bg);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  max-width: 90vw;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* iPad / wider screens — keep mobile feel but cap content width */
@media (min-width: 720px) {
  main { align-items: center; }
  .tab-panel { width: 100%; max-width: 640px; }
}
