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

:root {
  --bg:      #0f0f18;
  --surface: #19192e;
  --surf2:   #22223a;
  --border:  #2e2e4a;
  --text:    #ddddef;
  --muted:   #5a5a78;
  --accent:  #6366f1;
  --todo:    #4b5563;
  --prog:    #d97706;
  --done:    #16a34a;
  --bad:     #dc2626;
  --tab-h:   56px;
}

html { background: var(--bg); color: var(--text); }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* ── LAYOUT ────────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.masthead {
  padding: 12px 16px 8px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
}
.masthead-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.masthead-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 1px;
}

#main-content {
  flex: 1;
  padding: 14px 16px;
  padding-bottom: calc(var(--tab-h) + 20px);
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

/* ── TAB BAR ───────────────────────────────────────────────────────────────── */
#tab-bar {
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  z-index: 20;
  display: flex;
  height: var(--tab-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 4px;
  min-height: 44px;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}
.tab-btn.active { color: var(--accent); }
.tab-icon { font-size: 18px; line-height: 1; }

/* ── CARDS ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 10px;
}
.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

/* ── PROPERTY CARD ─────────────────────────────────────────────────────────── */
.prop-card {}
.prop-address {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
}
.prop-price {
  font-size: 13px;
  color: var(--muted);
  margin-top: 3px;
}
.status-pill {
  display: inline-block;
  margin-top: 8px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  background: var(--surf2);
  border: 1px solid var(--border);
  color: var(--text);
}
.listing-link {
  display: inline-block;
  margin-top: 8px;
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
}
.listing-link:hover { text-decoration: underline; }
.prop-notes {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
}

/* ── PROGRESS BAR ──────────────────────────────────────────────────────────── */
.progress-wrap { margin-bottom: 14px; }
.progress-track {
  height: 6px;
  background: var(--surf2);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 5px;
}
.progress-fill {
  height: 100%;
  background: var(--done);
  border-radius: 99px;
  transition: width 0.4s ease;
}
.progress-label { font-size: 12px; color: var(--muted); }

/* ── SECTION HEADER ────────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

/* ── STAGE LIST ────────────────────────────────────────────────────────────── */
.stage-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stage-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid transparent;
  border-radius: 8px;
  padding: 10px 10px 10px 8px;
  transition: opacity 0.15s, box-shadow 0.15s;
  touch-action: pan-y;
}
.stage-row.is-dragging {
  opacity: 0.45;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
  z-index: 5;
  position: relative;
}
.stage-row.stage-over { border-left-color: var(--bad); }

