:root {
  --primary: #0d7a5f;
  --primary-dark: #095c47;
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #1c2b26;
  --muted: #6b7c76;
  --border: #dde4e1;
  --danger: #c0392b;
  --radius: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
}
#app { max-width: 640px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }

/* Header */
.topbar {
  background: var(--primary); color: #fff; padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
  display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 10;
}
.topbar h1 { font-size: 18px; font-weight: 600; flex: 1; }
.topbar .back { background: none; border: none; color: #fff; font-size: 24px; cursor: pointer; padding: 0 4px; line-height: 1; }
.topbar .icon-btn { background: rgba(255,255,255,.15); border: none; color: #fff; font-size: 16px; border-radius: 8px; padding: 8px 10px; cursor: pointer; }

.content { padding: 16px; flex: 1; }

/* Cards y botones */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.btn {
  display: block; width: 100%; padding: 15px; border: none; border-radius: var(--radius);
  background: var(--primary); color: #fff; font-size: 17px; font-weight: 600; cursor: pointer; text-align: center; text-decoration: none;
}
.btn:active { background: var(--primary-dark); }
.btn.secondary { background: #e8eeec; color: var(--text); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 9px 14px; font-size: 14px; width: auto; display: inline-block; }
.btn-row { display: flex; gap: 10px; margin-top: 10px; }
.btn-row .btn { flex: 1; }

/* Menú principal */
.client-title { font-size: 14px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin: 18px 4px 8px; }
.job-btn {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); border: none; width: 100%; padding: 18px 16px; border-radius: var(--radius);
  font-size: 18px; font-weight: 600; color: var(--text); margin-bottom: 10px; cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.06); text-align: left;
}
.job-btn span.arrow { color: var(--muted); font-size: 20px; }

/* Formularios */
label.field-label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.field { margin-bottom: 16px; }
input[type=text], input[type=number], input[type=date], input[type=time], input[type=password], textarea, select {
  width: 100%; padding: 13px; border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 16px; background: #fff; color: var(--text); font-family: inherit;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); }
textarea { min-height: 80px; resize: vertical; }
.req { color: var(--danger); }

/* Sí/No */
.yesno { display: flex; gap: 10px; }
.yesno button {
  flex: 1; padding: 14px; font-size: 16px; font-weight: 600; border: 1.5px solid var(--border);
  border-radius: 10px; background: #fff; color: var(--muted); cursor: pointer;
}
.yesno button.sel-si { background: var(--primary); border-color: var(--primary); color: #fff; }
.yesno button.sel-no { background: var(--danger); border-color: var(--danger); color: #fff; }

/* Hora rápida */
.time-row { display: flex; gap: 10px; }
.time-row input { flex: 1; }
.time-row .now-btn {
  padding: 0 18px; border: none; border-radius: 10px; background: var(--primary);
  color: #fff; font-size: 15px; font-weight: 700; cursor: pointer; white-space: nowrap;
}

/* Fotos */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; margin-top: 10px; }
.photo-grid .ph { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: #ddd; }
.photo-grid img { width: 100%; height: 100%; object-fit: cover; }
.photo-grid .del {
  position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.6); color: #fff;
  border: none; border-radius: 50%; width: 26px; height: 26px; font-size: 14px; cursor: pointer;
}
.add-photo {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  padding: 14px; border: 2px dashed var(--border); border-radius: 10px; background: none;
  color: var(--muted); font-size: 15px; font-weight: 600; cursor: pointer;
}

/* Lista de visitas */
.visit-item {
  background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px;
  cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.visit-item .vi-top { display: flex; justify-content: space-between; align-items: center; }
.visit-item .vi-title { font-weight: 700; font-size: 16px; }
.visit-item .vi-date { color: var(--muted); font-size: 13px; }
.visit-item .vi-sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
.badge { background: #e8eeec; color: var(--primary-dark); font-size: 12px; font-weight: 700; border-radius: 20px; padding: 3px 9px; }
.badge.pending { background: #fdecd3; color: #a05a00; }

/* Calendario */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-head button { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--primary); padding: 4px 12px; }
.cal-head .cal-month { font-weight: 700; font-size: 16px; text-transform: capitalize; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-grid .dow { text-align: center; font-size: 12px; color: var(--muted); font-weight: 700; padding: 4px 0; }
.cal-day {
  aspect-ratio: 1; border: none; background: none; border-radius: 10px; font-size: 15px;
  color: var(--text); cursor: pointer; position: relative; display: flex; align-items: center; justify-content: center;
}
.cal-day.other { color: #c3ccc8; }
.cal-day.today { border: 2px solid var(--primary); font-weight: 700; }
.cal-day.selected { background: var(--primary); color: #fff; }
.cal-day .dot {
  position: absolute; bottom: 5px; width: 6px; height: 6px; border-radius: 50%; background: var(--primary);
}
.cal-day.selected .dot { background: #fff; }

/* Detalle */
.detail-row { padding: 12px 0; border-bottom: 1px solid var(--border); }
.detail-row:last-child { border-bottom: none; }
.detail-row .dr-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.detail-row .dr-flex { display: flex; align-items: flex-start; gap: 10px; }
.detail-row .dr-value { font-size: 16px; margin-top: 2px; flex: 1; white-space: pre-wrap; }
.copy-btn {
  background: #e8eeec; border: none; border-radius: 8px; padding: 7px 11px; font-size: 13px;
  color: var(--primary-dark); font-weight: 700; cursor: pointer; flex-shrink: 0;
}
.copy-btn.copied { background: var(--primary); color: #fff; }

/* Editor de campos */
.field-editor-item {
  background: var(--card); border-radius: 10px; padding: 12px; margin-bottom: 8px;
  display: flex; align-items: center; gap: 10px; box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.field-editor-item .fe-info { flex: 1; }
.field-editor-item .fe-label { font-weight: 600; font-size: 15px; }
.field-editor-item .fe-type { font-size: 12px; color: var(--muted); }
.fe-btn { background: #e8eeec; border: none; border-radius: 8px; padding: 8px 10px; cursor: pointer; font-size: 14px; }

/* Login */
.login-wrap { display: flex; flex-direction: column; justify-content: center; min-height: 80vh; padding: 24px; }
.login-wrap .logo { text-align: center; margin-bottom: 28px; }
.login-wrap .logo h1 { color: var(--primary); font-size: 30px; }
.login-wrap .logo p { color: var(--muted); margin-top: 6px; }

/* Toast */
#toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #1c2b26; color: #fff; padding: 12px 22px; border-radius: 30px; font-size: 15px;
  opacity: 0; transition: all .25s; pointer-events: none; z-index: 100; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); }

/* Offline banner */
.offline-banner { background: #a05a00; color: #fff; text-align: center; padding: 8px; font-size: 14px; font-weight: 600; }
.sync-banner { background: var(--primary); color: #fff; text-align: center; padding: 8px; font-size: 14px; font-weight: 600; }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 15px; }
.muted { color: var(--muted); font-size: 14px; }
h2.section { font-size: 16px; font-weight: 700; margin: 18px 4px 10px; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.filters .full { grid-column: 1 / -1; }
