:root {
  --brand: #0f172a;
  --accent: #2563eb;
  --todo: #f59e0b;
  --invoiced: #3b82f6;
  --paid: #10b981;
}

* { -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: "Segoe UI", "Heebo", "Rubik", system-ui, -apple-system, sans-serif;
  overscroll-behavior-y: none;
}

/* --------------------------- app layout --------------------------- */
.app-shell { min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--brand); color: #fff;
  padding: 0.6rem 1rem;
  display: flex; align-items: center; gap: 0.75rem;
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.25);
}
.topbar h1 { font-size: 1.05rem; font-weight: 700; margin: 0; }
.topbar .spacer { flex: 1; }

.content { flex: 1; width: 100%; max-width: 720px; margin: 0 auto; padding: 0.75rem; }

/* --------------------------- job list --------------------------- */
.job-list { display: flex; flex-direction: column; gap: 0.5rem; padding-bottom: 6rem; }

.job-card {
  background: #fff; border-radius: 0.75rem;
  padding: 0.5rem 0.7rem;
  display: flex; align-items: center; gap: 0.5rem;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  border: 1px solid #e2e8f0;
  transition: box-shadow .15s, transform .15s;
  position: relative;
}
.job-card:active { transform: scale(0.995); }
.job-card.dragging { opacity: 0.5; box-shadow: 0 8px 24px rgba(15,23,42,.25); }
.job-card.drop-target { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(37,99,235,.25); }
/* Long-press to drag: keep vertical scrolling but hand the gesture to JS.
   Without touch-action the browser cancels the pointer stream and reordering
   never starts on a phone. */
.job-card.draggable { touch-action: pan-y; }

/* small edit icon — an INLINE flex item, never absolutely positioned, so it
   can never overlap the drag handle (that overlap silently killed reordering). */
