/* ── Reset ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: #ECEFF1;
  color: #1C1C1E;
  min-height: 100%;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ────────────────────────────────────────────────────────── */
#app {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: #ECEFF1;
}

/* ── Header ────────────────────────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #fff;
  border-bottom: 1px solid rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  height: 56px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.header-back {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  margin: -8px;
  color: #007AFF;
  font-size: 22px;
  line-height: 1;
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
}
.header-back:active { background: #E5E5EA; }
.header-back.visible { display: flex; }
.header-title {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  color: #1C1C1E;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-area-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  display: none;
}
.header-area-dot.visible { display: block; }
.sync-status {
  font-size: 14px;
  font-weight: 700;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
  transition: color 0.2s;
  cursor: default;
}
.header-gear {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  padding: 8px;
  margin: -8px -4px -8px 0;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
  display: none;
  align-items: center;
  justify-content: center;
  color: #3A3A3C;
  line-height: 1;
}
.header-gear.visible { display: flex; }
.header-gear:active { background: #E5E5EA; }

/* ── Main content ───────────────────────────────────────────────────── */
.view { flex: 1; padding: 16px; display: none; flex-direction: column; gap: 16px; }
.view.active { display: flex; }

/* ── Section labels ─────────────────────────────────────────────────── */
.section-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #8E8E93;
  padding: 0 4px;
  margin-bottom: -8px;
}

/* ── Cards ──────────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  overflow: hidden;
}
.card-list { display: flex; flex-direction: column; }
.card-row {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  gap: 12px;
  cursor: pointer;
  border-bottom: 1px solid #F2F2F7;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s;
  text-decoration: none;
  color: inherit;
}
.card-row:last-child { border-bottom: none; }
.card-row:active { background: #F2F2F7; }

.card-row-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.card-row-text { flex: 1; min-width: 0; }
.card-row-title {
  font-size: 16px;
  font-weight: 500;
  color: #1C1C1E;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-row-sub {
  font-size: 13px;
  color: #8E8E93;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-row-chevron {
  color: #C7C7CC;
  font-size: 16px;
  flex-shrink: 0;
}
.card-row-badge {
  font-size: 12px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 20px;
  flex-shrink: 0;
}

/* ── Area cards (home screen) ───────────────────────────────────────── */
.area-card {
  border-radius: 16px;
  padding: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 16px;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s, box-shadow 0.1s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  color: #fff;
  text-decoration: none;
}
.area-card:active { transform: scale(0.98); box-shadow: 0 1px 4px rgba(0,0,0,0.12); }
.area-card-icon { font-size: 36px; line-height: 1; }
.area-card-text { flex: 1; }
.area-card-name    { font-size: 20px; font-weight: 700; }
.area-card-sub     { font-size: 14px; opacity: 0.85; margin-top: 2px; }
.area-card-overdue { font-size: 13px; font-weight: 600; margin-top: 4px; background: rgba(0,0,0,0.18); display: inline-block; padding: 2px 10px; border-radius: 20px; }
.area-card-arrow   { font-size: 20px; opacity: 0.7; }

/* ── Overdue badge (site list rows) ─────────────────────────────────── */
.overdue-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  flex-shrink: 0;
  white-space: nowrap;
}

/* ── Site detail header ─────────────────────────────────────────────── */
.site-header {
  border-radius: 14px;
  padding: 20px;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.site-header-name { font-size: 20px; font-weight: 700; line-height: 1.3; }
.site-header-meta { font-size: 14px; opacity: 0.85; margin-top: 6px; display: flex; gap: 12px; flex-wrap: wrap; }
.site-header-pill {
  background: rgba(255,255,255,0.2);
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 13px;
}

/* ── Previous todos callout ─────────────────────────────────────────── */
.prev-todos {
  border-radius: 12px;
  padding: 14px 16px;
  border-left: 4px solid;
}
.prev-todos-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; opacity: 0.7; }
.prev-todos-text  { font-size: 15px; white-space: pre-wrap; line-height: 1.5; }

