:root {
  --teal: #0d9488;
  --teal-600: #0f766e;
  --aqua: #06b6d4;
  --aqua-400: #22d3ee;
  --grad: linear-gradient(135deg, #14b8a6 0%, #0891b2 100%);

  --ink: #0f2b33;
  --muted: #5b7683;
  --line: #e3edf0;
  --bg: #f2f7f8;
  --card: #ffffff;
  --stop: #e11d48;
  --shadow: 0 10px 30px rgba(8, 66, 74, 0.10);
  --radius: 18px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 0 16px calc(84px + env(safe-area-inset-bottom));
}

/* ---- Bottom tab bar (main navigation) ---- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -4px 16px rgba(8, 66, 74, 0.06);
}
.tabbar .tab {
  flex: 1; max-width: 200px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 4px 8px; text-decoration: none;
  color: var(--muted); font-size: 0.7rem; font-weight: 700;
}
.tabbar .tab .ico { font-size: 1.3rem; line-height: 1; }
.tabbar .tab.active { color: var(--teal-600); }

/* Header */
.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 2px 14px;
  position: sticky;
  top: 0;
  background: linear-gradient(var(--bg), var(--bg) 70%, transparent);
  z-index: 5;
}
.logo { border-radius: 12px; box-shadow: var(--shadow); flex: 0 0 auto; }
.brand { flex: 1 1 auto; min-width: 0; }
.company {
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tagline { font-size: 0.8rem; color: var(--muted); }

.install-btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--teal-600);
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 999px;
  box-shadow: var(--shadow);
}

.content { display: flex; flex-direction: column; gap: 16px; }

/* Cards */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 6px; font-size: 1.15rem; }

.muted { color: var(--muted); }
.muted em { font-style: normal; opacity: 0.85; }

/* Fields */
.field { display: block; margin: 12px 0; }
.field[hidden] { display: none; }   /* a display: rule otherwise beats the hidden attribute */
.field > span { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; }
.field input {
  width: 100%;
  padding: 14px;
  font-size: 1.05rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfeff;
  color: var(--ink);
}
.field input:focus { outline: 2px solid var(--aqua-400); border-color: var(--aqua); }

