:root {
  color-scheme: dark;

  /* chrome — black ground, boardroom-quiet */
  --page-plane: #000000;
  --surface-1: #0c0e13;
  --surface-2: #14171f;
  --border: rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.18);

  --text-primary: #f5f7fb;
  --text-secondary: #a7adba;
  --text-muted: #6b7180;

  --accent: #ffffff;
  --accent-soft: rgba(255,255,255,0.08);

  /* the network wiring — warm and fine, like an engraved schematic */
  --wire: rgba(201,169,98,0.28);
  --wire-active: #c9a962;
  --wire-soft: rgba(201,169,98,0.14);

  --font-display: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;

  /* status (fixed) */
  --status-good: #34b37a;
  --status-warning: #d1a13e;
  --status-critical: #d1554f;
}

* { box-sizing: border-box; }

.svg-icon {
  width: 1em;
  height: 1em;
  flex-shrink: 0;
  vertical-align: -0.15em;
}

.undo-fab {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  border-radius: 10px;
  font-size: 15px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
}
.undo-fab:hover:not(:disabled) { border-color: var(--wire-active); }
.undo-fab:disabled { opacity: 0.4; cursor: not-allowed; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: var(--font-display);
}

body {
  background:
    radial-gradient(ellipse 900px 700px at 8% 30%, rgba(255,255,255,0.035), transparent 60%),
    radial-gradient(ellipse 1100px 900px at 100% 50%, rgba(255,255,255,0.02), transparent 65%),
    var(--page-plane);
  min-height: 100vh;
}

.app {
  display: grid;
  grid-template-columns: 250px minmax(420px, 1fr) 380px;
  gap: 20px;
  padding: 28px;
  min-height: 100vh;
  align-items: start;
  animation: appFadeIn .45s ease both;
}

@keyframes appFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Left hub: orb + stat cards ---------- */

.hub {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  position: sticky;
  top: 28px;
}

.orb-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
}

.orb {
  width: 112px;
  height: 112px;
  border-radius: 26px;
  background-image: url('network-hero.jpg');
  background-size: cover;
  background-position: center;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.08),
    0 0 0 1px rgba(255,255,255,0.14),
    0 0 40px 4px rgba(255,255,255,0.07),
    0 0 80px 14px rgba(255,255,255,0.04);
  animation: pulse 4.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: inset 0 1px 0 rgba(255,255,255,0.08), 0 0 0 1px rgba(255,255,255,0.14), 0 0 40px 4px rgba(255,255,255,0.07), 0 0 80px 14px rgba(255,255,255,0.04); }
  50% { box-shadow: inset 0 1px 0 rgba(255,255,255,0.1), 0 0 0 1px rgba(255,255,255,0.2), 0 0 50px 8px rgba(255,255,255,0.1), 0 0 96px 20px rgba(255,255,255,0.06); }
}

.orb-label { font-size: 15px; font-weight: 700; margin-top: 4px; letter-spacing: -0.01em; }
.orb-tag {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 2px 9px;
  border-radius: 999px;
}

.stat-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 15px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.03);
  transition: border-color .15s, background .15s, transform .15s;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  color: var(--text-primary);
  animation: fadeInUp .3s ease both;
}
.stat-cards .stat-card:nth-child(1) { animation-delay: 0ms; }
.stat-cards .stat-card:nth-child(2) { animation-delay: 30ms; }
.stat-cards .stat-card:nth-child(3) { animation-delay: 60ms; }
.stat-cards .stat-card:nth-child(4) { animation-delay: 90ms; }
.stat-cards .stat-card:nth-child(5) { animation-delay: 120ms; }
.stat-cards .stat-card:nth-child(n+6) { animation-delay: 150ms; }
.stat-card:hover { border-color: var(--border-strong); transform: translateY(-1px); }

.stat-card.active {
  border-color: var(--wire-active);
  background: linear-gradient(90deg, var(--wire-soft), var(--surface-1) 65%);
}

.stat-card .icon {
  font-size: 17px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  background: rgba(255,255,255,0.05);
  flex-shrink: 0;
}

