:root {
  --radius: 12px;
  --font: "DM Sans", system-ui, -apple-system, sans-serif;
  --danger: #dc2626;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Page chrome: match body theme (vars are defined on body). */
html {
  background: #0a0f1e;
}

html:has(body.theme-light) {
  background: #ffffff;
}

body.theme-dark {
  color-scheme: dark;
  --bg: #0a0f1e;
  --surface: #111827;
  --elevated: #0d1526;
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #2563eb;
  --accent-hover: #3b82f6;
  --accent-dim: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.2);
  --accent-soft-border: rgba(37, 99, 235, 0.45);
  --border: #1e2d4a;
  --header-bg: rgba(10, 15, 30, 0.92);
  --header-border: #1e2d4a;
  --header-shadow: none;
  --focus-ring: rgba(37, 99, 235, 0.35);
  --strength-on: #fbbf24;
  --strength-off: #64748b;
  --fresh-green: #22c55e;
  --fresh-green-ring: rgba(34, 197, 94, 0.35);
  --fresh-yellow: #eab308;
  --fresh-yellow-ring: rgba(234, 179, 8, 0.35);
  --fresh-red: #ef4444;
  --fresh-red-ring: rgba(239, 68, 68, 0.35);
  --fresh-grey: #64748b;
  --fresh-grey-ring: rgba(100, 116, 139, 0.35);
  /* Muted steel for filled/outline action buttons (not links/pills). */
  --btn-steel: #4a9ebb;
  --btn-steel-hover: #3d8aa5;
  --btn-steel-outline-hover-bg: rgba(74, 158, 187, 0.18);
}

body.theme-light {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #f3f4f6;
  --elevated: #e5e7eb;
  --text: #111827;
  --muted: #4b5563;
  --accent: #2563eb;
  --accent-hover: #3b82f6;
  --accent-dim: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.12);
  --accent-soft-border: rgba(37, 99, 235, 0.4);
  --border: #e5e7eb;
  --header-bg: rgba(255, 255, 255, 0.96);
  --header-border: #e5e7eb;
  --header-shadow: 0 1px 0 rgba(15, 23, 42, 0.06), 0 4px 14px rgba(15, 23, 42, 0.07);
  --focus-ring: rgba(37, 99, 235, 0.35);
  --strength-on: #ca8a04;
  --strength-off: #9ca3af;
  --fresh-green: #16a34a;
  --fresh-green-ring: rgba(22, 163, 74, 0.28);
  --fresh-yellow: #ca8a04;
  --fresh-yellow-ring: rgba(202, 138, 4, 0.28);
  --fresh-red: #dc2626;
  --fresh-red-ring: rgba(220, 38, 38, 0.28);
  --fresh-grey: #6b7280;
  --fresh-grey-ring: rgba(107, 114, 128, 0.25);
  --btn-steel: #4a9ebb;
  --btn-steel-hover: #3d8aa5;
  --btn-steel-outline-hover-bg: rgba(74, 158, 187, 0.14);
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

body.theme-dark,
body.theme-light {
  background: var(--bg);
  color: var(--text);
}

a {
  color: var(--accent);
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding: 0;
  background: var(--header-bg);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--header-border);
  box-shadow: var(--header-shadow);
}

.header-masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  min-width: 0;
}

.header-logo-link {
  display: flex;
  align-items: center;
  flex: 0 1 auto;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.header-logo-link:hover {
  opacity: 0.92;
}

.header-logo-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}

.header-banner {
  display: block;
  height: 72px;
  width: auto;
  max-width: min(88vw, 540px);
  object-fit: contain;
  object-position: left center;
}

@media (max-width: 520px) {
  .header-banner {
    max-height: 60px;
    height: 60px;
    max-width: min(90vw, 450px);
  }
}

.header-pagebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  border-top: 1px solid var(--header-border);
  padding: 0.7rem 1rem 0.65rem;
}