.card-edit {
  flex-shrink: 0; align-self: center;
  width: 1.5rem; height: 1.5rem; border-radius: 999px;
  border: none; background: #f1f5f9; color: #94a3b8;
  display: grid; place-items: center; cursor: pointer; font-size: 0.7rem;
}
.card-edit:active { background: #e2e8f0; color: var(--accent); }

/* dev access-code block on the login screen */
.dev-login { margin-top: 1rem; padding-top: 1rem; border-top: 1px dashed #e2e8f0; text-align: start; }

/* drag & drop visuals */
.drag-hint {
  font-size: 0.72rem; color: #94a3b8; text-align: center;
  padding: 0.1rem 0 0.35rem; display: flex; align-items: center; justify-content: center; gap: 0.35rem;
}
.drag-hint i { opacity: 0.7; }
.drag-ghost {
  position: fixed; z-index: 999; pointer-events: none;
  opacity: 0.95; transform: scale(1.02);
  box-shadow: 0 14px 34px rgba(15,23,42,.32);
  border-color: var(--accent) !important;
  background: #fff; border-radius: 0.75rem;
  padding: 0.7rem 0.85rem; display: flex; align-items: flex-start; gap: 0.6rem;
}
.drag-placeholder {
  border: 2px dashed var(--accent); border-radius: 0.75rem;
  background: rgba(37,99,235,.06); margin: 0;
}
.drag-handle {
  cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none;
  color: #94a3b8; padding: 0.15rem 0.3rem; flex-shrink: 0;
  font-size: 1.15rem; line-height: 1; align-self: stretch;
  display: flex; align-items: center;
}
.drag-handle:active { cursor: grabbing; color: var(--accent); }

.job-main { flex: 1; min-width: 0; }
.job-line1 { display: flex; align-items: baseline; gap: 0.4rem; min-width: 0; }
.job-title {
  font-weight: 700; font-size: 0.95rem; line-height: 1.2;
  min-width: 0; word-break: break-word; overflow-wrap: anywhere;
}
/* Address is now noticeably larger/legible, but its line-height is pinned to
   the title's (0.95rem * 1.2) so it can NEVER make the card taller. */
.job-addr {
  flex: 1 1 auto; min-width: 0;
  font-size: 0.86rem; line-height: 1.2; color: #64748b; font-weight: 600;
  text-align: end;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.job-addr i { margin-inline-end: 0.2rem; color: #94a3b8; }

/* Navigation button — opens Google Maps directions for this job's address.
   An inline flex item (not absolute) so it never overlaps the drag handle. */
.job-nav {
  flex-shrink: 0; align-self: center;
  width: 2rem; height: 2rem; border-radius: 999px;
  display: grid; place-items: center;
  background: #eff6ff; color: var(--accent);
  text-decoration: none; font-size: 0.9rem;
  border: 1px solid #dbeafe;
}
.job-nav:active { background: #dbeafe; transform: scale(0.94); }
.job-sub {
  font-size: 0.78rem; color: #64748b; margin-top: 0.05rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.job-meta { display: flex; flex-wrap: wrap; gap: 0.35rem 0.75rem; font-size: 0.78rem; color: #64748b; margin-top: 0.3rem; }
.job-meta i { color: #94a3b8; margin-inline-end: 0.2rem; }

.job-actions { display: flex; flex-direction: column; gap: 0.2rem; flex-shrink: 0; }

.chip {
  display: inline-flex; align-items: center; gap: 0.25rem;
  font-size: 0.7rem; padding: 0.12rem 0.5rem; border-radius: 999px;
  background: #f1f5f9; color: #475569; font-weight: 600;
}
.chip.todo { background: #fef3c7; color: #92400e; }
.chip.invoiced { background: #dbeafe; color: #1e40af; }
.chip.paid { background: #d1fae5; color: #065f46; }

/* --------------------------- buttons --------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  border: none; border-radius: 0.6rem; cursor: pointer;
  font-size: 0.85rem; font-weight: 600; padding: 0.5rem 0.85rem;
  transition: filter .15s, background .15s;
}
.btn:active { filter: brightness(0.94); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-green { background: var(--paid); color: #fff; }
.btn-amber { background: var(--todo); color: #fff; }
.btn-ghost { background: #f1f5f9; color: #334155; }
.btn-danger { background: #fee2e2; color: #b91c1c; }
.btn-sm { font-size: 0.73rem; padding: 0.24rem 0.55rem; border-radius: 0.5rem; }
.btn-block { width: 100%; }

/* floating add button */
.fab {
  position: fixed; inset-inline-start: 1rem; bottom: calc(4.6rem + env(safe-area-inset-bottom));
  width: 3.5rem; height: 3.5rem; border-radius: 999px;
  background: var(--accent); color: #fff; border: none;
  font-size: 1.5rem; box-shadow: 0 8px 22px rgba(37,99,235,.45);
  cursor: pointer; z-index: 50; display: grid; place-items: center;
}

/* bottom nav */
.bottom-nav {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 45;
  background: #fff; border-top: 1px solid #e2e8f0;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav button {
  background: none; border: none; cursor: pointer;
  padding: 0.5rem 0.25rem 0.55rem; display: flex; flex-direction: column;
  align-items: center; gap: 0.15rem; color: #94a3b8; font-size: 0.68rem; font-weight: 600;
}
.bottom-nav button i { font-size: 1.15rem; }
.bottom-nav button.active { color: var(--accent); }
.bottom-nav .badge {
  position: absolute; margin-top: -0.55rem; margin-inline-start: 1.1rem;
  background: #ef4444; color: #fff; border-radius: 999px;
  font-size: 0.6rem; min-width: 1.05rem; height: 1.05rem;
  display: grid; place-items: center; padding: 0 0.2rem;
}

/* --------------------------- modal / form --------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(15,23,42,.55); backdrop-filter: blur(2px);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: #fff; width: 100%; max-width: 640px;
  border-radius: 1.1rem 1.1rem 0 0;
  max-height: 92dvh; display: flex; flex-direction: column;
  animation: slideUp .22s ease-out;
}
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; }
  .modal { border-radius: 1.1rem; max-height: 88dvh; }
}
@keyframes slideUp { from { transform: translateY(24px); opacity: .6 } to { transform: none; opacity: 1 } }

.modal-head {
  padding: 0.9rem 1rem; border-bottom: 1px solid #e2e8f0;
  display: flex; align-items: center; gap: 0.5rem;
}
.modal-head h2 { font-size: 1.05rem; font-weight: 700; margin: 0; flex: 1; }
.modal-body { padding: 0.9rem 1rem; overflow-y: auto; }
.modal-foot {
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
  border-top: 1px solid #e2e8f0; display: flex; gap: 0.5rem;
}

.field { margin-bottom: 0.85rem; }
.field label { display: block; font-size: 0.8rem; font-weight: 600; color: #475569; margin-bottom: 0.25rem; }
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid #cbd5e1; border-radius: 0.6rem;
  padding: 0.55rem 0.7rem; font-size: 0.92rem; background: #fff; color: #0f172a;
  font-family: inherit;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.field textarea { resize: vertical; min-height: 4.2rem; }
.hint { font-size: 0.72rem; color: #94a3b8; margin-top: 0.2rem; }

/* customer / address pickers */
.picker { display: flex; gap: 0.4rem; }
.picker input, .picker select { flex: 1; }
.addr-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.4rem; }
.addr-chip {
  border: 1px solid #cbd5e1; background: #f8fafc; color: #334155;
  border-radius: 999px; padding: 0.28rem 0.65rem; font-size: 0.78rem; cursor: pointer;
}
.addr-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* toast */
#toast-root { position: fixed; inset-inline: 0; top: 0.75rem; z-index: 90; display: flex; flex-direction: column; align-items: center; gap: 0.4rem; pointer-events: none; }
.toast {
  background: #0f172a; color: #fff; padding: 0.5rem 0.9rem; border-radius: 999px;
  font-size: 0.82rem; box-shadow: 0 6px 20px rgba(15,23,42,.3); animation: fadeIn .2s;
}
.toast.error { background: #b91c1c; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-6px) } to { opacity: 1 } }

/* --------------------------- confirm dialog --------------------------- */
.confirm-modal { max-width: 400px; }
.confirm-body { padding: 1.4rem 1.25rem 0.6rem; text-align: center; }
.confirm-icon {
  width: 3.2rem; height: 3.2rem; border-radius: 999px; margin: 0 auto 0.8rem;
  display: grid; place-items: center; font-size: 1.5rem;
  background: #dbeafe; color: var(--accent);
}
.confirm-icon.danger { background: #fee2e2; color: #b91c1c; }
.confirm-body h2 { font-size: 1.1rem; font-weight: 700; margin: 0 0 0.4rem; }
.confirm-body p { font-size: 0.88rem; color: #64748b; margin: 0; line-height: 1.5; }

/* small icon button (topbar) */
.icon-btn {
  background: rgba(255,255,255,.12); border: none; color: #cbd5e1;
  width: 1.9rem; height: 1.9rem; border-radius: 999px; cursor: pointer;
  display: grid; place-items: center; font-size: 0.8rem;
}
.icon-btn:active { background: rgba(255,255,255,.24); }

/* google sign-in host */
.google-btn-host { display: flex; justify-content: center; min-height: 2.75rem; align-items: center; }

/* address row in customer modal */
.addr-row {
  display: flex; justify-content: space-between; align-items: center; gap: .5rem;
  border: 1px solid #cbd5e1; background: #f8fafc; color: #334155;
  border-radius: .5rem; padding: .4rem .6rem; font-size: .82rem;
}

/* empty state */
.empty { text-align: center; color: #94a3b8; padding: 3rem 1rem; }
.empty i { font-size: 2.4rem; display: block; margin-bottom: 0.6rem; opacity: .5; }

/* login */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem; }
.login-card { background: #fff; border-radius: 1.25rem; padding: 2rem 1.5rem; max-width: 380px; width: 100%; text-align: center; box-shadow: 0 12px 40px rgba(15,23,42,.15); }
.login-card .logo { width: 4rem; height: 4rem; border-radius: 1rem; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 1.8rem; margin: 0 auto 1rem; }
.btn-google { background: #fff; color: #374151; border: 1px solid #d1d5db; font-weight: 600; }
.btn-google img { width: 1.1rem; height: 1.1rem; }
.lock-note {
  margin-top: 1rem; padding-top: 0.85rem; border-top: 1px dashed #e2e8f0;
  font-size: 0.72rem; color: #94a3b8; display: flex; align-items: center; justify-content: center; gap: 0.35rem;
}
.lock-note i { color: #64748b; }
#login-msg { color: #b91c1c; font-size: 0.78rem; }
.avatar-badge {
  width: 1.9rem; height: 1.9rem; border-radius: 999px; flex-shrink: 0;
  background: #334155; color: #e2e8f0; display: grid; place-items: center;
  font-size: 0.8rem; font-weight: 700;
}

/* skeleton */
.skel { height: 3.6rem; border-radius: 0.75rem; background: linear-gradient(90deg,#eef2f7 25%,#e2e8f0 37%,#eef2f7 63%); background-size: 400% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { from { background-position: 100% 0 } to { background-position: 0 0 } }