.stat-card .num { font-size: 18px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-card .lbl { font-size: 10.5px; color: var(--text-muted); line-height: 1.3; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; margin-top: 2px; }

.stat-card.warn {
  border-color: var(--status-warning);
  background: linear-gradient(90deg, rgba(209,161,62,0.14), var(--surface-1) 65%);
}

/* ---------- Middle: toolbar + filters + radial branches ---------- */

.branches-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.toolbar {
  display: flex;
  gap: 10px;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}
.search-wrap-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.search-input {
  width: 100%;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px 10px 38px;
  color: var(--text-primary);
  font-size: 13px;
}
.search-input:focus {
  outline: none;
  border-color: var(--wire-active);
}

.btn-primary {
  background: var(--accent);
  color: #0a0a0c;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.btn-primary:hover { filter: brightness(1.08); }

.chips-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  --chip-color: var(--text-muted);
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.045em;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
.chip:hover { border-color: var(--border-strong); color: var(--text-primary); }
.chip.active {
  color: var(--chip-color);
  border-color: var(--chip-color);
  background: color-mix(in srgb, var(--chip-color) 18%, var(--surface-1));
}

.branches-wrap {
  position: relative;
  min-height: 480px;
}

.empty-state {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.6;
  padding: 30px 10px;
  text-align: center;
}

.curves {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  pointer-events: none;
}

.curves path {
  fill: none;
  stroke: var(--wire);
  stroke-width: 1;
  transition: stroke .15s, stroke-width .15s;
}

.curves path.active {
  stroke: var(--wire-active);
  stroke-width: 1.3;
}

.branches {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0;
}

.contact-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 15px 8px 7px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: 12px;
  cursor: pointer;
  width: fit-content;
  max-width: 100%;
  transition: border-color .15s, background .15s, transform .1s;
  animation: fadeInUp .32s ease both;
}

.contact-row:hover { border-top-color: var(--border-strong); border-right-color: var(--border-strong); border-bottom-color: var(--border-strong); }

.contact-row.selected {
  border-color: var(--wire-active);
  background: linear-gradient(90deg, var(--wire-soft), var(--surface-1) 70%);
}

.contact-row .name { font-size: 13px; font-weight: 600; white-space: nowrap; }
.contact-row .addr { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

@keyframes rowAddedGlow {
  0% { box-shadow: 0 0 0 0 rgba(201,169,98,0.5); }
  70% { box-shadow: 0 0 0 9px rgba(201,169,98,0); }
  100% { box-shadow: 0 0 0 0 rgba(201,169,98,0); }
}
.contact-row.row-added {
  border-color: var(--wire-active);
  animation: rowAddedGlow 1.1s ease-out;
}

@keyframes rowRemoveOut {
  to { opacity: 0; transform: scale(.94) translateX(8px); }
}
.contact-row.row-removing {
  animation: rowRemoveOut .22s ease forwards;
  pointer-events: none;
}

/* ---------- Compact density mode ---------- */
.branches-wrap.compact .branches { gap: 4px; }
.branches-wrap.compact .contact-row { padding: 4px 12px 4px 7px; gap: 8px; }
.branches-wrap.compact .contact-row .addr { display: none; }
.branches-wrap.compact .avatar-sm { width: 20px; height: 20px; font-size: 9px; }
.branches-wrap.compact .contact-row .name { font-size: 12px; }

.contact-row .pillrow {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-left: 6px;
}

.contact-row .star { font-size: 11px; }

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

/* ---------- Category-grouped view ---------- */

.category-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 6px;
}

.category-group-head {
  --cat-color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 9px;
  width: fit-content;
  max-width: 100%;
  padding: 6px 14px 6px 12px;
  background: none;
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
}
.category-group-head:hover { border-color: var(--border); }

.cg-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.cg-name {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--cat-color);
}
.cg-empty {
  text-align: left;
  padding: 2px 12px 4px;
  font-size: 11.5px;
}

.cg-count {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-muted);
  background: rgba(255,255,255,0.06);
  border-radius: 999px;
  padding: 1px 8px;
}

/* ---------- Birthdays / calendar view ---------- */

.bday-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}
.bday-section:last-child { margin-bottom: 0; }

.bday-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.bday-row .addr { color: var(--text-secondary); }

.bday-tag {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  background: rgba(255,255,255,0.06);
  border-radius: 999px;
  padding: 2px 9px;
  white-space: nowrap;
}
.bday-tag.today {
  color: #0a0a0c;
  background: var(--wire-active);
}