.header-pagebar.hidden {
  display: none;
}

.header-pagebar .header-screen-title {
  flex: 1;
  min-width: 0;
}

.header-screen-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

/* Contacts list: screen title + Projects aligned with main content (tags, search). */
.list-screen-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  margin-bottom: 0.75rem;
}

/* Primary section tabs (Contacts / Projects): active = steel primary + underline + weight */
.main-nav-tabs .main-nav-tab {
  flex: 0 0 auto;
}

.main-nav-tabs .btn.primary {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.22em;
  font-weight: 700;
}

.main-nav-tabs .btn:not(.primary) {
  font-weight: 600;
}

/* Admin tab is an in-nav link to the server-rendered /admin page */
.main-nav-tabs a.main-nav-tab.main-nav-tab--link {
  text-decoration: none;
  color: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-shrink: 0;
}

.ai-status-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.38rem 0.62rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.78rem;
  font-weight: 600;
}

.ai-status-btn:hover {
  border-color: var(--accent);
}

.ai-status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #64748b;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.22);
}

.ai-status-dot--green {
  background: #22c55e;
}

.ai-status-dot--yellow {
  background: #eab308;
}

.ai-status-dot--red {
  background: #ef4444;
}

.ai-status-dot--unknown {
  background: #64748b;
}

