/* ContactVault — single stylesheet, mobile-first, no framework. */

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --accent: #38bdf8;
  --accent-text: #04202e;
  --danger: #f87171;
  --border: #334155;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-2: #f1f5f9;
    --text: #0f172a;
    --text-dim: #64748b;
    --accent: #0284c7;
    --accent-text: #ffffff;
    --danger: #dc2626;
    --border: #e2e8f0;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#view-root {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: 5rem;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: max(0.75rem, env(safe-area-inset-top)) 1rem 0.75rem;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.topbar h1 {
  font-size: 1.15rem;
  margin: 0;
  flex: 1;
}

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  width: 2.25rem;
  height: 2.25rem;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.search-row {
  padding: 0 1rem 0.5rem;
}

#search-input {
  width: 100%;
  padding: 0.6rem 0.9rem;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
}

.chip-row {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding: 0 1rem 0.75rem;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 0.85rem;
  cursor: pointer;
}
.chip-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.contact-list {
  list-style: none;
  margin: 0;
  padding: 0 0.5rem;
}

.contact-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem;
  border-radius: 0.75rem;
  cursor: pointer;
}
.contact-row:active { background: var(--surface); }

.avatar {
  flex: none;
  width: 3rem;
  height: 3rem;
  border-radius: 999px;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  overflow: hidden;
  font-size: 1.1rem;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.avatar-large {
  width: 6rem;
  height: 6rem;
  margin: 0.5rem auto 0;
  font-size: 2rem;
}

.contact-row-info { flex: 1; min-width: 0; }
.contact-row-name { font-weight: 600; }
.contact-row-sub {
  color: var(--text-dim);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--accent);
  font-size: 0.75rem;
}
.badge-center {
  display: block;
  width: fit-content;
  margin: 0.5rem auto 0;
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 3rem 1.5rem;
  line-height: 1.5;
}

.fab {
  position: fixed;
  right: max(1.25rem, calc((100vw - 480px) / 2 + 1.25rem));
  bottom: max(1.5rem, env(safe-area-inset-bottom));
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  font-size: 1.75rem;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
  cursor: pointer;
}

.detail-body { padding: 0 1.25rem 2rem; }

.detail-section { margin-top: 1.5rem; }
.detail-section h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin: 0 0 0.5rem;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.7rem 0.9rem;
  background: var(--surface);
  border-radius: 0.75rem;
  margin-bottom: 0.5rem;
  color: var(--text);
  text-decoration: none;
}
.detail-row-label { color: var(--text-dim); font-size: 0.85rem; text-transform: capitalize; }
.detail-row-value { font-weight: 500; }

.detail-row-address {
  align-items: flex-start;
  gap: 0.75rem;
}
.detail-row-address .detail-row-value { white-space: pre-wrap; line-height: 1.4; }
.detail-row-address .detail-row-label { flex: none; white-space: nowrap; }

.phone-row { gap: 0.5rem; }
.phone-row-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
  overflow: hidden;
}
.phone-row-text .detail-row-value { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.row-actions {
  display: flex;
  gap: 0.4rem;
  flex: none;
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--accent);
  text-decoration: none;
  flex: none;
}
.action-btn-whatsapp {
  background: #25d366;
  color: #ffffff;
}

.detail-notes {
  background: var(--surface);
  border-radius: 0.75rem;
  padding: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

.detail-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.75rem;
}

.btn {
  flex: 1;
  padding: 0.75rem;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.btn-danger {
  color: var(--danger);
  border-color: var(--danger);
}

/* Delete is deliberately separated from the other actions, low-emphasis,
   and small — so a mis-tap near Edit/Save can't land on it by accident. */
.danger-zone {
  margin-top: 3rem;
  padding-top: 1rem;
  text-align: center;
}
.btn-link-danger {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 0.85rem;
  padding: 0.6rem 1rem;
  cursor: pointer;
  opacity: 0.75;
}
.btn-link-danger:active { opacity: 1; }

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0.4rem 0;
}

.contact-form {
  padding: 0 1.25rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.field { display: flex; flex-direction: column; gap: 0.4rem; }
.field > span:first-child { font-size: 0.85rem; color: var(--text-dim); }
.field-hint { font-weight: 400; font-size: 0.8rem; }

.field input[type="text"],
.field input[type="tel"],
.field input[type="email"],
.field input[type="url"],
.field textarea {
  padding: 0.65rem 0.8rem;
  border-radius: 0.65rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

.photo-picker {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}
.photo-picker input[type="file"] { max-width: 100%; }

.dynamic-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
  align-items: flex-start;
}
.dynamic-row-fields {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.dynamic-row .row-label {
  width: 45%;
  min-width: 5.5rem;
  padding: 0.5rem 0.6rem;
  border-radius: 0.6rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
}
.dynamic-row .row-value {
  width: 100%;
  padding: 0.55rem 0.6rem;
  border-radius: 0.6rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.row-remove {
  flex: none;
  width: 2rem;
  height: 2rem;
  font-size: 0.85rem;
  margin-top: 0.1rem;
}

.form-error {
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 0.6rem 0.8rem;
  border-radius: 0.65rem;
  font-size: 0.9rem;
}
.form-error-ok {
  background: rgba(56, 189, 248, 0.12);
  border-color: var(--accent);
  color: var(--accent);
}

.backup-body { padding: 0 1.25rem 2rem; }
.hint { color: var(--text-dim); font-size: 0.9rem; line-height: 1.5; }

.backup-body .btn { margin-bottom: 0.5rem; width: 100%; }