/* Address autocomplete */
.autocomplete { position: relative; }
.suggestions {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px);
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); list-style: none; margin: 0; padding: 6px;
  z-index: 30; max-height: 260px; overflow-y: auto;
}
.suggestion { padding: 11px 12px; border-radius: 8px; cursor: pointer; font-size: 0.95rem; }
.suggestion:hover { background: #eefafa; }

/* Selects styled like inputs */
.field select {
  width: 100%; padding: 14px; font-size: 1rem; border: 1px solid var(--line);
  border-radius: 12px; background: #fbfeff; color: var(--ink);
}
.row2 { display: flex; gap: 12px; }
.row2 > * { flex: 1; }
.btn-ghost { background: #eef4f5; color: var(--teal-600); }

/* ---- Schedule / calendar ---- */
.sched-toolbar { display: flex; align-items: center; gap: 10px; margin: 2px 2px 12px; }
.seg { display: flex; background: #e6eef0; border-radius: 999px; padding: 3px; flex: 0 0 auto; }
.seg-btn {
  border: none; background: none; cursor: pointer;
  padding: 7px 16px; border-radius: 999px;
  font-size: 0.85rem; font-weight: 700; color: var(--muted);
}
.seg-btn.active { background: var(--card); color: var(--teal-600); box-shadow: 0 2px 6px rgba(8, 66, 74, 0.12); }
.who-filter {
  flex: 1; min-width: 0;
  padding: 9px 12px; font-size: 0.88rem; font-weight: 600;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--card); color: var(--ink); box-shadow: var(--shadow);
}

.week-nav { display: flex; align-items: center; gap: 10px; margin: 4px 2px 14px; }
.nav-btn { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 13px; font-weight: 700; box-shadow: var(--shadow); cursor: pointer; }
.week-label { flex: 1; text-align: center; font-weight: 800; }

.period-summary { font-size: 0.85rem; color: var(--muted); text-align: center; margin: -6px 2px 14px; }
.period-summary strong { color: var(--ink); }
.sum-open { color: #b45309; font-weight: 700; }
.sum-done { color: #065f46; font-weight: 700; }
.sum-who { color: var(--teal-600); font-weight: 700; }

/* Month grid */
.mgrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.mdow {
  text-align: center; font-size: 0.66rem; font-weight: 800; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.04em; padding-bottom: 2px;
}
.mcell {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px;
  min-height: 62px; padding: 6px 3px 5px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer; font: inherit; color: var(--ink);
}
.mcell.other-month { background: #f7fafb; color: #a9bcc4; }
.mcell.has-jobs { border-color: #cfe6e6; }
.mcell.is-today { border-color: var(--teal); box-shadow: inset 0 0 0 1px var(--teal); }
.mcell.selected { background: #e8f8f8; border-color: var(--teal-600); box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.28); }
.mday { font-size: 0.84rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.mcell.is-today .mday { color: var(--teal-600); }
.mchips { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; }
.mchip { display: block; width: 14px; height: 5px; border-radius: 3px; background: var(--line); }
.mchip.status-open { background: #f59e0b; }
.mchip.status-assigned { background: var(--teal); }
.mchip.status-done { background: #a7f3d0; }
.mchip.status-cancelled { background: #fca5a5; }
.mmore { font-size: 0.6rem; font-weight: 800; color: var(--muted); line-height: 1; }
.mlegend {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px;
  font-size: 0.72rem; color: var(--muted); padding: 12px 2px 2px;
}
.mlegend span { display: flex; align-items: center; gap: 5px; }
.mlegend-hint { margin-left: auto; font-style: italic; }

.day-panel-block { margin-top: 14px; }
.day-add {
  border: none; background: #e6f4f4; color: var(--teal-600);
  width: 24px; height: 24px; border-radius: 8px;
  font-size: 1rem; font-weight: 800; line-height: 1; cursor: pointer;
}
.day-close {
  border: none; background: none; color: var(--muted);
  font-size: 0.9rem; cursor: pointer; padding: 2px 4px;
}

.day-block { margin-bottom: 14px; }
.day-block-head { font-weight: 700; font-size: 0.9rem; padding: 6px 2px; border-bottom: 2px solid var(--line); display: flex; align-items: center; gap: 8px; }
.day-block-head .day-add { margin-left: auto; }
.day-block.is-today .day-block-head { color: var(--teal-600); border-color: var(--teal); }
.today-chip { font-size: 0.62rem; background: var(--teal); color: #fff; padding: 1px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.04em; }
.day-block-body { padding-top: 8px; }
.day-empty { color: var(--muted); padding: 4px 2px 8px; }

.job-card { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: 12px; margin-bottom: 8px; border-left: 4px solid var(--line); }
.job-card.status-open { border-left-color: #f59e0b; }
.job-card.status-assigned { border-left-color: var(--teal); }
.job-card.status-done { border-left-color: #10b981; opacity: 0.72; }
.job-card.status-cancelled { border-left-color: #e11d48; opacity: 0.6; }
.job-top { display: flex; gap: 12px; }
.job-time { font-weight: 800; color: var(--teal-600); font-variant-numeric: tabular-nums; min-width: 48px; }
.job-time small { display: block; font-weight: 600; color: var(--muted); font-size: 0.66rem; }
.job-main { flex: 1; min-width: 0; }
.job-title { font-weight: 700; }
.job-addr { font-size: 0.85rem; color: var(--muted); }
.job-notes { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.job-meta { margin-top: 4px; }
.job-who { font-size: 0.8rem; font-weight: 700; color: var(--teal-600); }
.job-who.open { color: #b45309; }
.jbadge { font-size: 0.6rem; text-transform: uppercase; letter-spacing: 0.04em; padding: 2px 7px; border-radius: 999px; font-weight: 800; vertical-align: middle; }
.jbadge.open { background: #fef3c7; color: #b45309; }
.jbadge.assigned { background: #ccfbf1; color: #0f766e; }
.jbadge.done { background: #d1fae5; color: #065f46; }
.jbadge.cancelled { background: #fee2e2; color: #b91c1c; }
.job-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.btn-mini { border: none; border-radius: 8px; padding: 7px 12px; font-size: 0.82rem; font-weight: 700; cursor: pointer; background: #eef4f5; color: var(--ink); }
.btn-mini.pick { background: var(--grad); color: #fff; }
.btn-mini.go { background: var(--teal-600); color: #fff; text-decoration: none; display: inline-block; }
.btn-mini.danger { background: #fff1f3; color: #e11d48; }
.btn-mini.ghost { background: #eef4f5; color: var(--teal-600); }
.assign-select { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 0.82rem; background: #fbfeff; }
.yours-tag { font-size: 0.78rem; font-weight: 800; color: #0f766e; background: #ccfbf1; padding: 4px 10px; border-radius: 999px; }

/* Buttons */
.btn {
  border: none;
  border-radius: 14px;
  padding: 14px 18px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.05s ease, filter 0.15s ease;
}
.btn:active { transform: scale(0.985); }
.btn.block { width: 100%; }
.btn.big { padding: 20px; font-size: 1.25rem; display: flex; align-items: center; justify-content: center; gap: 10px; }
.big-ico { font-size: 1.25em; line-height: 1; }
.btn-primary { background: var(--grad); color: #fff; box-shadow: 0 8px 20px rgba(8, 145, 178, 0.35); }
.btn-primary:hover { filter: brightness(1.03); }
.btn-stop { background: linear-gradient(135deg, #f43f5e, #e11d48); color: #fff; box-shadow: 0 8px 20px rgba(225, 29, 72, 0.32); }

.link {
  background: none; border: none; padding: 0;
  color: var(--teal-600); font-weight: 600; font-size: 0.85rem; cursor: pointer;
}
.link.danger { color: var(--stop); }

/* Check-in card */
.who { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 4px; }
.hi { font-size: 1.1rem; }
.status-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: #cbd5db; margin-top: 6px; flex: 0 0 auto;
}
.status-dot.on { background: #10b981; box-shadow: 0 0 0 4px rgba(16, 185, 129, 0.18); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.55; } }

.gps-hint { font-size: 0.78rem; margin: 10px 2px 0; text-align: center; }

/* Timer */
.timer-wrap { text-align: center; padding: 8px 0 18px; }
.timer {
  font-size: 3.2rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  color: var(--teal-600);
}
.timer-sub { font-size: 0.9rem; margin-top: 4px; }
.gps-line { font-size: 0.78rem; margin-top: 8px; }
.gps-line.warn { color: #b91c1c; font-weight: 700; }
.loc-warn { font-size: 0.9em; }
.badge.warn { color: #b91c1c; font-weight: 800; }

/* Summary */
.summary-row { display: flex; text-align: center; }
.stat { flex: 1; }
.stat + .stat { border-left: 1px solid var(--line); }
.stat-num { font-size: 1.7rem; font-weight: 800; color: var(--teal-600); font-variant-numeric: tabular-nums; }
.stat-label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* History */
.history-head { display: flex; align-items: center; justify-content: space-between; padding: 0 2px 8px; }
.history-head h2 { margin: 0; font-size: 1.05rem; }

.day-group { margin-bottom: 14px; }
.day-label {
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); margin: 4px 2px 8px;
}
.entry {
  background: var(--card);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.entry .pin { font-size: 1.2rem; flex: 0 0 auto; }
.entry .meta { flex: 1 1 auto; min-width: 0; }
.entry .loc { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry .times { font-size: 0.82rem; color: var(--muted); }
.entry .dur {
  flex: 0 0 auto; font-weight: 800; color: var(--teal-600);
  font-variant-numeric: tabular-nums; text-align: right;
}
.entry .dur small { display: block; font-weight: 600; color: var(--muted); font-size: 0.68rem; }

.empty { text-align: center; color: var(--muted); padding: 20px; }

.app-footer { text-align: center; font-size: 0.75rem; padding: 18px 0 6px; margin-top: auto; }

.toast {
  position: fixed;
  left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff;
  padding: 12px 18px; border-radius: 999px;
  font-size: 0.9rem; font-weight: 600;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- Login view ---- */
.app.wide { max-width: 620px; }
.login-view { padding-top: calc(32px + env(safe-area-inset-top)); }
.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand .logo.big { border-radius: 20px; box-shadow: var(--shadow); }
.login-brand .company { font-weight: 800; font-size: 1.4rem; margin-top: 12px; }
.login-brand .tagline { color: var(--muted); }
.offline-banner { text-align: center; margin-top: 14px; font-size: 0.85rem; }

.err-box { background: #fff1f3; color: #be123c; padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; font-size: 0.9rem; }
.ok-box { background: #ecfdf5; color: #065f46; padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; font-size: 0.9rem; }

.field.checkbox { display: flex; align-items: center; gap: 10px; }
.field.checkbox input { width: auto; }
.field.checkbox span { margin: 0; font-weight: 500; }

.who-actions { display: flex; gap: 14px; align-items: center; margin-top: 2px; }

/* ---- Sync banner ---- */
.sync-banner { border-radius: 12px; padding: 10px 14px; font-size: 0.85rem; font-weight: 600; margin-bottom: 4px; }
.sync-banner.syncing { background: #ecfeff; color: #0e7490; }
.sync-banner.offline { background: #fffbeb; color: #92400e; }

/* ---- Dashboard crew rows ---- */
.crew-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--line); }
.crew-row:last-child { border-bottom: none; }
.crew-name { font-weight: 700; }
.crew-name .tag { font-size: 0.65rem; background: var(--teal); color: #fff; padding: 1px 7px; border-radius: 999px; vertical-align: middle; margin-left: 4px; }
.crew-status { margin-top: 3px; }
.crew-actions { margin-top: 8px; }
.badge { font-size: 0.78rem; font-weight: 700; }
.badge.on { color: #0e9f6e; }
.badge.off { color: var(--muted); }
.crew-hours { display: flex; gap: 16px; text-align: right; }
.crew-hours strong { display: block; color: var(--teal-600); font-variant-numeric: tabular-nums; }
.crew-hours small { color: var(--muted); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.03em; }
.refreshed { text-align: center; font-size: 0.72rem; margin-top: 10px; }

/* ---- Manage people ---- */
.person-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding: 12px 2px; border-bottom: 1px solid var(--line);
}
.person-row:last-of-type { border-bottom: none; }
.person-row.is-off { opacity: 0.62; }
.person-main { flex: 1 1 160px; min-width: 0; }
.person-email { font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.crew-name .tag.off { background: #94a3b8; }
.crew-name .tag.you { background: #64748b; }
.pw-row { flex: 1 1 100%; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding-top: 4px; }
.pw-row[hidden] { display: none; }   /* an author `display` beats the hidden attribute — put it back */
.pw-input {
  flex: 1; min-width: 0; padding: 10px 12px; font-size: 0.95rem;
  border: 1px solid var(--line); border-radius: 10px; background: #fbfeff; color: var(--ink);
}
.pw-input:focus { outline: 2px solid var(--aqua-400); border-color: var(--aqua); }

/* ---- Live map ---- */
#map { height: 320px; border-radius: 12px; overflow: hidden; z-index: 0; background: #e8eef0; }
.leaflet-container { font: inherit; }
.map-note { font-size: 0.75rem; text-align: center; margin-top: 8px; }
.map-empty { text-align: center; padding: 8px; font-size: 0.85rem; }

/* ---- Recurring-job controls ---- */
.weekday-row { display: flex; gap: 6px; flex-wrap: wrap; }
.wd-toggle {
  flex: 1; min-width: 40px; padding: 9px 4px; border: 1px solid var(--line);
  border-radius: 9px; background: #fbfeff; color: var(--muted);
  font-weight: 700; font-size: 0.8rem; cursor: pointer;
}
.wd-toggle.on { background: var(--grad); color: #fff; border-color: transparent; }
.repeat-hint {
  font-size: 0.8rem; color: var(--teal-600); background: #ecfeff;
  padding: 8px 12px; border-radius: 10px; margin-bottom: 12px;
}
.recur-badge { font-size: 0.85em; }

/* ---- Length (hours + minutes) ---- */
.dur-row { display: flex; align-items: center; gap: 6px; }
.dur-row input { width: 64px; padding: 12px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fbfeff; color: var(--ink); font-size: 1rem; text-align: center; }
.dur-row input:focus { outline: 2px solid var(--aqua-400); border-color: var(--aqua); }
.dur-unit { color: var(--muted); font-weight: 600; margin-right: 8px; }

/* ---- Assignee chips (multi-select) ---- */
.assignee-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.assignee-chips.inline { flex-basis: 100%; margin-bottom: 2px; }
.ass-chip { padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px; background: #fbfeff; color: var(--muted); font-weight: 700; font-size: 0.8rem; cursor: pointer; }
.ass-chip.on { background: var(--grad); color: #fff; border-color: transparent; }
.ass-chip.svc.on { background: linear-gradient(135deg, #0ea5a4, #0369a1); }
.ass-chip small { font-weight: 600; opacity: 0.85; }

/* ---- Services manager + tags ---- */
.svc-add { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.svc-add > input { flex: 1; min-width: 0; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fbfeff; color: var(--ink); font-size: 0.95rem; }
.svc-min { max-width: 84px; flex: 0 0 auto !important; text-align: center; }
.svc-row { display: flex; align-items: center; gap: 10px; padding: 9px 2px; border-bottom: 1px solid var(--line); }
.svc-row:last-of-type { border-bottom: none; }
.svc-name { flex: 1; font-weight: 600; }
.svc-badge { font-size: 0.72rem; color: var(--teal-600); background: #ecfeff; padding: 2px 8px; border-radius: 999px; }
.job-services { margin-top: 3px; display: flex; flex-wrap: wrap; gap: 5px; }
.svc-tag { font-size: 0.72rem; background: #eef4f5; color: var(--teal-600); padding: 2px 8px; border-radius: 999px; font-weight: 700; }

/* ---- Hours / accounting ---- */
.range-presets { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.range-presets button { padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; background: #fbfeff; color: var(--muted); font-weight: 700; font-size: 0.8rem; cursor: pointer; }
.range-presets button.active { background: var(--grad); color: #fff; border-color: transparent; }
.acct-grand { font-size: 0.95rem; margin-bottom: 10px; }
.acct-grand-num { font-size: 1.8rem; font-weight: 800; color: var(--teal-600); font-variant-numeric: tabular-nums; }
.acct-total-row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 8px 2px; border-bottom: 1px solid var(--line); }
.acct-total-row:last-of-type { border-bottom: none; }
.acct-name { font-weight: 700; }
.acct-hours { font-weight: 800; color: var(--teal-600); font-variant-numeric: tabular-nums; white-space: nowrap; }
.acct-hours small { color: var(--muted); font-weight: 600; font-size: 0.7rem; }
.acct-group { margin-bottom: 12px; }
.acct-group-head { font-weight: 800; font-size: 0.9rem; padding: 6px 2px; border-bottom: 2px solid var(--line); }
.acct-entry { align-items: center; }
.acct-entry .dur { min-width: 54px; }
.acct-row-actions { display: flex; gap: 6px; flex: 0 0 auto; }
select:disabled { opacity: 0.7; }