.header-tab {
  padding: 0.45rem 0.8rem;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.header-tab:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.header-tab:active {
  transform: scale(0.98);
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--text);
  font-size: 1.1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.icon-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.icon-btn:active {
  transform: scale(0.96);
}

main {
  padding: 1rem;
  padding-bottom: 5.5rem;
  max-width: 720px;
  margin: 0 auto;
}

.search-wrap {
  margin-bottom: 1rem;
}

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

.contact-card {
  display: block;
  padding: 1rem;
  margin-bottom: 0.65rem;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  color: inherit;
}

.contact-card:active {
  border-color: var(--accent);
}

.contact-card .name {
  font-weight: 600;
  font-size: 1.05rem;
}

.contact-card .meta {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

.strength {
  display: inline-flex;
  gap: 2px;
  margin-top: 0.4rem;
}

.strength span {
  color: var(--strength-off);
  font-size: 0.75rem;
}

.strength span.on {
  color: var(--strength-on);
}

/* Voice FAB: original Rapport green gradient — fixed colors, not theme accent tokens. */
.fab {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: linear-gradient(145deg, #40916c, #2d6a4f);
  color: #fff;
  font-size: 1.6rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  z-index: 20;
  display: grid;
  place-items: center;
}

.fab:active {
  transform: scale(0.95);
}

.fab-upload {
  right: 5.7rem;
  background: linear-gradient(145deg, #3b5998, #2a3f6f);
  font-size: 1.35rem;
}

.hidden {
  display: none !important;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
}

.panel h2 {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.panel-title-row h2 {
  margin: 0;
}

.pulse {
  width: 72px;
  height: 72px;
  margin: 1rem auto;
  border-radius: 50%;
  background: var(--accent-dim);
  position: relative;
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0% {
    transform: scale(0.92);
    opacity: 0.7;
  }
  50% {
    transform: scale(1);
    opacity: 1;
  }
  100% {
    transform: scale(0.92);
    opacity: 0.7;
  }
}

textarea,
input[type="text"],
input[type="date"],
input[type="number"],
input[type="search"] {
  font-family: var(--font);
}

.transcript-box {
  min-height: 120px;
  width: 100%;
  padding: 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  resize: vertical;
}

.btn-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}

.btn {
  padding: 0.65rem 1rem;
  background: transparent;
  color: var(--btn-steel);
  font-weight: 500;
  border: 1px solid var(--btn-steel);
  border-radius: var(--radius);
}

.btn:hover:not(:disabled):not(.primary) {
  background: var(--btn-steel-outline-hover-bg);
  border-color: var(--btn-steel-hover);
  color: var(--btn-steel-hover);
}

.btn.primary {
  background: var(--btn-steel);
  border-color: var(--btn-steel);
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: var(--btn-steel-hover);
  border-color: var(--btn-steel-hover);
  color: #fff;
}

a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  border-radius: var(--radius);
  box-sizing: border-box;
}

.btn.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.picker-list {
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 0.5rem;
}

.picker-item {
  width: 100%;
  text-align: left;
  padding: 0.65rem 0.85rem;
  background: var(--bg);
  color: var(--text);
  border-radius: 0;
  border-bottom: 1px solid var(--border);
}

.picker-item:last-child {
  border-bottom: none;
}

.banner {
  padding: 0.85rem 1rem;
  background: var(--accent-soft);
  border: 1px solid var(--accent-soft-border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.95rem;
  color: var(--text);
}

.banner .actions {
  margin-top: 0.5rem;
  display: flex;
  gap: 0.5rem;
}

.brief-text {
  width: 100%;
  min-height: 180px;
  padding: 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  font-family: var(--font);
  line-height: 1.5;
}

.brief-text-editable {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
  outline: none;
  resize: vertical;
  overflow: auto;
}

.brief-text-editable:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--focus-ring);
}

.tags-input {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.segment-tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.segment-tab {
  flex: 1;
  padding: 0.5rem 0.65rem;
  font-size: 0.88rem;
  font-weight: 600;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.segment-tab.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.add-conversation-panel {
  margin-bottom: 0.25rem;
}

.conv-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  overflow: hidden;
}

.conv-search-wrap {
  margin: 0 0 0.55rem;
}

.conv-search-input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.92rem;
}

.conv-head {
  width: 100%;
  text-align: left;
  padding: 0.75rem;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.conv-body {
  padding: 0.75rem;
  background: var(--surface);
  font-size: 0.9rem;
}

.conv-body pre {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0.5rem 0 0;
  font-family: var(--font);
  font-size: 0.9rem;
  color: var(--muted);
}

.loader {
  display: inline-block;
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--muted);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 0.35rem;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  width: 100%;
  max-width: min(92vw, 720px);
  border: 1px solid var(--border);
  max-height: min(92vh, 900px);
  overflow-y: auto;
}

.modal h3 {
  margin: 0 0 1rem;
}

.field {
  margin-bottom: 0.65rem;
}

.field label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.2rem;
}

.field input {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.tag-pill {
  display: inline-block;
  padding: 0.35rem 0.65rem;
  margin: 0.15rem;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-soft-border);
  border-radius: 999px;
  font-size: 0.85rem;
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem;
}

.approve-sheet {
  padding-bottom: 2rem;
}

.approve-section-title {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 1.25rem 0 0.5rem;
}

.approve-conv-field {
  min-height: 72px;
}

.tag-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.tag-chip {
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  font-size: 0.85rem;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-soft-border);
}

.tag-chip:active {
  transform: scale(0.97);
}

.approve-actions {
  margin-top: 1.25rem;
  position: sticky;
  bottom: 0;
  padding: 0.75rem 0;
  background: linear-gradient(transparent, var(--bg) 35%);
}

.btn-delete-contact {
  width: auto;
  margin-top: 1rem;
  padding: 0.35rem 0.55rem;
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  font-weight: 500;
  font-size: 0.78rem;
}

.btn-delete-contact:active {
  background: rgba(231, 111, 81, 0.12);
}