/* ── Log visit button ───────────────────────────────────────────────── */
.btn-log {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s, box-shadow 0.1s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.btn-log:active { transform: scale(0.98); box-shadow: 0 1px 4px rgba(0,0,0,0.1); }

/* ── Form ───────────────────────────────────────────────────────────── */
.form-card { background: #fff; border-radius: 14px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); padding: 16px; display: flex; flex-direction: column; gap: 18px; }

.form-row { display: flex; gap: 12px; }
.form-group { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.form-label { font-size: 13px; font-weight: 600; color: #8E8E93; text-transform: uppercase; letter-spacing: 0.05em; }
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid #E5E5EA;
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  color: #1C1C1E;
  background: #fff;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: #007AFF;
}
.form-textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
.form-select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238E8E93' d='M6 8L0 0h12z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }

/* ── Task grid ──────────────────────────────────────────────────────── */
.task-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.task-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border: 1.5px solid #E5E5EA;
  border-radius: 12px;
  background: #F9F9FB;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.12s;
  font-size: 15px;
  font-weight: 500;
  color: #3A3A3C;
  user-select: none;
}
.task-chip:active { transform: scale(0.97); }
.task-chip.selected {
  background: #E8F5E9;
  border-color: #2E7D52;
  color: #1B5E20;
}
.task-chip-icon { font-size: 20px; line-height: 1; }

/* ── Submit button ──────────────────────────────────────────────────── */
.btn-submit {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s, box-shadow 0.1s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.btn-submit:active { transform: scale(0.98); }
.btn-submit:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ── History entries ─────────────────────────────────────────────────── */
.history-empty {
  text-align: center;
  padding: 32px 16px;
  color: #8E8E93;
  font-size: 15px;
}
.log-entry {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  overflow: hidden;
}
.log-entry-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  gap: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.log-entry-header:active { background: #F9F9FB; }
.log-entry-date { font-size: 16px; font-weight: 600; color: #1C1C1E; }
.log-entry-week { font-size: 13px; color: #8E8E93; }
.log-entry-chevron { color: #C7C7CC; font-size: 14px; transition: transform 0.2s; }
.log-entry.open .log-entry-chevron { transform: rotate(90deg); }
.log-entry-tasks { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 10px; }
.log-task-pill {
  font-size: 13px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 20px;
  background: #E8F5E9;
  color: #1B5E20;
}
.log-entry-body { display: none; padding: 0 16px 16px; border-top: 1px solid #F2F2F7; padding-top: 12px; display: none; flex-direction: column; gap: 12px; }
.log-entry.open .log-entry-body { display: flex; }
.log-field-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: #8E8E93; margin-bottom: 3px; }
.log-field-text  { font-size: 15px; color: #1C1C1E; white-space: pre-wrap; line-height: 1.5; }
.log-entry-crew { color: #8E8E93; font-style: italic; font-size: 12px; }
.log-entry-actions { display: flex; gap: 8px; margin-top: 4px; }
.log-edit-btn, .log-delete-btn {
  background: none;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}
.log-edit-btn {
  border: 1px solid #007AFF;
  color: #007AFF;
}
.log-edit-btn:active   { background: #F0F6FF; }
.log-delete-btn {
  border: 1px solid #FF3B30;
  color: #FF3B30;
}
.log-delete-btn:active { background: #FFF5F5; }

/* ── Toast ──────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1C1C1E;
  color: #fff;
  padding: 12px 20px;
  border-radius: 24px;
  font-size: 15px;
  font-weight: 500;
  z-index: 999;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  white-space: nowrap;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ── Empty state ────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: #8E8E93;
}
.empty-state-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state-text { font-size: 16px; }

/* ── Season info bar ────────────────────────────────────────────────── */
.season-bar {
  background: #fff;
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.season-bar-label { font-size: 14px; color: #8E8E93; }
.season-bar-week  { font-size: 17px; font-weight: 700; color: #1C1C1E; }
.season-bar-progress { flex: 1; height: 6px; background: #E5E5EA; border-radius: 3px; margin: 0 14px; overflow: hidden; }
.season-bar-fill  { height: 100%; border-radius: 3px; transition: width 0.3s; }

/* ── Visit Log filters ───────────────────────────────────────────────── */
.vl-filter {
  padding: 7px 16px;
  border-radius: 20px;
  border: 1.5px solid #E5E5EA;
  background: #fff;
  font-size: 14px;
  font-weight: 500;
  color: #3A3A3C;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.12s;
}
.vl-filter.active {
  background: #1C1C1E;
  border-color: #1C1C1E;
  color: #fff;
}

/* ── Export button ───────────────────────────────────────────────────── */
.btn-export {
  margin-left: auto;
  background: none;
  border: 1.5px solid #1C1C1E;
  color: #1C1C1E;
  padding: 7px 14px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
  font-family: inherit;
}
.btn-export:active { background: #F2F2F7; }

/* ── Visit Log date headers ──────────────────────────────────────────── */
.vl-date-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 4px 6px;
  font-size: 14px;
  font-weight: 700;
  color: #1C1C1E;
}
.vl-date-count {
  font-size: 12px;
  font-weight: 500;
  color: #8E8E93;
}

/* ── Visit Log entry group ───────────────────────────────────────────── */
.vl-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

/* ── Visit Log entry card ────────────────────────────────────────────── */
.vl-entry {
  background: #fff;
  border-radius: 12px;
  border-left: 4px solid #ccc;
  box-shadow: 0 1px 3px rgba(0,0,0,0.07);
  overflow: hidden;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.vl-entry:active { background: #FAFAFA; }
.vl-entry-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 8px;
}
.vl-entry-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.vl-entry-info { flex: 1; min-width: 0; }
.vl-entry-site {
  font-size: 15px;
  font-weight: 600;
  color: #1C1C1E;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.vl-entry-area {
  font-size: 12px;
  font-weight: 500;
  margin-top: 1px;
}
.vl-entry-chevron {
  color: #C7C7CC;
  font-size: 14px;
  transition: transform 0.2s;
  flex-shrink: 0;
}
.vl-entry.open .vl-entry-chevron { transform: rotate(90deg); }
.vl-entry .log-entry-body { display: none; }
.vl-entry.open .log-entry-body { display: flex; }

/* ── Utilities ──────────────────────────────────────────────────────── */
.pb-safe { padding-bottom: max(16px, env(safe-area-inset-bottom)); }
.mt-auto { margin-top: auto; }
