:root {
  --navy: #091435;
  --blue: #3E5CAA;
  --teal: #20c997;
  --purple: #6f42c1;
  --red: #ED2424;
  --green: #28a745;
  --cyan: #17a2b8;
  --orange: #fd7e14;
  --bg: #f3f5f9;
  --card: #ffffff;
  --text: #1a2332;
  --muted: #6b7385;
  --line: #e6e9f0;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-h: 56px;
  --nav-h: 64px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: Inter, system-ui, -apple-system, Segoe UI, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app { height: 100%; display: flex; flex-direction: column; }

.hidden { display: none !important; }

/* ── Login ── */
.login-screen {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
  position: relative;
  overflow: auto;
  background: #091435;
}
.login-bg {
  position: absolute; inset: 0;
  background: linear-gradient(135deg, #091435 0%, #1a2a5e 40%, #3E5CAA 100%);
}
.login-card {
  position: relative; z-index: 2;
  width: 100%; max-width: 400px;
  background: rgba(255,255,255,0.96);
  backdrop-filter: blur(16px);
  border-radius: 20px;
  padding: 2rem 1.4rem 1.5rem;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
}
.login-logo { text-align: center; margin-bottom: 1.25rem; }
.login-logo img { height: 52px; width: auto; max-width: 240px; object-fit: contain; }
.login-card h1 { text-align: center; font-size: 1.15rem; margin-bottom: 1.25rem; color: #333; }
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: 0.82rem; font-weight: 600; margin-bottom: 0.4rem; color: #333; }
.field input, .field select, .field textarea {
  width: 100%; padding: 0.8rem 0.85rem;
  border: 2px solid var(--line); border-radius: 10px;
  font-size: 16px; font-family: inherit; background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--blue);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  width: 100%; border: none; border-radius: 10px;
  padding: 0.85rem 1rem; font-size: 0.95rem; font-weight: 700;
  font-family: inherit; cursor: pointer; color: #fff;
  background: var(--blue); min-height: 48px;
}
.btn:active { transform: scale(0.98); }
.btn-navy { background: var(--navy); }
.btn-green { background: linear-gradient(135deg, #28a745, #20c997); }
.btn-purple { background: linear-gradient(135deg, #6f42c1, #563d7c); }
.btn-cyan { background: linear-gradient(135deg, #17a2b8, #138496); }
.btn-orange { background: linear-gradient(135deg, #fd7e14, #e8590c); }
.btn-red { background: linear-gradient(135deg, #dc3545, #c82333); }
.btn-ghost {
  background: #fff; color: var(--muted); border: 2px solid var(--line);
}
.btn-sm { width: auto; padding: 0.45rem 0.8rem; min-height: 36px; font-size: 0.8rem; }
.skip-link {
  display: block; text-align: center; margin-top: 0.9rem;
  color: #888; font-size: 0.82rem; text-decoration: none;
}
.error-box, .ok-box, .info-box {
  border-radius: 10px; padding: 0.75rem 0.85rem; margin-bottom: 1rem;
  font-size: 0.85rem; text-align: center;
}
.error-box { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.ok-box { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.info-box { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }
.pin-digits { display: flex; gap: 0.55rem; justify-content: center; margin: 1rem 0 1.25rem; }
.pin-digit {
  width: 58px; height: 64px; text-align: center;
  font-size: 1.5rem; font-weight: 700;
  border: 2px solid #dde2e8; border-radius: 12px;
  background: #f8f9fa; color: var(--navy);
  -webkit-text-security: disc;
}
.pin-digit:focus { outline: none; border-color: var(--blue); background: #fff; }
.pin-digit.filled { border-color: var(--blue); background: #eef2ff; }
.pin-welcome { text-align: center; margin-bottom: 0.5rem; }
.pin-welcome h2 { font-size: 1.15rem; }
.pin-welcome-email { display: block; color: var(--blue); font-weight: 600; font-size: 0.92rem; word-break: break-all; margin: 0.25rem 0; }
.version-foot { text-align: center; margin-top: 1.4rem; color: #888; font-size: 0.75rem; letter-spacing: 0.04em; }

/* ── App chrome ── */
.app-header {
  flex-shrink: 0;
  height: calc(var(--header-h) + var(--safe-top));
  padding: var(--safe-top) 12px 0;
  background: linear-gradient(135deg, #091435, #3E5CAA);
  color: #fff;
  display: flex; align-items: center; gap: 8px;
  z-index: 20;
}
.app-header .back {
  width: 40px; height: 40px; border: none; background: transparent; color: #fff;
  font-size: 1.1rem; border-radius: 10px; cursor: pointer;
}
.app-header .title {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 8px;
}
.app-header .title img { height: 26px; width: auto; }
.app-header h1 {
  font-size: 1rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.app-header .hdr-btn {
  width: 40px; height: 40px; border: none; background: rgba(255,255,255,0.12);
  color: #fff; border-radius: 10px; cursor: pointer;
}

.app-body {
  flex: 1; overflow: auto; -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
}

.app-nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: #fff;
  border-top: 1px solid var(--line);
  display: flex; z-index: 30;
}
.app-nav button {
  flex: 1; border: none; background: transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: #8a93a6; font-size: 0.68rem; font-weight: 600; font-family: inherit;
  cursor: pointer;
}
.app-nav button i { font-size: 1.15rem; }
.app-nav button.active { color: var(--blue); }
.app-nav .badge {
  position: absolute; top: 6px; margin-left: 18px;
  background: var(--red); color: #fff; font-size: 0.62rem;
  min-width: 16px; height: 16px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
}

/* ── Search ── */
.search-wrap { padding: 12px 12px 0; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border: 2px solid var(--line); border-radius: 14px; padding: 0 12px;
}
.search-box:focus-within { border-color: var(--blue); }
.search-box i { color: var(--muted); }
.search-box input {
  flex: 1; border: none; outline: none; padding: 12px 0; font-size: 16px; background: transparent; font-family: inherit;
}
.chips {
  display: flex; gap: 6px; overflow-x: auto; padding: 10px 0 8px;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; border: none; background: #fff; color: #445; border-radius: 999px;
  padding: 0.4rem 0.75rem; font-size: 0.75rem; font-weight: 700; font-family: inherit;
  border: 1px solid var(--line); cursor: pointer;
}
.chip.active { background: var(--blue); color: #fff; border-color: var(--blue); }

.result-list { padding: 4px 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.result-card {
  background: #fff; border-radius: 14px; padding: 12px 12px 10px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05);
  display: flex; gap: 10px; align-items: flex-start;
  text-decoration: none; color: inherit;
}
.result-card.our { box-shadow: inset 3px 0 0 #22c55e; }
.avatar {
  width: 44px; height: 44px; border-radius: 12px; flex-shrink: 0;
  background: linear-gradient(135deg, #3E5CAA, #091435);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.rc-body { flex: 1; min-width: 0; }
.rc-name { font-weight: 700; font-size: 0.95rem; }
.rc-name.our { color: #15803d; }
.rc-meta { color: var(--muted); font-size: 0.78rem; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rc-tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 6px; }
.tag {
  font-size: 0.65rem; font-weight: 700; padding: 2px 7px; border-radius: 8px;
  background: #eef2ff; color: var(--blue);
}
.tag.vireb { background: #dcfce7; color: #166534; }
.tag.vreb { background: #e0f2fe; color: #075985; }
.tag.local { background: #f3f4f6; color: #4b5563; }
.tag.alert { background: #fee2e2; color: #b91c1c; }
.tag.notes { background: #fef3c7; color: #92400e; }
.rc-actions { display: flex; flex-direction: column; gap: 6px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: none;
  background: #f1f5f9; color: var(--navy); display: flex; align-items: center; justify-content: center;
  text-decoration: none; font-size: 0.95rem;
}
.icon-btn.call { background: #f3e8ff; color: var(--purple); }
.icon-btn.mail { background: #e0f7fa; color: var(--cyan); }

.empty {
  text-align: center; color: var(--muted); padding: 2.5rem 1.5rem;
}
.empty i { font-size: 2rem; margin-bottom: 0.6rem; color: #c5cad6; display: block; }
.spinner {
  width: 28px; height: 28px; border: 3px solid #e9ecef; border-top-color: var(--blue);
  border-radius: 50%; animation: spin 0.7s linear infinite; margin: 2rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Member ── */
.member-hero {
  background: #fff; padding: 16px 16px 12px; border-bottom: 1px solid var(--line);
}
.mh-top { display: flex; gap: 12px; align-items: center; }
.mh-avatar { width: 64px; height: 64px; border-radius: 16px; font-size: 1.3rem; }
.mh-name { font-size: 1.2rem; font-weight: 800; line-height: 1.25; }
.mh-office { font-size: 0.82rem; color: var(--muted); margin-top: 3px; }
.mh-office.our { color: #15803d; font-weight: 700; }
.mh-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.mh-actions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px;
}
.mh-actions .btn { font-size: 0.82rem; padding: 0.7rem 0.5rem; }
.stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  padding: 12px;
}
.stat {
  background: #fff; border-radius: 12px; padding: 10px 8px; text-align: center;
}
.stat b { display: block; font-size: 1.15rem; color: var(--navy); }
.stat span { font-size: 0.68rem; color: var(--muted); font-weight: 600; }

.section { padding: 0 12px 12px; }
.section h3 {
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin: 8px 4px 8px;
}
.info-card {
  background: #fff; border-radius: 14px; padding: 12px 14px;
}
.info-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 8px 0; border-bottom: 1px solid #f1f3f7; font-size: 0.88rem;
}
.info-row:last-child { border-bottom: none; }
.info-row .k { color: var(--muted); }
.info-row .v { font-weight: 600; text-align: right; word-break: break-word; }
.info-row a { color: var(--blue); text-decoration: none; }

/* ── Notes ── */
.note-card {
  background: #fff; border-radius: 14px; padding: 12px 14px; margin-bottom: 8px;
  border-left: 4px solid var(--green);
}
.note-card.alert { border-left-color: var(--red); background: #fff5f5; }
.note-card.phone { border-left-color: var(--purple); }
.note-card.phone_followup { border-left-color: var(--orange); background: #fff7ed; }
.note-card.email { border-left-color: var(--cyan); }
.note-card.billing { border-left-color: #e67e22; }
.note-card.task { border-left-color: var(--green); }
.note-meta { display: flex; justify-content: space-between; gap: 8px; font-size: 0.72rem; color: var(--muted); margin-bottom: 6px; }
.note-type {
  font-weight: 800; font-size: 0.65rem; letter-spacing: 0.04em;
  padding: 2px 6px; border-radius: 6px; background: #f1f5f9; color: #334;
}
.note-body { font-size: 0.88rem; white-space: pre-wrap; word-break: break-word; line-height: 1.4; }
.note-acts { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: linear-gradient(135deg, #28a745, #20c997); color: #fff;
  font-size: 1.25rem; box-shadow: 0 8px 20px rgba(40,167,69,0.4); z-index: 25; cursor: pointer;
}

/* ── Sheets / modals ── */
.overlay {
  position: fixed; inset: 0; background: rgba(9,20,53,0.45); z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: #fff; width: 100%; max-width: 560px;
  border-radius: 18px 18px 0 0;
  padding: 14px 16px calc(18px + var(--safe-bottom));
  max-height: 88vh; overflow: auto;
}
.sheet h3 { font-size: 1.05rem; margin-bottom: 12px; }
.sheet-handle {
  width: 40px; height: 4px; background: #d8dde6; border-radius: 4px; margin: 0 auto 12px;
}
.check-row { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; font-size: 0.88rem; font-weight: 600; }
.sheet-btns { display: flex; gap: 8px; margin-top: 8px; }
.sheet-btns .btn { flex: 1; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
  background: var(--navy); color: #fff; padding: 12px 14px; border-radius: 12px;
  font-size: 0.88rem; font-weight: 600; z-index: 50; text-align: center;
  box-shadow: 0 10px 24px rgba(0,0,0,0.2);
}

.account-card { background: #fff; margin: 16px 12px; border-radius: 16px; padding: 18px; text-align: center; }
.account-card .who { font-weight: 800; font-size: 1.1rem; }
.account-card .role { color: var(--blue); font-size: 0.82rem; font-weight: 600; margin: 4px 0 14px; }

.alert-item { cursor: pointer; }
.install-hint {
  margin: 12px; background: #eef2ff; color: #273; border-radius: 12px; padding: 12px;
  font-size: 0.82rem; color: #334;
}
.install-hint strong { color: var(--navy); }