.contact-header-actions {
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.btn-delete-contact.btn-delete-inline {
  width: auto;
  margin-top: 0;
  margin-left: auto;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}

.conv-transcript-edit {
  min-height: 100px;
  margin-top: 0.35rem;
}

/* Topic filters (conversation topics) */
.list-page-actions {
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

/* Contacts toolbar: keep primary actions on one row when space allows */
.list-page-toolbar {
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  overflow: visible;
  padding-bottom: 0.15rem;
  margin-top: 0.5rem;
}

.list-page-toolbar > a.btn,
.list-page-toolbar > .btn {
  flex: 0 0 auto;
  white-space: nowrap;
  padding: 0.55rem 0.75rem;
  font-size: 0.88rem;
}

.list-page-toolbar .import-dropdown-wrap {
  flex: 0 0 auto;
}

.import-dropdown-wrap {
  position: relative;
}

.import-dropdown-trigger {
  white-space: nowrap;
}

.import-dropdown-caret {
  opacity: 0.75;
  font-size: 0.75em;
}

.import-dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 220px;
  z-index: 20;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  padding: 0.35rem 0;
}

.import-dropdown-menu.hidden {
  display: none;
}

.import-dropdown-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.55rem 0.9rem;
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  border: none;
  border-radius: 0;
  cursor: pointer;
}

.import-dropdown-item:hover,
.import-dropdown-item:focus {
  background: var(--accent-soft);
  outline: none;
}

.modal-bc-processing .modal {
  max-width: 320px;
  text-align: center;
}

/* Google Contacts CSV import */
.import-intro {
  margin-bottom: 1rem;
}

.import-section {
  margin-bottom: 1rem;
}

.import-section h2 {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
}

.import-section-hint {
  margin: 0 0 0.65rem;
  font-size: 0.88rem;
}

.import-name-list {
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 0;
  background: var(--bg);
}

.import-line {
  padding: 0.5rem 0.85rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}

.import-line:last-child {
  border-bottom: none;
}

.import-line-name {
  font-weight: 600;
  display: block;
}

.import-line-meta {
  display: block;
  font-size: 0.82rem;
  margin-top: 0.15rem;
  word-break: break-word;
}

.import-actions {
  margin-top: 1rem;
}

.import-done-msg {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 1.25rem;
  line-height: 1.4;
}

/* Business card scan preview */
.bc-preview-wrap {
  margin: 0 0 1rem;
  padding: 0.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  text-align: center;
}

.bc-preview-wrap--modal {
  margin-top: 0.5rem;
  margin-bottom: 0.75rem;
}

.bc-scan-preview {
  max-width: 100%;
  max-height: min(42vh, 280px);
  width: auto;
  height: auto;
  object-fit: contain;
  vertical-align: middle;
  border-radius: calc(var(--radius) - 4px);
}

.bc-scan-field label {
  display: block;
  margin-bottom: 0.35rem;
}

.topic-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.85rem;
  align-items: center;
}

.topic-pill {
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.82rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 500;
}

.topic-pill.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.topic-pill-clear {
  border-color: var(--muted);
  color: var(--muted);
  background: transparent;
}

.topic-pill:active {
  transform: scale(0.98);
}

.topic-pill-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

/* List avatars */
.contact-card-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.contact-card-body {
  flex: 1;
  min-width: 0;
}

.avatar-sm {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  flex-shrink: 0;
  object-fit: cover;
}

.avatar-img.avatar-sm {
  display: block;
}

