/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #0f1117;
  --surface:    #1a1d27;
  --surface2:   #22263a;
  --primary:    #4f7cff;
  --primary-dk: #3a62d9;
  --text:       #e8eaf0;
  --text-muted: #7a7f9a;
  --border:     #2e3248;
  --danger:     #e05252;
  --success:    #3dba7e;
  --radius:     12px;
  --radius-sm:  8px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
}

.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
}
.screen.active { display: flex; }

/* ── Header ───────────────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-header h1 { font-size: 1rem; font-weight: 600; }
.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}
.btn-icon:active { background: var(--surface2); }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card-label {
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 8px;
}
.card-title { font-size: 1rem; font-weight: 600; }
.card-sub   { font-size: .82rem; color: var(--text-muted); margin-top: 2px; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: block;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: opacity .15s;
}
.btn:active { opacity: .8; }
.btn-primary  { background: var(--primary);  color: #fff; }
.btn-outline  { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-danger   { background: var(--danger);   color: #fff; }
.btn + .btn   { margin-top: 10px; }

/* ── Form fields ──────────────────────────────────────────────────────────── */
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.field input, .field select, .field textarea {
  font-family: inherit;
  width: 100%;
  padding: 13px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: .95rem;
  outline: none;
  -webkit-appearance: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.field textarea { resize: vertical; }

/* ── Thumbnails (agent listing photos, renter request photos) ─────────────── */
.thumb-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.thumb-grid .spinner, .thumb-grid p { grid-column: 1 / -1; }
.thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface2);
  border: 1px solid var(--border);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: pointer; }
.thumb-del {
  position: absolute; left: 4px; right: 4px; bottom: 4px;
  padding: 4px 0;
  border: none;
  border-radius: 6px;
  background: rgba(0,0,0,.65);
  color: #fff;
  font-size: .72rem;
  font-weight: 600;
  cursor: pointer;
}
.link-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: .85rem; }
.link-row a { flex: 1; color: var(--primary); word-break: break-all; }
.link-row .thumb-del { position: static; padding: 4px 10px; background: var(--surface2); }
.mr-desc { font-size: .9rem; margin: 4px 0 8px; white-space: pre-wrap; word-break: break-word; }

/* ── Status badge ─────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  font-size: .7rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-pending  { background: #2a2d1a; color: #c9b84c; }
.badge-active   { background: #1a2a20; color: var(--success); }
.badge-complete { background: #1a2038; color: var(--primary); }

/* ── Phase list ───────────────────────────────────────────────────────────── */
.phase-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.phase-row:last-child { border-bottom: none; }
.phase-row:active { opacity: .7; }
.phase-name { font-size: .95rem; font-weight: 500; }
.phase-count { font-size: .8rem; color: var(--text-muted); }
.phase-check { color: var(--success); font-size: 1.1rem; }

/* ── Photo grid ───────────────────────────────────────────────────────────── */
.photo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}
.photo-slot {
  aspect-ratio: 4/3;
  background: var(--surface2);
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  position: relative;
}
.photo-slot.filled { border-style: solid; border-color: var(--primary); }
.photo-slot img { width: 100%; height: 100%; object-fit: cover; }
.photo-slot-label {
  font-size: .72rem;
  color: var(--text-muted);
  text-align: center;
  padding: 6px;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,.6);
}
.photo-slot.filled .photo-slot-label { color: #fff; }
.photo-slot-icon { font-size: 1.6rem; margin-bottom: 4px; color: var(--text-muted); }

/* ── Instruction box ──────────────────────────────────────────────────────── */
.instruction-box {
  background: var(--surface2);
  border-left: 3px solid var(--primary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 12px 14px;
  font-size: .85rem;
  color: var(--text-muted);
  margin-bottom: 16px;
  line-height: 1.5;
}

/* ── Toast ────────────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 24px;
  font-size: .88rem;
  font-weight: 500;
  transition: transform .25s ease;
  z-index: 100;
  white-space: nowrap;
  box-shadow: 0 4px 20px rgba(0,0,0,.4);
}
#toast.show { transform: translateX(-50%) translateY(0); }

/* ── Loading spinner ──────────────────────────────────────────────────────── */
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Login screen ─────────────────────────────────────────────────────────── */
#screen-login {
  justify-content: center;
  padding-top: 60px;
}
.login-logo {
  text-align: center;
  margin-bottom: 36px;
}
.login-logo h2 { font-size: 1.4rem; font-weight: 700; }
.login-logo p  { color: var(--text-muted); font-size: .85rem; margin-top: 4px; }
.error-msg {
  color: var(--danger);
  font-size: .82rem;
  text-align: center;
  margin-top: 8px;
  min-height: 20px;
}

/* ── Property list ────────────────────────────────────────────────────────── */
.property-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
}
.property-item:active { opacity: .75; }
.property-thumb {
  width: 44px; height: 44px;
  border-radius: var(--radius-sm);
  background: var(--surface2);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  font-size: 1.3rem;
}
.property-info { flex: 1; }
.property-addr { font-size: .95rem; font-weight: 600; }
.property-meta { font-size: .78rem; color: var(--text-muted); margin-top: 2px; }
.property-arrow { color: var(--text-muted); font-size: .9rem; }

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.tab-btn {
  flex: 1;
  padding: 12px 0;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
}
.tab-btn.tab-active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ── Crew select buttons ──────────────────────────────────────────────────── */
.crew-select-btn {
  display: block;
  width: 100%;
  padding: 16px;
  text-align: left;
  margin-bottom: 10px;
  border-radius: var(--radius);
}

/* ── Progress bar ─────────────────────────────────────────────────────────── */
.progress-wrap { margin: 16px 0; }
.progress-bar {
  height: 5px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width .3s ease;
}
.progress-label {
  font-size: .75rem;
  color: var(--text-muted);
  margin-top: 5px;
  text-align: right;
}