.selected-with-add {
  display: flex;
  align-items: center;
  gap: 34px;
}

.swa-main { flex-shrink: 0; }

.swa-connections {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.back-to-all {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
  margin-bottom: 4px;
}
.back-to-all:hover { color: var(--wire-active); }

.add-node-row {
  border-style: dashed;
  border-color: var(--border-strong);
  border-left-width: 1px;
  padding-left: 15px;
  color: var(--text-secondary);
}
.add-node-row:hover { border-color: var(--wire-active); color: var(--text-primary); }

.add-node-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-weight: 700;
  font-size: 14px;
  color: var(--text-primary);
  flex-shrink: 0;
}

/* ---------- Avatars ---------- */

.avatar {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.avatar-sm { width: 26px; height: 26px; font-size: 10.5px; }
.avatar-lg { width: 60px; height: 60px; font-size: 20px; }

/* ---------- Right: detail panel ---------- */

.detail {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: 28px;
}

.d-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--wire-active);
  font-size: 12px;
  font-weight: 600;
}

.d-icon-actions { display: flex; gap: 6px; }
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  font-size: 13px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--border-strong); color: var(--text-primary); }
.icon-btn-danger:hover { border-color: var(--status-critical); color: var(--status-critical); }

.d-profile-row { display: flex; align-items: center; gap: 12px; }
.d-profile-text { min-width: 0; flex: 1; }

.d-title {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.3;
  border-radius: 6px;
  padding: 1px 4px;
  margin: 0 -4px;
}
.d-title:hover { box-shadow: inset 0 0 0 1px var(--border-strong); cursor: text; }
.d-title:focus { outline: none; box-shadow: inset 0 0 0 1px var(--wire-active); }
.d-addr { font-size: 12.5px; color: var(--text-secondary); margin-top: 2px; }

.d-pill-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  width: fit-content;
}

.star-toggle {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
  color: var(--text-muted);
}
.star-toggle.on { color: var(--wire-active); }

.d-meta-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.d-meta-text { font-size: 11.5px; color: var(--text-muted); }
.d-meta-text b { color: var(--text-secondary); font-weight: 600; }
.d-meta-text a { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
.d-meta-text a:hover b { color: var(--wire-active); }

.btn-ghost {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-ghost:hover { border-color: var(--border-strong); }

.btn-ghost.icon-only {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  padding: 6px;
  flex-shrink: 0;
}
.btn-ghost.icon-only.active {
  border-color: var(--wire-active);
  color: var(--wire-active);
  background: var(--wire-soft);
}

.card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 15px 17px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.03);
}

.subpoint-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.subpoint-tab { flex: 1 1 92px; }