.avatar-placeholder.avatar-sm {
  display: grid;
  place-items: center;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.avatar-placeholder.avatar-lg {
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  border-radius: 14px;
  flex-shrink: 0;
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.avatar-header-photo {
  width: 96px;
  height: 96px;
  border-radius: 14px;
  object-fit: cover;
  flex-shrink: 0;
}

.avatar-person-icon {
  width: 55%;
  height: 55%;
  fill: currentColor;
  opacity: 0.95;
}

.contact-title-row {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  margin-bottom: 1rem;
}

.contact-title-text {
  flex: 1;
  min-width: 0;
}

.contact-header-body {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
}

.contact-header-main {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 96px;
  gap: 0.3rem;
}

.contact-header-right {
  margin-left: auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-end;
  min-height: 96px;
  gap: 0.35rem;
}

.contact-header-orgline {
  margin: 0;
  font-size: 0.82rem;
}

.contact-name-freshness {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

.contact-name-title {
  flex: 1 1 auto;
  min-width: 0;
}

.freshness-row {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.freshness-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.freshness-dot.freshness-green {
  background: var(--fresh-green);
  box-shadow: 0 0 0 2px var(--fresh-green-ring);
}

.freshness-dot.freshness-yellow {
  background: var(--fresh-yellow);
  box-shadow: 0 0 0 2px var(--fresh-yellow-ring);
}

.freshness-dot.freshness-red {
  background: var(--fresh-red);
  box-shadow: 0 0 0 2px var(--fresh-red-ring);
}

.freshness-dot.freshness-grey {
  background: var(--fresh-grey);
  box-shadow: 0 0 0 2px var(--fresh-grey-ring);
}

.freshness-label {
  font-size: 0.82rem;
  white-space: nowrap;
  color: var(--muted);
  font-weight: 500;
}

/* Relationships */
.relationships-panel .relationships-table {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.relationships-head,
.relationships-row {
  display: grid;
  grid-template-columns: 1fr 1.4fr auto;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.9rem;
}

.relationships-head {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 0.15rem;
}

.rel-col-action {
  text-align: right;
}

.rel-link {
  color: var(--accent);
  font-weight: 500;
}

.rel-create-btn {
  padding: 0.35rem 0.55rem;
  font-size: 0.78rem;
  background: transparent;
  color: var(--btn-steel);
  border: 1px solid var(--btn-steel);
  border-radius: var(--radius);
}

.rel-delete-btn {
  color: var(--danger);
  border-color: var(--danger);
}

.rel-context {
  font-size: 0.85rem;
  line-height: 1.35;
}

/* Projects list: goal type uses topic-pill shape + goal tint (see .topic-pill.project-goal-pill) */
.project-card-lead {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  padding-top: 0.12rem;
}

.goal-badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
}

.goal-badge[data-goal="relationship-building"],
.topic-pill.project-goal-pill[data-goal="relationship-building"] {
  color: #a8dadc;
  background: rgba(168, 218, 220, 0.14);
}

.goal-badge[data-goal="marketing"],
.topic-pill.project-goal-pill[data-goal="marketing"] {
  color: #cdb4db;
  background: rgba(205, 180, 219, 0.14);
}

.goal-badge[data-goal="political"],
.topic-pill.project-goal-pill[data-goal="political"] {
  color: #f4a261;
  background: rgba(244, 162, 97, 0.14);
}

.goal-badge[data-goal="operational"],
.topic-pill.project-goal-pill[data-goal="operational"] {
  color: #8ecae6;
  background: rgba(142, 202, 230, 0.14);
}

.goal-badge[data-goal="other"],
.topic-pill.project-goal-pill[data-goal="other"] {
  color: var(--muted);
}

.project-detail-title {
  margin: 0.5rem 0 0.25rem;
  font-size: 1.35rem;
}

.project-dates {
  font-size: 0.82rem;
  margin: 0.35rem 0 0.75rem;
}

.project-tags-line {
  margin: 0 0 0.75rem;
  font-size: 0.92rem;
}

.project-desc-panel .project-desc-body {
  white-space: pre-wrap;
  font-size: 0.95rem;
  line-height: 1.5;
  margin: 0;
}

.project-desc-input {
  min-height: 12rem;
  width: 100%;
}

.project-goal-select {
  width: 100%;
  padding: 0.65rem 0.75rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.suggested-contact-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

.suggested-contact-row:last-child {
  border-bottom: none;
}

.suggested-contact-main {
  flex: 1;
  min-width: 0;
}

.suggested-name {
  font-weight: 600;
  color: var(--accent);
}

.suggested-meta {
  font-size: 0.82rem;
  margin-top: 0.2rem;
}

.suggested-log-btn {
  flex-shrink: 0;
  align-self: center;
  font-size: 0.82rem;
  padding: 0.45rem 0.65rem;
  background: var(--surface);
  color: var(--btn-steel);
  border: 1px solid var(--btn-steel);
  border-radius: var(--radius);
}

/* Visually hidden file inputs — triggered by styled buttons (still opens native picker). */
.visually-hidden-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.form-card-layout {
  display: grid;
  gap: 1.1rem;
  align-items: start;
}

@media (min-width: 720px) {
  .form-card-layout {
    grid-template-columns: minmax(200px, 1fr) minmax(0, 1.25fr);
  }

  .form-card-layout--modal {
    grid-template-columns: minmax(180px, 0.95fr) minmax(0, 1.2fr);
  }
}

.form-card-layout__media .bc-preview-wrap {
  margin-bottom: 0.65rem;
}

/* New contact: one column so fields align with intro text (no wide-screen two-column shift). */
.new-contact-page {
  max-width: 100%;
}

.new-contact-intro {
  margin: 0 0 0.75rem;
  text-align: left;
}

.form-card-layout.form-card-layout--stacked {
  grid-template-columns: 1fr;
}

@media (min-width: 720px) {
  .form-card-layout.form-card-layout--stacked {
    grid-template-columns: 1fr;
  }
}

.form-card-layout--stacked .form-card-layout__media,
.form-card-layout--stacked .form-card-layout__form {
  min-width: 0;
  width: 100%;
}

.form-card-layout--stacked .form-card-layout__media .bc-scan-field {
  margin-bottom: 0;
}

.new-contact-actions {
  margin-top: 1rem;
  margin-left: 0;
  justify-content: flex-start;
}

.btn-google-import-tile {
  display: block;
  width: 100%;
  text-align: center;
  padding: 0.85rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  background: var(--surface);
  color: var(--btn-steel);
  border: 1px solid var(--btn-steel);
  border-radius: var(--radius);
}

.file-picker-tile {
  display: block;
  width: 100%;
  text-align: center;
  padding: 0.75rem 1rem;
  font-weight: 600;
  background: var(--surface);
  color: var(--btn-steel);
  border: 1px solid var(--btn-steel);
  border-radius: var(--radius);
}

.phone-rows {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.phone-row {
  display: grid;
  grid-template-columns: 1fr minmax(5.5rem, auto) auto;
  gap: 0.45rem;
  align-items: center;
}

@media (max-width: 480px) {
  .phone-row {
    grid-template-columns: 1fr;
  }

  .phone-row .phone-row-remove {
    justify-self: start;
  }
}

.phone-row-remove {
  font-size: 0.8rem;
  padding: 0.4rem 0.55rem;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
}

.phone-add-btn {
  margin-top: 0.35rem;
  font-size: 0.88rem;
  padding: 0.45rem 0.65rem;
  background: var(--surface);
  color: var(--btn-steel);
  border: 1px solid var(--btn-steel);
}

input.scan-null-field::placeholder,
.phone-num.scan-null-field::placeholder {
  color: var(--danger);
  opacity: 0.85;
}

.contact-meta-panel {
  margin-bottom: 0.5rem;
}

.contact-detail-line {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  align-items: baseline;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
}

.contact-detail-line:last-child {
  border-bottom: none;
}

.contact-detail-k {
  min-width: 6.5rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.conv-head-wrap {
  background: var(--bg);
}

.conv-head-project-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.35rem 0.65rem 0.55rem;
  border-top: 1px solid var(--border);
}

.conv-head-project-pill {
  font-size: 0.78rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-soft-border);
  color: var(--accent);
  font-weight: 600;
}

/* Conversation ↔ project associations */
.conv-projects-section {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.conv-project-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.conv-project-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.2rem 0.35rem 0.2rem 0.5rem;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-soft-border);
  font-size: 0.82rem;
}

.conv-project-pill-link {
  color: var(--accent);
  font-weight: 600;
}

.conv-project-pill-remove {
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  line-height: 1;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
}

.conv-project-pill-remove:hover {
  color: var(--danger);
  background: rgba(231, 111, 81, 0.12);
}

.conv-project-manual-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.35rem;
}

.conv-project-manual-row .conv-project-select {
  flex: 1;
  min-width: 12rem;
}

.conv-assoc-suggest-btn {
  font-size: 0.82rem;
  padding: 0.4rem 0.65rem;
}

/* Project detail — linked conversations */
.related-conv-row {
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
}

.related-conv-row:last-child {
  border-bottom: none;
}

.related-conv-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: baseline;
  margin-bottom: 0.25rem;
}

.related-conv-contact {
  font-weight: 600;
  color: var(--accent);
}

.related-conv-date {
  font-size: 0.82rem;
}

.related-conv-summary {
  font-size: 0.88rem;
  line-height: 1.4;
}

/* Settings — cloud backup (local-only phase) */
.settings-backup-panel {
  margin-bottom: 1rem;
}

.cloud-backup-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.cloud-backup-checkbox {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--accent);
  cursor: pointer;
}

.cloud-backup-label {
  font-weight: 600;
  cursor: pointer;
  margin: 0;
}

.modal-cloud-backup {
  max-width: 26rem;
}

.btn-crm-import-tile {
  display: block;
  width: 100%;
  text-align: center;
  padding: 0.75rem 1rem;
  font-size: 0.92rem;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--border);
}

