:root {
  --bg: #FAF6F0;
  --surface: #FFFFFF;
  --surface-warm: #FFF9F2;
  --border: #E6DCCF;
  --border-strong: #D2C3AE;
  --text: #1F1A17;
  --text-muted: #6B5E54;
  --primary: #B45309;      /* Warm Saffron / Marigold */
  --primary-hover: #92400E;
  --primary-soft: #FEF3C7;
  --accent: #0F766E;       /* Deep Heritage Teal */
  --accent-soft: #CCFBF1;
  --terracotta: #C2410C;
  --rose: #9D174D;
  --danger: #B91C1C;
  --shadow-sm: 0 1px 3px rgba(31, 26, 23, 0.08);
  --shadow-md: 0 8px 24px rgba(31, 26, 23, 0.12);
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}

.topbar-left {
  flex: 1 1 auto;
}

.topbar-right {
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #C2410C, #D97706);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

.brand-name {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.brand-sub {
  font-weight: 500;
  font-size: 12px;
  color: var(--text-muted);
  margin-left: 4px;
}

.tree-switcher-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
  flex-wrap: wrap;
  min-width: 0;
}

select.tree-select {
  width: clamp(210px, 24vw, 310px);
  min-width: 210px;
  max-width: 310px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface-warm);
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  text-overflow: ellipsis;
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: #065F46;
  background: #D1FAE5;
  padding: 4px 10px;
  border-radius: 999px;
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10B981;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Subbar */
.subbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
}

.tab {
  border: none;
  background: transparent;
  padding: 11px 14px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2.5px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.badge {
  background: var(--border);
  color: var(--text);
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
}

.badge-warn {
  background: var(--primary-soft);
  color: var(--primary-hover);
}

.subbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
}

.search-box {
  position: relative;
}

.search-box input {
  width: 240px;
  padding: 7px 11px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  font-size: 13px;
  background: var(--bg);
}

.search-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  max-height: 280px;
  overflow-y: auto;
  z-index: 60;
}

.search-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--bg);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.search-item:hover {
  background: var(--surface-warm);
}

/* Buttons */
.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}

.btn-sm {
  padding: 6px 11px;
  font-size: 12.5px;
}

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

.btn-accent {
  background: var(--accent);
  color: #fff;
}
.btn-accent:hover {
  background: #115E59;
}

.btn-soft {
  background: var(--primary-soft);
  color: var(--primary-hover);
}
.btn-soft:hover {
  background: #FDE68A;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-ghost:hover {
  background: var(--bg);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
  border-color: #FECACA;
}
.btn-danger-ghost:hover {
  background: #FEF2F2;
}

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 15px;
  display: grid;
  place-items: center;
  color: var(--text);
}
.icon-btn:hover {
  background: var(--bg);
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
  padding: 0;
}

.full-width {
  width: 100%;
}

/* Workspace & Tabs */
.workspace {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
}

.tab-panel {
  display: none;
  width: 100%;
  height: 100%;
  overflow-y: auto;
}

.tab-panel.active {
  display: flex;
}

#tab-tree.active {
  overflow: hidden;
}

/* Tree Stage */
.tree-stage-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  gap: 10px;
  flex-wrap: wrap;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.toolbar-info {
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 500;
}

.chip {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
}

.chip.active {
  background: var(--text);
  color: #fff;
  border-color: var(--text);
}

.zoom-label {
  font-size: 12px;
  font-weight: 600;
  min-width: 42px;
  text-align: center;
  color: var(--text-muted);
}

.tree-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
  background-image: radial-gradient(#DED3C3 1px, transparent 1px);
  background-size: 24px 24px;
}

.tree-viewport:active {
  cursor: grabbing;
}

.tree-canvas {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
}

.tree-svg {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  overflow: visible;
}

.tree-nodes-layer {
  position: absolute;
  top: 0;
  left: 0;
}

.gen-band-label {
  position: absolute;
  left: 16px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #8C7A6B;
  background: rgba(250, 246, 240, 0.9);
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px dashed var(--border-strong);
  pointer-events: none;
}