.stage-main {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}
.drag-handle {
  cursor: grab;
  color: var(--muted);
  font-size: 16px;
  user-select: none;
  touch-action: none;
  flex-shrink: 0;
  padding: 4px 2px;
  line-height: 1;
}
.drag-handle:active { cursor: grabbing; }
.stage-title {
  flex: 1;
  font-size: 14px;
  cursor: pointer;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stage-title:hover { color: var(--accent); }

.stage-detail {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding-left: 30px;
}
.stage-dates {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.date-label {
  font-size: 11px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 5px;
}
.date-input {
  background: var(--surf2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 12px;
  padding: 3px 6px;
  outline: none;
  min-height: 28px;
  color-scheme: dark;
  font-family: inherit;
}
.date-input:focus { border-color: var(--accent); }
.date-disp { font-size: 12px; color: var(--muted); }
.date-over { color: var(--bad) !important; font-weight: 600; }

.note-input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  padding: 3px 0;
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s, color 0.15s;
}
.note-input:focus { border-color: var(--accent); color: var(--text); }
.note-input::placeholder { color: var(--muted); opacity: 0.55; }

/* ── STATUS CHIPS ──────────────────────────────────────────────────────────── */
.status-chip {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 99px;
  border: none;
  cursor: pointer;
  min-height: 28px;
  flex-shrink: 0;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.12s;
  letter-spacing: 0.02em;
}
.status-chip:active { opacity: 0.65; }
.chip-todo { background: var(--todo); color: #d1d5db; }
.chip-prog { background: var(--prog); color: #fff; }
.chip-done { background: var(--done); color: #fff; }

/* ── BUTTONS ───────────────────────────────────────────────────────────────── */
.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  padding: 6px 12px;
  cursor: pointer;
  min-height: 34px;
  font-family: inherit;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
  white-space: nowrap;
}
.btn-ghost:hover { background: var(--surf2); }

.btn-primary {
  background: var(--accent);
  border: none;
  border-radius: 6px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 18px;
  cursor: pointer;
  min-height: 42px;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.88; }
.btn-primary:disabled { opacity: 0.45; cursor: default; }

.btn-icon {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  width: 34px;
  height: 34px;
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  flex-shrink: 0;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}
.btn-icon:hover { color: var(--bad); background: rgba(220,38,38,0.1); }

.btn-chain {
  width: 100%;
  margin-top: 10px;
  background: var(--surf2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  padding: 10px;
  cursor: pointer;
  min-height: 44px;
  font-family: inherit;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-chain:hover { background: var(--border); }

/* ── VIEWINGS ──────────────────────────────────────────────────────────────── */
.viewing-list { display: flex; flex-direction: column; gap: 12px; }
.viewing-addr { font-size: 15px; font-weight: 600; }
.viewing-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

.checklist {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.checklist-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 6px;
  border: 1px solid var(--border);
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  min-height: 34px;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.12s;
  background: none;
  color: var(--text);
}
.checklist-item:active { opacity: 0.65; }
.score-unset { background: var(--surf2); color: var(--muted); }
.score-good  { background: rgba(22,163,74,0.15); border-color: rgba(22,163,74,0.4);  color: #4ade80; }
.score-okay  { background: rgba(217,119,6,0.15);  border-color: rgba(217,119,6,0.4);   color: #fbbf24; }
.score-poor  { background: rgba(220,38,38,0.15);  border-color: rgba(220,38,38,0.4);   color: #f87171; }

.score-badge { font-weight: 700; font-size: 11px; }
.checklist-tally { margin-top: 8px; font-size: 12px; color: var(--muted); }

.viewing-notes {
  display: block;
  width: 100%;
  margin-top: 10px;
  background: var(--surf2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  padding: 8px 10px;
  outline: none;
  font-family: inherit;
  resize: vertical;
  min-height: 64px;
  transition: border-color 0.15s;
  color-scheme: dark;
}
.viewing-notes:focus { border-color: var(--accent); }
.viewing-notes::placeholder { color: var(--muted); opacity: 0.55; }

/* ── CONTACTS ──────────────────────────────────────────────────────────────── */
.contact-list { display: flex; flex-direction: column; gap: 8px; }
.contact-role {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}
.contact-name { font-size: 15px; font-weight: 500; margin-top: 2px; }
.contact-btns { display: flex; align-items: center; gap: 4px; }
.contact-links {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.contact-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 14px;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.contact-link:hover { text-decoration: underline; }

/* ── SPARKS ────────────────────────────────────────────────────────────────── */
.muted-sm { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.spark-form {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.spark-input { flex: 1; min-width: 0; }
.spark-list { display: flex; flex-direction: column; gap: 6px; }
.spark-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.spark-text { font-size: 14px; margin-bottom: 6px; line-height: 1.4; }
.spark-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.spark-ts { font-size: 11px; color: var(--muted); }

/* ── FORM FIELDS ───────────────────────────────────────────────────────────── */
.field-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.02em;
}
.field-input {
  background: var(--surf2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  padding: 8px 10px;
  outline: none;
  font-family: inherit;
  width: 100%;
  min-height: 42px;
  transition: border-color 0.15s;
  color-scheme: dark;
}
.field-input:focus { border-color: var(--accent); }
.field-textarea { min-height: 80px; resize: vertical; }
.modal-form { display: flex; flex-direction: column; gap: 14px; }

/* ── MODAL ─────────────────────────────────────────────────────────────────── */
#modal { position: fixed; inset: 0; z-index: 100; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(2px);
}
.modal-box {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  max-height: 90dvh;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  overflow-y: auto;
  animation: slideUp 0.2s ease;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
.modal-inner { padding: 20px 16px 36px; }
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 18px; }
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding-top: 4px;
}

/* ── PIN GATE ──────────────────────────────────────────────────────────────── */
#pin-gate {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.pin-box { width: 100%; max-width: 340px; text-align: center; }
.pin-logo {
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 4px;
}
.pin-sub {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 32px;
}
.pin-form { display: flex; flex-direction: column; gap: 12px; }
.pin-input {
  width: 100%;
  text-align: center;
  font-size: 22px;
  letter-spacing: 0.2em;
  min-height: 54px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  padding: 10px;
  outline: none;
  transition: border-color 0.15s;
  color-scheme: dark;
}
.pin-input:focus { border-color: var(--accent); }
.pin-submit { font-size: 15px; font-weight: 700; min-height: 50px; }
.pin-err { font-size: 13px; color: var(--bad); min-height: 20px; margin-top: 4px; }

/* ── TOAST ─────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--tab-h) + 12px);
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  z-index: 200;
  pointer-events: none;
  white-space: nowrap;
  transition: opacity 0.3s;
}
.toast-ok     { background: var(--done); color: #fff; }
.toast-err    { background: var(--bad);  color: #fff; }
.toast-hidden { opacity: 0; pointer-events: none; }

/* ── UTILITIES ─────────────────────────────────────────────────────────────── */
.muted { color: var(--muted); }
.empty-state {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 28px 0;
}