.subpoint-tab {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
  padding: 11px 11px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  text-align: left;
  transition: border-color .15s, background .15s;
}
.subpoint-tab:hover { border-color: var(--border-strong); }
.subpoint-tab .t-icon { font-size: 14px; }
.subpoint-tab .t-lbl { font-size: 9.5px; color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.subpoint-tab .t-val { font-size: 12.5px; font-weight: 700; }

.subpoint-tab.active {
  border-color: var(--wire-active);
  background: var(--wire-soft);
}

.subpoint-detail {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.kv-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.kv-row:last-child { border-bottom: none; }
.kv-row .k { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; font-weight: 600; flex-shrink: 0; }
.kv-row .v { color: var(--text-primary); font-weight: 600; text-align: right; }

.kv-editable { gap: 10px; }
.kv-input {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  border-bottom: 1px dashed transparent;
  color: var(--text-primary);
  font-weight: 600;
  font-family: inherit;
  font-size: 12.5px;
  text-align: right;
  padding: 2px 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kv-input::placeholder { color: var(--text-muted); font-weight: 400; }
.kv-input:hover { border-bottom-color: var(--border-strong); }
.kv-input:focus { outline: none; border-bottom-color: var(--wire-active); }

.kv-row.kv-stack {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}
.kv-row.kv-stack .kv-input {
  text-align: left;
  resize: vertical;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
}
.kv-row.kv-stack .kv-input:hover { border-color: var(--border-strong); }
.kv-row.kv-stack .kv-input:focus { border-color: var(--wire-active); }

.ai-box {
  background: linear-gradient(135deg, var(--wire-soft), var(--surface-2) 60%);
  border: 1px solid var(--border);
}
.ai-head { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; color: var(--wire-active); margin-bottom: 6px; }
.ai-title { font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.ai-text { font-size: 12px; color: var(--text-secondary); line-height: 1.5; }

/* ---------- Modal (add / edit contact) ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 22px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-head h3 { margin: 0; font-size: 17px; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: var(--text-primary); }

.avatar-upload {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.avatar-preview {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--text-muted);
  overflow: hidden;
  flex-shrink: 0;
}
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.form-field.span-2 { grid-column: 1 / -1; }

.form-field input[type="text"],
.form-field input[type="tel"],
.form-field input[type="email"],
.form-field input[type="date"],
.form-field select,
.form-field textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 400;
  font-family: inherit;
}
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--wire-active);
}
.form-field textarea { resize: vertical; }

.form-field.checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
}
.form-field.checkbox-field input { width: 15px; height: 15px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* ---------- Related contacts picker (form) ---------- */

.related-picker {
  display: flex;
  gap: 8px;
}
.related-picker input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 400;
}
.related-picker input:focus { outline: none; border-color: var(--wire-active); }

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--wire-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 6px 3px 10px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-primary);
}
.tag-chip-x {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  padding: 2px;
  line-height: 1;
}
.tag-chip-x:hover { color: var(--text-primary); }

/* ---------- Tools modal ---------- */

.tools-section {
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.tools-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.tools-section h4 { margin: 0 0 6px; font-size: 13px; color: var(--wire-active); }

.tools-hint {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0 0 10px;
}

.tools-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* ---------- History timeline ---------- */

.timeline {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 4px 0 12px;
}

.timeline-item {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.timeline-item:last-child { border-bottom: none; }

.timeline-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--wire-active);
  margin-top: 5px;
  flex-shrink: 0;
}

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

.timeline-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
}
.timeline-head span { color: var(--text-muted); font-size: 11px; }

.timeline-note {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 3px;
  line-height: 1.4;
}

.interaction-form {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 6px;
}
.interaction-form input[type="date"],
.interaction-form input[type="text"],
.interaction-form select {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 8px;
  color: var(--text-primary);
  font-size: 12px;
}
.interaction-form input[type="text"] { grid-column: 1 / -1; }
.interaction-form button { grid-column: 1 / -1; }

/* ---------- Related contacts list (detail panel) ---------- */

.related-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  border-radius: 8px;
}
.related-row:last-child { border-bottom: none; }
.related-row:hover { background: var(--surface-1); }
.related-name { font-size: 13px; font-weight: 600; }
.related-sub { font-size: 11px; color: var(--text-muted); }

.related-add-tile {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-top: 8px;
  padding: 10px 12px;
  background: none;
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.related-add-tile:hover { border-color: var(--wire-active); color: var(--text-primary); }

.related-add-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border-radius: 8px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

/* ---------- Photo gallery (Fotos tab) ---------- */

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.photo-tile {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.photo-tile img { width: 100%; height: 100%; object-fit: cover; cursor: pointer; display: block; }

.photo-remove-btn {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(0,0,0,0.65);
  border: none;
  color: #fff;
  font-size: 10px;
  cursor: pointer;
}
.photo-remove-btn:hover { background: var(--status-critical); }

.photo-add-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  aspect-ratio: 1;
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  background: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 600;
  cursor: pointer;
}
.photo-add-tile:hover { border-color: var(--wire-active); color: var(--text-primary); }

.photo-lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
  padding: 30px;
}
.photo-lightbox-overlay img { max-width: 100%; max-height: 100%; border-radius: 10px; }
.photo-lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
}

@media (max-width: 1100px) {
  .app { grid-template-columns: 1fr; }
  .hub { position: static; flex-direction: row; flex-wrap: wrap; }
  .stat-cards { flex-direction: row; flex-wrap: wrap; }
  .stat-card { flex: 1 1 160px; }
  .detail { position: static; }
  .curves { display: none; }
}

@media (max-width: 560px) {
  .toolbar { flex-direction: column; align-items: stretch; }
  .form-grid { grid-template-columns: 1fr; }
  .form-field.span-2 { grid-column: auto; }
  .subpoint-tab { flex-basis: 75px; }
}

@media (prefers-reduced-motion: reduce) {
  .app, .stat-card, .contact-row, .orb { animation: none !important; }
}