/* Person Node Card */
.person-node {
  position: absolute;
  width: 204px;
  min-height: 104px;
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: 12px;
  padding: 10px 11px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
  user-select: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.person-node:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary);
}

.person-node.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(180, 83, 9, 0.22), var(--shadow-md);
}

.person-node.is-me {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.22), var(--shadow-sm);
}

.person-node.gender-male {
  border-top: 4px solid #1D4ED8;
}
.person-node.gender-female {
  border-top: 4px solid #BE185D;
}
.person-node.gender-other {
  border-top: 4px solid #B45309;
}

.person-node.is-placeholder {
  border-style: dashed;
  border-color: #A8A29E;
  background: #F5F5F4;
  border-top: 4px dashed #78716C;
}

.node-top {
  display: flex;
  align-items: center;
  gap: 9px;
}

.node-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14);
}

.node-avatar img,
.drawer-avatar img,
.photo-preview-circle img,
.dir-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.node-title-wrap {
  min-width: 0;
  flex: 1;
}

.node-name {
  font-weight: 700;
  font-size: 13.5px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.node-nick {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.node-meta {
  margin-top: 7px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  gap: 6px;
}

.node-city {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.node-pills {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}

.mini-pill {
  background: var(--primary-soft);
  color: var(--primary-hover);
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
}

.mini-pill-me {
  background: var(--accent-soft);
  color: var(--accent);
}

.node-quick-plus {
  position: absolute;
  right: -10px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--primary);
  background: #fff;
  color: var(--primary);
  font-weight: 700;
  font-size: 14px;
  line-height: 1;
  display: none;
  place-items: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.person-node:hover .node-quick-plus,
.person-node.selected .node-quick-plus {
  display: grid;
}

.canvas-legend {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 6px 16px;
  font-size: 11.5px;
  color: var(--text-muted);
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 4px;
}
.dot-male { background: #1D4ED8; }
.dot-female { background: #BE185D; }
.dot-placeholder { background: #78716C; }

.legend-hint {
  margin-left: auto;
}

/* Right Drawer */
.person-drawer {
  width: 370px;
  max-width: 100vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 25;
  box-shadow: -4px 0 18px rgba(0, 0, 0, 0.06);
}

.drawer-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-warm);
}

.drawer-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.drawer-avatar {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  font-size: 20px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  overflow: hidden;
  border: 2px solid #fff;
  box-shadow: var(--shadow-sm);
}

.avatar-upload-pill {
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  display: grid;
  place-items: center;
  font-size: 12px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.drawer-drag-handle {
  display: none;
}

.drawer-badges-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.ig-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: linear-gradient(135deg, #F58529, #DD2A7B, #8134AF);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  text-decoration: none;
}
.ig-pill:hover {
  opacity: 0.92;
}

.btn-ig {
  background: linear-gradient(135deg, #F58529, #DD2A7B, #8134AF);
  color: #fff;
}
.btn-ig:hover {
  opacity: 0.92;
}

.relation-pill {
  display: inline-block;
  background: var(--accent-soft);
  color: #0F766E;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.drawer-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-label {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.section-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.quick-add-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.quick-btn {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface-warm);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.quick-btn:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary-hover);
}

.quick-add-secondary {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 2px;
}

.placeholder-banner {
  background: #FEF3C7;
  border: 1px solid #F59E0B;
  border-radius: 10px;
  padding: 11px;
  font-size: 12.5px;
}
.placeholder-banner p {
  margin: 4px 0 8px;
}

.details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  font-size: 12.5px;
}

.detail-item span {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
}

.drawer-bio {
  margin: 4px 0 0;
  font-size: 13px;
  line-height: 1.45;
}

.added-by-meta {
  font-size: 11.5px;
  color: var(--text-muted);
}

.connections-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.conn-group-title {
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.conn-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.conn-chip {
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.conn-chip:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.drawer-stories {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mini-story {
  background: var(--surface-warm);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-size: 12.5px;
}

.mini-story-title {
  font-weight: 700;
  margin-bottom: 4px;
}

.mini-story-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 5px;
}

.drawer-footer {
  display: flex;
  justify-content: space-between;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* Other Tabs Content */
.panel-container {
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

.panel-container.two-col {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 24px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.panel-header h2 {
  margin: 0 0 4px;
  font-size: 21px;
}

.panel-header p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13.5px;
}

/* Kinship Calculator */
.kinship-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.kinship-selectors {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.kinship-selectors .form-group {
  flex: 1;
  min-width: 200px;
}

.swap-btn {
  margin-bottom: 4px;
}

.kinship-result {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.kinship-hero {
  background: linear-gradient(135deg, #FFFBEB, #FEF3C7);
  border: 1px solid #F59E0B;
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 16px;
}

.kinship-indian {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary-hover);
}

.kinship-english {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 3px;
}

.path-chain {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.path-node {
  background: var(--surface-warm);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 7px 11px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.path-node:hover {
  border-color: var(--primary);
}

.path-arrow {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

/* Stories & Gaps & Directory Grids */
.stories-grid, .gaps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}

.story-card, .gap-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.story-card h3, .gap-card h3 {
  margin: 0;
  font-size: 15.5px;
}

.story-about {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
}

.story-content {
  font-size: 13.5px;
  line-height: 1.5;
  margin: 0;
}

.story-footer {
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--bg);
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

.gap-missing-list {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  color: var(--text-muted);
}

.directory-list, .activity-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dir-row, .act-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.dir-row {
  cursor: pointer;
}
.dir-row:hover {
  border-color: var(--primary);
}

.muted {
  color: var(--text-muted);
  font-size: 13px;
}

/* Modals & Forms */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(24, 18, 14, 0.55);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border-radius: 14px;
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.modal-sm {
  max-width: 420px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-warm);
}

.modal-header h3 {
  margin: 0;
  font-size: 16.5px;
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 8px;
}

.form-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.form-row > .form-group {
  flex: 1;
  min-width: 140px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

input[type="text"],
input[type="number"],
input[type="search"],
input[type="email"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  font-family: var(--font);
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface);
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(180, 83, 9, 0.25);
  border-color: var(--primary);
}

.checkbox-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface-warm);
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  cursor: pointer;
}

.context-banner {
  background: var(--primary-soft);
  border: 1px solid #F59E0B;
  color: var(--primary-hover);
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
}

.share-box {
  background: var(--surface-warm);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.invite-code-row, .copy-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.invite-code {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--primary-hover);
  background: #fff;
  padding: 5px 12px;
  border-radius: 8px;
  border: 1px dashed var(--primary);
}

.tiny-hint {
  margin: 0;
  font-size: 11.5px;
  color: var(--text-muted);
}

.right-align {
  display: flex;
  justify-content: flex-end;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  pointer-events: none;
}

.empty-card {
  pointer-events: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 28px;
  max-width: 440px;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #1F1A17;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  z-index: 200;
  box-shadow: var(--shadow-md);
}

/* Photo Picker & Instagram Share */
.photo-picker-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface-warm);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

.photo-preview-circle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 20px;
  display: grid;
  place-items: center;
  overflow: hidden;
  flex-shrink: 0;
}

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

.ig-share-layout {
  display: flex;
  gap: 14px;
  align-items: center;
}

.ig-preview-canvas {
  width: 118px;
  height: 210px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
  background: #FFF9F2;
}

.ig-share-actions {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

.share-btn-row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.dir-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.dir-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  display: grid;
  place-items: center;
  overflow: hidden;
  flex-shrink: 0;
}

.dir-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Auth, Onboarding Wizard & Claim Card */
.auth-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.user-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-warm);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12.5px;
  font-weight: 600;
}

.auth-mode-tabs {
  display: flex;
  gap: 8px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.wizard-steps-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.wizard-pill {
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.wizard-pill.active {
  background: var(--primary-soft);
  color: var(--primary-hover);
  border-color: var(--primary);
}

.wizard-step {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.invite-preview-hero {
  background: linear-gradient(135deg, #FFFBEB, #FEF3C7);
  border: 1px solid #F59E0B;
  border-radius: 12px;
  padding: 16px;
}

.claim-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
}

.claim-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-warm);
}

.claim-row.suggested {
  border-color: var(--accent);
  background: #F0FDFA;
}

@media (max-width: 1120px) {
  .topbar {
    gap: 8px;
  }
  .topbar-left {
    width: 100%;
    justify-content: space-between;
  }
  .tree-switcher-wrap {
    flex: 1 1 320px;
  }
  select.tree-select {
    flex: 1 1 200px;
    width: auto;
    min-width: 180px;
    max-width: 340px;
  }
  .topbar-right {
    width: 100%;
    justify-content: flex-end;
  }
}

@media (max-width: 820px) {
  .panel-container.two-col {
    grid-template-columns: 1fr;
  }
  .topbar {
    padding: 8px 12px;
    gap: 8px;
  }
  .topbar-left {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .tree-switcher-wrap {
    padding-left: 0;
    border-left: none;
    width: 100%;
    flex: none;
  }
  select.tree-select {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
    max-width: none;
  }
  .topbar-right {
    justify-content: space-between;
  }
  .live-pill {
    display: none;
  }
  .subbar {
    padding: 0 10px;
  }
  .subbar-actions {
    width: 100%;
    padding-bottom: 8px;
  }
  .search-box {
    flex: 1;
  }
  .search-box input {
    width: 100%;
  }
  .canvas-toolbar {
    padding: 6px 10px;
  }
  .toolbar-info {
    display: none;
  }
  .legend-hint {
    display: none;
  }
  .person-drawer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    max-width: 100%;
    height: 76dvh;
    border-left: none;
    border-top: 1px solid var(--border-strong);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.18);
  }
  .drawer-drag-handle {
    display: block;
    width: 42px;
    height: 4px;
    border-radius: 999px;
    background: var(--border-strong);
    margin: 8px auto 2px;
    flex-shrink: 0;
  }
  .quick-btn, .btn {
    min-height: 40px;
  }
  input[type="text"],
  input[type="number"],
  input[type="search"],
  input[type="email"],
  input[type="password"],
  select,
  textarea {
    font-size: 16px;
  }
  .ig-share-layout {
    flex-direction: column;
    align-items: stretch;
  }
  .ig-preview-canvas {
    align-self: center;
  }
  .modal-backdrop {
    padding: 8px;
  }
}

/* Boot Loader (prevents flash before auth check completes) */
.boot-loader {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: linear-gradient(145deg, #FFFBEB 0%, #FAF6F0 52%, #FDE68A 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.boot-loader .brand-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
}

.boot-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.02em;
}

/* Welcome / Auth Landing Gate */
.welcome-gate {
  position: fixed;
  inset: 0;
  z-index: 90;
  overflow-y: auto;
  background: linear-gradient(145deg, #FFFBEB 0%, #FAF6F0 52%, #FDE68A 100%);
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.welcome-shell {
  width: 100%;
  max-width: 980px;
  display: grid;
  grid-template-columns: 1.15fr 0.95fr;
  gap: 28px;
  align-items: center;
}

.welcome-brand-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.welcome-brand-title {
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.02em;
}

.welcome-hero h1 {
  margin: 0 0 12px;
  font-size: clamp(28px, 4vw, 40px);
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: #1F1A17;
}

.welcome-lead {
  margin: 0 0 20px;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text-muted);
}

.welcome-features {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.wf-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 13px;
  line-height: 1.4;
}

.wf-item span {
  font-size: 20px;
  line-height: 1.2;
}

.welcome-card {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: 24px;
  box-shadow: var(--shadow-md);
}

.wg-invite-row {
  display: flex;
  gap: 8px;
}

.wg-demo-link-wrap {
  margin-top: 12px;
  text-align: center;
}

@media (max-width: 820px) {
  .welcome-shell {
    grid-template-columns: 1fr;
    gap: 18px;
  }
  .welcome-card {
    padding: 18px;
  }
}