.crm-mapping-rows {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.crm-mapping-row {
  display: grid;
  grid-template-columns: minmax(7rem, 0.35fr) 1fr;
  gap: 0.5rem;
  align-items: center;
}

@media (max-width: 520px) {
  .crm-mapping-row {
    grid-template-columns: 1fr;
  }
}

.crm-mapping-label {
  font-size: 0.82rem;
  color: var(--muted);
}

textarea:focus-visible,
input[type="text"]:focus-visible,
input[type="search"]:focus-visible,
input[type="date"]:focus-visible,
input[type="number"]:focus-visible,
select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--focus-ring);
}

select {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.theme-toggle-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.35rem;
}

.settings-profile-panel {
  margin-bottom: 1rem;
}

.founding-member-badge {
  display: inline-block;
  margin: 0 0 0.65rem;
  padding: 0.2rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--accent-contrast, #0a0f1e);
  background: color-mix(in oklab, var(--accent) 88%, transparent);
  border-radius: 999px;
  border: 1px solid color-mix(in oklab, var(--accent) 55%, var(--border));
}

.whatsapp-import-status {
  margin: 0 0 0.8rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: color-mix(in oklab, var(--surface) 92%, var(--accent) 8%);
}

.whatsapp-progress-bar {
  width: 100%;
}

.app-toast {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  z-index: 1000;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 0.5rem 0.85rem;
  font-size: 0.88rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.app-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

body.theme-light .goal-badge[data-goal="relationship-building"],
body.theme-light .topic-pill.project-goal-pill[data-goal="relationship-building"] {
  color: #0f766e;
  background: rgba(20, 184, 166, 0.2);
  border-color: rgba(20, 184, 166, 0.45);
}

body.theme-light .goal-badge[data-goal="marketing"],
body.theme-light .topic-pill.project-goal-pill[data-goal="marketing"] {
  color: #6d28d9;
  background: rgba(109, 40, 217, 0.12);
  border-color: rgba(109, 40, 217, 0.32);
}

body.theme-light .goal-badge[data-goal="political"],
body.theme-light .topic-pill.project-goal-pill[data-goal="political"] {
  color: #c2410c;
  background: rgba(234, 88, 12, 0.12);
  border-color: rgba(234, 88, 12, 0.35);
}

body.theme-light .goal-badge[data-goal="operational"],
body.theme-light .topic-pill.project-goal-pill[data-goal="operational"] {
  color: #0369a1;
  background: rgba(3, 105, 161, 0.12);
  border-color: rgba(3, 105, 161, 0.35);
}
